NewItemDialog uses dynamically generated control widgets for model data as well. Added a WidgetHelper class to consolidate identical source code for ItemDetailMapper and NewItemDialog.
This commit is contained in:
45
widgethelper.cpp
Normal file
45
widgethelper.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#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() {}
|
||||
Reference in New Issue
Block a user