performance enhancements
memory enhancements prevent starting sensors more than once fix for wifi lag issues map scaling for huge buildings
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
#include <QResizeEvent>
|
||||
#include <QSlider>
|
||||
#include <QGridLayout>
|
||||
#include <QGestureEvent>
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/floorplan/v2/FloorplanHelper.h>
|
||||
|
||||
#include "Floor2D.h"
|
||||
#include "ColorPoints2D.h"
|
||||
@@ -67,7 +69,12 @@ MapView2D::MapView2D(QWidget *parent) : QWidget(parent) {
|
||||
lay->addWidget(btnLayerPlus, row, 2, 1, 1);
|
||||
|
||||
|
||||
// start with invisible particles. speeds things up a bit
|
||||
colorPoints->setVisible(false);
|
||||
|
||||
// we want to receive pinch gestures
|
||||
//setAttribute(Qt::WA_AcceptTouchEvents, true);
|
||||
grabGesture(Qt::PinchGesture);
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +103,11 @@ void MapView2D::setMap(WiFiCalibrationDataModel* mdl, Floorplan::IndoorMap* map)
|
||||
wifiCalib = new WiFiCalibTool(mdl, map);
|
||||
elementsB.push_back(wifiCalib);
|
||||
|
||||
scaler.setCenterM(Point2(70, 35));
|
||||
const BBox3 bbox3 = FloorplanHelper::getBBox(map);
|
||||
const BBox2 bbox2 = BBox2(bbox3.getMin().xy(), bbox3.getMax().xy());
|
||||
|
||||
scaler.setMapBBox(bbox2);
|
||||
scaler.setCenterM(Point2(bbox2.getCenter().x, bbox2.getCenter().y));
|
||||
|
||||
}
|
||||
|
||||
@@ -169,6 +180,16 @@ void MapView2D::mouseReleaseEvent(QMouseEvent* evt) {
|
||||
|
||||
}
|
||||
|
||||
void MapView2D::wheelEvent(QWheelEvent* event) {
|
||||
if (event->delta() < 0) {
|
||||
scaler.mulScale(0.5);
|
||||
emit update();
|
||||
} else {
|
||||
scaler.mulScale(2.0);
|
||||
emit update();
|
||||
}
|
||||
}
|
||||
|
||||
void MapView2D::paintEvent(QPaintEvent*) {
|
||||
|
||||
QPainter qp(this);
|
||||
@@ -183,3 +204,42 @@ void MapView2D::paintEvent(QPaintEvent*) {
|
||||
qp.end();
|
||||
|
||||
}
|
||||
|
||||
bool MapView2D::event(QEvent *event) {
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::Gesture:
|
||||
return gestureEvent(static_cast<QGestureEvent*>(event));
|
||||
|
||||
case QEvent::TouchBegin:
|
||||
case QEvent::TouchUpdate:
|
||||
case QEvent::TouchEnd:
|
||||
|
||||
// prevent [additional] mouse events for undetected gestures [more than 1 finger]
|
||||
// TODO: not yet stable... improvements?
|
||||
if (static_cast<QTouchEvent*>(event)->touchPoints().count() == 2) {return true;}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// event not consumed. bubble it to following stages.
|
||||
// this will e.g. generate mouseMoveEvent etc.
|
||||
return QWidget::event(event);
|
||||
|
||||
}
|
||||
|
||||
bool MapView2D::gestureEvent(QGestureEvent *event) {
|
||||
|
||||
if (QGesture* pinch = event->gesture(Qt::PinchGesture)) {
|
||||
const QPinchGesture* pg = static_cast<QPinchGesture *>(pinch);
|
||||
scaler.mulScale(pg->scaleFactor());
|
||||
emit update();
|
||||
return true; // event consumed
|
||||
}
|
||||
|
||||
// event not consumed
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class MyGridNode;
|
||||
class Renderable2D;
|
||||
class QSlider;
|
||||
class QPushButton;
|
||||
class QGestureEvent;
|
||||
class ColorPoints2D;
|
||||
class Path2D;
|
||||
|
||||
@@ -127,6 +128,10 @@ public slots:
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void mouseReleaseEvent(QMouseEvent*);
|
||||
void wheelEvent(QWheelEvent*);
|
||||
|
||||
bool event(QEvent*);
|
||||
bool gestureEvent(QGestureEvent *event);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QPoint>
|
||||
#include <Indoor/geo/Point2.h>
|
||||
#include <Indoor/geo/BBox2.h>
|
||||
|
||||
class Scaler2D {
|
||||
|
||||
@@ -13,6 +14,8 @@ private:
|
||||
float rotation_rad = 0.0f;
|
||||
float scaleFactor = 1;
|
||||
|
||||
BBox2 mapBBox_m;
|
||||
|
||||
public:
|
||||
|
||||
Scaler2D() {
|
||||
@@ -32,11 +35,17 @@ public:
|
||||
/** change the point displayed within the center of the screen */
|
||||
void setCenterM(const Point2 center_m) {
|
||||
this->center_m = center_m;
|
||||
if (!mapBBox_m.isInvalid()) {
|
||||
if (this->center_m.x < mapBBox_m.getMin().x) {this->center_m.x = mapBBox_m.getMin().x;}
|
||||
if (this->center_m.y < mapBBox_m.getMin().y) {this->center_m.y = mapBBox_m.getMin().y;}
|
||||
if (this->center_m.x > mapBBox_m.getMax().x) {this->center_m.x = mapBBox_m.getMax().x;}
|
||||
if (this->center_m.y > mapBBox_m.getMax().y) {this->center_m.y = mapBBox_m.getMax().y;}
|
||||
}
|
||||
}
|
||||
|
||||
/** change the point displayed within the center of the screen */
|
||||
void setCenterPX(const Point2 center_px) {
|
||||
this->center_m = pxToM(center_px);
|
||||
setCenterM(pxToM(center_px));
|
||||
}
|
||||
|
||||
Point2 getCenterPX() const {
|
||||
@@ -48,10 +57,21 @@ public:
|
||||
this->rotation_rad = rad;
|
||||
}
|
||||
|
||||
/** set the map's scaling */
|
||||
void setScale(const float scale) {
|
||||
this->scaleFactor = scale;
|
||||
if (this->scaleFactor < 0.1) {this->scaleFactor = 0.1;}
|
||||
if (this->scaleFactor > 4.0) {this->scaleFactor = 4.0;}
|
||||
}
|
||||
|
||||
void mulScale(const float mod) {
|
||||
setScale(this->scaleFactor * mod);
|
||||
}
|
||||
|
||||
/** set the map's bbox. used to prevent from scrolling outside of the map */
|
||||
void setMapBBox(const BBox2 bbox_m) {
|
||||
this->mapBBox_m = bbox_m;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user