initial commit

This commit is contained in:
kazu
2016-05-24 16:55:19 +02:00
commit 13a89df8d6
77 changed files with 7454 additions and 0 deletions

106
params/LayerParamWidget.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include "LayerParamWidget.h"
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include "mapview/model/MMFloor.h"
LayerParamWidget::LayerParamWidget(QWidget *parent) : QGroupBox(parent) {
setMinimumSize(100, 100);
setMaximumWidth(200);
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<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());}
}
}
void LayerParamWidget::onAtHeightChanged() {
MMFloor* floor = dynamic_cast<MMFloor*>(curElement);
try {
if (floor) {floor->getFloor().atHeight = std::stof(atHeight.txt->text().toStdString());}
} catch (...) {;}
}
void LayerParamWidget::onHeightChanged() {
MMFloor* floor = dynamic_cast<MMFloor*>(curElement);
try {
if (floor) {floor->getFloor().height = std::stof(height.txt->text().toStdString());}
} catch (...) {;}
}
void LayerParamWidget::onNameChanged() {
dynamic_cast<IHasName*>(curElement)->setName(name.txt->text().toStdString());
}