forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -47,9 +47,6 @@ class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
|
||||
class UniqueIDManager;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class ActionContainerPrivate;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -61,7 +61,6 @@ public:
|
||||
|
||||
ActionManager *actionManager() const;
|
||||
FileManager *fileManager() const ;
|
||||
UniqueIDManager *uniqueIDManager() const;
|
||||
MessageManager *messageManager() const;
|
||||
EditorManager *editorManager() const;
|
||||
ProgressManager *progressManager() const;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -109,13 +109,6 @@
|
||||
The file manager keeps track of files for changes outside the application.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
/*!
|
||||
\class Core::Id
|
||||
|
||||
\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()); }
|
||||
|
||||
static QHash<Core::Id, int> &theUniqueIdentifiers()
|
||||
{
|
||||
m_instance = this;
|
||||
static QHash<Core::Id, int> data;
|
||||
return data;
|
||||
}
|
||||
|
||||
UniqueIDManager::~UniqueIDManager()
|
||||
int Id::uniqueIdentifier() const
|
||||
{
|
||||
m_instance = 0;
|
||||
}
|
||||
if (theUniqueIdentifiers().contains(*this))
|
||||
return theUniqueIdentifiers().value(*this);
|
||||
|
||||
bool UniqueIDManager::hasUniqueIdentifier(const Id &id) const
|
||||
{
|
||||
return m_uniqueIdentifiers.contains(id);
|
||||
}
|
||||
|
||||
int UniqueIDManager::uniqueIdentifier(const Id &id)
|
||||
{
|
||||
if (hasUniqueIdentifier(id))
|
||||
return m_uniqueIdentifiers.value(id);
|
||||
|
||||
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
|
||||
|
||||
@@ -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)) {}
|
||||
Id(const char *name) : m_name(name) {}
|
||||
// FIXME: Replace with QByteArray
|
||||
Id(const QString &name) : m_name(name) {}
|
||||
// FIXME: Remove.
|
||||
operator QString() const { return m_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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user