added a ruler for measuring
added support for meta-data editing improved element selection changed zooming fixed some issues with layer events fixed issue with 3D outline fixed loading issue for old maps some interface changes
This commit is contained in:
@@ -20,9 +20,9 @@ public:
|
||||
Scaler& s = m->getScaler();
|
||||
|
||||
if (e->delta() < 0) {
|
||||
s.setScale(s.getScale() * 0.5);
|
||||
s.setScale(s.getScale() * 0.75);
|
||||
} else {
|
||||
s.setScale(s.getScale() / 0.5);
|
||||
s.setScale(s.getScale() / 0.75);
|
||||
}
|
||||
|
||||
if (s.getScale() > 1000) {s.setScale(1000);}
|
||||
|
||||
0
mapview/2D/tools/ToolMeasure.cpp
Normal file
0
mapview/2D/tools/ToolMeasure.cpp
Normal file
132
mapview/2D/tools/ToolMeasure.h
Normal file
132
mapview/2D/tools/ToolMeasure.h
Normal file
@@ -0,0 +1,132 @@
|
||||
#ifndef TOOLMEASURE_H
|
||||
#define TOOLMEASURE_H
|
||||
|
||||
|
||||
#include "Tool.h"
|
||||
#include "../MapView2D.h"
|
||||
|
||||
#include "../../model/MapModelElement.h"
|
||||
#include "../../model/MapModel.h"
|
||||
#include "../MapViewElementHelper.h"
|
||||
|
||||
|
||||
/**
|
||||
* this tool allows:
|
||||
* - selecting elements within the 2D view (focus/unfocus)
|
||||
* - selecting and moving nodes of elements inheriting from HasMoveableNodes
|
||||
*
|
||||
*/
|
||||
class ToolMeasure : public Tool {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** register this tool into the given tools-queue */
|
||||
Tools& tools;
|
||||
Tool* oldMainTool;
|
||||
|
||||
std::vector<Point2> pts_m;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
ToolMeasure(Tools& tools) : tools(tools) {
|
||||
|
||||
oldMainTool = tools.getMain(); // keep the current tool to reset it later
|
||||
tools.setMain(this);
|
||||
|
||||
resetMe();
|
||||
|
||||
}
|
||||
|
||||
/** dtor */
|
||||
virtual ~ToolMeasure() {
|
||||
tools.setMain(oldMainTool); // reset to the previous tool
|
||||
}
|
||||
|
||||
const std::string getName() const {
|
||||
return "Measure";
|
||||
}
|
||||
|
||||
virtual bool mousePressEvent(MapView2D*, QMouseEvent* e) override {
|
||||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||||
pts_m.push_back(pts_m.back());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) override {
|
||||
const Point2 onScreen(e->x(), e->y());
|
||||
Point2 onMap = m->getScaler().sm(onScreen);
|
||||
onMap = m->getScaler().snap(onMap);
|
||||
pts_m.back() = onMap;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool mouseReleaseEvent(MapView2D*, QMouseEvent* e) override {
|
||||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||||
return true;
|
||||
} else if (e->button() == Qt::MouseButton::RightButton) {
|
||||
resetMe();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
||||
(void) m;
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
disableMe();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void paintAfter(MapView2D*, Painter& p) override {
|
||||
|
||||
if (pts_m.size() < 1) {return;}
|
||||
|
||||
p.setPen(Qt::black);
|
||||
|
||||
for (const Point2 p_m : pts_m) {
|
||||
p.drawCircle(p_m);
|
||||
}
|
||||
|
||||
float totalLen_m = 0;
|
||||
for (size_t i = 0; i < pts_m.size() - 1; ++i) {
|
||||
const Point2 p1 = pts_m[i];
|
||||
const Point2 p2 = pts_m[i+1];
|
||||
const float len_m = p1.getDistance(p2);
|
||||
p.drawLine(p1, p2);
|
||||
p.drawLength(p1, p2, len_m);
|
||||
totalLen_m += len_m;
|
||||
}
|
||||
|
||||
if (pts_m.size() > 1) {
|
||||
emit onHelpTextChange("total length is: " + QString::number(totalLen_m) + "m | right-click to restart");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
void resetMe() {
|
||||
pts_m.resize(1);
|
||||
emit onHelpTextChange("select the starting point for measuring");
|
||||
}
|
||||
|
||||
/** finish creating new elements */
|
||||
void disableMe() {
|
||||
delete this; // see dtor!
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // TOOLMEASURE_H
|
||||
@@ -46,6 +46,15 @@ public:
|
||||
setFocused(m, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief change the currently focused element. throws an event.
|
||||
* @param el the to-be-focused element or null
|
||||
* @return true if the focused element has changed. false otherwise
|
||||
*/
|
||||
bool focus(MapView2D* v, MapModelElement* el) {
|
||||
setFocused(v, el);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void processUnfocus(MapView2D* m, MapModelElement* elem) {
|
||||
@@ -202,9 +211,11 @@ private:
|
||||
|
||||
const float g = m->getScaler().sm(15); // increase each BBox by 15 px (needed mainly for hor/ver lines)
|
||||
|
||||
#warning "which elements to select? among all currently visible? or only among the selected layer?"
|
||||
// get all elements with bounding-box matchings
|
||||
std::vector<MapModelElement*> possible;
|
||||
for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) {
|
||||
// for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) {
|
||||
for (MapModelElement* el : m->getModel()->getVisibleElements()) {
|
||||
if (!el->getMV2D()) {continue;}
|
||||
BBox2 bbox = el->getMV2D()->getBoundingBox(); // elements 2D bbox
|
||||
bbox.grow(Point2(g, g)); // grow a little (needed for straight lines)
|
||||
|
||||
Reference in New Issue
Block a user