forked from qt-creator/qt-creator
Wizards: Add the ability to remember user choices
Wizard authors can now provide a persistence key to values where that makes sense. For now, we make use of it for the build system type in all wizards and the minimum Qt version as well as the virtual keyboard settings in the QtQuick wizards. Fixes: QTCREATORBUG-16657 Change-Id: I179930665bd163b1cf198467ab8b43bc72f8ec4a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -683,6 +683,11 @@
|
|||||||
\li \c trIncompleteMessage is shown when the field's \c isComplete was
|
\li \c trIncompleteMessage is shown when the field's \c isComplete was
|
||||||
evaluated to \c false.
|
evaluated to \c false.
|
||||||
|
|
||||||
|
\li \c persistenceKey makes the user choice persistent. The value is
|
||||||
|
taken to be a settings key. If the user changes the default
|
||||||
|
value of the widget, the user-provided value is stored and will
|
||||||
|
become the new default value the next time the wizard is run.
|
||||||
|
|
||||||
\li \c data specifies settings for the widget:
|
\li \c data specifies settings for the widget:
|
||||||
|
|
||||||
\list
|
\list
|
||||||
|
@@ -171,6 +171,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -54,6 +54,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -79,6 +80,7 @@
|
|||||||
"name": "QtVersion",
|
"name": "QtVersion",
|
||||||
"trDisplayName": "Minimal required Qt version:",
|
"trDisplayName": "Minimal required Qt version:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "QtQuick.minimumQtVersion",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 1,
|
"index": 1,
|
||||||
@@ -163,6 +165,7 @@
|
|||||||
"name": "UseVirtualKeyboard",
|
"name": "UseVirtualKeyboard",
|
||||||
"trDisplayName": "Use Qt Virtual Keyboard",
|
"trDisplayName": "Use Qt Virtual Keyboard",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"persistenceKey": "QtQuick.UseVirtualKeyboard.%{UseVirtualKeyboardByDefault}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checked": "%{UseVirtualKeyboardByDefault}"
|
"checked": "%{UseVirtualKeyboardByDefault}"
|
||||||
|
@@ -46,6 +46,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
"name": "QtVersion",
|
"name": "QtVersion",
|
||||||
"trDisplayName": "Minimal required Qt version:",
|
"trDisplayName": "Minimal required Qt version:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "QtQuick.minimumQtVersion",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 1,
|
"index": 1,
|
||||||
@@ -214,6 +216,7 @@
|
|||||||
"name": "UseVirtualKeyboard",
|
"name": "UseVirtualKeyboard",
|
||||||
"trDisplayName": "Use Qt Virtual Keyboard",
|
"trDisplayName": "Use Qt Virtual Keyboard",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"persistenceKey": "QtQuick.UseVirtualKeyboard.%{UseVirtualKeyboardByDefault}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checked": "%{UseVirtualKeyboardByDefault}"
|
"checked": "%{UseVirtualKeyboardByDefault}"
|
||||||
|
@@ -46,6 +46,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
"name": "QtVersion",
|
"name": "QtVersion",
|
||||||
"trDisplayName": "Minimal required Qt version:",
|
"trDisplayName": "Minimal required Qt version:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "QtQuick.minimumQtVersion",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 1,
|
"index": 1,
|
||||||
@@ -232,6 +234,7 @@
|
|||||||
"name": "UseVirtualKeyboard",
|
"name": "UseVirtualKeyboard",
|
||||||
"trDisplayName": "Use Qt Virtual Keyboard",
|
"trDisplayName": "Use Qt Virtual Keyboard",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"persistenceKey": "QtQuick.UseVirtualKeyboard.%{UseVirtualKeyboardByDefault}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checked": "%{UseVirtualKeyboardByDefault}"
|
"checked": "%{UseVirtualKeyboardByDefault}"
|
||||||
|
@@ -46,6 +46,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
"name": "QtVersion",
|
"name": "QtVersion",
|
||||||
"trDisplayName": "Minimal required Qt version:",
|
"trDisplayName": "Minimal required Qt version:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "QtQuick.minimumQtVersion",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 1,
|
"index": 1,
|
||||||
@@ -232,6 +234,7 @@
|
|||||||
"name": "UseVirtualKeyboard",
|
"name": "UseVirtualKeyboard",
|
||||||
"trDisplayName": "Use Qt Virtual Keyboard",
|
"trDisplayName": "Use Qt Virtual Keyboard",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"persistenceKey": "QtQuick.UseVirtualKeyboard.%{UseVirtualKeyboardByDefault}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checked": "%{UseVirtualKeyboardByDefault}"
|
"checked": "%{UseVirtualKeyboardByDefault}"
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
"name": "BuildSystem",
|
"name": "BuildSystem",
|
||||||
"trDisplayName": "Build system:",
|
"trDisplayName": "Build system:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
|
"persistenceKey": "BuildSystemType",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "jsonwizard.h"
|
#include "jsonwizard.h"
|
||||||
#include "jsonwizardfactory.h"
|
#include "jsonwizardfactory.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -57,6 +58,7 @@ const char NAME_KEY[] = "name";
|
|||||||
const char DISPLAY_NAME_KEY[] = "trDisplayName";
|
const char DISPLAY_NAME_KEY[] = "trDisplayName";
|
||||||
const char TOOLTIP_KEY[] = "trToolTip";
|
const char TOOLTIP_KEY[] = "trToolTip";
|
||||||
const char MANDATORY_KEY[] = "mandatory";
|
const char MANDATORY_KEY[] = "mandatory";
|
||||||
|
const char PERSISTENCE_KEY_KEY[] = "persistenceKey";
|
||||||
const char VISIBLE_KEY[] = "visible";
|
const char VISIBLE_KEY[] = "visible";
|
||||||
const char ENABLED_KEY[] = "enabled";
|
const char ENABLED_KEY[] = "enabled";
|
||||||
const char SPAN_KEY[] = "span";
|
const char SPAN_KEY[] = "span";
|
||||||
@@ -153,6 +155,21 @@ QString JsonFieldPage::Field::type()
|
|||||||
return d->m_type;
|
return d->m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonFieldPage::Field::setHasUserChanges()
|
||||||
|
{
|
||||||
|
d->m_hasUserChanges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonFieldPage::Field::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
Q_UNUSED(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant JsonFieldPage::Field::toSettings() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
JsonFieldPage::Field *JsonFieldPage::Field::parse(const QVariant &input, QString *errorMessage)
|
JsonFieldPage::Field *JsonFieldPage::Field::parse(const QVariant &input, QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (input.type() != QVariant::Map) {
|
if (input.type() != QVariant::Map) {
|
||||||
@@ -192,6 +209,7 @@ JsonFieldPage::Field *JsonFieldPage::Field::parse(const QVariant &input, QString
|
|||||||
data->setHasSpan(consumeValue(tmp, SPAN_KEY, false).toBool());
|
data->setHasSpan(consumeValue(tmp, SPAN_KEY, false).toBool());
|
||||||
data->setIsCompleteExpando(consumeValue(tmp, IS_COMPLETE_KEY, true),
|
data->setIsCompleteExpando(consumeValue(tmp, IS_COMPLETE_KEY, true),
|
||||||
consumeValue(tmp, IS_COMPLETE_MESSAGE_KEY).toString());
|
consumeValue(tmp, IS_COMPLETE_MESSAGE_KEY).toString());
|
||||||
|
data->setPersistenceKey(consumeValue(tmp, PERSISTENCE_KEY_KEY).toString());
|
||||||
|
|
||||||
QVariant dataVal = consumeValue(tmp, DATA_KEY);
|
QVariant dataVal = consumeValue(tmp, DATA_KEY);
|
||||||
if (!data->parseData(dataVal, errorMessage)) {
|
if (!data->parseData(dataVal, errorMessage)) {
|
||||||
@@ -295,6 +313,11 @@ QString JsonFieldPage::Field::toolTip()
|
|||||||
return d->m_toolTip;
|
return d->m_toolTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString JsonFieldPage::Field::persistenceKey() const
|
||||||
|
{
|
||||||
|
return d->m_persistenceKey;
|
||||||
|
}
|
||||||
|
|
||||||
bool JsonFieldPage::Field::isMandatory()
|
bool JsonFieldPage::Field::isMandatory()
|
||||||
{
|
{
|
||||||
return d->m_isMandatory;
|
return d->m_isMandatory;
|
||||||
@@ -305,6 +328,11 @@ bool JsonFieldPage::Field::hasSpan()
|
|||||||
return d->m_hasSpan;
|
return d->m_hasSpan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JsonFieldPage::Field::hasUserChanges() const
|
||||||
|
{
|
||||||
|
return d->m_hasUserChanges;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant JsonFieldPage::value(const QString &key)
|
QVariant JsonFieldPage::value(const QString &key)
|
||||||
{
|
{
|
||||||
QVariant v = property(key.toUtf8());
|
QVariant v = property(key.toUtf8());
|
||||||
@@ -353,6 +381,11 @@ void JsonFieldPage::Field::setIsCompleteExpando(const QVariant &v, const QString
|
|||||||
d->m_isCompleteExpandoMessage = m;
|
d->m_isCompleteExpandoMessage = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonFieldPage::Field::setPersistenceKey(const QString &key)
|
||||||
|
{
|
||||||
|
d->m_persistenceKey = key;
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// LabelFieldData:
|
// LabelFieldData:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -494,6 +527,7 @@ QWidget *LineEditField::createWidget(const QString &displayName, JsonFieldPage *
|
|||||||
w->setHistoryCompleter(m_historyId, m_restoreLastHistoryItem);
|
w->setHistoryCompleter(m_historyId, m_restoreLastHistoryItem);
|
||||||
|
|
||||||
w->setEchoMode(m_isPassword ? QLineEdit::Password : QLineEdit::Normal);
|
w->setEchoMode(m_isPassword ? QLineEdit::Password : QLineEdit::Normal);
|
||||||
|
QObject::connect(w, &FancyLineEdit::textEdited, [this] { setHasUserChanges(); });
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
@@ -551,6 +585,16 @@ void LineEditField::initializeData(MacroExpander *expander)
|
|||||||
m_isValidating = false;
|
m_isValidating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LineEditField::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_defaultText = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant LineEditField::toSettings() const
|
||||||
|
{
|
||||||
|
return qobject_cast<FancyLineEdit *>(widget())->text();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// TextEditFieldData:
|
// TextEditFieldData:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -585,6 +629,10 @@ QWidget *TextEditField::createWidget(const QString &displayName, JsonFieldPage *
|
|||||||
Q_UNUSED(page)
|
Q_UNUSED(page)
|
||||||
auto w = new QTextEdit;
|
auto w = new QTextEdit;
|
||||||
w->setAcceptRichText(m_acceptRichText);
|
w->setAcceptRichText(m_acceptRichText);
|
||||||
|
QObject::connect(w, &QTextEdit::textChanged, [this, w] {
|
||||||
|
if (w->toPlainText() != m_defaultText)
|
||||||
|
setHasUserChanges();
|
||||||
|
});
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,6 +670,16 @@ void TextEditField::initializeData(MacroExpander *expander)
|
|||||||
w->setPlainText(expander->expand(m_defaultText));
|
w->setPlainText(expander->expand(m_defaultText));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditField::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_defaultText = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant TextEditField::toSettings() const
|
||||||
|
{
|
||||||
|
return qobject_cast<QTextEdit *>(widget())->toPlainText();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// PathChooserFieldData:
|
// PathChooserFieldData:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -678,6 +736,10 @@ QWidget *PathChooserField::createWidget(const QString &displayName, JsonFieldPag
|
|||||||
auto w = new PathChooser;
|
auto w = new PathChooser;
|
||||||
if (!m_historyId.isEmpty())
|
if (!m_historyId.isEmpty())
|
||||||
w->setHistoryCompleter(m_historyId);
|
w->setHistoryCompleter(m_historyId);
|
||||||
|
QObject::connect(w, &PathChooser::pathChanged, [this, w] {
|
||||||
|
if (w->path() != m_path)
|
||||||
|
setHasUserChanges();
|
||||||
|
});
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,6 +782,16 @@ void PathChooserField::initializeData(MacroExpander *expander)
|
|||||||
w->setPath(m_currentPath);
|
w->setPath(m_currentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PathChooserField::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_path = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant PathChooserField::toSettings() const
|
||||||
|
{
|
||||||
|
return qobject_cast<PathChooser *>(widget())->path();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// CheckBoxFieldData:
|
// CheckBoxFieldData:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -770,6 +842,7 @@ void CheckBoxField::setup(JsonFieldPage *page, const QString &name)
|
|||||||
|
|
||||||
QObject::connect(w, &QCheckBox::stateChanged, page, [this, page]() {
|
QObject::connect(w, &QCheckBox::stateChanged, page, [this, page]() {
|
||||||
m_isModified = true;
|
m_isModified = true;
|
||||||
|
setHasUserChanges();
|
||||||
emit page->completeChanged();
|
emit page->completeChanged();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -795,6 +868,16 @@ void CheckBoxField::initializeData(MacroExpander *expander)
|
|||||||
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
w->setChecked(JsonWizard::boolFromVariant(m_checkedExpression, expander));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckBoxField::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_checkedExpression = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CheckBoxField::toSettings() const
|
||||||
|
{
|
||||||
|
return qobject_cast<QCheckBox *>(widget())->isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// ListFieldData:
|
// ListFieldData:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -958,7 +1041,7 @@ QStandardItemModel *ListField::itemModel()
|
|||||||
return m_itemModel;
|
return m_itemModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
QItemSelectionModel *ListField::selectionModel()
|
QItemSelectionModel *ListField::selectionModel() const
|
||||||
{
|
{
|
||||||
return m_selectionModel;
|
return m_selectionModel;
|
||||||
}
|
}
|
||||||
@@ -991,6 +1074,22 @@ void ListField::updateIndex()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListField::fromSettings(const QVariant &value)
|
||||||
|
{
|
||||||
|
for (decltype(m_itemList)::size_type i = 0; i < m_itemList.size(); ++i) {
|
||||||
|
if (m_itemList.at(i)->data(ValueRole) == value) {
|
||||||
|
m_index = int(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ListField::toSettings() const
|
||||||
|
{
|
||||||
|
const int idx = selectionModel()->currentIndex().row();
|
||||||
|
return idx >= 0 ? m_itemList.at(idx)->data(ValueRole) : QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
|
void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
|
||||||
{
|
{
|
||||||
auto w = qobject_cast<QComboBox*>(widget());
|
auto w = qobject_cast<QComboBox*>(widget());
|
||||||
@@ -1030,7 +1129,10 @@ void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
|
|||||||
|
|
||||||
QWidget *ComboBoxField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
QWidget *ComboBoxField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
||||||
{
|
{
|
||||||
return new QComboBox;
|
const auto comboBox = new QComboBox;
|
||||||
|
QObject::connect(comboBox, QOverload<int>::of(&QComboBox::activated),
|
||||||
|
[this] { setHasUserChanges(); });
|
||||||
|
return comboBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComboBoxField::initializeData(MacroExpander *expander)
|
void ComboBoxField::initializeData(MacroExpander *expander)
|
||||||
@@ -1068,7 +1170,10 @@ void IconListField::setup(JsonFieldPage *page, const QString &name)
|
|||||||
|
|
||||||
QWidget *IconListField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
QWidget *IconListField::createWidget(const QString & /*displayName*/, JsonFieldPage * /*page*/)
|
||||||
{
|
{
|
||||||
return new QListView;
|
const auto listView = new QListView;
|
||||||
|
QObject::connect(listView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
|
[this] { setHasUserChanges(); });
|
||||||
|
return listView;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconListField::initializeData(MacroExpander *expander)
|
void IconListField::initializeData(MacroExpander *expander)
|
||||||
@@ -1131,6 +1236,13 @@ bool JsonFieldPage::setup(const QVariant &data)
|
|||||||
if (!f)
|
if (!f)
|
||||||
continue;
|
continue;
|
||||||
f->createWidget(this);
|
f->createWidget(this);
|
||||||
|
if (!f->persistenceKey().isEmpty()) {
|
||||||
|
f->setPersistenceKey(m_expander->expand(f->persistenceKey()));
|
||||||
|
const QVariant value = Core::ICore::settings()
|
||||||
|
->value(fullSettingsKey(f->persistenceKey()));
|
||||||
|
if (value.isValid())
|
||||||
|
f->fromSettings(value);
|
||||||
|
}
|
||||||
m_fields.append(f);
|
m_fields.append(f);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1172,6 +1284,17 @@ void JsonFieldPage::cleanupPage()
|
|||||||
f->cleanup(m_expander);
|
f->cleanup(m_expander);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JsonFieldPage::validatePage()
|
||||||
|
{
|
||||||
|
for (Field * const f : qAsConst(m_fields))
|
||||||
|
if (!f->persistenceKey().isEmpty() && f->hasUserChanges()) {
|
||||||
|
const QVariant value = f->toSettings();
|
||||||
|
if (value.isValid())
|
||||||
|
Core::ICore::settings()->setValue(fullSettingsKey(f->persistenceKey()), value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void JsonFieldPage::showError(const QString &m) const
|
void JsonFieldPage::showError(const QString &m) const
|
||||||
{
|
{
|
||||||
m_errorLabel->setText(m);
|
m_errorLabel->setText(m);
|
||||||
@@ -1199,4 +1322,9 @@ JsonFieldPage::Field *JsonFieldPage::createFieldData(const QString &type)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString JsonFieldPage::fullSettingsKey(const QString &fieldKey)
|
||||||
|
{
|
||||||
|
return "Wizards/" + fieldKey;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -83,8 +83,10 @@ public:
|
|||||||
QString name();
|
QString name();
|
||||||
QString displayName();
|
QString displayName();
|
||||||
QString toolTip();
|
QString toolTip();
|
||||||
|
QString persistenceKey() const;
|
||||||
bool isMandatory();
|
bool isMandatory();
|
||||||
bool hasSpan();
|
bool hasSpan();
|
||||||
|
bool hasUserChanges() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QWidget *widget() const;
|
QWidget *widget() const;
|
||||||
@@ -95,8 +97,12 @@ public:
|
|||||||
{ Q_UNUSED(page); Q_UNUSED(name) }
|
{ Q_UNUSED(page); Q_UNUSED(name) }
|
||||||
|
|
||||||
QString type();
|
QString type();
|
||||||
|
void setHasUserChanges();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void fromSettings(const QVariant &value);
|
||||||
|
virtual QVariant toSettings() const;
|
||||||
|
|
||||||
void setTexts(const QString &n, const QString &dn, const QString &tt);
|
void setTexts(const QString &n, const QString &dn, const QString &tt);
|
||||||
void setIsMandatory(bool b);
|
void setIsMandatory(bool b);
|
||||||
void setHasSpan(bool b);
|
void setHasSpan(bool b);
|
||||||
@@ -104,6 +110,7 @@ public:
|
|||||||
void setVisibleExpression(const QVariant &v);
|
void setVisibleExpression(const QVariant &v);
|
||||||
void setEnabledExpression(const QVariant &v);
|
void setEnabledExpression(const QVariant &v);
|
||||||
void setIsCompleteExpando(const QVariant &v, const QString &m);
|
void setIsCompleteExpando(const QVariant &v, const QString &m);
|
||||||
|
void setPersistenceKey(const QString &key);
|
||||||
|
|
||||||
friend class JsonFieldPage;
|
friend class JsonFieldPage;
|
||||||
|
|
||||||
@@ -121,6 +128,7 @@ public:
|
|||||||
bool isComplete() const override;
|
bool isComplete() const override;
|
||||||
void initializePage() override;
|
void initializePage() override;
|
||||||
void cleanupPage() override;
|
void cleanupPage() override;
|
||||||
|
bool validatePage() override;
|
||||||
|
|
||||||
QFormLayout *layout() const { return m_formLayout; }
|
QFormLayout *layout() const { return m_formLayout; }
|
||||||
|
|
||||||
@@ -135,6 +143,7 @@ private:
|
|||||||
static QHash<QString, FieldFactory> m_factories;
|
static QHash<QString, FieldFactory> m_factories;
|
||||||
|
|
||||||
static Field *createFieldData(const QString &type);
|
static Field *createFieldData(const QString &type);
|
||||||
|
static QString fullSettingsKey(const QString &fieldKey);
|
||||||
|
|
||||||
QFormLayout *m_formLayout;
|
QFormLayout *m_formLayout;
|
||||||
QLabel *m_errorLabel;
|
QLabel *m_errorLabel;
|
||||||
|
@@ -57,11 +57,13 @@ public:
|
|||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
bool m_isMandatory = false;
|
bool m_isMandatory = false;
|
||||||
bool m_hasSpan = false;
|
bool m_hasSpan = false;
|
||||||
|
bool m_hasUserChanges = false;
|
||||||
|
|
||||||
QVariant m_visibleExpression;
|
QVariant m_visibleExpression;
|
||||||
QVariant m_enabledExpression;
|
QVariant m_enabledExpression;
|
||||||
QVariant m_isCompleteExpando;
|
QVariant m_isCompleteExpando;
|
||||||
QString m_isCompleteExpandoMessage;
|
QString m_isCompleteExpandoMessage;
|
||||||
|
QString m_persistenceKey;
|
||||||
|
|
||||||
QLabel *m_label = nullptr;
|
QLabel *m_label = nullptr;
|
||||||
QWidget *m_widget = nullptr;
|
QWidget *m_widget = nullptr;
|
||||||
@@ -106,6 +108,9 @@ private:
|
|||||||
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
||||||
void initializeData(Utils::MacroExpander *expander) override;
|
void initializeData(Utils::MacroExpander *expander) override;
|
||||||
|
|
||||||
|
void fromSettings(const QVariant &value) override;
|
||||||
|
QVariant toSettings() const override;
|
||||||
|
|
||||||
bool m_isModified = false;
|
bool m_isModified = false;
|
||||||
bool m_isValidating = false;
|
bool m_isValidating = false;
|
||||||
bool m_restoreLastHistoryItem = false;
|
bool m_restoreLastHistoryItem = false;
|
||||||
@@ -130,6 +135,9 @@ private:
|
|||||||
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
||||||
void initializeData(Utils::MacroExpander *expander) override;
|
void initializeData(Utils::MacroExpander *expander) override;
|
||||||
|
|
||||||
|
void fromSettings(const QVariant &value) override;
|
||||||
|
QVariant toSettings() const override;
|
||||||
|
|
||||||
QString m_defaultText;
|
QString m_defaultText;
|
||||||
bool m_acceptRichText = false;
|
bool m_acceptRichText = false;
|
||||||
QString m_disabledText;
|
QString m_disabledText;
|
||||||
@@ -150,6 +158,9 @@ private:
|
|||||||
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
||||||
void initializeData(Utils::MacroExpander *expander) override;
|
void initializeData(Utils::MacroExpander *expander) override;
|
||||||
|
|
||||||
|
void fromSettings(const QVariant &value) override;
|
||||||
|
QVariant toSettings() const override;
|
||||||
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
QString m_basePath;
|
QString m_basePath;
|
||||||
QString m_historyId;
|
QString m_historyId;
|
||||||
@@ -172,6 +183,8 @@ private:
|
|||||||
|
|
||||||
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
||||||
void initializeData(Utils::MacroExpander *expander) override;
|
void initializeData(Utils::MacroExpander *expander) override;
|
||||||
|
void fromSettings(const QVariant &value) override;
|
||||||
|
QVariant toSettings() const override;
|
||||||
|
|
||||||
QString m_checkedValue;
|
QString m_checkedValue;
|
||||||
QString m_uncheckedValue;
|
QString m_uncheckedValue;
|
||||||
@@ -200,7 +213,7 @@ public:
|
|||||||
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
bool validate(Utils::MacroExpander *expander, QString *message) override;
|
||||||
void initializeData(Utils::MacroExpander *expander) override;
|
void initializeData(Utils::MacroExpander *expander) override;
|
||||||
QStandardItemModel *itemModel();
|
QStandardItemModel *itemModel();
|
||||||
QItemSelectionModel *selectionModel();
|
QItemSelectionModel *selectionModel() const;
|
||||||
void setSelectionModel(QItemSelectionModel *selectionModel);
|
void setSelectionModel(QItemSelectionModel *selectionModel);
|
||||||
QSize maxIconSize();
|
QSize maxIconSize();
|
||||||
|
|
||||||
@@ -208,6 +221,9 @@ private:
|
|||||||
void addPossibleIconSize(const QIcon &icon);
|
void addPossibleIconSize(const QIcon &icon);
|
||||||
void updateIndex();
|
void updateIndex();
|
||||||
|
|
||||||
|
void fromSettings(const QVariant &value) override;
|
||||||
|
QVariant toSettings() const override;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<QStandardItem>> m_itemList;
|
std::vector<std::unique_ptr<QStandardItem>> m_itemList;
|
||||||
QStandardItemModel *m_itemModel = nullptr;
|
QStandardItemModel *m_itemModel = nullptr;
|
||||||
QItemSelectionModel *m_selectionModel = nullptr;
|
QItemSelectionModel *m_selectionModel = nullptr;
|
||||||
|
Reference in New Issue
Block a user