46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include "widgethelper.h"
|
|
|
|
#include <QComboBox>
|
|
#include <QLineEdit>
|
|
#include <QSpinBox>
|
|
#include <QStringListModel>
|
|
|
|
QWidget* WidgetHelper::createControlWidget(const UserRoles role, QWidget* parent) {
|
|
QWidget* control;
|
|
if (STRING_ROLES.contains(role)) {
|
|
control = new QLineEdit();
|
|
} else if (TYPE_ROLES.contains(role)) {
|
|
control = createComboBox(role, parent);
|
|
} else if (INT_ROLES.contains(role)) {
|
|
QSpinBox* spinBox = new QSpinBox();
|
|
spinBox->setMaximum(1000);
|
|
control = spinBox;
|
|
} else if (DOUBLE_ROLES.contains(role)) {
|
|
QDoubleSpinBox* spinBox = new QDoubleSpinBox();
|
|
spinBox->setMaximum(1000);
|
|
control = spinBox;
|
|
} else {
|
|
qCritical() << QString("Unsupported role %1!!!").arg(role);
|
|
qDebug() << "Using line edit as well and pretend it's a string role...";
|
|
control = new QLineEdit();
|
|
}
|
|
return control;
|
|
}
|
|
|
|
QWidget* WidgetHelper::createComboBox(const UserRoles role, QWidget* parent) {
|
|
QStringListModel* typeModel;
|
|
if (role == TypeRole) {
|
|
typeModel = new QStringListModel(TYPES, parent);
|
|
} else {
|
|
qCritical() << "Unsupported type with role:" << role
|
|
<< "- Using string list model with only one empty string!";
|
|
typeModel = new QStringListModel({""}, parent);
|
|
}
|
|
QComboBox* comboBox = new QComboBox();
|
|
comboBox->setModel(typeModel);
|
|
comboBox->setCurrentText("");
|
|
return comboBox;
|
|
}
|
|
|
|
WidgetHelper::WidgetHelper() {}
|