diff options
author | hjk <qtc-committer@nokia.com> | 2011-09-02 12:45:36 +0200 |
---|---|---|
committer | hjk <qthjk@ovi.com> | 2011-09-05 15:28:46 +0200 |
commit | df2858bb6c1bf8024d7f655b79c06f9a0a228a23 (patch) | |
tree | 25e43631533db6383a08995edbf211de0ae3695e | |
parent | efa79035d4a6023cdcab18f6682d5961cca7dc12 (diff) | |
download | qt-creator-df2858bb6c1bf8024d7f655b79c06f9a0a228a23.tar.gz |
core: progress on the QString->QByteArray for Core::Id, remove UniqueIDManager
Change-Id: I94bec127866822b790a6e45a4201a7a5fe71d6ce
Reviewed-on: http://codereview.qt.nokia.com/4208
Reviewed-by: hjk <qthjk@ovi.com>
-rw-r--r-- | src/plugins/coreplugin/actionmanager/actionmanager.cpp | 63 | ||||
-rw-r--r-- | src/plugins/coreplugin/actionmanager/actionmanager_p.h | 3 | ||||
-rw-r--r-- | src/plugins/coreplugin/actionmanager/command.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/actionmanager/commandsfile.cpp | 8 | ||||
-rw-r--r-- | src/plugins/coreplugin/coreimpl.cpp | 5 | ||||
-rw-r--r-- | src/plugins/coreplugin/coreimpl.h | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/dialogs/shortcutsettings.cpp | 8 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.cpp | 7 | ||||
-rw-r--r-- | src/plugins/coreplugin/icore.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.cpp | 8 | ||||
-rw-r--r-- | src/plugins/coreplugin/mainwindow.h | 3 | ||||
-rw-r--r-- | src/plugins/coreplugin/uniqueidmanager.cpp | 58 | ||||
-rw-r--r-- | src/plugins/coreplugin/uniqueidmanager.h | 41 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 13 | ||||
-rw-r--r-- | src/plugins/help/helpplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/macros/actionmacrohandler.cpp | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 4 |
17 files changed, 85 insertions, 147 deletions
diff --git a/src/plugins/coreplugin/actionmanager/actionmanager.cpp b/src/plugins/coreplugin/actionmanager/actionmanager.cpp index 04424ec1e5..b428616007 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager.cpp +++ b/src/plugins/coreplugin/actionmanager/actionmanager.cpp @@ -274,10 +274,9 @@ bool ActionManagerPrivate::hasContext(int context) const QDebug operator<<(QDebug in, const Context &context) { - UniqueIDManager *uidm = UniqueIDManager::instance(); in << "CONTEXT: "; foreach (int c, context) - in << " " << c << uidm->stringForUniqueIdentifier(c); + in << " " << c << Id::fromUniqueIdentifier(c).toString(); return in; } @@ -303,13 +302,13 @@ bool ActionManagerPrivate::hasContext(const Context &context) const ActionContainer *ActionManagerPrivate::createMenu(const Id &id) { - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid); if (it != m_idContainerMap.constEnd()) return it.value(); QMenu *m = new QMenu(m_mainWnd); - m->setObjectName(id); + m->setObjectName(id.name()); MenuActionContainer *mc = new MenuActionContainer(uid); mc->setMenu(m); @@ -322,13 +321,13 @@ ActionContainer *ActionManagerPrivate::createMenu(const Id &id) ActionContainer *ActionManagerPrivate::createMenuBar(const Id &id) { - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid); if (it != m_idContainerMap.constEnd()) return it.value(); QMenuBar *mb = new QMenuBar; // No parent (System menu bar on Mac OS X) - mb->setObjectName(id); + mb->setObjectName(id.toString()); MenuBarActionContainer *mbc = new MenuBarActionContainer(uid); mbc->setMenuBar(mb); @@ -351,7 +350,7 @@ Command *ActionManagerPrivate::registerAction(QAction *action, const Id &id, con if (a) { a->addOverrideAction(action, context, scriptable); emit commandListChanged(); - emit commandAdded(id); + emit commandAdded(id.toString()); } return a; } @@ -359,18 +358,19 @@ Command *ActionManagerPrivate::registerAction(QAction *action, const Id &id, con Action *ActionManagerPrivate::overridableAction(const Id &id) { Action *a = 0; - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); if (CommandPrivate *c = m_idCmdMap.value(uid, 0)) { a = qobject_cast<Action *>(c); if (!a) { - qWarning() << "registerAction: id" << id << "is registered with a different command type."; + qWarning() << "registerAction: id" << id.name() + << "is registered with a different command type."; return 0; } } else { a = new Action(uid); m_idCmdMap.insert(uid, a); m_mainWnd->addAction(a->action()); - a->action()->setObjectName(id); + a->action()->setObjectName(id.toString()); a->action()->setShortcutContext(Qt::ApplicationShortcut); a->setCurrentContext(m_context); } @@ -381,12 +381,13 @@ Action *ActionManagerPrivate::overridableAction(const Id &id) void ActionManagerPrivate::unregisterAction(QAction *action, const Id &id) { Action *a = 0; - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); CommandPrivate *c = m_idCmdMap.value(uid, 0); QTC_ASSERT(c, return); a = qobject_cast<Action *>(c); if (!a) { - qWarning() << "unregisterAction: id" << id << "is registered with a different command type."; + qWarning() << "unregisterAction: id" << id.name() + << "is registered with a different command type."; return; } a->removeOverrideAction(action); @@ -404,11 +405,12 @@ void ActionManagerPrivate::unregisterAction(QAction *action, const Id &id) Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &id, const Context &context, bool scriptable) { Shortcut *sc = 0; - int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); if (CommandPrivate *c = m_idCmdMap.value(uid, 0)) { sc = qobject_cast<Shortcut *>(c); if (!sc) { - qWarning() << "registerShortcut: id" << id << "is registered with a different command type."; + qWarning() << "registerShortcut: id" << id.name() + << "is registered with a different command type."; return c; } } else { @@ -417,13 +419,13 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &i } if (sc->shortcut()) { - qWarning() << "registerShortcut: action already registered (id" << id << "."; + qWarning() << "registerShortcut: action already registered, id" << id.name() << "."; return sc; } if (!hasContext(context)) shortcut->setEnabled(false); - shortcut->setObjectName(id); + shortcut->setObjectName(id.toString()); shortcut->setParent(m_mainWnd); sc->setShortcut(shortcut); sc->setScriptable(scriptable); @@ -434,17 +436,18 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &i sc->setContext(context); emit commandListChanged(); - emit commandAdded(id); + emit commandAdded(id.toString()); return sc; } Command *ActionManagerPrivate::command(const Id &id) const { - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); const IdCmdMap::const_iterator it = m_idCmdMap.constFind(uid); if (it == m_idCmdMap.constEnd()) { if (warnAboutFindFailures) - qWarning() << "ActionManagerPrivate::command(): failed to find :" << id << '/' << uid; + qWarning() << "ActionManagerPrivate::command(): failed to find :" + << id.name() << '/' << uid; return 0; } return it.value(); @@ -452,11 +455,12 @@ Command *ActionManagerPrivate::command(const Id &id) const ActionContainer *ActionManagerPrivate::actionContainer(const Id &id) const { - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid); if (it == m_idContainerMap.constEnd()) { if (warnAboutFindFailures) - qWarning() << "ActionManagerPrivate::actionContainer(): failed to find :" << id << '/' << uid; + qWarning() << "ActionManagerPrivate::actionContainer(): failed to find :" + << id.name() << '/' << uid; return 0; } return it.value(); @@ -467,7 +471,8 @@ Command *ActionManagerPrivate::command(int uid) const const IdCmdMap::const_iterator it = m_idCmdMap.constFind(uid); if (it == m_idCmdMap.constEnd()) { if (warnAboutFindFailures) - qWarning() << "ActionManagerPrivate::command(): failed to find :" << UniqueIDManager::instance()->stringForUniqueIdentifier(uid) << '/' << uid; + qWarning() << "ActionManagerPrivate::command(): failed to find :" + << Id::fromUniqueIdentifier(uid).toString() << '/' << uid; return 0; } return it.value(); @@ -478,7 +483,8 @@ ActionContainer *ActionManagerPrivate::actionContainer(int uid) const const IdContainerMap::const_iterator it = m_idContainerMap.constFind(uid); if (it == m_idContainerMap.constEnd()) { if (warnAboutFindFailures) - qWarning() << "ActionManagerPrivate::actionContainer(): failed to find :" << UniqueIDManager::instance()->stringForUniqueIdentifier(uid) << uid; + qWarning() << "ActionManagerPrivate::actionContainer(): failed to find :" + << Id::fromUniqueIdentifier(uid).toString() << uid; return 0; } return it.value(); @@ -492,11 +498,11 @@ void ActionManagerPrivate::initialize() { QSettings *settings = Core::ICore::instance()->settings(); const int shortcuts = settings->beginReadArray(QLatin1String(settingsGroup)); - for (int i=0; i<shortcuts; ++i) { + for (int i = 0; i < shortcuts; ++i) { settings->setArrayIndex(i); const QString sid = settings->value(QLatin1String(idKey)).toString(); const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString()); - const int id = UniqueIDManager::instance()->uniqueIdentifier(sid); + const int id = Id(sid).uniqueIdentifier(); Command *cmd = command(id); if (cmd) @@ -516,7 +522,7 @@ void ActionManagerPrivate::saveSettings(QSettings *settings) CommandPrivate *cmd = j.value(); QKeySequence key = cmd->keySequence(); if (key != cmd->defaultKeySequence()) { - const QString sid = UniqueIDManager::instance()->stringForUniqueIdentifier(id); + const QString sid = Id::fromUniqueIdentifier(id).toString(); settings->setArrayIndex(count); settings->setValue(QLatin1String(idKey), sid); settings->setValue(QLatin1String(sequenceKey), key.toString()); @@ -530,12 +536,13 @@ void ActionManagerPrivate::saveSettings(QSettings *settings) void ActionManagerPrivate::unregisterShortcut(const Core::Id &id) { Shortcut *sc = 0; - const int uid = UniqueIDManager::instance()->uniqueIdentifier(id); + const int uid = id.uniqueIdentifier(); CommandPrivate *c = m_idCmdMap.value(uid, 0); QTC_ASSERT(c, return); sc = qobject_cast<Shortcut *>(c); if (!sc) { - qWarning() << "unregisterShortcut: id" << id << "is registered with a different command type."; + qWarning() << "unregisterShortcut: id" << id.name() + << "is registered with a different command type."; return; } delete sc->shortcut(); diff --git a/src/plugins/coreplugin/actionmanager/actionmanager_p.h b/src/plugins/coreplugin/actionmanager/actionmanager_p.h index fa6736b8d8..537aaec027 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager_p.h +++ b/src/plugins/coreplugin/actionmanager/actionmanager_p.h @@ -47,9 +47,6 @@ class QSettings; QT_END_NAMESPACE namespace Core { - -class UniqueIDManager; - namespace Internal { class ActionContainerPrivate; diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp index fe8a3a9620..8749e2973c 100644 --- a/src/plugins/coreplugin/actionmanager/command.cpp +++ b/src/plugins/coreplugin/actionmanager/command.cpp @@ -435,7 +435,7 @@ void Action::updateActiveState() setActive(m_action->isEnabled() && m_action->isVisible() && !m_action->isSeparator()); } -static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAction) +static QString msgActionWarning(QAction *newAction, int k, QAction *oldAction) { QString msg; QTextStream str(&msg); @@ -444,7 +444,7 @@ static inline QString msgActionWarning(QAction *newAction, int k, QAction *oldAc if (oldAction) str << oldAction->objectName() << '/' << oldAction->text(); str << " is already registered for context " << k << ' ' - << Core::ICore::instance()->uniqueIDManager()->stringForUniqueIdentifier(k) + << Core::Id::fromUniqueIdentifier(k).toString() << '.'; return msg; } diff --git a/src/plugins/coreplugin/actionmanager/commandsfile.cpp b/src/plugins/coreplugin/actionmanager/commandsfile.cpp index 4554702c9f..f504e38b03 100644 --- a/src/plugins/coreplugin/actionmanager/commandsfile.cpp +++ b/src/plugins/coreplugin/actionmanager/commandsfile.cpp @@ -135,8 +135,6 @@ QMap<QString, QKeySequence> CommandsFile::importCommands() const bool CommandsFile::exportCommands(const QList<ShortcutItem *> &items) { - const UniqueIDManager *idmanager = UniqueIDManager::instance(); - Utils::FileSaver saver(m_filename, QIODevice::Text); if (!saver.hasError()) { const Context ctx; @@ -150,13 +148,13 @@ bool CommandsFile::exportCommands(const QList<ShortcutItem *> &items) QDateTime::currentDateTime().toString(Qt::ISODate))); w.writeStartElement(ctx.mappingElement); foreach (const ShortcutItem *item, items) { - const QString id = idmanager->stringForUniqueIdentifier(item->m_cmd->id()); + const Id id = Id::fromUniqueIdentifier(item->m_cmd->id()); if (item->m_key.isEmpty()) { w.writeEmptyElement(ctx.shortCutElement); - w.writeAttribute(ctx.idAttribute, id); + w.writeAttribute(ctx.idAttribute, id.toString()); } else { w.writeStartElement(ctx.shortCutElement); - w.writeAttribute(ctx.idAttribute, id); + w.writeAttribute(ctx.idAttribute, id.toString()); w.writeEmptyElement(ctx.keyElement); w.writeAttribute(ctx.valueAttribute, item->m_key.toString()); w.writeEndElement(); // Shortcut diff --git a/src/plugins/coreplugin/coreimpl.cpp b/src/plugins/coreplugin/coreimpl.cpp index 5c76855308..c0342a28c9 100644 --- a/src/plugins/coreplugin/coreimpl.cpp +++ b/src/plugins/coreplugin/coreimpl.cpp @@ -102,11 +102,6 @@ FileManager *CoreImpl::fileManager() const return m_mainwindow->fileManager(); } -UniqueIDManager *CoreImpl::uniqueIDManager() const -{ - return m_mainwindow->uniqueIDManager(); -} - MessageManager *CoreImpl::messageManager() const { return m_mainwindow->messageManager(); diff --git a/src/plugins/coreplugin/coreimpl.h b/src/plugins/coreplugin/coreimpl.h index 41419c6169..27ebae2df3 100644 --- a/src/plugins/coreplugin/coreimpl.h +++ b/src/plugins/coreplugin/coreimpl.h @@ -61,7 +61,6 @@ public: ActionManager *actionManager() const; FileManager *fileManager() const ; - UniqueIDManager *uniqueIDManager() const; MessageManager *messageManager() const; EditorManager *editorManager() const; ProgressManager *progressManager() const; diff --git a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp index 49efe23fa5..8c6c104164 100644 --- a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp +++ b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp @@ -218,8 +218,6 @@ void ShortcutSettings::removeTargetIdentifier() void ShortcutSettings::importAction() { - UniqueIDManager *uidm = UniqueIDManager::instance(); - QString fileName = QFileDialog::getOpenFileName(0, tr("Import Keyboard Mapping Scheme"), ICore::instance()->resourcePath() + "/schemes/", tr("Keyboard Mapping Scheme (*.kms)")); @@ -229,7 +227,7 @@ void ShortcutSettings::importAction() QMap<QString, QKeySequence> mapping = cf.importCommands(); foreach (ShortcutItem *item, m_scitems) { - QString sid = uidm->stringForUniqueIdentifier(item->m_cmd->id()); + QString sid = Id::fromUniqueIdentifier(item->m_cmd->id()).toString(); if (mapping.contains(sid)) { item->m_key = mapping.value(sid); item->m_item->setText(2, item->m_key); @@ -294,8 +292,6 @@ void ShortcutSettings::initialize() return; clear(); Core::Internal::ActionManagerPrivate *am = ActionManagerPrivate::instance(); - UniqueIDManager *uidm = UniqueIDManager::instance(); - QMap<QString, QTreeWidgetItem *> sections; foreach (Command *c, am->commands()) { @@ -311,7 +307,7 @@ void ShortcutSettings::initialize() s->m_cmd = c; s->m_item = item; - const QString identifier = uidm->stringForUniqueIdentifier(c->id()); + const QString identifier = Id::fromUniqueIdentifier(c->id()).toString(); int pos = identifier.indexOf(QLatin1Char('.')); const QString section = identifier.left(pos); const QString subId = identifier.mid(pos+1); diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index 41cb7c7015..49200de30a 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -110,13 +110,6 @@ */ /*! - \fn UniqueIDManager *ICore::uniqueIDManager() const - \brief Returns the application's id manager. - - The unique ID manager transforms strings in unique integers and the other way round. -*/ - -/*! \fn MessageManager *ICore::messageManager() const \brief Returns the application's message manager. diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h index c8a03fa254..2ccd05936b 100644 --- a/src/plugins/coreplugin/icore.h +++ b/src/plugins/coreplugin/icore.h @@ -60,7 +60,6 @@ class ModeManager; class ProgressManager; class ScriptManager; class SettingsDatabase; -class UniqueIDManager; class VariableManager; class VcsManager; @@ -90,7 +89,6 @@ public: virtual ActionManager *actionManager() const = 0; virtual FileManager *fileManager() const = 0; - virtual UniqueIDManager *uniqueIDManager() const = 0; virtual MessageManager *messageManager() const = 0; virtual EditorManager *editorManager() const = 0; virtual ProgressManager *progressManager() const = 0; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 8d105922e9..95f0e31046 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -127,7 +127,6 @@ enum { debugMainWindow = 0 }; MainWindow::MainWindow() : EventFilteringMainWindow(), m_coreImpl(new CoreImpl(this)), - m_uniqueIDManager(new UniqueIDManager()), m_additionalContexts(Constants::C_GLOBAL), m_settings(ExtensionSystem::PluginManager::instance()->settings()), m_globalSettings(new QSettings(QSettings::IniFormat, QSettings::SystemScope, @@ -280,8 +279,6 @@ MainWindow::~MainWindow() m_settings = 0; delete m_printer; m_printer = 0; - delete m_uniqueIDManager; - m_uniqueIDManager = 0; delete m_vcsManager; m_vcsManager = 0; //we need to delete editormanager and statusbarmanager explicitly before the end of the destructor, @@ -1027,11 +1024,6 @@ FileManager *MainWindow::fileManager() const return m_fileManager; } -UniqueIDManager *MainWindow::uniqueIDManager() const -{ - return m_uniqueIDManager; -} - MessageManager *MainWindow::messageManager() const { return m_messageManager; diff --git a/src/plugins/coreplugin/mainwindow.h b/src/plugins/coreplugin/mainwindow.h index 2a189de8db..9109e9619f 100644 --- a/src/plugins/coreplugin/mainwindow.h +++ b/src/plugins/coreplugin/mainwindow.h @@ -64,7 +64,6 @@ class NavigationWidget; class RightPaneWidget; class ScriptManager; class SettingsDatabase; -class UniqueIDManager; class VariableManager; class VcsManager; @@ -103,7 +102,6 @@ public: Core::ActionManager *actionManager() const; Core::FileManager *fileManager() const; - Core::UniqueIDManager *uniqueIDManager() const; Core::MessageManager *messageManager() const; Core::EditorManager *editorManager() const; Core::ProgressManager *progressManager() const; @@ -180,7 +178,6 @@ private: void writeSettings(); CoreImpl *m_coreImpl; - UniqueIDManager *m_uniqueIDManager; Context m_additionalContexts; QSettings *m_settings; QSettings *m_globalSettings; diff --git a/src/plugins/coreplugin/uniqueidmanager.cpp b/src/plugins/coreplugin/uniqueidmanager.cpp index 9f347d9400..dc5e1e1667 100644 --- a/src/plugins/coreplugin/uniqueidmanager.cpp +++ b/src/plugins/coreplugin/uniqueidmanager.cpp @@ -32,61 +32,57 @@ #include "uniqueidmanager.h" #include "coreconstants.h" +#include "icontext.h" -using namespace Core; +#include <QtCore/QHash> -UniqueIDManager *UniqueIDManager::m_instance = 0; +namespace Core { -UniqueIDManager::UniqueIDManager() -{ - m_instance = this; -} +/*! + \class Core::Id -UniqueIDManager::~UniqueIDManager() -{ - m_instance = 0; -} + \brief The class Id encapsulates an identifier. It is used as a type-safe + helper class instead of a \c QString or \c QByteArray. The internal + representation of the id is assumed to be plain 7-bit-clean ASCII. + +*/ + +uint qHash(const Core::Id &id) { return qHash(id.name()); } -bool UniqueIDManager::hasUniqueIdentifier(const Id &id) const +static QHash<Core::Id, int> &theUniqueIdentifiers() { - return m_uniqueIdentifiers.contains(id); + static QHash<Core::Id, int> data; + return data; } -int UniqueIDManager::uniqueIdentifier(const Id &id) +int Id::uniqueIdentifier() const { - if (hasUniqueIdentifier(id)) - return m_uniqueIdentifiers.value(id); + if (theUniqueIdentifiers().contains(*this)) + return theUniqueIdentifiers().value(*this); - int uid = m_uniqueIdentifiers.count() + 1; - m_uniqueIdentifiers.insert(id, uid); + const int uid = theUniqueIdentifiers().count() + 1; + theUniqueIdentifiers().insert(*this, uid); return uid; } -QString UniqueIDManager::stringForUniqueIdentifier(int uid) const +Id Id::fromUniqueIdentifier(int uid) { - return m_uniqueIdentifiers.key(uid); -} - -// FIXME: Move to some better place. -#include "icontext.h" - -static int toId(const char *id) -{ - return UniqueIDManager::instance()->uniqueIdentifier(id); + return theUniqueIdentifiers().key(uid); } Context::Context(const char *id, int offset) { - d.append(UniqueIDManager::instance() - -> uniqueIdentifier(Id(QString(id) + QString::number(offset)))); + d.append(Id(QString(id) + QString::number(offset)).uniqueIdentifier()); } void Context::add(const char *id) { - d.append(toId(id)); + d.append(Id(id).uniqueIdentifier()); } bool Context::contains(const char *id) const { - return d.contains(toId(id)); + return d.contains(Id(id).uniqueIdentifier()); } + +} // namespace Core diff --git a/src/plugins/coreplugin/uniqueidmanager.h b/src/plugins/coreplugin/uniqueidmanager.h index 35e60caa8b..fbf78c2b96 100644 --- a/src/plugins/coreplugin/uniqueidmanager.h +++ b/src/plugins/coreplugin/uniqueidmanager.h @@ -36,56 +36,31 @@ #include "core_global.h" #include <QtCore/QString> -#include <QtCore/QHash> namespace Core { -// FIXME: The intention is to use this class instead of the -// generic QString to identify actions. - class CORE_EXPORT Id { public: Id() {} - Id(const char *name) : m_name(QLatin1String(name)) {} - // FIXME: Replace with QByteArray - Id(const QString &name) : m_name(name) {} - // FIXME: Remove. - operator QString() const { return m_name; } + Id(const char *name) : m_name(name) {} // FIXME: Replace with QByteArray - QString name() const { return m_name; } + Id(const QString &name) : m_name(name.toLatin1()) {} + QByteArray name() const { return m_name; } + QString toString() const { return QString::fromLatin1(m_name); } bool isValid() const { return !m_name.isEmpty(); } bool operator==(const Id &id) const { return m_name == id.m_name; } bool operator!=(const Id &id) const { return m_name != id.m_name; } + int uniqueIdentifier() const; + static Id fromUniqueIdentifier(int uid); private: // Intentionally unimplemented Id(const QLatin1String &); - // FIXME: Replace with QByteArray - QString m_name; + QByteArray m_name; }; -inline uint qHash(const Id &id) -{ - return qHash(id.name()); -} - -class CORE_EXPORT UniqueIDManager -{ -public: - UniqueIDManager(); - ~UniqueIDManager(); - - static UniqueIDManager *instance() { return m_instance; } - - bool hasUniqueIdentifier(const Id &id) const; - int uniqueIdentifier(const Id &id); - QString stringForUniqueIdentifier(int uid) const; - -private: - QHash<Id, int> m_uniqueIdentifiers; - static UniqueIDManager *m_instance; -}; +uint qHash(const Id &id); } // namespace Core diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 9924d09bc7..46140c3828 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -380,8 +380,6 @@ void FakeVimExCommandsPage::initialize() { ActionManager *am = ICore::instance()->actionManager(); QTC_ASSERT(am, return); - UniqueIDManager *uidm = UniqueIDManager::instance(); - QTC_ASSERT(uidm, return); QMap<QString, QTreeWidgetItem *> sections; @@ -392,7 +390,7 @@ void FakeVimExCommandsPage::initialize() QTreeWidgetItem *item = new QTreeWidgetItem; item->setData(0, CommandRole, int(c->id())); - const QString name = uidm->stringForUniqueIdentifier(c->id()); + const QString name = Id::fromUniqueIdentifier(c->id()).toString(); const int pos = name.indexOf(QLatin1Char('.')); const QString section = name.left(pos); const QString subId = name.mid(pos + 1); @@ -445,9 +443,8 @@ void FakeVimExCommandsPage::targetIdentifierChanged() if (!current) return; - UniqueIDManager *uidm = UniqueIDManager::instance(); int id = current->data(0, CommandRole).toInt(); - const QString name = uidm->stringForUniqueIdentifier(id); + const QString name = Id::fromUniqueIdentifier(id).toString(); const QString regex = targetEdit()->text(); if (current->data(0, Qt::UserRole).isValid()) { @@ -463,9 +460,8 @@ void FakeVimExCommandsPage::resetTargetIdentifier() QTreeWidgetItem *current = commandList()->currentItem(); if (!current) return; - UniqueIDManager *uidm = UniqueIDManager::instance(); int id = current->data(0, CommandRole).toInt(); - const QString name = uidm->stringForUniqueIdentifier(id); + const QString name = Id::fromUniqueIdentifier(id).toString(); QString regex; if (defaultExCommandMap().contains(name)) regex = defaultExCommandMap()[name].pattern(); @@ -479,7 +475,6 @@ void FakeVimExCommandsPage::removeTargetIdentifier() void FakeVimExCommandsPage::defaultAction() { - UniqueIDManager *uidm = UniqueIDManager::instance(); int n = commandList()->topLevelItemCount(); for (int i = 0; i != n; ++i) { QTreeWidgetItem *section = commandList()->topLevelItem(i); @@ -487,7 +482,7 @@ void FakeVimExCommandsPage::defaultAction() for (int j = 0; j != m; ++j) { QTreeWidgetItem *item = section->child(j); const int id = item->data(0, CommandRole).toInt(); - const QString name = uidm->stringForUniqueIdentifier(id); + const QString name = Id::fromUniqueIdentifier(id).toString(); QString regex; if (defaultExCommandMap().contains(name)) regex = defaultExCommandMap()[name].pattern(); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 33ef291586..c10acf2932 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -442,7 +442,7 @@ void HelpPlugin::setupUi() ContentWindow *contentWindow = new ContentWindow(); contentWindow->setWindowTitle(tr(SB_CONTENTS)); - m_contentItem = new Core::SideBarItem(contentWindow, Core::Id(SB_CONTENTS)); + m_contentItem = new Core::SideBarItem(contentWindow, SB_CONTENTS); connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); diff --git a/src/plugins/macros/actionmacrohandler.cpp b/src/plugins/macros/actionmacrohandler.cpp index fc42170824..36019d9c74 100644 --- a/src/plugins/macros/actionmacrohandler.cpp +++ b/src/plugins/macros/actionmacrohandler.cpp @@ -73,7 +73,7 @@ ActionMacroHandler::ActionMacroHandler(): QList<Core::Command *> commands = am->commands(); foreach (Core::Command *command, commands) { if (command->isScriptable()) { - QString id = Core::UniqueIDManager::instance()->stringForUniqueIdentifier(command->id()); + QString id = Core::Id::fromUniqueIdentifier(command->id()).toString(); registerCommand(id); } } diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 60d64d4c8b..4416923a53 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -1359,7 +1359,7 @@ void ProjectExplorerPlugin::updateWelcomePage() void ProjectExplorerPlugin::currentModeChanged(Core::IMode *mode, Core::IMode *oldMode) { - if (mode && mode->id() == Core::Id(Core::Constants::MODE_WELCOME)) + if (mode && mode->id() == Core::Id(Core::Constants::MODE_WELCOME).toString()) updateWelcomePage(); if (oldMode == d->m_projectsMode) savePersistentSettings(); @@ -1746,7 +1746,7 @@ int ProjectExplorerPlugin::queue(QList<Project *> projects, QStringList stepIds) if (!pro || !pro->activeTarget()) continue; BuildStepList *bsl = 0; - if (id == Core::Id(Constants::BUILDSTEPS_DEPLOY) + if (id == Core::Id(Constants::BUILDSTEPS_DEPLOY).toString() && pro->activeTarget()->activeDeployConfiguration()) bsl = pro->activeTarget()->activeDeployConfiguration()->stepList(); else if (pro->activeTarget()->activeBuildConfiguration()) |