22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <QFormLayout>
25 #include <QDialogButtonBox>
26 #include <QScrollArea>
30 #include <QDoubleSpinBox>
46 EptAssert(currentAlgorithm,
"Current algorithm has to exist.");
48 QRect pr(parent->contentsRect());
49 setGeometry(pr.center().x() - pr.width() / 4, pr.center().y() - pr.height() / 4,
50 pr.width() / 2, pr.height() / 2);
57 const std::string &name = desc.first;
60 mAlgorithmNames.push_back(qMakePair(QString::fromStdString(name), QString::fromStdString(info->getName())));
62 LogW(
"Error during loading and adding the algorithm '%s'. Skipping...", name.c_str());
68 QVBoxLayout *mainLayout =
new QVBoxLayout;
69 setLayout(mainLayout);
72 QHBoxLayout *titleLayout =
new QHBoxLayout;
73 mainLayout->addLayout(titleLayout);
74 titleLayout->addWidget(
new QLabel(tr(
"Algorithm:")));
76 QComboBox *comboBox =
new QComboBox;
79 comboBox->addItem(alg.second, alg.first);
81 titleLayout->addWidget(comboBox);
83 comboBox->setCurrentIndex(comboBox->findData(QString::fromStdString(currentAlgorithm->getId())));
84 EptAssert(comboBox->currentIndex() >= 0,
"The default algotihm doesnt exist!");
101 QDialogButtonBox *buttons =
new QDialogButtonBox;
102 mainLayout->addWidget(buttons);
103 buttons->setStandardButtons(QDialogButtonBox::Ok);
105 QObject::connect(buttons, SIGNAL(accepted()),
this, SLOT(
accept()));
106 QObject::connect(buttons, SIGNAL(rejected()),
this, SLOT(reject()));
122 const QWidget *widget = paramWidget.second;
125 const QDoubleSpinBox *sb =
dynamic_cast<const QDoubleSpinBox*
>(widget);
126 EptAssert(sb,
"This parameter is described by a QDoubleSpinBox");
129 const QSpinBox *sb =
dynamic_cast<const QSpinBox*
>(widget);
130 EptAssert(sb,
"This parameter is described by a QSpinBox");
133 const QComboBox *cb = qobject_cast<
const QComboBox*>(widget);
155 setWindowTitle(tr(
"Info of algorithm: %1").arg(QString::fromStdString(info.getName())));
157 QWidget *scrollContentWidget =
new QWidget;
158 scrollContentWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
160 QVBoxLayout *scrollLayout =
new QVBoxLayout;
161 scrollContentWidget->setLayout(scrollLayout);
163 QGroupBox *infoGroupBox =
new QGroupBox(tr(
"Info"));
164 scrollLayout->addWidget(infoGroupBox);
166 QFormLayout *layout =
new QFormLayout;
167 infoGroupBox->setLayout(layout);
169 layout->addRow(
new QLabel(tr(
"Name:")),
new QLabel(QString::fromStdString(info.getName())));
170 layout->addRow(
new QLabel(tr(
"Author:")),
new QLabel(QString::fromStdString(info.getAuthor())));
171 layout->addRow(
new QLabel(tr(
"Year:")),
new QLabel(QString(
"%1").arg(info.getYear())));
173 QLabel *descriptionLabel =
new QLabel(QString::fromStdString(info.getDescription()));
174 descriptionLabel->setWordWrap(
true);
175 descriptionLabel->setAlignment(Qt::AlignTop);
176 layout->addRow(
new QLabel(tr(
"Description:")), descriptionLabel);
180 if (info.getParameters().size() > 0) {
181 QGroupBox *paramsBox =
new QGroupBox(tr(
"Parameters"));
182 scrollLayout->addWidget(paramsBox);
183 QFormLayout *paramsBoxLayout =
new QFormLayout;
184 paramsBox->setLayout(paramsBoxLayout);
186 QWidget *dataWidget =
nullptr;
187 QLayout *dataLayout =
nullptr;
190 QHBoxLayout *valueLayout =
new QHBoxLayout;
191 dataLayout = valueLayout;
193 QDoubleSpinBox *sb =
new QDoubleSpinBox();
196 sb->setMinimumWidth(sb->fontInfo().pointSizeF() * 15);
198 sb->setRange(param.getDoubleMinValue(), param.getDoubleMaxValue());
202 sb->setValue(param.getDoubleDefaultValue());
205 if (param.getDoublePrecision() >= 0) {
207 DoubleSlider *slider =
new DoubleSlider(param.getDoubleMinValue(), param.getDoubleMaxValue(), param.getDoublePrecision());
208 slider->setOrientation(Qt::Horizontal);
210 valueLayout->addWidget(slider);
212 QObject::connect(slider, SIGNAL(valueChanged(
double)), sb, SLOT(setValue(
double)));
213 QObject::connect(sb, SIGNAL(valueChanged(
double)), slider, SLOT(setValue(
double)));
215 sb->setDecimals(param.getDoublePrecision());
218 valueLayout->addWidget(sb);
222 QHBoxLayout *valueLayout =
new QHBoxLayout;
223 dataLayout = valueLayout;
225 QSpinBox *sb =
new QSpinBox();
228 sb->setMinimumWidth(sb->fontInfo().pointSizeF() * 15);
230 sb->setRange(param.getIntMinValue(), param.getIntMaxValue());
234 sb->setValue(param.getIntDefaultValue());
238 QSlider *slider =
new QSlider(Qt::Horizontal);
239 slider->setMinimum(param.getIntMinValue());
240 slider->setMaximum(param.getIntMaxValue());
241 slider->setValue(sb->value());
242 valueLayout->addWidget(slider);
244 QObject::connect(slider, SIGNAL(valueChanged(
int)), sb, SLOT(setValue(
int)));
245 QObject::connect(sb, SIGNAL(valueChanged(
int)), slider, SLOT(setValue(
int)));
247 valueLayout->addWidget(sb);
251 QComboBox *cb =
new QComboBox;
252 for (
const auto &p : param.getStringList()) {
253 cb->addItem(QString::fromStdString(p.second), QString::fromStdString(p.first));
255 int defaultIndex = cb->findData(QString::fromStdString(param.getStringDefaultValue()));
257 defaultIndex = cb->findData(QString::fromStdString(description.
getStringParameter(param.getID())));
259 cb->setCurrentIndex(defaultIndex);
266 EptAssert(dataWidget,
"A data widget has to exist.");
268 dataWidget->setWhatsThis(QString::fromStdString(param.getDescription()));
271 paramsBoxLayout->addRow(
new QLabel(QString::fromStdString(param.getLabel())), dataLayout);
272 }
else if (dataWidget) {
273 paramsBoxLayout->addRow(
new QLabel(QString::fromStdString(param.getLabel())), dataWidget);
static CalculationManager & getSingleton()
QComboBox * mAlgorithmSelection
void setDoubleParameter(const std::string &s, double p)
bool hasDoubleParameter(const std::string &s) const
const std::string & getAlgorithmName() const
bool hasIntParameter(const std::string &s) const
AlgorithmDialog(std::shared_ptr< const AlgorithmInformation > currentAlgorithm, QWidget *parent)
std::shared_ptr< const AlgorithmInformation > mCurrentAlgorithmInformation
static AlgorithmIdList mAlgorithmNames
AlgorithmWidgetConnectionList mAlgorithmWidgetConnectionList
double getDoubleParameter(const std::string &s) const
#define EPT_EXCEPT(num, desc)
QList< QPair< QString, QString >> AlgorithmIdList
AlgorithmFactoryDescription * mCurrentFactoryDescription
int getIntParameter(const std::string &s) const
void setStringParameter(const std::string &id, const std::string &s)
QScrollArea * mAlgorithmDescriptionScrollArea
std::shared_ptr< const AlgorithmInformation > loadAlgorithmInformation(const std::string &algorithmName) const
AlgorithmFactoryDescription & getAlgorithmDescription(const std::string &algorithmName) const
void algorithmSelectionChanged(int index)
const std::string & getStringParameter(const std::string &id) const
void setIntParameter(const std::string &s, int i)
const std::map< std::string, AlgorithmFactoryBase * > & getAlgorithms() const
bool hasStringParameter(const std::string &id) const