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