Commit f80db703 authored by hjk's avatar hjk Committed by hjk

use Core::Id for ids in INavigationWidgetFactory

Change-Id: Ic793e01edf6a4d2fe61baadb3aa5bef817436d35
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent e6a2f702
...@@ -777,9 +777,9 @@ int BookmarkViewFactory::priority() const ...@@ -777,9 +777,9 @@ int BookmarkViewFactory::priority() const
return 300; return 300;
} }
QString BookmarkViewFactory::id() const Id BookmarkViewFactory::id() const
{ {
return QLatin1String("Bookmarks"); return Id("Bookmarks");
} }
QKeySequence BookmarkViewFactory::activationSequence() const QKeySequence BookmarkViewFactory::activationSequence() const
......
...@@ -172,7 +172,7 @@ public: ...@@ -172,7 +172,7 @@ public:
BookmarkViewFactory(BookmarkManager *bm); BookmarkViewFactory(BookmarkManager *bm);
QString displayName() const; QString displayName() const;
int priority() const; int priority() const;
QString id() const; Core::Id id() const;
QKeySequence activationSequence() const; QKeySequence activationSequence() const;
Core::NavigationView createWidget(); Core::NavigationView createWidget();
private: private:
......
...@@ -73,9 +73,9 @@ int NavigationWidgetFactory::priority() const ...@@ -73,9 +73,9 @@ int NavigationWidgetFactory::priority() const
return 500; return 500;
} }
QString NavigationWidgetFactory::id() const Core::Id NavigationWidgetFactory::id() const
{ {
return QLatin1String("Class View"); return Core::Id("Class View");
} }
QKeySequence NavigationWidgetFactory::activationSequence() const QKeySequence NavigationWidgetFactory::activationSequence() const
......
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
int priority() const; int priority() const;
//! \implements Core::INavigationWidgetFactory::id //! \implements Core::INavigationWidgetFactory::id
QString id() const; Core::Id id() const;
//! \implements Core::INavigationWidgetFactory::activationSequence //! \implements Core::INavigationWidgetFactory::activationSequence
QKeySequence activationSequence() const; QKeySequence activationSequence() const;
......
...@@ -233,9 +233,9 @@ int OpenEditorsViewFactory::priority() const ...@@ -233,9 +233,9 @@ int OpenEditorsViewFactory::priority() const
return 200; return 200;
} }
QString OpenEditorsViewFactory::id() const Core::Id OpenEditorsViewFactory::id() const
{ {
return QLatin1String("Open Documents"); return Core::Id("Open Documents");
} }
QKeySequence OpenEditorsViewFactory::activationSequence() const QKeySequence OpenEditorsViewFactory::activationSequence() const
......
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
~OpenEditorsViewFactory(); ~OpenEditorsViewFactory();
QString displayName() const; QString displayName() const;
int priority() const; int priority() const;
QString id() const; Core::Id id() const;
QKeySequence activationSequence() const; QKeySequence activationSequence() const;
Core::NavigationView createWidget(); Core::NavigationView createWidget();
}; };
......
...@@ -36,14 +36,6 @@ ...@@ -36,14 +36,6 @@
using namespace Core; using namespace Core;
INavigationWidgetFactory::INavigationWidgetFactory()
{
}
INavigationWidgetFactory::~INavigationWidgetFactory()
{
}
QKeySequence INavigationWidgetFactory::activationSequence() const QKeySequence INavigationWidgetFactory::activationSequence() const
{ {
return QKeySequence(); return QKeySequence();
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#ifndef INAVIGATIONWIDGET_H #ifndef INAVIGATIONWIDGET_H
#define INAVIGATIONWIDGET_H #define INAVIGATIONWIDGET_H
#include <coreplugin/core_global.h> #include <coreplugin/id.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QList> #include <QtCore/QList>
...@@ -54,13 +55,13 @@ struct NavigationView ...@@ -54,13 +55,13 @@ struct NavigationView
class CORE_EXPORT INavigationWidgetFactory : public QObject class CORE_EXPORT INavigationWidgetFactory : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
INavigationWidgetFactory(); INavigationWidgetFactory() {}
virtual ~INavigationWidgetFactory();
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
virtual int priority() const = 0; virtual int priority() const = 0;
virtual QString id() const = 0; virtual Id id() const = 0;
virtual QKeySequence activationSequence() const; virtual QKeySequence activationSequence() const;
// This design is not optimal, think about it again once we need to extend it // This design is not optimal, think about it again once we need to extend it
// It could be implemented as returning an object which has both the widget // It could be implemented as returning an object which has both the widget
......
...@@ -176,8 +176,8 @@ void NavigationSubWidget::restoreSettings() ...@@ -176,8 +176,8 @@ void NavigationSubWidget::restoreSettings()
Core::Command *NavigationSubWidget::command(const QString &title) const Core::Command *NavigationSubWidget::command(const QString &title) const
{ {
const QHash<QString, Core::Command*> commandMap = m_parentWidget->commandMap(); const QHash<Id, Command *> commandMap = m_parentWidget->commandMap();
QHash<QString, Core::Command*>::const_iterator r = commandMap.find(title); QHash<Id, Command *>::const_iterator r = commandMap.find(Id(title));
if (r != commandMap.end()) if (r != commandMap.end())
return r.value(); return r.value();
return 0; return 0;
......
...@@ -139,12 +139,13 @@ void NavigationWidgetPlaceHolder::currentModeAboutToChange(Core::IMode *mode) ...@@ -139,12 +139,13 @@ void NavigationWidgetPlaceHolder::currentModeAboutToChange(Core::IMode *mode)
} }
} }
struct NavigationWidgetPrivate { struct NavigationWidgetPrivate
{
explicit NavigationWidgetPrivate(QAction *toggleSideBarAction); explicit NavigationWidgetPrivate(QAction *toggleSideBarAction);
QList<Internal::NavigationSubWidget *> m_subWidgets; QList<Internal::NavigationSubWidget *> m_subWidgets;
QHash<QShortcut *, QString> m_shortcutMap; QHash<QShortcut *, Core::Id> m_shortcutMap;
QHash<QString, Core::Command*> m_commandMap; QHash<Core::Id, Core::Command *> m_commandMap;
QStandardItemModel *m_factoryModel; QStandardItemModel *m_factoryModel;
bool m_shown; bool m_shown;
...@@ -191,7 +192,7 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact ...@@ -191,7 +192,7 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact
Context navicontext(Core::Constants::C_NAVIGATION_PANE); Context navicontext(Core::Constants::C_NAVIGATION_PANE);
foreach (INavigationWidgetFactory *factory, factories) { foreach (INavigationWidgetFactory *factory, factories) {
const QString id = factory->id(); const Id id = factory->id();
QShortcut *shortcut = new QShortcut(this); QShortcut *shortcut = new QShortcut(this);
shortcut->setWhatsThis(tr("Activate %1 Pane").arg(factory->displayName())); shortcut->setWhatsThis(tr("Activate %1 Pane").arg(factory->displayName()));
...@@ -199,13 +200,13 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact ...@@ -199,13 +200,13 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact
d->m_shortcutMap.insert(shortcut, id); d->m_shortcutMap.insert(shortcut, id);
Command *cmd = am->registerShortcut(shortcut, Command *cmd = am->registerShortcut(shortcut,
Id(QLatin1String("QtCreator.Sidebar.") + id), navicontext); Id(QLatin1String("QtCreator.Sidebar.") + id.name()), navicontext);
cmd->setDefaultKeySequence(factory->activationSequence()); cmd->setDefaultKeySequence(factory->activationSequence());
d->m_commandMap.insert(id, cmd); d->m_commandMap.insert(id, cmd);
QStandardItem *newRow = new QStandardItem(factory->displayName()); QStandardItem *newRow = new QStandardItem(factory->displayName());
newRow->setData(qVariantFromValue(factory), FactoryObjectRole); newRow->setData(qVariantFromValue(factory), FactoryObjectRole);
newRow->setData(factory->id(), FactoryIdRole); newRow->setData(QVariant::fromValue(factory->id()), FactoryIdRole);
newRow->setData(factory->priority(), FactoryPriorityRole); newRow->setData(factory->priority(), FactoryPriorityRole);
d->m_factoryModel->appendRow(newRow); d->m_factoryModel->appendRow(newRow);
} }
...@@ -266,11 +267,11 @@ Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int ...@@ -266,11 +267,11 @@ Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,int
void NavigationWidget::activateSubWidget() void NavigationWidget::activateSubWidget()
{ {
QShortcut *original = qobject_cast<QShortcut *>(sender()); QShortcut *original = qobject_cast<QShortcut *>(sender());
QString id = d->m_shortcutMap[original]; Id id = d->m_shortcutMap[original];
activateSubWidget(id); activateSubWidget(id);
} }
void NavigationWidget::activateSubWidget(const QString &factoryId) void NavigationWidget::activateSubWidget(const Id &factoryId)
{ {
setShown(true); setShown(true);
foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) { foreach (Internal::NavigationSubWidget *subWidget, d->m_subWidgets) {
...@@ -312,7 +313,7 @@ void NavigationWidget::saveSettings(QSettings *settings) ...@@ -312,7 +313,7 @@ void NavigationWidget::saveSettings(QSettings *settings)
QStringList viewIds; QStringList viewIds;
for (int i=0; i<d->m_subWidgets.count(); ++i) { for (int i=0; i<d->m_subWidgets.count(); ++i) {
d->m_subWidgets.at(i)->saveSettings(); d->m_subWidgets.at(i)->saveSettings();
viewIds.append(d->m_subWidgets.at(i)->factory()->id()); viewIds.append(d->m_subWidgets.at(i)->factory()->id().toString());
} }
settings->setValue(QLatin1String("Navigation/Views"), viewIds); settings->setValue(QLatin1String("Navigation/Views"), viewIds);
settings->setValue(QLatin1String("Navigation/Visible"), isShown()); settings->setValue(QLatin1String("Navigation/Visible"), isShown());
...@@ -343,7 +344,7 @@ void NavigationWidget::restoreSettings(QSettings *settings) ...@@ -343,7 +344,7 @@ void NavigationWidget::restoreSettings(QSettings *settings)
int position = 0; int position = 0;
foreach (const QString &id, viewIds) { foreach (const QString &id, viewIds) {
int index = factoryIndex(id); int index = factoryIndex(Id(id));
if (index >= 0) { if (index >= 0) {
// Only add if the id was actually found! // Only add if the id was actually found!
insertSubItem(position, index); insertSubItem(position, index);
...@@ -355,7 +356,7 @@ void NavigationWidget::restoreSettings(QSettings *settings) ...@@ -355,7 +356,7 @@ void NavigationWidget::restoreSettings(QSettings *settings)
if (d->m_subWidgets.isEmpty()) if (d->m_subWidgets.isEmpty())
// Make sure we have at least the projects widget // Make sure we have at least the projects widget
insertSubItem(0, qMax(0, factoryIndex(QLatin1String("Projects")))); insertSubItem(0, qMax(0, factoryIndex(Id("Projects"))));
setShown(settings->value(QLatin1String("Navigation/Visible"), true).toBool()); setShown(settings->value(QLatin1String("Navigation/Visible"), true).toBool());
...@@ -421,17 +422,17 @@ void NavigationWidget::setSuppressed(bool b) ...@@ -421,17 +422,17 @@ void NavigationWidget::setSuppressed(bool b)
NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed); NavigationWidgetPlaceHolder::m_current->setVisible(d->m_shown && !d->m_suppressed);
} }
int NavigationWidget::factoryIndex(const QString &id) int NavigationWidget::factoryIndex(const Id &id)
{ {
for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) { for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) {
if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).toString() == id) { if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).value<Core::Id>() == id) {
return row; return row;
} }
} }
return -1; return -1;
} }
QHash<QString, Core::Command*> NavigationWidget::commandMap() const QHash<Id, Command *> NavigationWidget::commandMap() const
{ {
return d->m_commandMap; return d->m_commandMap;
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define NAVIGATIONWIDGET_H #define NAVIGATIONWIDGET_H
#include <coreplugin/minisplitter.h> #include <coreplugin/minisplitter.h>
#include <coreplugin/id.h>
#include <QtCore/QHash> #include <QtCore/QHash>
...@@ -92,7 +93,7 @@ public: ...@@ -92,7 +93,7 @@ public:
void saveSettings(QSettings *settings); void saveSettings(QSettings *settings);
void restoreSettings(QSettings *settings); void restoreSettings(QSettings *settings);
void activateSubWidget(const QString &factoryId); void activateSubWidget(const Id &factoryId);
void closeSubWidgets(); void closeSubWidgets();
bool isShown() const; bool isShown() const;
...@@ -108,7 +109,7 @@ public: ...@@ -108,7 +109,7 @@ public:
// Called from the place holders // Called from the place holders
void placeHolderChanged(NavigationWidgetPlaceHolder *holder); void placeHolderChanged(NavigationWidgetPlaceHolder *holder);
QHash<QString, Core::Command*> commandMap() const; QHash<Id, Core::Command *> commandMap() const;
QAbstractItemModel *factoryModel() const; QAbstractItemModel *factoryModel() const;
protected: protected:
...@@ -122,7 +123,7 @@ private slots: ...@@ -122,7 +123,7 @@ private slots:
private: private:
void updateToggleText(); void updateToggleText();
Internal::NavigationSubWidget *insertSubItem(int position, int index); Internal::NavigationSubWidget *insertSubItem(int position, int index);
int factoryIndex(const QString &id); int factoryIndex(const Id &id);
NavigationWidgetPrivate *d; NavigationWidgetPrivate *d;
}; };
......
...@@ -416,7 +416,7 @@ void CppPlugin::openTypeHierarchy() ...@@ -416,7 +416,7 @@ void CppPlugin::openTypeHierarchy()
CPPEditorWidget *editor = qobject_cast<CPPEditorWidget*>(em->currentEditor()->widget()); CPPEditorWidget *editor = qobject_cast<CPPEditorWidget*>(em->currentEditor()->widget());
if (editor) { if (editor) {
Core::NavigationWidget *navigation = Core::NavigationWidget::instance(); Core::NavigationWidget *navigation = Core::NavigationWidget::instance();
navigation->activateSubWidget(QLatin1String(Constants::TYPE_HIERARCHY_ID)); navigation->activateSubWidget(Core::Id(Constants::TYPE_HIERARCHY_ID));
emit typeHierarchyRequested(); emit typeHierarchyRequested();
} }
} }
......
...@@ -237,9 +237,9 @@ int CppTypeHierarchyFactory::priority() const ...@@ -237,9 +237,9 @@ int CppTypeHierarchyFactory::priority() const
return Constants::TYPE_HIERARCHY_PRIORITY; return Constants::TYPE_HIERARCHY_PRIORITY;
} }
QString CppTypeHierarchyFactory::id() const Core::Id CppTypeHierarchyFactory::id() const
{ {
return QLatin1String(Constants::TYPE_HIERARCHY_ID); return Core::Id(Constants::TYPE_HIERARCHY_ID);
} }
QKeySequence CppTypeHierarchyFactory::activationSequence() const QKeySequence CppTypeHierarchyFactory::activationSequence() const
......
...@@ -111,7 +111,7 @@ public: ...@@ -111,7 +111,7 @@ public:
virtual QString displayName() const; virtual QString displayName() const;
virtual int priority() const; virtual int priority() const;
virtual QString id() const; virtual Core::Id id() const;
virtual QKeySequence activationSequence() const; virtual QKeySequence activationSequence() const;
virtual Core::NavigationView createWidget(); virtual Core::NavigationView createWidget();
}; };
......
...@@ -404,9 +404,9 @@ int FolderNavigationWidgetFactory::priority() const ...@@ -404,9 +404,9 @@ int FolderNavigationWidgetFactory::priority() const
return 400; return 400;
} }
QString FolderNavigationWidgetFactory::id() const Core::Id FolderNavigationWidgetFactory::id() const
{ {
return QLatin1String("File System"); return "File System";
} }
QKeySequence FolderNavigationWidgetFactory::activationSequence() const QKeySequence FolderNavigationWidgetFactory::activationSequence() const
......
...@@ -100,7 +100,7 @@ public: ...@@ -100,7 +100,7 @@ public:
QString displayName() const; QString displayName() const;
int priority() const; int priority() const;
QString id() const; Core::Id id() const;
QKeySequence activationSequence() const; QKeySequence activationSequence() const;
Core::NavigationView createWidget(); Core::NavigationView createWidget();
}; };
......
...@@ -407,9 +407,9 @@ int ProjectTreeWidgetFactory::priority() const ...@@ -407,9 +407,9 @@ int ProjectTreeWidgetFactory::priority() const
return 100; return 100;
} }
QString ProjectTreeWidgetFactory::id() const Core::Id ProjectTreeWidgetFactory::id() const
{ {
return QLatin1String("Projects"); return Core::Id("Projects");
} }
QKeySequence ProjectTreeWidgetFactory::activationSequence() const QKeySequence ProjectTreeWidgetFactory::activationSequence() const
......
...@@ -113,7 +113,7 @@ public: ...@@ -113,7 +113,7 @@ public:
~ProjectTreeWidgetFactory(); ~ProjectTreeWidgetFactory();
QString displayName() const; QString displayName() const;
int priority() const; int priority() const;
QString id() const; Core::Id id() const;
QKeySequence activationSequence() const; QKeySequence activationSequence() const;
Core::NavigationView createWidget(); Core::NavigationView createWidget();
void restoreSettings(int position, QWidget *widget); void restoreSettings(int position, QWidget *widget);
......
...@@ -668,19 +668,18 @@ void DesignModeWidget::setup() ...@@ -668,19 +668,18 @@ void DesignModeWidget::setup()
QWidget *fileSystemExplorer = 0; QWidget *fileSystemExplorer = 0;
foreach(Core::INavigationWidgetFactory *factory, factories) foreach (Core::INavigationWidgetFactory *factory, factories) {
{
Core::NavigationView navigationView; Core::NavigationView navigationView;
navigationView.widget = 0; navigationView.widget = 0;
if (factory->id() == QLatin1String("Projects")) { if (factory->id() == Core::Id("Projects")) {
navigationView = factory->createWidget(); navigationView = factory->createWidget();
projectsExplorer = navigationView.widget; projectsExplorer = navigationView.widget;
projectsExplorer->setWindowTitle(tr("Projects")); projectsExplorer->setWindowTitle(tr("Projects"));
} else if (factory->id() == QLatin1String("File System")) { } else if (factory->id() == Core::Id("File System")) {
navigationView = factory->createWidget(); navigationView = factory->createWidget();
fileSystemExplorer = navigationView.widget; fileSystemExplorer = navigationView.widget;
fileSystemExplorer->setWindowTitle(tr("File System")); fileSystemExplorer->setWindowTitle(tr("File System"));
} else if (factory->id() == QLatin1String("Open Documents")) { } else if (factory->id() == Core::Id("Open Documents")) {
navigationView = factory->createWidget(); navigationView = factory->createWidget();
openDocumentsWidget = navigationView.widget; openDocumentsWidget = navigationView.widget;
openDocumentsWidget->setWindowTitle(tr("Open Documents")); openDocumentsWidget->setWindowTitle(tr("Open Documents"));
......
...@@ -178,11 +178,6 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor) ...@@ -178,11 +178,6 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
} }
} }
OutlineFactory::OutlineFactory() :
Core::INavigationWidgetFactory()
{
}
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
{ {
return m_factories; return m_factories;
...@@ -203,9 +198,9 @@ int OutlineFactory::priority() const ...@@ -203,9 +198,9 @@ int OutlineFactory::priority() const
return 600; return 600;
} }
QString OutlineFactory::id() const Core::Id OutlineFactory::id() const
{ {
return QLatin1String("Outline"); return Core::Id("Outline");
} }
QKeySequence OutlineFactory::activationSequence() const QKeySequence OutlineFactory::activationSequence() const
......
...@@ -83,7 +83,7 @@ class OutlineFactory : public Core::INavigationWidgetFactory ...@@ -83,7 +83,7 @@ class OutlineFactory : public Core::INavigationWidgetFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
OutlineFactory(); OutlineFactory() {}
QList<IOutlineWidgetFactory*> widgetFactories() const; QList<IOutlineWidgetFactory*> widgetFactories() const;
void setWidgetFactories(QList<IOutlineWidgetFactory*> factories); void setWidgetFactories(QList<IOutlineWidgetFactory*> factories);
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
// from INavigationWidgetFactory // from INavigationWidgetFactory
virtual QString displayName() const; virtual QString displayName() const;
virtual int priority() const; virtual int priority() const;