forked from qt-creator/qt-creator
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:
@@ -73,25 +73,6 @@ namespace ProjectExplorer {
|
|||||||
// Helper:
|
// 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
|
class LineEditValidator : public QRegularExpressionValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -909,6 +890,8 @@ void ComboBoxField::initializeData(MacroExpander *expander)
|
|||||||
// JsonFieldPage:
|
// JsonFieldPage:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
QHash<QString, JsonFieldPage::FieldFactory> JsonFieldPage::m_factories;
|
||||||
|
|
||||||
JsonFieldPage::JsonFieldPage(MacroExpander *expander, QWidget *parent) :
|
JsonFieldPage::JsonFieldPage(MacroExpander *expander, QWidget *parent) :
|
||||||
WizardPage(parent),
|
WizardPage(parent),
|
||||||
m_formLayout(new QFormLayout),
|
m_formLayout(new QFormLayout),
|
||||||
@@ -935,6 +918,12 @@ JsonFieldPage::~JsonFieldPage()
|
|||||||
qDeleteAll(m_fields);
|
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)
|
bool JsonFieldPage::setup(const QVariant &data)
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
@@ -1002,4 +991,11 @@ MacroExpander *JsonFieldPage::expander()
|
|||||||
return m_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
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ public:
|
|||||||
JsonFieldPage(Utils::MacroExpander *expander, QWidget *parent = 0);
|
JsonFieldPage(Utils::MacroExpander *expander, QWidget *parent = 0);
|
||||||
~JsonFieldPage();
|
~JsonFieldPage();
|
||||||
|
|
||||||
|
typedef std::function<Field *()> FieldFactory;
|
||||||
|
static void registerFieldFactory(const QString &id, const FieldFactory &ff);
|
||||||
|
|
||||||
bool setup(const QVariant &data);
|
bool setup(const QVariant &data);
|
||||||
|
|
||||||
bool isComplete() const;
|
bool isComplete() const;
|
||||||
@@ -129,6 +132,10 @@ public:
|
|||||||
Utils::MacroExpander *expander();
|
Utils::MacroExpander *expander();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static QHash<QString, FieldFactory> m_factories;
|
||||||
|
|
||||||
|
static Field *createFieldData(const QString &type);
|
||||||
|
|
||||||
QFormLayout *m_formLayout;
|
QFormLayout *m_formLayout;
|
||||||
QLabel *m_errorLabel;
|
QLabel *m_errorLabel;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "jsonwizardpagefactory_p.h"
|
#include "jsonwizardpagefactory_p.h"
|
||||||
|
|
||||||
#include "jsonfieldpage.h"
|
#include "jsonfieldpage.h"
|
||||||
|
#include "jsonfieldpage_p.h"
|
||||||
#include "jsonfilepage.h"
|
#include "jsonfilepage.h"
|
||||||
#include "jsonkitspage.h"
|
#include "jsonkitspage.h"
|
||||||
#include "jsonprojectpage.h"
|
#include "jsonprojectpage.h"
|
||||||
@@ -53,6 +54,14 @@ namespace Internal {
|
|||||||
FieldPageFactory::FieldPageFactory()
|
FieldPageFactory::FieldPageFactory()
|
||||||
{
|
{
|
||||||
setTypeIdsSuffix(QLatin1String("Fields"));
|
setTypeIdsSuffix(QLatin1String("Fields"));
|
||||||
|
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("Label"), []() { return new LabelField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("Spacer"), []() { return new SpacerField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("LineEdit"), []() { return new LineEditField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("TextEdit"), []() { return new TextEditField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("PathChooser"), []() { return new PathChooserField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("CheckBox"), []() { return new CheckBoxField; });
|
||||||
|
JsonFieldPage::registerFieldFactory(QLatin1String("ComboBox"), []() { return new ComboBoxField; });
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::WizardPage *FieldPageFactory::create(JsonWizard *wizard, Core::Id typeId, const QVariant &data)
|
Utils::WizardPage *FieldPageFactory::create(JsonWizard *wizard, Core::Id typeId, const QVariant &data)
|
||||||
|
|||||||
Reference in New Issue
Block a user