#include "LayerParamWidget.h" #include #include #include #include "mapview/model/IHasName.h" #include "mapview/model/MMFloor.h" LayerParamWidget::LayerParamWidget(QWidget *parent) : QGroupBox(parent) { setMinimumSize(100, 100); setMaximumWidth(250); setTitle("MapLayer Parameters"); QGridLayout* lay = new QGridLayout(this); int r = 0; selected.lbl = new QLabel("selected"); selected.info = new QLabel(); lay->addWidget(selected.lbl, r, 0); lay->addWidget(selected.info, r, 1); ++r; name.lbl = new QLabel("name"); name.txt = new QLineEdit(); lay->addWidget(name.lbl, r, 0); lay->addWidget(name.txt, r, 1); connect(name.txt, SIGNAL(textChanged(QString)), this, SLOT(onNameChanged())); ++r; atHeight.lbl = new QLabel("at height"); atHeight.txt = new QLineEdit(); lay->addWidget(atHeight.lbl, r, 0); lay->addWidget(atHeight.txt, r, 1); connect(atHeight.txt, SIGNAL(textChanged(QString)), this, SLOT(onAtHeightChanged())); ++r; height.lbl = new QLabel("height"); height.txt = new QLineEdit(); lay->addWidget(height.lbl, r, 0); lay->addWidget(height.txt, r, 1); connect(height.txt, SIGNAL(textChanged(QString)), this, SLOT(onHeightChanged())); ++r; // start empty setElement(nullptr); } 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("-"); } { MMFloor* floor = dynamic_cast(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(l); name.lbl->setVisible(elem); name.txt->setVisible(elem); if (elem) {name.txt->setText(elem->getName().c_str());} } } void LayerParamWidget::onAtHeightChanged() { MMFloor* floor = dynamic_cast(curElement); try { if (floor) {floor->getFloor().atHeight = std::stof(atHeight.txt->text().toStdString());} } catch (...) {;} } void LayerParamWidget::onHeightChanged() { MMFloor* floor = dynamic_cast(curElement); try { if (floor) {floor->getFloor().height = std::stof(height.txt->text().toStdString());} } catch (...) {;} } void LayerParamWidget::onNameChanged() { dynamic_cast(curElement)->setName(name.txt->text().toStdString()); }