merged
This commit is contained in:
143
params/EditFields.h
Normal file
143
params/EditFields.h
Normal file
@@ -0,0 +1,143 @@
|
||||
#ifndef EDITFIELDS_H
|
||||
#define EDITFIELDS_H
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include "../mapview/model/IHasParams.h"
|
||||
|
||||
class EditFields {
|
||||
|
||||
public:
|
||||
|
||||
static void get(QGridLayout* lay, IHasParams* elem) {
|
||||
|
||||
int r = 0;
|
||||
|
||||
for(int i = 0; i < elem->getNumParams(); ++i) {
|
||||
|
||||
const Param param = elem->getParamDesc(i);
|
||||
const ParamValue value = elem->getParamValue(i);
|
||||
|
||||
// skip Not-Available entries
|
||||
if (param.type == ParamType::NOT_AVAILABLE) {continue;}
|
||||
|
||||
lay->addWidget(new QLabel(param.name.c_str()),r,0);
|
||||
|
||||
switch(param.type) {
|
||||
|
||||
case ParamType::BOOL: {
|
||||
QCheckBox* chk = new QCheckBox( );
|
||||
chk->setChecked(value.toBool());
|
||||
if (param.readOnly) {
|
||||
chk->setEnabled(false);
|
||||
} else {
|
||||
chk->connect(chk, &QCheckBox::clicked, [i,elem] (const bool checked) {
|
||||
elem->setParamValue(i, ParamValue(checked));
|
||||
});
|
||||
}
|
||||
lay->addWidget(chk,r,1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::FLOAT: {
|
||||
const std::string str = std::to_string(value.toFloat());
|
||||
if (param.readOnly) {
|
||||
lay->addWidget(new QLabel(str.c_str()),r,1);
|
||||
} else {
|
||||
QLineEdit* le = new QLineEdit( str.c_str() );
|
||||
le->connect(le, &QLineEdit::textChanged, [i,elem] (const QString& str) {
|
||||
const float val = str.toFloat();
|
||||
elem->setParamValue(i, ParamValue(val));
|
||||
});
|
||||
lay->addWidget(le,r,1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::INT: {
|
||||
const std::string str = std::to_string(value.toInt());
|
||||
QLineEdit* le = new QLineEdit( str.c_str() );
|
||||
le->connect(le, &QLineEdit::textChanged, [i,elem] (const QString& str) {
|
||||
const int val = str.toInt();
|
||||
elem->setParamValue(i, ParamValue(val));
|
||||
});
|
||||
lay->addWidget(le,r,1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::STRING: {
|
||||
const std::string str = value.toString();
|
||||
QLineEdit* le = new QLineEdit( str.c_str() );
|
||||
le->connect(le, &QLineEdit::textChanged, [i,elem] (const QString& str) {
|
||||
elem->setParamValue(i, ParamValue(str.toStdString()));
|
||||
});
|
||||
lay->addWidget(le,r,1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::FILE: {
|
||||
const std::string str = value.toString();
|
||||
QLabel* lblFile = new QLabel(str.c_str());
|
||||
QPushButton* btn = new QPushButton("<");
|
||||
btn->setMaximumSize(32,32);
|
||||
btn->connect(btn, &QPushButton::clicked, [i,elem,lblFile] (const bool checked) {
|
||||
QString res = QFileDialog::getOpenFileName();
|
||||
elem->setParamValue(i, ParamValue(res.toStdString()));
|
||||
lblFile->setText(res);
|
||||
});
|
||||
lay->addWidget(lblFile,r,1);
|
||||
lay->addWidget(btn,r,2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::POINT2: {
|
||||
const Point2 p2 = value.toPoint2();
|
||||
QWidget* subWidget = new QWidget();
|
||||
QGridLayout* laySub = new QGridLayout(subWidget); laySub->setMargin(0);
|
||||
QLineEdit* txtX = new QLineEdit(QString::number(p2.x));
|
||||
QLineEdit* txtY = new QLineEdit(QString::number(p2.y));
|
||||
laySub->addWidget(txtX,0,0);
|
||||
laySub->addWidget(txtY,0,1);
|
||||
lay->addWidget(subWidget,r,1);
|
||||
auto onChange = [i,elem,txtX,txtY] (const QString& str) {
|
||||
elem->setParamValue(i, ParamValue( Point2(txtX->text().toFloat(), txtY->text().toFloat()) ));
|
||||
};
|
||||
txtX->connect(txtX, &QLineEdit::textChanged, onChange);
|
||||
txtY->connect(txtY, &QLineEdit::textChanged, onChange);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParamType::POINT3: {
|
||||
const Point3 p3 = value.toPoint3();
|
||||
QWidget* subWidget = new QWidget();
|
||||
QGridLayout* laySub = new QGridLayout(subWidget); laySub->setMargin(0);
|
||||
QLineEdit* txtX = new QLineEdit(QString::number(p3.x));
|
||||
QLineEdit* txtY = new QLineEdit(QString::number(p3.y));
|
||||
QLineEdit* txtZ = new QLineEdit(QString::number(p3.z));
|
||||
laySub->addWidget(txtX,0,0);
|
||||
laySub->addWidget(txtY,0,1);
|
||||
laySub->addWidget(txtZ,0,2);
|
||||
lay->addWidget(subWidget,r,1);
|
||||
auto onChange = [i,elem,txtX,txtY,txtZ] (const QString& str) {
|
||||
(void) str;
|
||||
elem->setParamValue(i, ParamValue( Point3(txtX->text().toFloat(), txtY->text().toFloat(), txtZ->text().toFloat()) ));
|
||||
};
|
||||
txtX->connect(txtX, &QLineEdit::textChanged, onChange);
|
||||
txtY->connect(txtY, &QLineEdit::textChanged, onChange);
|
||||
txtZ->connect(txtZ, &QLineEdit::textChanged, onChange);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
++r;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // EDITFIELDS_H
|
||||
@@ -4,9 +4,10 @@
|
||||
#include "../mapview/model/MMFloorObstacleLine.h"
|
||||
#include "../mapview/model/MMFloorOutlinePolygon.h"
|
||||
|
||||
#include "../mapview/model/IHasMAC.h"
|
||||
#include "../mapview/model/IHasFile.h"
|
||||
#include "../mapview/model/IHasParams.h"
|
||||
#include "../mapview/model/IHasEditableMeta.h"
|
||||
|
||||
#include "MetaEditWidget.h"
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
@@ -68,11 +69,14 @@ ElementParamWidget::ElementParamWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
this->lay = new QGridLayout(this);
|
||||
|
||||
setMinimumSize(100, 100);
|
||||
setMaximumWidth(250);
|
||||
//setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
//lay->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
setMinimumSize(200, 25);
|
||||
setMaximumSize(200, 9999);
|
||||
//setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
//setTitle("MapElement Parameters");
|
||||
QGridLayout* lay = new QGridLayout();
|
||||
lay = new QGridLayout();
|
||||
|
||||
// start empty
|
||||
setElement(nullptr);
|
||||
@@ -90,7 +94,6 @@ void ElementParamWidget::refresh() {
|
||||
|
||||
while ( QWidget* w = this->findChild<QWidget*>() ) {delete w;}
|
||||
delete this->layout();
|
||||
|
||||
this->lay = new QGridLayout();
|
||||
this->setLayout(lay);
|
||||
int r = 0;
|
||||
@@ -136,13 +139,15 @@ void ElementParamWidget::refresh() {
|
||||
lay->addWidget(cmb,r,1);
|
||||
cmb->setCurrentIndex((int)elem->getMethod());
|
||||
connect(cmb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [elem, cmb] (int idx) {
|
||||
(void) idx;
|
||||
elem->setMethod( (Floorplan::OutlineMethod) cmb->currentData().toInt() );
|
||||
});
|
||||
++r;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
{ // does the element have "parameters" ?
|
||||
IHasParams* elem = dynamic_cast<IHasParams*>(el);
|
||||
if (elem) {
|
||||
|
||||
@@ -158,6 +163,9 @@ void ElementParamWidget::refresh() {
|
||||
|
||||
switch(param.type) {
|
||||
|
||||
case ParamType::NOT_AVAILABLE:
|
||||
break;
|
||||
|
||||
case ParamType::BOOL: {
|
||||
QCheckBox* chk = new QCheckBox( );
|
||||
chk->setChecked(value.toBool());
|
||||
@@ -214,6 +222,7 @@ void ElementParamWidget::refresh() {
|
||||
QPushButton* btn = new QPushButton("<");
|
||||
btn->setMaximumSize(32,32);
|
||||
connect(btn, &QPushButton::clicked, [i,elem,lblFile] (const bool checked) {
|
||||
(void) checked;
|
||||
QString res = QFileDialog::getOpenFileName();
|
||||
elem->setParamValue(i, ParamValue(res.toStdString()));
|
||||
lblFile->setText(res);
|
||||
@@ -233,6 +242,7 @@ void ElementParamWidget::refresh() {
|
||||
laySub->addWidget(txtY,0,1);
|
||||
lay->addWidget(subWidget,r,1);
|
||||
auto onChange = [i,elem,txtX,txtY] (const QString& str) {
|
||||
(void) str;
|
||||
elem->setParamValue(i, ParamValue( Point2(txtX->text().toFloat(), txtY->text().toFloat()) ));
|
||||
};
|
||||
connect(txtX, &QLineEdit::textChanged, onChange);
|
||||
@@ -267,10 +277,39 @@ void ElementParamWidget::refresh() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{ // does the element have editable metadata?
|
||||
IHasEditableMeta* elem = dynamic_cast<IHasEditableMeta*>(el);
|
||||
if (elem) {
|
||||
|
||||
QPushButton* btn = new QPushButton("edit");
|
||||
connect(btn, &QPushButton::clicked, [elem] (const bool checked) {
|
||||
(void) checked;
|
||||
if (!elem->getMeta()) {elem->setMeta(new Floorplan::Meta());} // ensure meta-object is present
|
||||
MetaEditWidget* mew = new MetaEditWidget(elem->getMeta()); // edit
|
||||
mew->show();
|
||||
});
|
||||
lay->addWidget(new QLabel("Meta"),r,0);
|
||||
lay->addWidget(btn,r,1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
//lay->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
//setLayout(lay);
|
||||
setMinimumSize(150, 30+r*24);
|
||||
setMaximumSize(250, 30+r*24);
|
||||
//resize(100, 20+r*22);
|
||||
//emit update();
|
||||
//setVisible(false);
|
||||
//setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ElementParamWidget::onMaterialChange() {
|
||||
IHasMaterial* el = dynamic_cast<IHasMaterial*>(this->curElement);
|
||||
if (el) {el->setMaterial( (Floorplan::Material) material.cmb->currentData().toInt() );}
|
||||
@@ -280,23 +319,3 @@ void ElementParamWidget::onObstacleTypeChange() {
|
||||
IHasObstacleType* el = dynamic_cast<IHasObstacleType*>(this->curElement);
|
||||
if (el) {el->setObstacleType((Floorplan::ObstacleType) obstacleType.cmb->currentData().toInt() );}
|
||||
}
|
||||
|
||||
//void ElementParamWidget::onNameChange() {
|
||||
// IHasName* el = dynamic_cast<IHasName*>(this->curElement);
|
||||
// if (el) {el->setName(name.txt->text().toStdString());}
|
||||
//}
|
||||
|
||||
//void ElementParamWidget::onOutlineMethodChange() {
|
||||
// MMFloorOutlinePolygon* el = dynamic_cast<MMFloorOutlinePolygon*>(this->curElement);
|
||||
// if (el) {el->setMethod( (Floorplan::OutlineMethod) outlineMethod.cmb->currentData().toInt() );}
|
||||
//}
|
||||
|
||||
//void ElementParamWidget::onMACChanged() {
|
||||
// dynamic_cast<IHasMAC*>(curElement)->setMAC(mac.txt->text().toStdString());
|
||||
//}
|
||||
|
||||
//void ElementParamWidget::onSelectFileName() {
|
||||
// QString res = QFileDialog::getOpenFileName(this);
|
||||
// dynamic_cast<IHasFile*>(curElement)->setFileName(res.toStdString());
|
||||
// fileName.txt->setText(res);
|
||||
//}
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
/** refresh the currently selected element */
|
||||
void refresh();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
QGridLayout* lay;
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
#include "mapview/model/IHasName.h"
|
||||
#include "mapview/model/MMFloor.h"
|
||||
|
||||
#include "EditFields.h"
|
||||
|
||||
LayerParamWidget::LayerParamWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
setMinimumSize(100, 100);
|
||||
setMinimumSize(100, 50);
|
||||
setMaximumWidth(250);
|
||||
//setTitle("MapLayer Parameters");
|
||||
|
||||
QGridLayout* lay = new QGridLayout(this);
|
||||
lay = new QGridLayout(this);
|
||||
int r = 0;
|
||||
|
||||
|
||||
@@ -53,35 +55,50 @@ void LayerParamWidget::setElement(MapLayer* l) {
|
||||
|
||||
this->curElement = l;
|
||||
|
||||
if (l) {
|
||||
std::string info = l->getLayerName() + " (" + std::to_string(l->getNumElements()) + " elements)";
|
||||
selected.info->setText(info.c_str());
|
||||
} else {
|
||||
selected.info->setText("-");
|
||||
}
|
||||
// if (l) {
|
||||
// std::string info = l->getLayerName() + " (" + std::to_string(l->getNumElements()) + " elements)";
|
||||
// selected.info->setText(info.c_str());
|
||||
// } else {
|
||||
// selected.info->setText("-");
|
||||
// }
|
||||
|
||||
while ( QWidget* w = this->findChild<QWidget*>() ) {delete w;}
|
||||
delete this->layout();
|
||||
this->lay = new QGridLayout();
|
||||
this->setLayout(lay);
|
||||
int r = 0;
|
||||
|
||||
|
||||
// {
|
||||
// MMFloor* floor = dynamic_cast<MMFloor*>(l);
|
||||
// atHeight.lbl->setVisible(floor);
|
||||
// atHeight.txt->setVisible(floor);
|
||||
// height.lbl->setVisible(floor);
|
||||
// height.txt->setVisible(floor);
|
||||
// if (floor) {
|
||||
// std::string _atHeight = std::to_string(floor->getFloor().atHeight);
|
||||
// atHeight.txt->setText( _atHeight.c_str() );
|
||||
// std::string _height = std::to_string(floor->getFloor().height);
|
||||
// height.txt->setText( _height.c_str() );
|
||||
// }
|
||||
// }
|
||||
|
||||
// // has name
|
||||
// {
|
||||
// IHasName* elem = dynamic_cast<IHasName*>(l);
|
||||
// name.lbl->setVisible(elem);
|
||||
// name.txt->setVisible(elem);
|
||||
// if (elem) {name.txt->setText(elem->getName().c_str());}
|
||||
// }
|
||||
|
||||
|
||||
{
|
||||
MMFloor* floor = dynamic_cast<MMFloor*>(l);
|
||||
atHeight.lbl->setVisible(floor);
|
||||
atHeight.txt->setVisible(floor);
|
||||
height.lbl->setVisible(floor);
|
||||
height.txt->setVisible(floor);
|
||||
if (floor) {
|
||||
std::string _atHeight = std::to_string(floor->getFloor().atHeight);
|
||||
atHeight.txt->setText( _atHeight.c_str() );
|
||||
std::string _height = std::to_string(floor->getFloor().height);
|
||||
height.txt->setText( _height.c_str() );
|
||||
IHasParams* elem = dynamic_cast<IHasParams*>(l);
|
||||
if (elem) {
|
||||
EditFields::get(lay, elem);
|
||||
}
|
||||
}
|
||||
|
||||
// has name
|
||||
{
|
||||
IHasName* elem = dynamic_cast<IHasName*>(l);
|
||||
name.lbl->setVisible(elem);
|
||||
name.txt->setVisible(elem);
|
||||
if (elem) {name.txt->setText(elem->getName().c_str());}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,11 +8,16 @@ class MapLayer;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QComboBox;
|
||||
class QGridLayout;
|
||||
|
||||
class LayerParamWidget : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
QGridLayout* lay;
|
||||
|
||||
public:
|
||||
|
||||
explicit LayerParamWidget(QWidget *parent = 0);
|
||||
|
||||
92
params/LayerTree.cpp
Normal file
92
params/LayerTree.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "LayerTree.h"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include "../tree/MapTreeModel.h"
|
||||
#include "../UIHelper.h"
|
||||
|
||||
LayerTree::LayerTree(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
QGridLayout* layGrid = new QGridLayout(this);
|
||||
|
||||
tree = new QTreeView(this);
|
||||
tree->setMinimumSize(150, 200);
|
||||
|
||||
QWidget* wButtons = new QWidget();
|
||||
QHBoxLayout* layButtons = new QHBoxLayout(wButtons);
|
||||
|
||||
btnNew = new QPushButton(this);
|
||||
btnNew->setIcon(UIHelper::getIcon("add"));
|
||||
btnNew->setMaximumSize(32,32);
|
||||
btnNew->setMinimumSize(32,32);
|
||||
btnNew->setEnabled(false);
|
||||
layButtons->addWidget(btnNew);
|
||||
|
||||
|
||||
btnDelete = new QPushButton(this);
|
||||
btnDelete->setIcon(UIHelper::getIcon("remove"));
|
||||
btnDelete->setMaximumSize(32,32);
|
||||
btnDelete->setMinimumSize(32,32);
|
||||
btnDelete->setEnabled(false);
|
||||
layButtons->addWidget(btnDelete);
|
||||
|
||||
layGrid->addWidget(tree, 0,0,1,1);
|
||||
layGrid->addWidget(wButtons, 1, 0, 1, 1);
|
||||
|
||||
connect(btnNew, SIGNAL(clicked(bool)), this, SLOT(onBtnNew()));
|
||||
connect(btnDelete, SIGNAL(clicked(bool)), this, SLOT(onBtnDelete()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LayerTree::expandAll() {
|
||||
tree->expandAll();
|
||||
}
|
||||
|
||||
void LayerTree::setModel(MapTreeModel* model) {
|
||||
|
||||
this->model = model;
|
||||
this->tree->setModel(model);
|
||||
|
||||
// tree model selection events
|
||||
if (!connect(tree->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(onLayerSelected(QModelIndex)))) {throw "error";}
|
||||
|
||||
}
|
||||
|
||||
void LayerTree::onLayerSelected(QModelIndex idx) {
|
||||
|
||||
MapLayer* ml = static_cast<MapLayer*>(idx.internalPointer());
|
||||
|
||||
MMFloors* floors = dynamic_cast<MMFloors*>(ml);
|
||||
btnNew->setEnabled( floors != nullptr );
|
||||
|
||||
MMFloor* floor = dynamic_cast<MMFloor*>(ml);
|
||||
btnDelete->setEnabled( floor != nullptr );
|
||||
|
||||
emit layerSelected(idx);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LayerTree::onBtnNew() {
|
||||
QModelIndex idx = tree->selectionModel()->selectedIndexes().first();
|
||||
MapLayer* ml = static_cast<MapLayer*>(idx.internalPointer());
|
||||
MMFloors* floors = dynamic_cast<MMFloors*>(ml);
|
||||
if (floors) {
|
||||
floors->createFloor();
|
||||
model->getMapModel()->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTree::onBtnDelete() {
|
||||
QModelIndex idx = tree->selectionModel()->selectedIndexes().first();
|
||||
MapLayer* ml = static_cast<MapLayer*>(idx.internalPointer());
|
||||
MMFloor* floor= dynamic_cast<MMFloor*>(ml);
|
||||
if (floor) {
|
||||
floor->deleteMe();
|
||||
model->getMapModel()->reset();
|
||||
}
|
||||
}
|
||||
49
params/LayerTree.h
Normal file
49
params/LayerTree.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef LAYERTREE_H
|
||||
#define LAYERTREE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QTreeView;
|
||||
class QPushButton;
|
||||
class MapTreeModel;
|
||||
|
||||
#include <QModelIndex>
|
||||
|
||||
class LayerTree : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit LayerTree(QWidget *parent = 0);
|
||||
|
||||
//QTreeView* getTree() const {return tree;}
|
||||
|
||||
void setModel(MapTreeModel* model);
|
||||
|
||||
void expandAll();
|
||||
|
||||
signals:
|
||||
|
||||
void layerSelected(QModelIndex);
|
||||
|
||||
private slots:
|
||||
|
||||
void onLayerSelected(QModelIndex);
|
||||
|
||||
void onBtnNew();
|
||||
|
||||
void onBtnDelete();
|
||||
|
||||
private:
|
||||
|
||||
QTreeView* tree;
|
||||
QPushButton* btnNew;
|
||||
QPushButton* btnDelete;
|
||||
MapTreeModel* model;
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // LAYERTREE_H
|
||||
87
params/MetaEditModel.cpp
Normal file
87
params/MetaEditModel.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "MetaEditModel.h"
|
||||
|
||||
|
||||
MetaEditModel::MetaEditModel(QObject* parent) : QAbstractTableModel(parent) {
|
||||
|
||||
setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
|
||||
setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
|
||||
}
|
||||
|
||||
void MetaEditModel::setSource(Floorplan::Meta* meta) {
|
||||
beginResetModel();
|
||||
this->meta = meta;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int MetaEditModel::rowCount(const QModelIndex &parent) const {
|
||||
return (meta) ? (meta->size()) : (0);
|
||||
}
|
||||
|
||||
int MetaEditModel::columnCount(const QModelIndex &parent) const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant MetaEditModel::data(const QModelIndex &index, int role) const {
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(index.column()) {
|
||||
case 0: return meta->getKey(index.row()).c_str();
|
||||
case 1: return meta->getVal(index.row()).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
||||
}
|
||||
|
||||
bool MetaEditModel::setData(const QModelIndex & index, const QVariant &value, int role) {
|
||||
|
||||
if (role == Qt::EditRole) {
|
||||
switch(index.column()) {
|
||||
case 0: meta->setKey(index.row(), value.toString().toStdString()); return true;
|
||||
case 1: meta->setVal(index.row(), value.toString().toStdString()); return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void MetaEditModel::deleteEntry(const int idx) {
|
||||
beginResetModel();
|
||||
meta->deleteEntry(idx);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void MetaEditModel::addEntry() {
|
||||
beginResetModel();
|
||||
meta->add("key", "val");
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
Qt::ItemFlags MetaEditModel::flags(const QModelIndex &index) const {
|
||||
|
||||
if (!index.isValid()) {return Qt::ItemIsEnabled;}
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVariant MetaEditModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
if(orientation == Qt::Horizontal) {
|
||||
if (section == 0) {return "key";}
|
||||
if (section == 1) {return "value";}
|
||||
} else {
|
||||
return QString::number(section);
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
||||
}
|
||||
|
||||
41
params/MetaEditModel.h
Normal file
41
params/MetaEditModel.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef METAEDITMODEL_H
|
||||
#define METAEDITMODEL_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class MetaEditModel : public QAbstractTableModel {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::Meta* meta = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
MetaEditModel(QObject* parent = nullptr);
|
||||
|
||||
/** delete the idx-th entry */
|
||||
void deleteEntry(const int idx);
|
||||
|
||||
/** add a new entry at the end */
|
||||
void addEntry();
|
||||
|
||||
void setSource(Floorplan::Meta* meta);
|
||||
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
int columnCount(const QModelIndex& parent) const override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
bool setData(const QModelIndex & index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
};
|
||||
|
||||
#endif // METAEDITMODEL_H
|
||||
67
params/MetaEditWidget.cpp
Normal file
67
params/MetaEditWidget.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "MetaEditWidget.h"
|
||||
#include "MetaEditModel.h"
|
||||
|
||||
#include <QTableView>
|
||||
#include <QGridLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QPushButton>
|
||||
|
||||
MetaEditWidget::MetaEditWidget(Floorplan::Meta* meta) : QWidget(nullptr), metaOrig(meta) {
|
||||
|
||||
// local copy. for the abort button [orig is unchanged]
|
||||
metaCopy.params = metaOrig->params;
|
||||
|
||||
QGridLayout* lay = new QGridLayout(this);
|
||||
|
||||
tbl = new QTableView();
|
||||
lay->addWidget(tbl, 0, 0, 1, 3);
|
||||
|
||||
model = new MetaEditModel();
|
||||
model->setSource(&metaCopy); // we edit the copy
|
||||
|
||||
tbl->setModel(model);
|
||||
tbl->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
tbl->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
|
||||
// events
|
||||
QPushButton* btnAdd = new QPushButton("add entry");
|
||||
lay->addWidget(btnAdd, 1, 0);
|
||||
btnAdd->connect(btnAdd, &QPushButton::clicked, [this] (const bool) {
|
||||
model->addEntry();
|
||||
});
|
||||
btnAdd->setToolTip("add a new, empty entry. delete an entry using the keyboard");
|
||||
|
||||
QPushButton* btnCancel = new QPushButton("abort");
|
||||
lay->addWidget(btnCancel, 1, 1);
|
||||
btnCancel->connect(btnCancel, &QPushButton::clicked, [this] (const bool) {
|
||||
// do not apply changes. juts close
|
||||
close();
|
||||
});
|
||||
btnCancel->setToolTip("close the dialog without committing the changes");
|
||||
|
||||
QPushButton* btnOK = new QPushButton("OK");
|
||||
lay->addWidget(btnOK, 1, 2);
|
||||
btnOK->connect(btnOK, &QPushButton::clicked, [this] (const bool) {
|
||||
metaOrig->params = metaCopy.params; // apply changed
|
||||
close();
|
||||
});
|
||||
btnOK->setToolTip("commit the changes and close the dialog");
|
||||
|
||||
|
||||
// sizing
|
||||
resize(500,400);
|
||||
|
||||
}
|
||||
|
||||
void MetaEditWidget::keyPressEvent(QKeyEvent* e) {
|
||||
|
||||
if (e->key() == Qt::Key_Delete) {
|
||||
QModelIndexList indices = tbl->selectionModel()->selectedIndexes();
|
||||
for (const QModelIndex& idx : indices) {
|
||||
model->deleteEntry(idx.row());
|
||||
break; // the list contains one entry per column!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
35
params/MetaEditWidget.h
Normal file
35
params/MetaEditWidget.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef METAEDITWIDGET_H
|
||||
#define METAEDITWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
class MetaEditModel;
|
||||
class QTableView;
|
||||
|
||||
/**
|
||||
* helper class to edit the Floorplan::Meta
|
||||
* key value attribute
|
||||
*/
|
||||
class MetaEditWidget : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::Meta* metaOrig;
|
||||
Floorplan::Meta metaCopy; // used for the abort button
|
||||
|
||||
MetaEditModel* model;
|
||||
|
||||
QTableView* tbl;
|
||||
|
||||
public:
|
||||
|
||||
MetaEditWidget(Floorplan::Meta* meta);
|
||||
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
};
|
||||
|
||||
#endif // METAEDITWIDGET_H
|
||||
@@ -14,8 +14,19 @@
|
||||
#include "../mapview/model/MMFloorBeacon.h"
|
||||
#include "../mapview/model/MMFloorGroundTruthPoints.h"
|
||||
|
||||
#include "../mapview/2D/tools/ToolMeasure.h"
|
||||
|
||||
#include "../UIHelper.h"
|
||||
|
||||
QSplitter* getSplitter() {
|
||||
|
||||
QSplitter* splt = new QSplitter();
|
||||
splt->setStyleSheet("background-color:black;");
|
||||
splt->setMinimumHeight(1);
|
||||
return splt;
|
||||
|
||||
}
|
||||
|
||||
ToolBoxWidget::ToolBoxWidget(MapView2D* view, QWidget *parent) : QWidget(parent), view(view) {
|
||||
|
||||
const int s = 32;
|
||||
@@ -31,6 +42,16 @@ ToolBoxWidget::ToolBoxWidget(MapView2D* view, QWidget *parent) : QWidget(parent)
|
||||
connect(btnSelect, SIGNAL(clicked(bool)), this, SLOT(onSelect()));
|
||||
|
||||
|
||||
// MEASURE
|
||||
btnMeasure = new QPushButton(UIHelper::getIcon("ruler"), "");
|
||||
btnMeasure->setMinimumSize(s,s);
|
||||
lay->addWidget(btnMeasure, r++, 0, 1,1,Qt::AlignTop);
|
||||
connect(btnMeasure, SIGNAL(clicked(bool)), this, SLOT(onMeasure()));
|
||||
|
||||
|
||||
// splitter
|
||||
lay->addWidget(getSplitter(), r++, 0, 1,1,Qt::AlignTop);
|
||||
|
||||
|
||||
// OBSTACLES
|
||||
btnGround = new QPushButton(UIHelper::getIcon("floor"), "");
|
||||
@@ -64,6 +85,10 @@ ToolBoxWidget::ToolBoxWidget(MapView2D* view, QWidget *parent) : QWidget(parent)
|
||||
connect(btnElevator, SIGNAL(clicked(bool)), this, SLOT(onNewElevator()));
|
||||
|
||||
|
||||
// splitter
|
||||
lay->addWidget(getSplitter(), r++, 0, 1,1,Qt::AlignTop);
|
||||
|
||||
|
||||
// TRANSMITTERS
|
||||
btnWifi = new QPushButton(UIHelper::getIcon("wifi"), "");
|
||||
btnWifi->setMinimumSize(s,s);
|
||||
@@ -350,116 +375,25 @@ public:
|
||||
|
||||
};
|
||||
|
||||
//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::onMeasure() {
|
||||
|
||||
new ToolMeasure(view->getTools());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ToolBoxWidget::onNewWall() {
|
||||
|
||||
new NewWallTool(view->getTools(), curLayer);
|
||||
//view->getModel()->reselect();
|
||||
|
||||
}
|
||||
|
||||
void ToolBoxWidget::onNewPillar() {
|
||||
@@ -484,21 +418,6 @@ void ToolBoxWidget::onNewDoor() {
|
||||
|
||||
new NewDoorTool(view->getTools(), curLayer);
|
||||
|
||||
// const Point2 center = view->getScaler().getCenter();
|
||||
// float s = view->getScaler().sm(50);
|
||||
|
||||
// Floorplan::FloorObstacleDoor* door = new Floorplan::FloorObstacleDoor(
|
||||
// Floorplan::DoorType::SWING,
|
||||
// Floorplan::Material::WOOD,
|
||||
// Point2(center.x-s, center.y),
|
||||
// Point2(center.x+s, center.y)
|
||||
// );
|
||||
|
||||
// MMFloorObstacles* obs = (MMFloorObstacles*)curLayer;
|
||||
// obs->createDoor(door);
|
||||
|
||||
//view->getModel()->reselect();
|
||||
|
||||
}
|
||||
|
||||
void ToolBoxWidget::onNewStair() {
|
||||
|
||||
@@ -8,7 +8,9 @@ class QPushButton;
|
||||
class MapView2D;
|
||||
|
||||
/**
|
||||
* gui element with actions to perform
|
||||
* the toolbox on the left of the map.
|
||||
* gui element with actions to perform.
|
||||
* add new elements, etc.
|
||||
*/
|
||||
class ToolBoxWidget : public QWidget {
|
||||
|
||||
@@ -32,6 +34,7 @@ private:
|
||||
int r = 0;
|
||||
|
||||
QPushButton* btnSelect;
|
||||
QPushButton* btnMeasure;
|
||||
|
||||
QPushButton* btnGround;
|
||||
QPushButton* btnWall;
|
||||
@@ -50,6 +53,7 @@ private:
|
||||
private slots:
|
||||
|
||||
void onSelect();
|
||||
void onMeasure();
|
||||
|
||||
void onNewGround();
|
||||
void onNewWall();
|
||||
|
||||
Reference in New Issue
Block a user