From 42c16ff7d3a598ad77824871fe5d47847da9995d Mon Sep 17 00:00:00 2001 From: hjk <qthjk@ovi.com> Date: Tue, 15 Jan 2013 13:28:17 +0100 Subject: [PATCH] Core: Use the new Id methods in a few places There are a lot more left. Change-Id: I97d32629aa6deef0f4819f70cc0b8437f2814257 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com> --- .../actionmanager/actioncontainer.cpp | 5 +- .../actionmanager/actionmanager.cpp | 2 +- .../coreplugin/dialogs/settingsdialog.cpp | 2 +- src/plugins/coreplugin/documentmanager.cpp | 2 +- .../editormanager/editormanager.cpp | 12 ++--- src/plugins/coreplugin/icontext.cpp | 11 ---- src/plugins/coreplugin/icontext.h | 1 - src/plugins/coreplugin/id.cpp | 52 +++++++++++++++++-- src/plugins/coreplugin/id.h | 11 ++-- src/plugins/coreplugin/infobar.cpp | 2 +- src/plugins/coreplugin/modemanager.cpp | 2 +- src/plugins/coreplugin/navigationwidget.cpp | 2 +- src/plugins/cpptools/modelmanagertesthelper.h | 2 +- 13 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp index 751f3f7f1f6..ca40999dc3b 100644 --- a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp +++ b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp @@ -307,9 +307,8 @@ Command *ActionContainerPrivate::addSeparator(const Context &context, const Id & static int separatorIdCount = 0; QAction *separator = new QAction(this); separator->setSeparator(true); - Command *cmd = ActionManager::registerAction(separator, Id(QString::fromLatin1("%1.Separator.%2") - .arg(id().toString()).arg(++separatorIdCount)), - context); + Id sepId = id().withSuffix(".Separator.").withSuffix(++separatorIdCount); + Command *cmd = ActionManager::registerAction(separator, sepId, context); addAction(cmd, group); if (outSeparator) *outSeparator = separator; diff --git a/src/plugins/coreplugin/actionmanager/actionmanager.cpp b/src/plugins/coreplugin/actionmanager/actionmanager.cpp index 55430acae28..2eebd9a2d4d 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager.cpp +++ b/src/plugins/coreplugin/actionmanager/actionmanager.cpp @@ -566,7 +566,7 @@ void ActionManagerPrivate::initialize() for (int i = 0; i < shortcuts; ++i) { settings->setArrayIndex(i); const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString()); - const Id id = Id(settings->value(QLatin1String(idKey)).toString()); + const Id id = Id::fromSetting(settings->value(QLatin1String(idKey))); Command *cmd = ActionManager::command(id); if (cmd) diff --git a/src/plugins/coreplugin/dialogs/settingsdialog.cpp b/src/plugins/coreplugin/dialogs/settingsdialog.cpp index 518752a9f4f..0400407f998 100644 --- a/src/plugins/coreplugin/dialogs/settingsdialog.cpp +++ b/src/plugins/coreplugin/dialogs/settingsdialog.cpp @@ -334,7 +334,7 @@ void SettingsDialog::showPage(Id categoryId, Id pageId) QString initialPage = pageId.toString(); if (!initialCategory.isValid() && initialPage.isEmpty()) { QSettings *settings = ICore::settings(); - initialCategory = Id(settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString()); + initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC))); initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString(); } diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 59bd39936a8..fdcbcf6de71 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -1183,7 +1183,7 @@ void readSettings() editorId = ids.next(); if (QFileInfo(fileName).isFile()) d->m_recentFiles.append(DocumentManager::RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings - Id(editorId))); + Id::fromString(editorId))); } s->beginGroup(QLatin1String(directoryGroupC)); diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 64ede70b751..1a57cdcfb89 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1232,14 +1232,14 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName, //Unable to determine mime type of fileName. Falling back to text/plain", if (!mt) mt = ICore::mimeDatabase()->findByType(QLatin1String("text/plain")); - QStringList allEditorIds; + QList<Id> allEditorIds; QStringList allEditorDisplayNames; QList<Id> externalEditorIds; // Built-in const EditorFactoryList editors = editorFactories(mt, false); const int size = editors.size(); for (int i = 0; i < size; i++) { - allEditorIds.push_back(editors.at(i)->id().toString()); + allEditorIds.push_back(editors.at(i)->id()); allEditorDisplayNames.push_back(editors.at(i)->displayName()); } // External editors @@ -1247,7 +1247,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName, const int esize = exEditors.size(); for (int i = 0; i < esize; i++) { externalEditorIds.push_back(exEditors.at(i)->id()); - allEditorIds.push_back(exEditors.at(i)->id().toString()); + allEditorIds.push_back(exEditors.at(i)->id()); allEditorDisplayNames.push_back(exEditors.at(i)->displayName()); } if (allEditorIds.empty()) @@ -1259,7 +1259,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName, dialog.setCurrentEditor(0); if (dialog.exec() != QDialog::Accepted) return Id(); - const Id selectedId = Id(allEditorIds.at(dialog.editor())); + const Id selectedId = allEditorIds.at(dialog.editor()); if (isExternalEditor) *isExternalEditor = externalEditorIds.contains(selectedId); return selectedId; @@ -2019,9 +2019,9 @@ bool EditorManager::restoreState(const QByteArray &state) continue; QFileInfo rfi(autoSaveName(fileName)); if (rfi.exists() && fi.lastModified() < rfi.lastModified()) - openEditor(fileName, Id(QString::fromUtf8(id))); + openEditor(fileName, Id::fromName(id)); else - d->m_editorModel->addRestoredEditor(fileName, displayName, Id(QString::fromUtf8(id))); + d->m_editorModel->addRestoredEditor(fileName, displayName, Id::fromName(id)); } } diff --git a/src/plugins/coreplugin/icontext.cpp b/src/plugins/coreplugin/icontext.cpp index 236f7455f39..6114a3f1cbc 100644 --- a/src/plugins/coreplugin/icontext.cpp +++ b/src/plugins/coreplugin/icontext.cpp @@ -28,14 +28,3 @@ ****************************************************************************/ #include "icontext.h" - -#include <QString> - -namespace Core { - -Context::Context(const char *id, int offset) -{ - d.append(Id(QLatin1String(id) + QString::number(offset)).uniqueIdentifier()); -} - -} // namespace Core diff --git a/src/plugins/coreplugin/icontext.h b/src/plugins/coreplugin/icontext.h index e3395d8a5d5..9a43d96394f 100644 --- a/src/plugins/coreplugin/icontext.h +++ b/src/plugins/coreplugin/icontext.h @@ -48,7 +48,6 @@ public: explicit Context(Id c1) { add(c1); } Context(Id c1, Id c2) { add(c1); add(c2); } Context(Id c1, Id c2, Id c3) { add(c1); add(c2); add(c3); } - Context(const char *base, int offset); bool contains(Id c) const { return d.contains(c); } int size() const { return d.size(); } bool isEmpty() const { return d.isEmpty(); } diff --git a/src/plugins/coreplugin/id.cpp b/src/plugins/coreplugin/id.cpp index 3a9f38465fb..b947cb8229b 100644 --- a/src/plugins/coreplugin/id.cpp +++ b/src/plugins/coreplugin/id.cpp @@ -207,6 +207,8 @@ QString Id::toString() const This should not be used to handle a persistent version of the Id, use \c{fromSetting()} instead. + \deprecated + \sa toString(), fromSetting() */ @@ -215,6 +217,22 @@ Id Id::fromString(const QString &name) return Id(theId(name.toUtf8())); } +/*! + Creates an id from a string representation. + + This should not be used to handle a persistent version + of the Id, use \c{fromSetting()} instead. + + \deprecated + + \sa toString(), fromSetting() +*/ + +Id Id::fromName(const QByteArray &name) +{ + return Id(theId(name)); +} + /*! Returns a persistent value representing the id which is suitable to be stored in QSettings. @@ -239,15 +257,41 @@ Id Id::fromSetting(const QVariant &variant) return Id(theId(ba)); } -Id Id::withSuffix(Id id, int suffix) +/*! + Constructs a derived id. + + This can be used to construct groups of ids logically + belonging together. The associated internal name + will be generated by appending \c{suffix}. +*/ + +Id Id::withSuffix(int suffix) const +{ + const QByteArray ba = name() + QByteArray::number(suffix); + return Id(ba.constData()); +} + +/*! + \overload +*/ + +Id Id::withSuffix(const char *suffix) const { - const QByteArray ba = id.name() + QByteArray::number(suffix); + const QByteArray ba = name() + suffix; return Id(ba.constData()); } -Id Id::withSuffix(Id id, const char *suffix) +/*! + Constructs a derived id. + + This can be used to construct groups of ids logically + belonging together. The associated internal name + will be generated by prepending \c{prefix}. +*/ + +Id Id::withPrefix(const char *prefix) const { - const QByteArray ba = id.name() + suffix; + const QByteArray ba = prefix + name(); return Id(ba.constData()); } diff --git a/src/plugins/coreplugin/id.h b/src/plugins/coreplugin/id.h index e19f2336ad2..d2d3e93456e 100644 --- a/src/plugins/coreplugin/id.h +++ b/src/plugins/coreplugin/id.h @@ -47,9 +47,13 @@ public: Id() : m_id(0) {} Id(int uid) : m_id(uid) {} Id(const char *name); - explicit Id(const QByteArray &name); - // FIXME: Remove explicit Id(const QString &name); + explicit Id(const QByteArray &name); + + Id withSuffix(int suffix) const; + Id withSuffix(const char *name) const; + Id withPrefix(const char *name) const; + QByteArray name() const; QString toString() const; // Avoid. QVariant toSetting() const; // Good to use. @@ -63,9 +67,8 @@ public: int uniqueIdentifier() const { return m_id; } static Id fromUniqueIdentifier(int uid) { return Id(uid); } static Id fromString(const QString &str); // FIXME: avoid. + static Id fromName(const QByteArray &ba); // FIXME: avoid. static Id fromSetting(const QVariant &variant); // Good to use. - static Id withSuffix(Id base, int suffix); - static Id withSuffix(Id base, const char *name); static void registerId(int uid, const char *name); private: diff --git a/src/plugins/coreplugin/infobar.cpp b/src/plugins/coreplugin/infobar.cpp index 50257f03f68..38e20d275ad 100644 --- a/src/plugins/coreplugin/infobar.cpp +++ b/src/plugins/coreplugin/infobar.cpp @@ -143,7 +143,7 @@ void InfoBar::initializeGloballySuppressed() { QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList(); foreach (const QString &id, list) - globallySuppressed.insert(Id(id.toLatin1())); + globallySuppressed.insert(Id::fromString(id)); } void InfoBar::clearGloballySuppressed() diff --git a/src/plugins/coreplugin/modemanager.cpp b/src/plugins/coreplugin/modemanager.cpp index 583ce0cee63..e3c610ab523 100644 --- a/src/plugins/coreplugin/modemanager.cpp +++ b/src/plugins/coreplugin/modemanager.cpp @@ -198,7 +198,7 @@ void ModeManager::objectAdded(QObject *obj) d->m_modeStack->setTabEnabled(index, mode->isEnabled()); // Register mode shortcut - const Id shortcutId(QLatin1String("QtCreator.Mode.") + mode->id().toString()); + const Id shortcutId = mode->id().withPrefix("QtCreator.Mode."); QShortcut *shortcut = new QShortcut(d->m_mainWindow); shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName())); Command *cmd = ActionManager::registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL)); diff --git a/src/plugins/coreplugin/navigationwidget.cpp b/src/plugins/coreplugin/navigationwidget.cpp index 5c6fcb86b80..cfd699cc965 100644 --- a/src/plugins/coreplugin/navigationwidget.cpp +++ b/src/plugins/coreplugin/navigationwidget.cpp @@ -195,7 +195,7 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact d->m_shortcutMap.insert(shortcut, id); Command *cmd = ActionManager::registerShortcut(shortcut, - Id(QLatin1String("QtCreator.Sidebar.") + QLatin1String(id.name())), navicontext); + id.withPrefix("QtCreator.Sidebar."), navicontext); cmd->setDefaultKeySequence(factory->activationSequence()); d->m_commandMap.insert(id, cmd); diff --git a/src/plugins/cpptools/modelmanagertesthelper.h b/src/plugins/cpptools/modelmanagertesthelper.h index 5de107888d8..f0e1a2af299 100644 --- a/src/plugins/cpptools/modelmanagertesthelper.h +++ b/src/plugins/cpptools/modelmanagertesthelper.h @@ -49,7 +49,7 @@ public: { return m_name; } virtual Core::Id id() const - { return Core::Id(m_name); } + { return Core::Id::fromString(m_name); } virtual Core::IDocument *document() const { return 0; } -- GitLab