forked from qt-creator/qt-creator
ProjectExplorer: FilePath-ify JsonWizardFactory
Change-Id: Ib56daffeb7e6eac3879e00e41812c699338e1fcb Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -106,7 +106,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyWizard()
|
|||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
const QJsonObject wizard = createGeneralWizard(QJsonObject());
|
const QJsonObject wizard = createGeneralWizard(QJsonObject());
|
||||||
|
|
||||||
const FactoryPtr factory(ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY(factory == nullptr);
|
QVERIFY(factory == nullptr);
|
||||||
QCOMPARE(qPrintable(errorMessage), "Page has no typeId set.");
|
QCOMPARE(qPrintable(errorMessage), "Page has no typeId set.");
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyPage()
|
|||||||
const QJsonObject pages = createFieldPageJsonObject(QJsonArray());
|
const QJsonObject pages = createFieldPageJsonObject(QJsonArray());
|
||||||
const QJsonObject wizard = createGeneralWizard(pages);
|
const QJsonObject wizard = createGeneralWizard(pages);
|
||||||
|
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY(factory == nullptr);
|
QVERIFY(factory == nullptr);
|
||||||
QCOMPARE(qPrintable(errorMessage), "When parsing fields of page \"PE.Wizard.Page.Fields\": ");
|
QCOMPARE(qPrintable(errorMessage), "When parsing fields of page \"PE.Wizard.Page.Fields\": ");
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsUnusedKeyAtFields()
|
|||||||
const QJsonObject wizard = createGeneralWizard(pages);
|
const QJsonObject wizard = createGeneralWizard(pages);
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("has unsupported keys: wrong"));
|
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("has unsupported keys: wrong"));
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY(factory);
|
QVERIFY(factory);
|
||||||
QVERIFY(errorMessage.isEmpty());
|
QVERIFY(errorMessage.isEmpty());
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsCheckBox()
|
|||||||
});
|
});
|
||||||
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
||||||
const QJsonObject wizardObject = createGeneralWizard(pages);
|
const QJsonObject wizardObject = createGeneralWizard(pages);
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY2(factory, qPrintable(errorMessage));
|
QVERIFY2(factory, qPrintable(errorMessage));
|
||||||
|
|
||||||
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
||||||
@@ -205,7 +205,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsLineEdit()
|
|||||||
});
|
});
|
||||||
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
||||||
const QJsonObject wizardObject = createGeneralWizard(pages);
|
const QJsonObject wizardObject = createGeneralWizard(pages);
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY2(factory, qPrintable(errorMessage));
|
QVERIFY2(factory, qPrintable(errorMessage));
|
||||||
|
|
||||||
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
||||||
@@ -234,7 +234,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsComboBox()
|
|||||||
|
|
||||||
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
||||||
const QJsonObject wizardObject = createGeneralWizard(pages);
|
const QJsonObject wizardObject = createGeneralWizard(pages);
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY2(factory, qPrintable(errorMessage));
|
QVERIFY2(factory, qPrintable(errorMessage));
|
||||||
Utils::Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
Utils::Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsIconList()
|
|||||||
|
|
||||||
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
const QJsonObject pages = createFieldPageJsonObject(widgets);
|
||||||
const QJsonObject wizardObject = createGeneralWizard(pages);
|
const QJsonObject wizardObject = createGeneralWizard(pages);
|
||||||
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
|
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), {}, &errorMessage));
|
||||||
QVERIFY2(factory, qPrintable(errorMessage));
|
QVERIFY2(factory, qPrintable(errorMessage));
|
||||||
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
|
||||||
|
|
||||||
|
@@ -217,8 +217,7 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QDir dir(path.toString());
|
if (!path.exists()) {
|
||||||
if (!dir.exists()) {
|
|
||||||
if (verbose())
|
if (verbose())
|
||||||
verboseLog.append(tr("Path \"%1\" does not exist when checking Json wizard search paths.\n")
|
verboseLog.append(tr("Path \"%1\" does not exist when checking Json wizard search paths.\n")
|
||||||
.arg(path.toUserOutput()));
|
.arg(path.toUserOutput()));
|
||||||
@@ -227,22 +226,19 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
|
|
||||||
const QDir::Filters filters = QDir::Dirs|QDir::Readable|QDir::NoDotAndDotDot;
|
const QDir::Filters filters = QDir::Dirs|QDir::Readable|QDir::NoDotAndDotDot;
|
||||||
const QDir::SortFlags sortflags = QDir::Name|QDir::IgnoreCase;
|
const QDir::SortFlags sortflags = QDir::Name|QDir::IgnoreCase;
|
||||||
QFileInfoList dirs = dir.entryInfoList(filters, sortflags);
|
FilePaths dirs = path.dirEntries({}, filters, sortflags);
|
||||||
|
|
||||||
while (!dirs.isEmpty()) {
|
while (!dirs.isEmpty()) {
|
||||||
const QFileInfo dirFi = dirs.takeFirst();
|
const FilePath currentDir = dirs.takeFirst();
|
||||||
const QDir current(dirFi.absoluteFilePath());
|
|
||||||
if (verbose())
|
if (verbose())
|
||||||
verboseLog.append(tr("Checking \"%1\" for %2.\n")
|
verboseLog.append(tr("Checking \"%1\" for %2.\n")
|
||||||
.arg(QDir::toNativeSeparators(current.absolutePath()))
|
.arg(currentDir.toUserOutput())
|
||||||
.arg(wizardFileName));
|
.arg(wizardFileName));
|
||||||
if (current.exists(wizardFileName)) {
|
const FilePath currentFile = currentDir / wizardFileName;
|
||||||
QFile configFile(current.absoluteFilePath(wizardFileName));
|
if (currentFile.exists()) {
|
||||||
configFile.open(QIODevice::ReadOnly);
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
const QByteArray fileData = configFile.readAll();
|
const QByteArray fileData = currentFile.fileContents();
|
||||||
const QJsonDocument json = QJsonDocument::fromJson(fileData, &error);
|
const QJsonDocument json = QJsonDocument::fromJson(fileData, &error);
|
||||||
configFile.close();
|
|
||||||
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
int line = 1;
|
int line = 1;
|
||||||
@@ -256,7 +252,7 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
verboseLog.append(tr("* Failed to parse \"%1\":%2:%3: %4\n")
|
verboseLog.append(tr("* Failed to parse \"%1\":%2:%3: %4\n")
|
||||||
.arg(configFile.fileName())
|
.arg(currentFile.fileName())
|
||||||
.arg(line).arg(column)
|
.arg(line).arg(column)
|
||||||
.arg(error.errorString()));
|
.arg(error.errorString()));
|
||||||
continue;
|
continue;
|
||||||
@@ -264,7 +260,7 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
|
|
||||||
if (!json.isObject()) {
|
if (!json.isObject()) {
|
||||||
verboseLog.append(tr("* Did not find a JSON object in \"%1\".\n")
|
verboseLog.append(tr("* Did not find a JSON object in \"%1\".\n")
|
||||||
.arg(configFile.fileName()));
|
.arg(currentFile.fileName()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +275,7 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonWizardFactory *factory = createWizardFactory(data, current, &errorMessage);
|
JsonWizardFactory *factory = createWizardFactory(data, currentDir, &errorMessage);
|
||||||
if (!factory) {
|
if (!factory) {
|
||||||
verboseLog.append(tr("* Failed to create: %1\n").arg(errorMessage));
|
verboseLog.append(tr("* Failed to create: %1\n").arg(errorMessage));
|
||||||
continue;
|
continue;
|
||||||
@@ -287,7 +283,7 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
|
|
||||||
result << factory;
|
result << factory;
|
||||||
} else {
|
} else {
|
||||||
QFileInfoList subDirs = current.entryInfoList(filters, sortflags);
|
FilePaths subDirs = currentDir.dirEntries({}, filters, sortflags);
|
||||||
if (!subDirs.isEmpty()) {
|
if (!subDirs.isEmpty()) {
|
||||||
// There is no QList::prepend(QList)...
|
// There is no QList::prepend(QList)...
|
||||||
dirs.swap(subDirs);
|
dirs.swap(subDirs);
|
||||||
@@ -307,7 +303,8 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data, const QDir &baseDir,
|
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
|
||||||
|
const FilePath &baseDir,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
auto *factory = new JsonWizardFactory;
|
auto *factory = new JsonWizardFactory;
|
||||||
@@ -381,7 +378,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const FilePath &path, QWidget *p
|
|||||||
wizard->setWindowIcon(icon());
|
wizard->setWindowIcon(icon());
|
||||||
wizard->setWindowTitle(displayName());
|
wizard->setWindowTitle(displayName());
|
||||||
|
|
||||||
wizard->setValue(QStringLiteral("WizardDir"), m_wizardDir);
|
wizard->setValue(QStringLiteral("WizardDir"), m_wizardDir.toVariant());
|
||||||
QSet<Utils::Id> tmp = requiredFeatures();
|
QSet<Utils::Id> tmp = requiredFeatures();
|
||||||
tmp.subtract(pluginFeatures());
|
tmp.subtract(pluginFeatures());
|
||||||
wizard->setValue(QStringLiteral("RequiredFeatures"), Utils::Id::toStringList(tmp));
|
wizard->setValue(QStringLiteral("RequiredFeatures"), Utils::Id::toStringList(tmp));
|
||||||
@@ -537,7 +534,7 @@ void JsonWizardFactory::destroyAllFactories()
|
|||||||
s_generatorFactories.clear();
|
s_generatorFactories.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir, QString *errorMessage)
|
bool JsonWizardFactory::initialize(const QVariantMap &data, const FilePath &baseDir, QString *errorMessage)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(errorMessage, return false);
|
QTC_ASSERT(errorMessage, return false);
|
||||||
|
|
||||||
@@ -582,29 +579,27 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
|
|||||||
setCategory(strVal);
|
setCategory(strVal);
|
||||||
|
|
||||||
strVal = data.value(QLatin1String(ICON_KEY)).toString();
|
strVal = data.value(QLatin1String(ICON_KEY)).toString();
|
||||||
if (!strVal.isEmpty()) {
|
const FilePath iconPath = baseDir.resolvePath(strVal);
|
||||||
strVal = baseDir.absoluteFilePath(strVal);
|
if (!iconPath.exists()) {
|
||||||
if (!QFileInfo::exists(strVal)) {
|
*errorMessage = tr("Icon file \"%1\" not found.").arg(iconPath.toUserOutput());
|
||||||
*errorMessage = tr("Icon file \"%1\" not found.").arg(QDir::toNativeSeparators(strVal));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const QString iconText = data.value(QLatin1String(ICON_TEXT_KEY)).toString();
|
const QString iconText = data.value(QLatin1String(ICON_TEXT_KEY)).toString();
|
||||||
setIcon(strVal.isEmpty() ? QIcon() : QIcon(strVal), iconText);
|
setIcon(strVal.isEmpty() ? QIcon() : QIcon(iconPath.toString()), iconText);
|
||||||
|
|
||||||
strVal = data.value(QLatin1String(IMAGE_KEY)).toString();
|
strVal = data.value(QLatin1String(IMAGE_KEY)).toString();
|
||||||
if (!strVal.isEmpty()) {
|
if (!strVal.isEmpty()) {
|
||||||
strVal = baseDir.absoluteFilePath(strVal);
|
const FilePath imagePath = baseDir.resolvePath(strVal);
|
||||||
if (!QFileInfo::exists(strVal)) {
|
if (!imagePath.exists()) {
|
||||||
*errorMessage = tr("Image file \"%1\" not found.").arg(QDir::toNativeSeparators(strVal));
|
*errorMessage = tr("Image file \"%1\" not found.").arg(imagePath.toUserOutput());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setDescriptionImage(strVal);
|
setDescriptionImage(imagePath.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
strVal = baseDir.absoluteFilePath("detailsPage.qml");
|
const FilePath detailsPage = baseDir.resolvePath(QString("detailsPage.qml"));
|
||||||
if (QFileInfo::exists(strVal))
|
if (detailsPage.exists())
|
||||||
setDetailsPageQmlPath(strVal);
|
setDetailsPageQmlPath(detailsPage.toString());
|
||||||
|
|
||||||
setRequiredFeatures(Utils::Id::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList()));
|
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 = Utils::Id::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList());
|
||||||
|
@@ -31,15 +31,10 @@
|
|||||||
|
|
||||||
#include <coreplugin/iwizardfactory.h>
|
#include <coreplugin/iwizardfactory.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QDir;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
class JsonWizardFactory;
|
class JsonWizardFactory;
|
||||||
@@ -94,7 +89,8 @@ private:
|
|||||||
// Create all wizards. As other plugins might register factories for derived
|
// Create all wizards. As other plugins might register factories for derived
|
||||||
// classes. Called when the new file dialog is shown for the first time.
|
// classes. Called when the new file dialog is shown for the first time.
|
||||||
static QList<IWizardFactory *> createWizardFactories();
|
static QList<IWizardFactory *> createWizardFactories();
|
||||||
static JsonWizardFactory *createWizardFactory(const QVariantMap &data, const QDir &baseDir,
|
static JsonWizardFactory *createWizardFactory(const QVariantMap &data,
|
||||||
|
const Utils::FilePath &baseDir,
|
||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
static Utils::FilePaths &searchPaths();
|
static Utils::FilePaths &searchPaths();
|
||||||
|
|
||||||
@@ -102,10 +98,10 @@ private:
|
|||||||
static int verbose();
|
static int verbose();
|
||||||
|
|
||||||
static void destroyAllFactories();
|
static void destroyAllFactories();
|
||||||
bool initialize(const QVariantMap &data, const QDir &baseDir, QString *errorMessage);
|
bool initialize(const QVariantMap &data, const Utils::FilePath &baseDir, QString *errorMessage);
|
||||||
|
|
||||||
QVariant m_enabledExpression;
|
QVariant m_enabledExpression;
|
||||||
QString m_wizardDir;
|
Utils::FilePath m_wizardDir;
|
||||||
QList<Generator> m_generators;
|
QList<Generator> m_generators;
|
||||||
|
|
||||||
QList<Page> m_pages;
|
QList<Page> m_pages;
|
||||||
|
Reference in New Issue
Block a user