This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/params/LayerParamWidget.cpp
2018-10-25 12:15:13 +02:00

137 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#include "../fixC11.h"
#include "LayerParamWidget.h"
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include "mapview/model/IHasName.h"
#include "mapview/model/MMFloor.h"
#include "EditFields.h"
LayerParamWidget::LayerParamWidget(QWidget *parent) : QWidget(parent) {
setMinimumSize(100, 50);
setMaximumWidth(250);
//setTitle("MapLayer Parameters");
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("-");
// }
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());}
// }
{
IHasParams* elem = dynamic_cast<IHasParams*>(l);
if (elem) {
EditFields::get(this, r, lay, elem);
}
}
}
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());
}