forked from qt-creator/qt-creator
Replace BaseMode convenience class by individual implementation.
Using the convienience class does not really save code and adds another needless level in the hierarchy. This affects the three remaining BaseMode users: Help, ProjectExplorer and HelloWorld.
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "basemode.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
/*!
|
||||
\class BaseMode
|
||||
\mainclass
|
||||
\inheaderfile basemode.h
|
||||
\brief A base implementation of the mode interface IMode.
|
||||
|
||||
The BaseMode class can be used directly for most IMode implementations. It has setter functions
|
||||
for the mode properties and a convenience constructor.
|
||||
|
||||
The ownership of the widget is given to the BaseMode, so when the BaseMode is destroyed it
|
||||
deletes its widget.
|
||||
|
||||
A typical use case is to do the following in the init method of a plugin:
|
||||
\code
|
||||
bool MyPlugin::init(QString *error_message)
|
||||
{
|
||||
[...]
|
||||
addObject(new Core::BaseMode("mymode",
|
||||
"MyPlugin.ModeId",
|
||||
icon,
|
||||
50, // priority
|
||||
new MyWidget));
|
||||
[...]
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn BaseMode::BaseMode(QObject *parent)
|
||||
|
||||
Creates a mode with empty display name, no icon, lowest priority and no widget. You should use the
|
||||
setter functions to give the mode a meaning.
|
||||
|
||||
\a parent
|
||||
*/
|
||||
BaseMode::BaseMode(QObject *parent):
|
||||
IMode(parent),
|
||||
m_priority(0),
|
||||
m_widget(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn BaseMode::~BaseMode()
|
||||
*/
|
||||
BaseMode::~BaseMode()
|
||||
{
|
||||
delete m_widget;
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef BASEMODE_H
|
||||
#define BASEMODE_H
|
||||
|
||||
#include "core_global.h"
|
||||
#include "imode.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
|
||||
class CORE_EXPORT BaseMode
|
||||
: public IMode
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BaseMode(QObject *parent = 0);
|
||||
~BaseMode();
|
||||
|
||||
// IMode
|
||||
QString displayName() const { return m_displayName; }
|
||||
QIcon icon() const { return m_icon; }
|
||||
int priority() const { return m_priority; }
|
||||
QWidget *widget() { return m_widget; }
|
||||
QString id() const { return m_id; }
|
||||
QString type() const { return m_type; }
|
||||
Context context() const { return m_context; }
|
||||
QString contextHelpId() const { return m_helpId; }
|
||||
|
||||
void setDisplayName(const QString &name) { m_displayName = name; }
|
||||
void setIcon(const QIcon &icon) { m_icon = icon; }
|
||||
void setPriority(int priority) { m_priority = priority; }
|
||||
void setWidget(QWidget *widget) { m_widget = widget; }
|
||||
void setId(const QString &id) { m_id = id; }
|
||||
void setType(const QString &type) { m_type = type; }
|
||||
void setContextHelpId(const QString &helpId) { m_helpId = helpId; }
|
||||
void setContext(const Context &context) { m_context = context; }
|
||||
|
||||
private:
|
||||
QString m_displayName;
|
||||
QIcon m_icon;
|
||||
int m_priority;
|
||||
QWidget *m_widget;
|
||||
QString m_id;
|
||||
QString m_type;
|
||||
QString m_helpId;
|
||||
Context m_context;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // BASEMODE_H
|
||||
|
||||
@@ -56,7 +56,6 @@ SOURCES += mainwindow.cpp \
|
||||
progressmanager/progressbar.cpp \
|
||||
progressmanager/futureprogress.cpp \
|
||||
scriptmanager/scriptmanager.cpp \
|
||||
basemode.cpp \
|
||||
statusbarwidget.cpp \
|
||||
coreplugin.cpp \
|
||||
variablemanager.cpp \
|
||||
@@ -167,7 +166,6 @@ HEADERS += mainwindow.h \
|
||||
scriptmanager/scriptmanager.h \
|
||||
scriptmanager/scriptmanager_p.h \
|
||||
core_global.h \
|
||||
basemode.h \
|
||||
statusbarwidget.h \
|
||||
coreplugin.h \
|
||||
variablemanager.h \
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/basemode.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/imode.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
|
||||
@@ -44,7 +44,29 @@
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
using namespace HelloWorld::Internal;
|
||||
namespace HelloWorld {
|
||||
namespace Internal {
|
||||
|
||||
/*! A mode with a push button based on BaseMode. */
|
||||
|
||||
class HelloMode : public Core::IMode
|
||||
{
|
||||
public:
|
||||
HelloMode() : m_widget(new QPushButton(tr("Hello World PushButton!"))) {}
|
||||
|
||||
QString displayName() const { return tr("Hello world!"); }
|
||||
QIcon icon() const { return QIcon(); }
|
||||
int priority() const { return 0; }
|
||||
QWidget *widget() { return m_widget; }
|
||||
QString id() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
|
||||
QString type() const { return QLatin1String("HelloWorld.HelloWorldMode"); }
|
||||
Core::Context context() const { return Core::Context("HelloWorld.MainView"); };
|
||||
QString contextHelpId() const { return QString(); }
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
/*! Constructs the Hello World plugin. Normally plugins don't do anything in
|
||||
their constructor except for initializing their member variables. The
|
||||
@@ -76,7 +98,7 @@ bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_m
|
||||
// Get the primary access point to the workbench.
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
|
||||
// Create a unique context id for our own view, that will be used for the
|
||||
// Create a unique context for our own view, that will be used for the
|
||||
// menu entry later.
|
||||
Core::Context context("HelloWorld.MainView");
|
||||
|
||||
@@ -107,15 +129,8 @@ bool HelloWorldPlugin::initialize(const QStringList &arguments, QString *error_m
|
||||
|
||||
// Add a mode with a push button based on BaseMode. Like the BaseView,
|
||||
// it will unregister itself from the plugin manager when it is deleted.
|
||||
Core::BaseMode *baseMode = new Core::BaseMode;
|
||||
baseMode->setId(QLatin1String("HelloWorld.HelloWorldMode"));
|
||||
baseMode->setType(QLatin1String("HelloWorld.HelloWorldMode"));
|
||||
baseMode->setDisplayName(tr("Hello world!"));
|
||||
baseMode->setIcon(QIcon());
|
||||
baseMode->setPriority(0);
|
||||
baseMode->setWidget(new QPushButton(tr("Hello World PushButton!")));
|
||||
baseMode->setContext(context);
|
||||
addAutoReleasedObject(baseMode);
|
||||
Core::IMode *helloMode = new HelloMode;
|
||||
addAutoReleasedObject(helloMode);
|
||||
|
||||
// Add the Hello World action command to the mode manager (with 0 priority)
|
||||
Core::ModeManager *modeManager = core->modeManager();
|
||||
@@ -147,4 +162,7 @@ void HelloWorldPlugin::sayHelloWorld()
|
||||
0, tr("Hello World!"), tr("Hello World! Beautiful day today, isn't it?"));
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(HelloWorldPlugin)
|
||||
} // namespace Internal
|
||||
} // namespace HelloWorld
|
||||
|
||||
Q_EXPORT_PLUGIN(HelloWorld::Internal::HelloWorldPlugin)
|
||||
|
||||
@@ -50,8 +50,6 @@ public:
|
||||
|
||||
private slots:
|
||||
void sayHelloWorld();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define HELPCONSTANTS_H
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
#include <QtCore/QLatin1String>
|
||||
|
||||
namespace Help {
|
||||
namespace Constants {
|
||||
|
||||
@@ -30,20 +30,16 @@
|
||||
#include "helpmode.h"
|
||||
#include "helpconstants.h"
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
using namespace Help;
|
||||
using namespace Help::Internal;
|
||||
|
||||
HelpMode::HelpMode(QWidget *widget, QObject *parent)
|
||||
: BaseMode(parent)
|
||||
HelpMode::HelpMode(QObject *parent)
|
||||
: Core::IMode(parent),
|
||||
m_widget(0),
|
||||
m_icon(QLatin1String(":/fancyactionbar/images/mode_Reference.png"))
|
||||
{
|
||||
setObjectName(QLatin1String("HelpMode"));
|
||||
setDisplayName(tr("Help"));
|
||||
setId(QLatin1String(Constants::ID_MODE_HELP));
|
||||
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Reference.png")));
|
||||
setPriority(Constants::P_MODE_HELP);
|
||||
setWidget(widget);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,19 +30,35 @@
|
||||
#ifndef HELPMODE_H
|
||||
#define HELPMODE_H
|
||||
|
||||
#include <coreplugin/basemode.h>
|
||||
#include "helpmode.h"
|
||||
#include "helpconstants.h"
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QWidget)
|
||||
#include <coreplugin/imode.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
class HelpMode : public Core::BaseMode
|
||||
class HelpMode : public Core::IMode
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HelpMode(QWidget *widget, QObject *parent = 0);
|
||||
HelpMode(QObject *parent = 0);
|
||||
|
||||
QString displayName() const { return tr("Help"); }
|
||||
QIcon icon() const { return m_icon; }
|
||||
int priority() const { return Constants::P_MODE_HELP; }
|
||||
QWidget *widget() { return m_widget; }
|
||||
QString id() const { return QLatin1String(Constants::ID_MODE_HELP); }
|
||||
QString type() const { return QString(); }
|
||||
Core::Context context() const { return Core::Context(Constants::C_MODE_HELP); }
|
||||
QString contextHelpId() const { return QString(); }
|
||||
void setWidget(QWidget *widget) { m_widget = widget; }
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -342,18 +342,18 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
Core::IMode*)), this, SLOT(modeChanged(Core::IMode*, Core::IMode*)));
|
||||
|
||||
m_externalWindow = new ExternalHelpWindow;
|
||||
m_mode = new HelpMode;
|
||||
if (contextHelpOption() == Help::Constants::ExternalHelpAlways) {
|
||||
m_mode = new HelpMode(new QWidget);
|
||||
m_mode->setWidget(new QWidget);
|
||||
m_mode->setEnabled(false);
|
||||
m_externalHelpBar->setVisible(true);
|
||||
m_externalWindow->setCentralWidget(m_splitter);
|
||||
QTimer::singleShot(0, this, SLOT(showExternalWindow()));
|
||||
} else {
|
||||
m_mode = new HelpMode(m_splitter);
|
||||
m_mode->setWidget(m_splitter);
|
||||
m_internalHelpBar->setVisible(true);
|
||||
}
|
||||
addAutoReleasedObject(m_mode);
|
||||
m_mode->setContext(modecontext);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <coreplugin/basemode.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
@@ -78,10 +78,10 @@
|
||||
#include "publishing/ipublishingwizardfactory.h"
|
||||
#include "publishing/publishingwizardselectiondialog.h"
|
||||
|
||||
#include <coreplugin/basemode.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/filemanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/imode.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
@@ -201,7 +201,7 @@ struct ProjectExplorerPluginPrivate {
|
||||
Internal::ProjectExplorerSettings m_projectExplorerSettings;
|
||||
Internal::ProjectWelcomePage *m_welcomePage;
|
||||
|
||||
Core::BaseMode * m_projectsMode;
|
||||
Core::IMode *m_projectsMode;
|
||||
};
|
||||
|
||||
ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
|
||||
@@ -212,6 +212,25 @@ ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
|
||||
{
|
||||
}
|
||||
|
||||
class ProjectsMode : public Core::IMode
|
||||
{
|
||||
public:
|
||||
ProjectsMode(QWidget *proWindow) : m_widget(proWindow) {}
|
||||
|
||||
QString displayName() const { return tr("Projects"); }
|
||||
QIcon icon() const { return QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")); }
|
||||
int priority() const { return Constants::P_MODE_SESSION; }
|
||||
QWidget *widget() { return m_widget; }
|
||||
QString id() const { return QLatin1String(Constants::MODE_SESSION); }
|
||||
QString type() const { return QString(); }
|
||||
Core::Context context() const { return Core::Context(Constants::C_PROJECTEXPLORER); }
|
||||
QString contextHelpId() const { return QLatin1String("Managing Projects"); }
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
@@ -280,18 +299,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
d->m_proWindow = new ProjectWindow;
|
||||
|
||||
Core::Context globalcontext(Core::Constants::C_GLOBAL);
|
||||
Core::Context pecontext(Constants::C_PROJECTEXPLORER);
|
||||
Core::Context projecTreeContext(Constants::C_PROJECT_TREE);
|
||||
|
||||
d->m_projectsMode = new Core::BaseMode;
|
||||
d->m_projectsMode->setDisplayName(tr("Projects"));
|
||||
d->m_projectsMode->setId(QLatin1String(Constants::MODE_SESSION));
|
||||
d->m_projectsMode->setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")));
|
||||
d->m_projectsMode->setPriority(Constants::P_MODE_SESSION);
|
||||
d->m_projectsMode->setWidget(d->m_proWindow);
|
||||
d->m_projectsMode->setContext(pecontext);
|
||||
d->m_projectsMode = new ProjectsMode(d->m_proWindow);
|
||||
d->m_projectsMode->setEnabled(session()->startupProject());
|
||||
d->m_projectsMode->setContextHelpId(QLatin1String("Managing Projects"));
|
||||
addAutoReleasedObject(d->m_projectsMode);
|
||||
d->m_proWindow->layout()->addWidget(new Core::FindToolBarPlaceHolder(d->m_proWindow));
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include <utils/styledbar.h>
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/basemode.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <coreplugin/outputpane.h>
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include "qmljsprivateapi.h"
|
||||
|
||||
#include <coreplugin/basemode.h>
|
||||
#include <debugger/debuggerconstants.h>
|
||||
#include <qmlprojectmanager/qmlprojectrunconfiguration.h>
|
||||
#include <utils/fileinprojectfinder.h>
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/imode.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user