JsonWizard: Allow for custom widgets in the Field page

... instead of having a hard-coded list of widgets you can use.

Change-Id: Iedf7016412ce9d619fea5cdffe6dbf86beda92b0
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Benjamin Zeller <benjamin.zeller@canonical.com>
This commit is contained in:
Tobias Hunger
2015-09-21 16:28:48 +02:00
parent 443f133d3e
commit 4b77ae0718
3 changed files with 31 additions and 19 deletions

View File

@@ -73,25 +73,6 @@ namespace ProjectExplorer {
// Helper:
// --------------------------------------------------------------------
static JsonFieldPage::Field *createFieldData(const QString &type)
{
if (type == QLatin1String("Label"))
return new LabelField;
else if (type == QLatin1String("Spacer"))
return new SpacerField;
else if (type == QLatin1String("LineEdit"))
return new LineEditField;
else if (type == QLatin1String("TextEdit"))
return new TextEditField;
else if (type == QLatin1String("PathChooser"))
return new PathChooserField;
else if (type == QLatin1String("CheckBox"))
return new CheckBoxField;
else if (type == QLatin1String("ComboBox"))
return new ComboBoxField;
return 0;
}
class LineEditValidator : public QRegularExpressionValidator
{
public:
@@ -909,6 +890,8 @@ void ComboBoxField::initializeData(MacroExpander *expander)
// JsonFieldPage:
// --------------------------------------------------------------------
QHash<QString, JsonFieldPage::FieldFactory> JsonFieldPage::m_factories;
JsonFieldPage::JsonFieldPage(MacroExpander *expander, QWidget *parent) :
WizardPage(parent),
m_formLayout(new QFormLayout),
@@ -935,6 +918,12 @@ JsonFieldPage::~JsonFieldPage()
qDeleteAll(m_fields);
}
void JsonFieldPage::registerFieldFactory(const QString &id, const JsonFieldPage::FieldFactory &ff)
{
QTC_ASSERT(!m_factories.contains(id), return);
m_factories.insert(id, ff);
}
bool JsonFieldPage::setup(const QVariant &data)
{
QString errorMessage;
@@ -1002,4 +991,11 @@ MacroExpander *JsonFieldPage::expander()
return m_expander;
}
JsonFieldPage::Field *JsonFieldPage::createFieldData(const QString &type)
{
if (!m_factories.contains(type))
return 0;
return m_factories.value(type)();
}
} // namespace ProjectExplorer