forked from qt-creator/qt-creator
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 <alessandro.portale@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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,6 +289,7 @@ Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, I
|
||||
s_reopenData.reopen();
|
||||
});
|
||||
s_inspectWizardAction->setEnabled(true);
|
||||
if (showWizard)
|
||||
wizard->show();
|
||||
Core::ICore::registerWindow(wizard, Core::Context("Core.NewWizard"));
|
||||
} else {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <QIcon>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -71,6 +72,8 @@ public:
|
||||
QString descriptionImage() const { return m_descriptionImage; }
|
||||
QSet<Utils::Id> requiredFeatures() const { return m_requiredFeatures; }
|
||||
WizardFlags flags() const { return m_flags; }
|
||||
QUrl detailsPageQmlPath() const { return m_detailsPageQmlPath; }
|
||||
|
||||
QSet<Utils::Id> supportedProjectTypes() const { return m_supportedProjectTypes; }
|
||||
|
||||
void setId(const Utils::Id id) { m_id = id; }
|
||||
@@ -85,12 +88,13 @@ public:
|
||||
void setRequiredFeatures(const QSet<Utils::Id> &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<Utils::Id> supportedPlatforms() const;
|
||||
@@ -118,7 +122,7 @@ protected:
|
||||
static QSet<Utils::Id> 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<Utils::Id> m_requiredFeatures;
|
||||
QSet<Utils::Id> m_supportedProjectTypes;
|
||||
WizardFlags m_flags;
|
||||
|
@@ -701,6 +701,14 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
|
||||
}));
|
||||
}
|
||||
|
||||
void LineEditField::setText(const QString &text)
|
||||
{
|
||||
m_currentText = text;
|
||||
|
||||
auto w = qobject_cast<FancyLineEdit *>(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<QComboBox *>(widget());
|
||||
w->setCurrentIndex(row);
|
||||
}
|
||||
|
||||
int ComboBoxField::selectedRow() const
|
||||
{
|
||||
auto w = qobject_cast<QComboBox *>(widget());
|
||||
return w->currentIndex();
|
||||
}
|
||||
|
||||
void IconListField::setup(JsonFieldPage *page, const QString &name)
|
||||
{
|
||||
auto w = qobject_cast<QListView*>(widget());
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/wizardpage.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QVariant>
|
||||
@@ -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<QString, FieldFactory> m_factories;
|
||||
|
||||
|
@@ -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,6 +282,9 @@ public:
|
||||
ListField();
|
||||
~ListField() override;
|
||||
|
||||
QStandardItemModel *model() { return m_itemModel; }
|
||||
virtual void selectRow(int row);
|
||||
|
||||
protected:
|
||||
bool parseData(const QVariant &data, QString *errorMessage) override;
|
||||
|
||||
@@ -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
|
||||
|
@@ -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,6 +464,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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());
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user