From b985530144da24f2aa1395aeb3982b934e4620a7 Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Mon, 6 Sep 2021 11:42:04 +0300 Subject: [PATCH] Make changes in the QtCreator side required for QDS new project dialog * We need the showing of the Wizard dialog to be optional * Each wizard has a "detailsPage.qml" file that stores wizard-specific UI configuration. We need a way to access that path (QUrl) from QDS. * ComboboxField is used directly by QDS, and the field object is fetched by a call to JsonFieldPage::jsonField() - hence, the ComboboxField needs to be dllexported. We need to access fields directly from QDS because the QML controls use those fields as backend. * From QDS we need to select / activate in a combobox field, and to see which item is current (activated). We also need to make use of the model that the ComboBoxField uses in order to show those same items in the qml controls of QDS. * From QDS we need to set the text in a LineEditField Task-number: QDS-4490 Change-Id: Ia42d539a5bcbf3dff4593fb027ac18c52da4d046 Reviewed-by: Alessandro Portale --- .../coreplugin/basefilewizardfactory.cpp | 4 ++- .../coreplugin/basefilewizardfactory.h | 2 +- src/plugins/coreplugin/iwizardfactory.cpp | 25 ++++++++++++++-- src/plugins/coreplugin/iwizardfactory.h | 9 ++++-- .../jsonwizard/jsonfieldpage.cpp | 30 +++++++++++++++++++ .../jsonwizard/jsonfieldpage.h | 8 +++++ .../jsonwizard/jsonfieldpage_p.h | 16 ++++++++-- .../jsonwizard/jsonwizardfactory.cpp | 9 ++++-- .../jsonwizard/jsonwizardfactory.h | 2 +- 9 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/plugins/coreplugin/basefilewizardfactory.cpp b/src/plugins/coreplugin/basefilewizardfactory.cpp index 48e5ed6a2a9..be88e636391 100644 --- a/src/plugins/coreplugin/basefilewizardfactory.cpp +++ b/src/plugins/coreplugin/basefilewizardfactory.cpp @@ -71,8 +71,10 @@ static int indexOfFile(const GeneratedFiles &f, const QString &path) Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Id platform, - const QVariantMap &extraValues) + const QVariantMap &extraValues, + bool showWizard) { + Q_UNUSED(showWizard); QTC_ASSERT(!path.isEmpty(), return nullptr); // Create dialog and run it. Ensure that the dialog is deleted when diff --git a/src/plugins/coreplugin/basefilewizardfactory.h b/src/plugins/coreplugin/basefilewizardfactory.h index 12e0f0d3195..7a2c3776be2 100644 --- a/src/plugins/coreplugin/basefilewizardfactory.h +++ b/src/plugins/coreplugin/basefilewizardfactory.h @@ -116,7 +116,7 @@ protected: private: // IWizard Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, - const QVariantMap &extraValues) override; + const QVariantMap &extraValues, bool showWizard = true) override; }; } // namespace Core diff --git a/src/plugins/coreplugin/iwizardfactory.cpp b/src/plugins/coreplugin/iwizardfactory.cpp index 2a5700d0fda..8b4940e5558 100644 --- a/src/plugins/coreplugin/iwizardfactory.cpp +++ b/src/plugins/coreplugin/iwizardfactory.cpp @@ -257,14 +257,17 @@ QString IWizardFactory::runPath(const QString &defaultPath) const created. The wizard should fill this in its path selection elements as a default path. */ -Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, Id platform, const QVariantMap &variables) +Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, Id platform, + const QVariantMap &variables, + bool showWizard) { QTC_ASSERT(!s_isWizardRunning, return nullptr); s_isWizardRunning = true; ICore::updateNewItemDialogState(); - Utils::Wizard *wizard = runWizardImpl(path, parent, platform, variables); + Utils::Wizard *wizard = runWizardImpl(path, parent, platform, variables, showWizard); + if (wizard) { s_currentWizard = wizard; @@ -286,7 +289,8 @@ Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, I s_reopenData.reopen(); }); s_inspectWizardAction->setEnabled(true); - wizard->show(); + if (showWizard) + wizard->show(); Core::ICore::registerWindow(wizard, Core::Context("Core.NewWizard")); } else { s_isWizardRunning = false; @@ -418,3 +422,18 @@ void IWizardFactory::initialize() s_inspectWizardAction = new QAction(tr("Inspect Wizard State"), ActionManager::instance()); ActionManager::registerAction(s_inspectWizardAction, "Wizard.Inspect"); } + +void IWizardFactory::setDetailsPageQmlPath(const QString &filePath) +{ + if (filePath.isEmpty()) + return; + + if (filePath.startsWith(':')) { + m_detailsPageQmlPath.setScheme(QLatin1String("qrc")); + QString path = filePath; + path.remove(0, 1); + m_detailsPageQmlPath.setPath(path); + } else { + m_detailsPageQmlPath = QUrl::fromLocalFile(filePath); + } +} diff --git a/src/plugins/coreplugin/iwizardfactory.h b/src/plugins/coreplugin/iwizardfactory.h index cc027eb7de4..b2b472aeb97 100644 --- a/src/plugins/coreplugin/iwizardfactory.h +++ b/src/plugins/coreplugin/iwizardfactory.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -71,6 +72,8 @@ public: QString descriptionImage() const { return m_descriptionImage; } QSet requiredFeatures() const { return m_requiredFeatures; } WizardFlags flags() const { return m_flags; } + QUrl detailsPageQmlPath() const { return m_detailsPageQmlPath; } + QSet supportedProjectTypes() const { return m_supportedProjectTypes; } void setId(const Utils::Id id) { m_id = id; } @@ -85,12 +88,13 @@ public: void setRequiredFeatures(const QSet &featureSet) { m_requiredFeatures = featureSet; } void addRequiredFeature(const Utils::Id &feature) { m_requiredFeatures |= feature; } void setFlags(WizardFlags flags) { m_flags = flags; } + void setDetailsPageQmlPath(const QString &filePath); QString runPath(const QString &defaultPath) const; // Does bookkeeping and the calls runWizardImpl. Please implement that. Utils::Wizard *runWizard(const QString &path, QWidget *parent, Utils::Id platform, - const QVariantMap &variables); + const QVariantMap &variables, bool showWizard = true); virtual bool isAvailable(Utils::Id platformId) const; QSet supportedPlatforms() const; @@ -118,7 +122,7 @@ protected: static QSet availableFeatures(Utils::Id platformId); virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, - const QVariantMap &variables) = 0; + const QVariantMap &variables, bool showWizard = true) = 0; private: static void initialize(); @@ -134,6 +138,7 @@ private: QString m_category; QString m_displayCategory; QString m_descriptionImage; + QUrl m_detailsPageQmlPath; QSet m_requiredFeatures; QSet m_supportedProjectTypes; WizardFlags m_flags; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index daaea5ffbf0..483b930d639 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -701,6 +701,14 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit) })); } +void LineEditField::setText(const QString &text) +{ + m_currentText = text; + + auto w = qobject_cast(widget()); + w->setText(m_currentText); +} + // -------------------------------------------------------------------- // TextEditFieldData: // -------------------------------------------------------------------- @@ -1145,6 +1153,14 @@ QStandardItemModel *ListField::itemModel() return m_itemModel; } +void ListField::selectRow(int row) +{ + auto index = itemModel()->index(row, 0); + selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); + + this->updateIndex(); +} + QItemSelectionModel *ListField::selectionModel() const { return m_selectionModel; @@ -1251,6 +1267,20 @@ QVariant ComboBoxField::toSettings() const return {}; } +void ComboBoxField::selectRow(int row) +{ + ListField::selectRow(row); + + auto w = qobject_cast(widget()); + w->setCurrentIndex(row); +} + +int ComboBoxField::selectedRow() const +{ + auto w = qobject_cast(widget()); + return w->currentIndex(); +} + void IconListField::setup(JsonFieldPage *page, const QString &name) { auto w = qobject_cast(widget()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h index 95b81713eae..8ee07366879 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -141,6 +142,13 @@ public: QVariant value(const QString &key); +public: + Field *jsonField(const QString &name) { + return Utils::findOr(m_fields, nullptr, [&name](Field *f) { + return f->name() == name; + }); + } + private: static QHash m_factories; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h index 97aaff4749d..f64ebd0b36a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage_p.h @@ -113,7 +113,7 @@ private: int m_factor = 1; }; -class LineEditField : public JsonFieldPage::Field +class PROJECTEXPLORER_EXPORT LineEditField : public JsonFieldPage::Field { private: bool parseData(const QVariant &data, QString *errorMessage) override; @@ -159,6 +159,9 @@ private: enum class Completion { Classes, Namespaces, None }; Completion m_completion = Completion::None; + +public: + void setText(const QString &text); }; class TextEditField : public JsonFieldPage::Field @@ -279,7 +282,10 @@ public: ListField(); ~ListField() override; - protected: + QStandardItemModel *model() { return m_itemModel; } + virtual void selectRow(int row); + +protected: bool parseData(const QVariant &data, QString *errorMessage) override; QWidget *createWidget(const QString &displayName, JsonFieldPage *page) override = 0; @@ -329,7 +335,7 @@ private: mutable int m_savedIndex = -1; }; -class ComboBoxField : public ListField +class PROJECTEXPLORER_EXPORT ComboBoxField : public ListField { private: void setup(JsonFieldPage *page, const QString &name) override; @@ -344,6 +350,10 @@ private: out << "ComboBox{" << ListField::toString() << "}"; return result; } + +public: + void selectRow(int row) override; + int selectedRow() const; }; class IconListField : public ListField diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp index 7a48be343b3..875636c3392 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp @@ -373,7 +373,7 @@ void JsonWizardFactory::registerGeneratorFactory(JsonWizardGeneratorFactory *fac Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, - const QVariantMap &variables) + const QVariantMap &variables, bool showWizard) { auto wizard = new JsonWizard(parent); wizard->setWindowIcon(icon()); @@ -464,7 +464,8 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa return nullptr; } - wizard->show(); + if (showWizard) + wizard->show(); return wizard; } @@ -602,6 +603,10 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir, setDescriptionImage(strVal); } + strVal = baseDir.absoluteFilePath("detailsPage.qml"); + if (QFileInfo::exists(strVal)) + setDetailsPageQmlPath(strVal); + setRequiredFeatures(Utils::Id::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList())); m_preferredFeatures = Utils::Id::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList()); m_preferredFeatures.unite(requiredFeatures()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h index 4d4ce62aa7a..e8865bfca4a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h @@ -89,7 +89,7 @@ public: private: Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, - const QVariantMap &variables) override; + const QVariantMap &variables, bool showWizard = true) override; // Create all wizards. As other plugins might register factories for derived // classes. Called when the new file dialog is shown for the first time.