a whole lotta work!!
- refactoring - completely changed the tooling (adding elements) - better re-use for more stable editing - new elements - ui adjustments - LINT for stair-editing - many more changes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "../mapview/model/MapLayers.h"
|
||||
|
||||
#include "../mapview/MapView2D.h"
|
||||
#include "../mapview/2D/MapView2D.h"
|
||||
#include "../mapview/model/MapModel.h"
|
||||
#include "../mapview/model/MMFloorAccessPoint.h"
|
||||
#include "../mapview/model/MMFloorBeacon.h"
|
||||
@@ -23,6 +23,13 @@ ToolBoxWidget::ToolBoxWidget(MapView2D* view, QWidget *parent) : QWidget(parent)
|
||||
|
||||
QGridLayout* lay = new QGridLayout(this);
|
||||
|
||||
// SELECTION
|
||||
btnSelect = new QPushButton(UIHelper::getIcon("cursor"), "");
|
||||
btnSelect->setMinimumSize(s,s);
|
||||
lay->addWidget(btnSelect, r++, 0, 1,1,Qt::AlignTop);
|
||||
connect(btnSelect, SIGNAL(clicked(bool)), this, SLOT(onSelect()));
|
||||
|
||||
|
||||
|
||||
// OBSTACLES
|
||||
btnGround = new QPushButton(UIHelper::getIcon("floor"), "");
|
||||
@@ -122,23 +129,323 @@ void ToolBoxWidget::onNewGround() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename FloorplanElement, typename MapModelElement> class NewElementTool : public Tool {
|
||||
|
||||
protected:
|
||||
|
||||
/** add another line after this one? */
|
||||
bool addAnother = true;
|
||||
|
||||
/** register this tool into the given tools-queue */
|
||||
Tools& tools;
|
||||
Tool* oldMainTool;
|
||||
|
||||
/** the layer to add the new element to */
|
||||
MapLayer* layer = nullptr;
|
||||
|
||||
/** currently edited element */
|
||||
FloorplanElement* foEL = nullptr;
|
||||
MapModelElement* mmEL = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
NewElementTool(Tools& tools, MapLayer* layer) : tools(tools), layer(layer) {
|
||||
oldMainTool = tools.getMain(); // keep the current tool to reset it later
|
||||
tools.setMain(this);
|
||||
}
|
||||
|
||||
virtual ~NewElementTool() {
|
||||
tools.setMain(oldMainTool); // reset to the previous tool
|
||||
}
|
||||
|
||||
virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) override {
|
||||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||||
(void) m; (void) e;
|
||||
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);
|
||||
moving(onMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
|
||||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||||
(void) m; (void) e;
|
||||
next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
||||
(void) m;
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
deleteCurrent();
|
||||
disableMe();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/** all subclasses must create a new, empty element here */
|
||||
virtual void createEmptyElement() = 0;
|
||||
|
||||
/** mouse is currently moved */
|
||||
virtual void moving(const Point2 mapPoint) = 0;
|
||||
|
||||
/** next pont */
|
||||
virtual void next() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
void create() {
|
||||
createEmptyElement();
|
||||
mmEL->getMV2D()->focus();
|
||||
}
|
||||
|
||||
/** delete the currently edited element */
|
||||
void deleteCurrent() {
|
||||
if (mmEL) {mmEL->deleteMe();}
|
||||
}
|
||||
|
||||
/** finalize the current element (if any) */
|
||||
void finalizeCurrent() {
|
||||
if (!mmEL) {return;}
|
||||
mmEL->getMV2D()->unfocus();
|
||||
mmEL = nullptr;
|
||||
}
|
||||
|
||||
/** finish creating new elements */
|
||||
void disableMe() {
|
||||
finalizeCurrent();
|
||||
delete this; // see dtor!
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class NewWallTool : public NewElementTool<Floorplan::FloorObstacleLine, MMFloorObstacleLine> {
|
||||
|
||||
private:
|
||||
|
||||
/** currently edited line node (has 2) */
|
||||
int idx = 0;
|
||||
|
||||
public:
|
||||
|
||||
NewWallTool(Tools& tools, MapLayer* layer) : NewElementTool(tools, layer) {
|
||||
create();
|
||||
}
|
||||
|
||||
const std::string getName() const override {
|
||||
return "new Wall";
|
||||
}
|
||||
|
||||
void createEmptyElement() override {
|
||||
|
||||
foEL = new Floorplan::FloorObstacleLine(Floorplan::ObstacleType::WALL, Floorplan::Material::DRYWALL, Point2(0, 0), Point2(0, 0));
|
||||
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
|
||||
mmEL = obs->createLine(foEL);
|
||||
|
||||
}
|
||||
|
||||
/** mouse is currently moved */
|
||||
void moving(const Point2 mapPoint) override {
|
||||
|
||||
if (idx == 0) { foEL->from = mapPoint; foEL->to = mapPoint; }
|
||||
if (idx == 1) { foEL->to = mapPoint; }
|
||||
|
||||
}
|
||||
|
||||
/** next pont */
|
||||
void next() override {
|
||||
|
||||
if (++idx == 2) {
|
||||
finalizeCurrent();
|
||||
if (addAnother) {
|
||||
idx = 0;
|
||||
create();
|
||||
} else {
|
||||
disableMe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class NewDoorTool : public NewElementTool<Floorplan::FloorObstacleDoor, MMFloorObstacleDoor> {
|
||||
|
||||
private:
|
||||
|
||||
/** currently edited line node (has 2) */
|
||||
int idx = 0;
|
||||
|
||||
public:
|
||||
|
||||
NewDoorTool(Tools& tools, MapLayer* layer) : NewElementTool(tools, layer) {
|
||||
create();
|
||||
}
|
||||
|
||||
const std::string getName() const override {
|
||||
return "new Door";
|
||||
}
|
||||
|
||||
void createEmptyElement() override {
|
||||
|
||||
foEL = new Floorplan::FloorObstacleDoor(Floorplan::DoorType::SWING, Floorplan::Material::WOOD, Point2(0, 0), Point2(0, 0));
|
||||
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
|
||||
mmEL = obs->createDoor(foEL);
|
||||
|
||||
}
|
||||
|
||||
/** mouse is currently moved */
|
||||
void moving(const Point2 mapPoint) override {
|
||||
|
||||
if (idx == 0) { foEL->from = mapPoint; foEL->to = mapPoint; }
|
||||
if (idx == 1) { foEL->to = mapPoint; }
|
||||
|
||||
}
|
||||
|
||||
/** next pont */
|
||||
void next() override {
|
||||
|
||||
if (++idx == 2) {
|
||||
finalizeCurrent();
|
||||
if (addAnother) {
|
||||
idx = 0;
|
||||
create();
|
||||
} else {
|
||||
disableMe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//struct NewLineTool : public Tool {
|
||||
|
||||
// /** add another line after this one? */
|
||||
// bool multiple = true;
|
||||
|
||||
// /** register this tool into the given tools-queue */
|
||||
// Tools& tools;
|
||||
|
||||
// /** the layer to add the new line to */
|
||||
// MapLayer* layer;
|
||||
|
||||
// /** currently edited line */
|
||||
// Floorplan::FloorObstacleLine* foLine;
|
||||
// MMFloorObstacleLine* mmLine;
|
||||
|
||||
// /** new line type */
|
||||
// Floorplan::ObstacleType type;
|
||||
|
||||
// /** new line material */
|
||||
// Floorplan::Material mat;
|
||||
|
||||
// /** currently edited line node (has 2) */
|
||||
// int idx = 0;
|
||||
|
||||
|
||||
// NewLineTool(Tools& tools, MapLayer* layer, Floorplan::ObstacleType type, Floorplan::Material mat) : tools(tools), layer(layer), type(type), mat(mat) {
|
||||
// createEmptyLine();
|
||||
// tools.addFront(this);
|
||||
// }
|
||||
|
||||
// virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) override {
|
||||
// (void) m; (void) e;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// 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);
|
||||
// if (idx == 0) { foLine->from = onMap; foLine->to = onMap; }
|
||||
// if (idx == 1) { foLine->to = onMap; }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
|
||||
// (void) m; (void) e;
|
||||
// ++idx;
|
||||
// if (idx == 2) {
|
||||
|
||||
// finalizeLine();
|
||||
|
||||
// if (multiple) {
|
||||
// idx = 0;
|
||||
// createEmptyLine();
|
||||
// } else {
|
||||
// disableMe();
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
||||
// (void) m;
|
||||
// if (e->key() == Qt::Key_Escape) {
|
||||
// if (mmLine) {mmLine->deleteMe();}
|
||||
// disableMe(); return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
//private:
|
||||
|
||||
// /** finalize the current line */
|
||||
// void finalizeLine() {
|
||||
// if (!mmLine) {return;}
|
||||
// mmLine->getMV2D()->unfocus();
|
||||
// mmLine = nullptr;
|
||||
// }
|
||||
|
||||
// /** stop creating new lines */
|
||||
// void disableMe() {
|
||||
// finalizeLine();
|
||||
// tools.remove(this);
|
||||
// delete this;
|
||||
// }
|
||||
|
||||
// /** create a new, empty line */
|
||||
// void createEmptyLine() {
|
||||
// foLine = new Floorplan::FloorObstacleLine(type, mat, Point2(0, 0), Point2(0, 0));
|
||||
// MMFloorObstacles* obs = (MMFloorObstacles*)layer;
|
||||
// mmLine = obs->createLine(foLine);
|
||||
// mmLine->getMV2D()->focus();
|
||||
// }
|
||||
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ToolBoxWidget::onSelect() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ToolBoxWidget::onNewWall() {
|
||||
|
||||
const Point2 center = view->getScaler().getCenter();
|
||||
float s = view->getScaler().sm(50);
|
||||
|
||||
Floorplan::FloorObstacleLine* wall = new Floorplan::FloorObstacleLine(
|
||||
Floorplan::ObstacleType::WALL,
|
||||
Floorplan::Material::DRYWALL,
|
||||
Point2(center.x-s, center.y),
|
||||
Point2(center.x+s, center.y)
|
||||
);
|
||||
|
||||
MMFloorObstacles* obs = (MMFloorObstacles*)curLayer;
|
||||
obs->createLine(wall);
|
||||
|
||||
view->getModel()->reselect();
|
||||
|
||||
new NewWallTool(view->getTools(), curLayer);
|
||||
//view->getModel()->reselect();
|
||||
}
|
||||
|
||||
void ToolBoxWidget::onNewPillar() {
|
||||
@@ -155,26 +462,28 @@ void ToolBoxWidget::onNewPillar() {
|
||||
MMFloorObstacles* obs = (MMFloorObstacles*)curLayer;
|
||||
obs->createCircle(pillar);
|
||||
|
||||
view->getModel()->reselect();
|
||||
//view->getModel()->reselect();
|
||||
|
||||
}
|
||||
|
||||
void ToolBoxWidget::onNewDoor() {
|
||||
|
||||
const Point2 center = view->getScaler().getCenter();
|
||||
float s = view->getScaler().sm(50);
|
||||
new NewDoorTool(view->getTools(), curLayer);
|
||||
|
||||
Floorplan::FloorObstacleDoor* door = new Floorplan::FloorObstacleDoor(
|
||||
Floorplan::DoorType::SWING,
|
||||
Floorplan::Material::WOOD,
|
||||
Point2(center.x-s, center.y),
|
||||
Point2(center.x+s, center.y)
|
||||
);
|
||||
// const Point2 center = view->getScaler().getCenter();
|
||||
// float s = view->getScaler().sm(50);
|
||||
|
||||
MMFloorObstacles* obs = (MMFloorObstacles*)curLayer;
|
||||
obs->createDoor(door);
|
||||
// Floorplan::FloorObstacleDoor* door = new Floorplan::FloorObstacleDoor(
|
||||
// Floorplan::DoorType::SWING,
|
||||
// Floorplan::Material::WOOD,
|
||||
// Point2(center.x-s, center.y),
|
||||
// Point2(center.x+s, center.y)
|
||||
// );
|
||||
|
||||
view->getModel()->reselect();
|
||||
// MMFloorObstacles* obs = (MMFloorObstacles*)curLayer;
|
||||
// obs->createDoor(door);
|
||||
|
||||
//view->getModel()->reselect();
|
||||
|
||||
}
|
||||
|
||||
@@ -192,7 +501,7 @@ void ToolBoxWidget::onNewStair() {
|
||||
MMFloorStairs* stairs = (MMFloorStairs*)curLayer;
|
||||
stairs->create(stair);
|
||||
|
||||
view->getModel()->reselect();
|
||||
//view->getModel()->reselect();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ class MapLayer;
|
||||
class QPushButton;
|
||||
class MapView2D;
|
||||
|
||||
/**
|
||||
* gui element with actions to perform
|
||||
*/
|
||||
class ToolBoxWidget : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
@@ -28,13 +31,14 @@ private:
|
||||
MapLayer* curLayer;
|
||||
int r = 0;
|
||||
|
||||
QPushButton* btnSelect;
|
||||
|
||||
QPushButton* btnGround;
|
||||
QPushButton* btnWall;
|
||||
QPushButton* btnPillar;
|
||||
QPushButton* btnDoor;
|
||||
QPushButton* btnStair;
|
||||
|
||||
|
||||
QPushButton* btnWifi;
|
||||
QPushButton* btnBeacon;
|
||||
QPushButton* btnPOI;
|
||||
@@ -43,6 +47,8 @@ private:
|
||||
|
||||
private slots:
|
||||
|
||||
void onSelect();
|
||||
|
||||
void onNewGround();
|
||||
void onNewWall();
|
||||
void onNewPillar();
|
||||
|
||||
Reference in New Issue
Block a user