184 lines
5.5 KiB
C++
184 lines
5.5 KiB
C++
#ifndef EDITFIELDS_H
|
|
#define EDITFIELDS_H
|
|
|
|
#include "fixC11.h"
|
|
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QLineEdit>
|
|
#include <QComboBox>
|
|
#include <QCheckBox>
|
|
#include <QFileDialog>
|
|
|
|
#include "../mapview/model/IHasParams.h"
|
|
|
|
class EditFields {
|
|
|
|
public:
|
|
|
|
static void get(QWidget* parent, int& r, QGridLayout* lay, IHasParams* elem) {
|
|
|
|
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::NOT_AVAILABLE:
|
|
break;
|
|
|
|
case ParamType::ENUM: {
|
|
QComboBox* cmb = new QComboBox(parent);
|
|
int idx = 0;
|
|
for (const std::string& str : param.getEnumValues()) {cmb->addItem(str.c_str(), idx++);}
|
|
cmb->setCurrentIndex(value.toInt());
|
|
cmb->connect(cmb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [i, elem, cmb] (int idx) {
|
|
(void) idx;
|
|
elem->setParamValue(i, cmb->currentData().toInt() );
|
|
});
|
|
lay->addWidget(cmb,r,1);
|
|
break;
|
|
}
|
|
|
|
case ParamType::BOOL: {
|
|
QCheckBox* chk = new QCheckBox(parent);
|
|
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(), parent),r,1);
|
|
} else {
|
|
QLineEdit* le = new QLineEdit(str.c_str(), parent);
|
|
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::DOUBLE: {
|
|
const std::string str = std::to_string(value.toDouble());
|
|
if (param.readOnly) {
|
|
lay->addWidget(new QLabel(str.c_str(), parent),r,1);
|
|
} else {
|
|
QLineEdit* le = new QLineEdit(str.c_str(), parent);
|
|
le->connect(le, &QLineEdit::textChanged, [i,elem] (const QString& str) {
|
|
const double val = str.toDouble();
|
|
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(), parent);
|
|
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(), parent);
|
|
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(), parent);
|
|
QPushButton* btn = new QPushButton("<",parent);
|
|
btn->setMaximumSize(32,32);
|
|
btn->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);
|
|
});
|
|
lay->addWidget(lblFile,r,1);
|
|
lay->addWidget(btn,r,2);
|
|
break;
|
|
}
|
|
|
|
case ParamType::POINT2: {
|
|
const Point2 p2 = value.toPoint2();
|
|
QWidget* subWidget = new QWidget(parent);
|
|
QGridLayout* laySub = new QGridLayout(subWidget); laySub->setMargin(0);
|
|
QLineEdit* txtX = new QLineEdit(QString::number(p2.x), subWidget);
|
|
QLineEdit* txtY = new QLineEdit(QString::number(p2.y), subWidget);
|
|
laySub->addWidget(txtX,0,0);
|
|
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()) ));
|
|
};
|
|
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(parent);
|
|
QGridLayout* laySub = new QGridLayout(subWidget); laySub->setMargin(0);
|
|
QLineEdit* txtX = new QLineEdit(QString::number(p3.x), subWidget);
|
|
QLineEdit* txtY = new QLineEdit(QString::number(p3.y), subWidget);
|
|
QLineEdit* txtZ = new QLineEdit(QString::number(p3.z), subWidget);
|
|
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
|