Commit edad1ba5 authored by Daniel Teske's avatar Daniel Teske

Project: Improve fromMap() error reporting interface

Instead of just a bool, return a tristate of: Ok, Error and UserAbort.
Also add a out parameter errorMessgge.

Change-Id: Icb076de49998e9372839d0631c2776e905e4a0f6
Task-number: QTCREATORBUG-13223
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@theqtcompany.com>
parent 2d12884f
...@@ -140,10 +140,11 @@ QStringList AutotoolsProject::files(FilesMode fileMode) const ...@@ -140,10 +140,11 @@ QStringList AutotoolsProject::files(FilesMode fileMode) const
// This function, is called at the very beginning, to // This function, is called at the very beginning, to
// restore the settings if there are some stored. // restore the settings if there are some stored.
bool AutotoolsProject::fromMap(const QVariantMap &map) Project::RestoreResult AutotoolsProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result != RestoreResult::Ok)
return result;
connect(m_fileWatcher, &Utils::FileSystemWatcher::fileChanged, connect(m_fileWatcher, &Utils::FileSystemWatcher::fileChanged,
this, &AutotoolsProject::onFileChanged); this, &AutotoolsProject::onFileChanged);
...@@ -155,7 +156,7 @@ bool AutotoolsProject::fromMap(const QVariantMap &map) ...@@ -155,7 +156,7 @@ bool AutotoolsProject::fromMap(const QVariantMap &map)
if (!activeTarget() && defaultKit) if (!activeTarget() && defaultKit)
addTarget(createTarget(defaultKit)); addTarget(createTarget(defaultKit));
return true; return RestoreResult::Ok;
} }
void AutotoolsProject::loadProjectTree() void AutotoolsProject::loadProjectTree()
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
QStringList buildTargets() const; QStringList buildTargets() const;
protected: protected:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
private slots: private slots:
/** /**
......
...@@ -506,16 +506,17 @@ QStringList CMakeProject::files(FilesMode fileMode) const ...@@ -506,16 +506,17 @@ QStringList CMakeProject::files(FilesMode fileMode) const
return m_files; return m_files;
} }
bool CMakeProject::fromMap(const QVariantMap &map) Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result != RestoreResult::Ok)
return result;
bool hasUserFile = activeTarget(); bool hasUserFile = activeTarget();
if (!hasUserFile) { if (!hasUserFile) {
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, projectDirectory().toString(), Environment::systemEnvironment()); CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, projectDirectory().toString(), Environment::systemEnvironment());
if (copw.exec() != QDialog::Accepted) if (copw.exec() != QDialog::Accepted)
return false; return RestoreResult::UserAbort;
Kit *k = copw.kit(); Kit *k = copw.kit();
Target *t = new Target(this, k); Target *t = new Target(this, k);
CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t)); CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t));
...@@ -542,8 +543,10 @@ bool CMakeProject::fromMap(const QVariantMap &map) ...@@ -542,8 +543,10 @@ bool CMakeProject::fromMap(const QVariantMap &map)
// We have a user file, but we could still be missing the cbp file // We have a user file, but we could still be missing the cbp file
// or simply run createXml with the saved settings // or simply run createXml with the saved settings
CMakeBuildConfiguration *activeBC = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration()); CMakeBuildConfiguration *activeBC = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!activeBC) if (!activeBC) {
return false; *errorMessage = tr("Internal Error: No build configuration found in settings file.");
return RestoreResult::Error;
}
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory().toString())); QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory().toString()));
QFileInfo cbpFileFi(cbpFile); QFileInfo cbpFileFi(cbpFile);
...@@ -557,7 +560,7 @@ bool CMakeProject::fromMap(const QVariantMap &map) ...@@ -557,7 +560,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
CMakeBuildInfo info(activeBC); CMakeBuildInfo info(activeBC);
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info); CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info);
if (copw.exec() != QDialog::Accepted) if (copw.exec() != QDialog::Accepted)
return false; return RestoreResult::UserAbort;
else else
activeBC->setUseNinja(copw.useNinja()); activeBC->setUseNinja(copw.useNinja());
} }
...@@ -573,7 +576,7 @@ bool CMakeProject::fromMap(const QVariantMap &map) ...@@ -573,7 +576,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)), connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
this, SLOT(activeTargetWasChanged(ProjectExplorer::Target*))); this, SLOT(activeTargetWasChanged(ProjectExplorer::Target*)));
return true; return RestoreResult::Ok;
} }
bool CMakeProject::setupTarget(Target *t) bool CMakeProject::setupTarget(Target *t)
......
...@@ -118,7 +118,7 @@ signals: ...@@ -118,7 +118,7 @@ signals:
void buildTargetsChanged(); void buildTargetsChanged();
protected: protected:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
bool setupTarget(ProjectExplorer::Target *t); bool setupTarget(ProjectExplorer::Target *t);
// called by CMakeBuildSettingsWidget // called by CMakeBuildSettingsWidget
......
...@@ -418,10 +418,11 @@ QStringList GenericProject::buildTargets() const ...@@ -418,10 +418,11 @@ QStringList GenericProject::buildTargets() const
return targets; return targets;
} }
bool GenericProject::fromMap(const QVariantMap &map) Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result != RestoreResult::Ok)
return result;
Kit *defaultKit = KitManager::defaultKit(); Kit *defaultKit = KitManager::defaultKit();
if (!activeTarget() && defaultKit) if (!activeTarget() && defaultKit)
...@@ -439,7 +440,7 @@ bool GenericProject::fromMap(const QVariantMap &map) ...@@ -439,7 +440,7 @@ bool GenericProject::fromMap(const QVariantMap &map)
} }
refresh(Everything); refresh(Everything);
return true; return RestoreResult::Ok;
} }
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
......
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
QStringList files() const; QStringList files() const;
protected: protected:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
private: private:
bool saveRawFileList(const QStringList &rawFileList); bool saveRawFileList(const QStringList &rawFileList);
......
...@@ -312,15 +312,15 @@ void Project::saveSettings() ...@@ -312,15 +312,15 @@ void Project::saveSettings()
d->m_accessor->saveSettings(toMap(), Core::ICore::mainWindow()); d->m_accessor->saveSettings(toMap(), Core::ICore::mainWindow());
} }
bool Project::restoreSettings() Project::RestoreResult Project::restoreSettings(QString *errorMessage)
{ {
if (!d->m_accessor) if (!d->m_accessor)
d->m_accessor = new Internal::UserFileAccessor(this); d->m_accessor = new Internal::UserFileAccessor(this);
QVariantMap map(d->m_accessor->restoreSettings(Core::ICore::mainWindow())); QVariantMap map(d->m_accessor->restoreSettings(Core::ICore::mainWindow()));
bool ok = fromMap(map); RestoreResult result = fromMap(map, errorMessage);
if (ok) if (result == RestoreResult::Ok)
emit settingsLoaded(); emit settingsLoaded();
return ok; return result;
} }
...@@ -364,7 +364,7 @@ Utils::FileName Project::projectDirectory(const Utils::FileName &top) ...@@ -364,7 +364,7 @@ Utils::FileName Project::projectDirectory(const Utils::FileName &top)
} }
bool Project::fromMap(const QVariantMap &map) Project::RestoreResult Project::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) { if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) {
QVariantMap values(map.value(QLatin1String(EDITOR_SETTINGS_KEY)).toMap()); QVariantMap values(map.value(QLatin1String(EDITOR_SETTINGS_KEY)).toMap());
...@@ -385,8 +385,9 @@ bool Project::fromMap(const QVariantMap &map) ...@@ -385,8 +385,9 @@ bool Project::fromMap(const QVariantMap &map)
for (int i = 0; i < maxI; ++i) { for (int i = 0; i < maxI; ++i) {
const QString key(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i)); const QString key(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i));
if (!map.contains(key)) { if (!map.contains(key)) {
qWarning() << key << "was not found in data."; if (errorMessage)
return false; *errorMessage = tr("Target key %1 was not found in project settings.").arg(key);
return RestoreResult::Error;
} }
QVariantMap targetMap = map.value(key).toMap(); QVariantMap targetMap = map.value(key).toMap();
...@@ -399,7 +400,7 @@ bool Project::fromMap(const QVariantMap &map) ...@@ -399,7 +400,7 @@ bool Project::fromMap(const QVariantMap &map)
setActiveTarget(t); setActiveTarget(t);
} }
return true; return RestoreResult::Ok;
} }
EditorConfiguration *Project::editorConfiguration() const EditorConfiguration *Project::editorConfiguration() const
......
...@@ -105,7 +105,8 @@ public: ...@@ -105,7 +105,8 @@ public:
Target *restoreTarget(const QVariantMap &data); Target *restoreTarget(const QVariantMap &data);
void saveSettings(); void saveSettings();
bool restoreSettings(); enum class RestoreResult { Ok, Error, UserAbort };
RestoreResult restoreSettings(QString *errorMessage);
virtual ProjectNode *rootProjectNode() const = 0; virtual ProjectNode *rootProjectNode() const = 0;
...@@ -168,7 +169,7 @@ signals: ...@@ -168,7 +169,7 @@ signals:
void projectLanguagesUpdated(); void projectLanguagesUpdated();
protected: protected:
virtual bool fromMap(const QVariantMap &map); virtual RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
virtual bool setupTarget(Target *t); virtual bool setupTarget(Target *t);
void setId(Core::Id id); void setId(Core::Id id);
......
...@@ -1725,14 +1725,16 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName ...@@ -1725,14 +1725,16 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
foundProjectManager = true; foundProjectManager = true;
QString tmp; QString tmp;
if (Project *pro = manager->openProject(filePath, &tmp)) { if (Project *pro = manager->openProject(filePath, &tmp)) {
if (pro->restoreSettings()) { QString restoreError;
Project::RestoreResult restoreResult = pro->restoreSettings(&restoreError);
if (restoreResult == Project::RestoreResult::Ok) {
connect(pro, &Project::fileListChanged, connect(pro, &Project::fileListChanged,
m_instance, &ProjectExplorerPlugin::fileListChanged); m_instance, &ProjectExplorerPlugin::fileListChanged);
SessionManager::addProject(pro); SessionManager::addProject(pro);
openedPro += pro; openedPro += pro;
} else { } else {
appendError(errorString, tr("Failed opening project \"%1\": Settings could not be restored.") if (restoreResult == Project::RestoreResult::Error)
.arg(QDir::toNativeSeparators(fileName))); appendError(errorString, restoreError);
delete pro; delete pro;
} }
} }
......
...@@ -603,10 +603,11 @@ void QbsProject::registerQbsProjectParser(QbsProjectParser *p) ...@@ -603,10 +603,11 @@ void QbsProject::registerQbsProjectParser(QbsProjectParser *p)
connect(m_qbsProjectParser, SIGNAL(done(bool)), this, SLOT(handleQbsParsingDone(bool))); connect(m_qbsProjectParser, SIGNAL(done(bool)), this, SLOT(handleQbsParsingDone(bool)));
} }
bool QbsProject::fromMap(const QVariantMap &map) Project::RestoreResult QbsProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result != RestoreResult::Ok)
return result;
Kit *defaultKit = KitManager::defaultKit(); Kit *defaultKit = KitManager::defaultKit();
if (!activeTarget() && defaultKit) { if (!activeTarget() && defaultKit) {
...@@ -617,7 +618,7 @@ bool QbsProject::fromMap(const QVariantMap &map) ...@@ -617,7 +618,7 @@ bool QbsProject::fromMap(const QVariantMap &map)
addTarget(t); addTarget(t);
} }
return true; return RestoreResult::Ok;
} }
void QbsProject::generateErrors(const qbs::ErrorInfo &e) void QbsProject::generateErrors(const qbs::ErrorInfo &e)
......
...@@ -129,7 +129,7 @@ private slots: ...@@ -129,7 +129,7 @@ private slots:
void startParsing(); void startParsing();
private: private:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
void parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir); void parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
......
...@@ -360,10 +360,11 @@ void QmakeProject::updateFileList() ...@@ -360,10 +360,11 @@ void QmakeProject::updateFileList()
} }
} }
bool QmakeProject::fromMap(const QVariantMap &map) Project::RestoreResult QmakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result != RestoreResult::Ok)
return result;
// Prune targets without buildconfigurations: // Prune targets without buildconfigurations:
// This can happen esp. when updating from a old version of Qt Creator // This can happen esp. when updating from a old version of Qt Creator
...@@ -390,7 +391,7 @@ bool QmakeProject::fromMap(const QVariantMap &map) ...@@ -390,7 +391,7 @@ bool QmakeProject::fromMap(const QVariantMap &map)
this, &QmakeProject::activeTargetWasChanged); this, &QmakeProject::activeTargetWasChanged);
scheduleAsyncUpdate(QmakeProFileNode::ParseNow); scheduleAsyncUpdate(QmakeProFileNode::ParseNow);
return true; return RestoreResult::Ok;
} }
/// equalFileList compares two file lists ignoring /// equalFileList compares two file lists ignoring
......
...@@ -153,7 +153,7 @@ public slots: ...@@ -153,7 +153,7 @@ public slots:
void scheduleAsyncUpdateLater() { scheduleAsyncUpdate(); } void scheduleAsyncUpdateLater() { scheduleAsyncUpdate(); }
protected: protected:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
private slots: private slots:
void asyncUpdate(); void asyncUpdate();
......
...@@ -343,10 +343,11 @@ QStringList QmlProject::files(FilesMode) const ...@@ -343,10 +343,11 @@ QStringList QmlProject::files(FilesMode) const
return files(); return files();
} }
bool QmlProject::fromMap(const QVariantMap &map) Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *errorMessage)
{ {
if (!Project::fromMap(map)) RestoreResult result = Project::fromMap(map, errorMessage);
return false; if (result == RestoreResult::Ok)
return result;
// refresh first - project information is used e.g. to decide the default RC's // refresh first - project information is used e.g. to decide the default RC's
refresh(Everything); refresh(Everything);
...@@ -407,7 +408,7 @@ bool QmlProject::fromMap(const QVariantMap &map) ...@@ -407,7 +408,7 @@ bool QmlProject::fromMap(const QVariantMap &map)
onActiveTargetChanged(activeTarget()); onActiveTargetChanged(activeTarget());
return true; return RestoreResult::Ok;
} }
} // namespace QmlProjectManager } // namespace QmlProjectManager
......
...@@ -102,7 +102,7 @@ private slots: ...@@ -102,7 +102,7 @@ private slots:
void addedRunConfiguration(ProjectExplorer::RunConfiguration *); void addedRunConfiguration(ProjectExplorer::RunConfiguration *);
protected: protected:
bool fromMap(const QVariantMap &map); RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
private: private:
// plain format // plain format
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment