added new param-editing to APs and Beacons
changed drawing for better debuging changed layer editing option to add and delete layers some minor changes
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
|
||||
@@ -68,11 +68,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 +93,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;
|
||||
@@ -269,8 +271,20 @@ void ElementParamWidget::refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
//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() );}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user