Commit 2f8f083b authored by Eike Ziller's avatar Eike Ziller
Browse files

Unify pattern used for privates and constructors



In the 'managers' from ICore

Change-Id: Iab98c9e0947b759843a62e3777ba46be3b304b06
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 3c32bb86
......@@ -141,15 +141,16 @@ using namespace Core::Internal;
*/
static ActionManager *m_instance = 0;
static ActionManagerPrivate *d;
/*!
\internal
*/
ActionManager::ActionManager(QObject *parent)
: QObject(parent),
d(new ActionManagerPrivate())
: QObject(parent)
{
m_instance = this;
d = new ActionManagerPrivate;
}
/*!
......@@ -179,8 +180,8 @@ ActionManager *ActionManager::instance()
*/
ActionContainer *ActionManager::createMenu(Id id)
{
const ActionManagerPrivate::IdContainerMap::const_iterator it = m_instance->d->m_idContainerMap.constFind(id);
if (it != m_instance->d->m_idContainerMap.constEnd())
const ActionManagerPrivate::IdContainerMap::const_iterator it = d->m_idContainerMap.constFind(id);
if (it != d->m_idContainerMap.constEnd())
return it.value();
QMenu *m = new QMenu(ICore::mainWindow());
......@@ -189,8 +190,8 @@ ActionContainer *ActionManager::createMenu(Id id)
MenuActionContainer *mc = new MenuActionContainer(id);
mc->setMenu(m);
m_instance->d->m_idContainerMap.insert(id, mc);
connect(mc, SIGNAL(destroyed()), m_instance->d, SLOT(containerDestroyed()));
d->m_idContainerMap.insert(id, mc);
connect(mc, SIGNAL(destroyed()), d, SLOT(containerDestroyed()));
return mc;
}
......@@ -204,8 +205,8 @@ ActionContainer *ActionManager::createMenu(Id id)
*/
ActionContainer *ActionManager::createMenuBar(Id id)
{
const ActionManagerPrivate::IdContainerMap::const_iterator it = m_instance->d->m_idContainerMap.constFind(id);
if (it != m_instance->d->m_idContainerMap.constEnd())
const ActionManagerPrivate::IdContainerMap::const_iterator it = d->m_idContainerMap.constFind(id);
if (it != d->m_idContainerMap.constEnd())
return it.value();
QMenuBar *mb = new QMenuBar; // No parent (System menu bar on Mac OS X)
......@@ -214,8 +215,8 @@ ActionContainer *ActionManager::createMenuBar(Id id)
MenuBarActionContainer *mbc = new MenuBarActionContainer(id);
mbc->setMenuBar(mb);
m_instance->d->m_idContainerMap.insert(id, mbc);
connect(mbc, SIGNAL(destroyed()), m_instance->d, SLOT(containerDestroyed()));
d->m_idContainerMap.insert(id, mbc);
connect(mbc, SIGNAL(destroyed()), d, SLOT(containerDestroyed()));
return mbc;
}
......@@ -233,7 +234,7 @@ ActionContainer *ActionManager::createMenuBar(Id id)
*/
Command *ActionManager::registerAction(QAction *action, Id id, const Context &context, bool scriptable)
{
Action *a = m_instance->d->overridableAction(id);
Action *a = d->overridableAction(id);
if (a) {
a->addOverrideAction(action, context, scriptable);
emit m_instance->commandListChanged();
......@@ -257,7 +258,7 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
{
QTC_CHECK(!context.isEmpty());
Shortcut *sc = 0;
if (CommandPrivate *c = m_instance->d->m_idCmdMap.value(id, 0)) {
if (CommandPrivate *c = d->m_idCmdMap.value(id, 0)) {
sc = qobject_cast<Shortcut *>(c);
if (!sc) {
qWarning() << "registerShortcut: id" << id.name()
......@@ -266,7 +267,7 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
}
} else {
sc = new Shortcut(id);
m_instance->d->m_idCmdMap.insert(id, sc);
d->m_idCmdMap.insert(id, sc);
}
if (sc->shortcut()) {
......@@ -274,7 +275,7 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
return sc;
}
if (!m_instance->d->hasContext(context))
if (!d->hasContext(context))
shortcut->setEnabled(false);
shortcut->setObjectName(id.toString());
shortcut->setParent(ICore::mainWindow());
......@@ -287,7 +288,7 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
emit m_instance->commandAdded(id.toString());
if (isPresentationModeEnabled())
connect(sc->shortcut(), SIGNAL(activated()), m_instance->d, SLOT(shortcutTriggered()));
connect(sc->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
return sc;
}
......@@ -299,8 +300,8 @@ Command *ActionManager::registerShortcut(QShortcut *shortcut, Id id, const Conte
*/
Command *ActionManager::command(Id id)
{
const ActionManagerPrivate::IdCmdMap::const_iterator it = m_instance->d->m_idCmdMap.constFind(id);
if (it == m_instance->d->m_idCmdMap.constEnd()) {
const ActionManagerPrivate::IdCmdMap::const_iterator it = d->m_idCmdMap.constFind(id);
if (it == d->m_idCmdMap.constEnd()) {
if (warnAboutFindFailures)
qWarning() << "ActionManagerPrivate::command(): failed to find :"
<< id.name();
......@@ -318,8 +319,8 @@ Command *ActionManager::command(Id id)
*/
ActionContainer *ActionManager::actionContainer(Id id)
{
const ActionManagerPrivate::IdContainerMap::const_iterator it = m_instance->d->m_idContainerMap.constFind(id);
if (it == m_instance->d->m_idContainerMap.constEnd()) {
const ActionManagerPrivate::IdContainerMap::const_iterator it = d->m_idContainerMap.constFind(id);
if (it == d->m_idContainerMap.constEnd()) {
if (warnAboutFindFailures)
qWarning() << "ActionManagerPrivate::actionContainer(): failed to find :"
<< id.name();
......@@ -335,7 +336,7 @@ QList<Command *> ActionManager::commands()
{
// transform list of CommandPrivate into list of Command
QList<Command *> result;
foreach (Command *cmd, m_instance->d->m_idCmdMap.values())
foreach (Command *cmd, d->m_idCmdMap.values())
result << cmd;
return result;
}
......@@ -351,7 +352,7 @@ QList<Command *> ActionManager::commands()
void ActionManager::unregisterAction(QAction *action, Id id)
{
Action *a = 0;
CommandPrivate *c = m_instance->d->m_idCmdMap.value(id, 0);
CommandPrivate *c = d->m_idCmdMap.value(id, 0);
QTC_ASSERT(c, return);
a = qobject_cast<Action *>(c);
if (!a) {
......@@ -365,7 +366,7 @@ void ActionManager::unregisterAction(QAction *action, Id id)
// ActionContainers listen to the commands' destroyed signals
ICore::mainWindow()->removeAction(a->action());
delete a->action();
m_instance->d->m_idCmdMap.remove(id);
d->m_idCmdMap.remove(id);
delete a;
}
emit m_instance->commandListChanged();
......@@ -382,7 +383,7 @@ void ActionManager::unregisterAction(QAction *action, Id id)
void ActionManager::unregisterShortcut(Id id)
{
Shortcut *sc = 0;
CommandPrivate *c = m_instance->d->m_idCmdMap.value(id, 0);
CommandPrivate *c = d->m_idCmdMap.value(id, 0);
QTC_ASSERT(c, return);
sc = qobject_cast<Shortcut *>(c);
if (!sc) {
......@@ -391,7 +392,7 @@ void ActionManager::unregisterShortcut(Id id)
return;
}
delete sc->shortcut();
m_instance->d->m_idCmdMap.remove(id);
d->m_idCmdMap.remove(id);
delete sc;
emit m_instance->commandListChanged();
}
......@@ -406,38 +407,53 @@ void ActionManager::setPresentationModeEnabled(bool enabled)
foreach (Command *c, commands()) {
if (c->action()) {
if (enabled)
connect(c->action(), SIGNAL(triggered()), m_instance->d, SLOT(actionTriggered()));
connect(c->action(), SIGNAL(triggered()), d, SLOT(actionTriggered()));
else
disconnect(c->action(), SIGNAL(triggered()), m_instance->d, SLOT(actionTriggered()));
disconnect(c->action(), SIGNAL(triggered()), d, SLOT(actionTriggered()));
}
if (c->shortcut()) {
if (enabled)
connect(c->shortcut(), SIGNAL(activated()), m_instance->d, SLOT(shortcutTriggered()));
connect(c->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
else
disconnect(c->shortcut(), SIGNAL(activated()), m_instance->d, SLOT(shortcutTriggered()));
disconnect(c->shortcut(), SIGNAL(activated()), d, SLOT(shortcutTriggered()));
}
}
// The label for the shortcuts:
if (!m_instance->d->m_presentationLabel) {
m_instance->d->m_presentationLabel = new QLabel(0, Qt::ToolTip | Qt::WindowStaysOnTopHint);
QFont font = m_instance->d->m_presentationLabel->font();
if (!d->m_presentationLabel) {
d->m_presentationLabel = new QLabel(0, Qt::ToolTip | Qt::WindowStaysOnTopHint);
QFont font = d->m_presentationLabel->font();
font.setPixelSize(45);
m_instance->d->m_presentationLabel->setFont(font);
m_instance->d->m_presentationLabel->setAlignment(Qt::AlignCenter);
m_instance->d->m_presentationLabel->setMargin(5);
d->m_presentationLabel->setFont(font);
d->m_presentationLabel->setAlignment(Qt::AlignCenter);
d->m_presentationLabel->setMargin(5);
connect(&m_instance->d->m_presentationLabelTimer, SIGNAL(timeout()), m_instance->d->m_presentationLabel, SLOT(hide()));
connect(&d->m_presentationLabelTimer, SIGNAL(timeout()), d->m_presentationLabel, SLOT(hide()));
} else {
m_instance->d->m_presentationLabelTimer.stop();
delete m_instance->d->m_presentationLabel;
m_instance->d->m_presentationLabel = 0;
d->m_presentationLabelTimer.stop();
delete d->m_presentationLabel;
d->m_presentationLabel = 0;
}
}
bool ActionManager::isPresentationModeEnabled()
{
return m_instance->d->m_presentationLabel;
return d->m_presentationLabel;
}
void ActionManager::initialize()
{
d->initialize();
}
void ActionManager::saveSettings(QSettings *settings)
{
d->saveSettings(settings);
}
void ActionManager::setContext(const Context &context)
{
d->setContext(context);
}
/*!
......
......@@ -39,6 +39,7 @@
QT_BEGIN_NAMESPACE
class QAction;
class QSettings;
class QShortcut;
class QString;
QT_END_NAMESPACE
......@@ -47,10 +48,7 @@ namespace Core {
class ActionContainer;
namespace Internal {
class ActionManagerPrivate;
class MainWindow;
}
namespace Internal { class MainWindow; }
class CORE_EXPORT ActionManager : public QObject
{
......@@ -82,7 +80,9 @@ signals:
private:
ActionManager(QObject *parent = 0);
~ActionManager();
Internal::ActionManagerPrivate *d;
void initialize();
void saveSettings(QSettings *settings);
void setContext(const Context &context);
friend class Core::Internal::MainWindow;
};
......
......@@ -47,6 +47,8 @@ namespace Core {
class IContext;
class IDocument;
namespace Internal { class MainWindow; }
class CORE_EXPORT DocumentManager : public QObject
{
Q_OBJECT
......@@ -58,9 +60,6 @@ public:
typedef QPair<QString, Id> RecentFile;
explicit DocumentManager(QMainWindow *ew);
virtual ~DocumentManager();
static DocumentManager *instance();
// file pool to monitor
......@@ -152,6 +151,12 @@ private slots:
void checkForReload();
void changedFile(const QString &file);
void syncWithEditor(const QList<Core::IContext *> &context);
private:
explicit DocumentManager(QMainWindow *ew);
virtual ~DocumentManager();
friend class Core::Internal::MainWindow;
};
/*! The FileChangeBlocker blocks all change notifications to all IDocument * that
......
......@@ -172,8 +172,9 @@ EditorManagerPlaceHolder* EditorManagerPlaceHolder::current()
namespace Core {
struct EditorManagerPrivate
class EditorManagerPrivate
{
public:
explicit EditorManagerPrivate(QWidget *parent);
~EditorManagerPrivate();
QList<EditLocation> m_globalHistory;
......@@ -265,13 +266,14 @@ EditorManagerPrivate::~EditorManagerPrivate()
}
static EditorManager *m_instance = 0;
static EditorManagerPrivate *d;
EditorManager *EditorManager::instance() { return m_instance; }
EditorManager::EditorManager(QWidget *parent) :
QWidget(parent),
d(new EditorManagerPrivate(parent))
QWidget(parent)
{
d = new EditorManagerPrivate(parent);
m_instance = this;
connect(ICore::instance(), SIGNAL(contextAboutToChange(QList<Core::IContext*>)),
......@@ -612,7 +614,7 @@ SplitterOrView *EditorManager::findRoot(const EditorView *view, int *rootIndex)
{
SplitterOrView *current = view->parentSplitterOrView();
while (current) {
int index = m_instance->d->m_root.indexOf(current);
int index = d->m_root.indexOf(current);
if (index >= 0) {
if (rootIndex)
*rootIndex = index;
......@@ -647,7 +649,7 @@ QList<IEditor *> EditorManager::editorsForDocument(IDocument *document) const
IEditor *EditorManager::currentEditor()
{
return m_instance->d->m_currentEditor;
return d->m_currentEditor;
}
void EditorManager::emptyView(Core::Internal::EditorView *view)
......@@ -702,8 +704,8 @@ void EditorManager::splitNewWindow(Internal::EditorView *view)
context->setContext(Context(Constants::C_EDITORMANAGER));
context->setWidget(splitter);
ICore::addContextObject(context);
m_instance->d->m_root.append(splitter);
m_instance->d->m_rootContext.append(context);
d->m_root.append(splitter);
d->m_rootContext.append(context);
connect(splitter, SIGNAL(destroyed(QObject*)), m_instance, SLOT(rootDestroyed(QObject*)));
splitter->show();
ICore::raiseWindow(splitter);
......
......@@ -63,18 +63,15 @@ enum MakeWritableResult {
Failed
};
struct EditorManagerPrivate;
class OpenEditorsModel;
namespace Internal {
class OpenEditorsWindow;
class EditorView;
class SplitterOrView;
class EditorClosingCoreListener;
class EditorView;
class MainWindow;
class OpenEditorsViewFactory;
class OpenEditorsWindow;
class SplitterOrView;
} // namespace Internal
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
......@@ -99,9 +96,6 @@ public:
typedef QList<IEditorFactory *> EditorFactoryList;
typedef QList<IExternalEditor *> ExternalEditorList;
explicit EditorManager(QWidget *parent);
virtual ~EditorManager();
void init();
static EditorManager *instance();
static EditorToolBar *createToolBar(QWidget *parent = 0);
......@@ -251,6 +245,10 @@ public slots:
void gotoOtherSplit();
private:
explicit EditorManager(QWidget *parent);
virtual ~EditorManager();
void init();
QList<IDocument *> documentsForEditors(QList<IEditor *> editors) const;
static IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
void addEditor(IEditor *editor, bool isDuplicate = false);
......@@ -285,8 +283,7 @@ private:
QString fileNameForEditor(IEditor *editor);
void setupSaveActions(IEditor *editor, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
EditorManagerPrivate *d;
friend class Core::Internal::MainWindow;
friend class Core::Internal::SplitterOrView;
friend class Core::Internal::EditorView;
friend class Core::EditorToolBar;
......
......@@ -65,6 +65,7 @@ struct HelpManagerPrivate
};
static HelpManager *m_instance = 0;
static HelpManagerPrivate *d;
static const char linksForKeyQuery[] = "SELECT d.Title, f.Name, e.Name, "
"d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, "
......@@ -83,10 +84,11 @@ struct DbCleaner
// -- HelpManager
HelpManager::HelpManager(QObject *parent) :
QObject(parent), d(new HelpManagerPrivate)
QObject(parent)
{
Q_ASSERT(!m_instance);
m_instance = this;
d = new HelpManagerPrivate;
}
HelpManager::~HelpManager()
......
......@@ -45,6 +45,7 @@ struct HelpManagerPrivate;
namespace Internal {
class CorePlugin;
class MainWindow;
}
class CORE_EXPORT HelpManager : public QObject
......@@ -53,8 +54,6 @@ class CORE_EXPORT HelpManager : public QObject
public:
typedef QHash<QString, QStringList> Filters;
explicit HelpManager(QObject *parent = 0);
virtual ~HelpManager();
static HelpManager* instance();
static QString collectionFilePath();
......@@ -93,10 +92,13 @@ signals:
void helpRequested(const QUrl &url);
private:
explicit HelpManager(QObject *parent = 0);
virtual ~HelpManager();
void setupHelpManager();
void verifyDocumenation();
HelpManagerPrivate *d;
friend class Internal::CorePlugin; // setupHelpManager
friend class Core::Internal::CorePlugin; // setupHelpManager
friend class Core::Internal::MainWindow; // constructor/destructor
};
} // Core
......
......@@ -99,22 +99,21 @@
\fn ActionManager *ICore::actionManager()
\obsolete
Use \c ActionManager::actionManager() directly.
Use Core::ActionManager directly.
*/
/*!
\fn DocumentManager *ICore::documentManager()
\obsolete
Use \c DocumentManager::documentManager() directly.
Use Core::DocumentManager directly.
*/
/*!
\fn MessageManager *ICore::messageManager()
\brief Returns the application's message manager.
\obsolete
The message manager is the interface to the "General" output pane for
general application debug messages.
Use Core::MessageManager directly.
*/
/*!
......@@ -134,11 +133,6 @@
show a progress bar the way Qt Creator does it.
*/
/*!
\fn ScriptManager *ICore::scriptManager()
\internal
*/
/*!
\fn VariableManager *ICore::variableManager()
\obsolete
......@@ -171,6 +165,13 @@
Use the mime database to manage mime types.
*/
/*!
\fn HelpManager *ICore::helpManager()
\brief Returns the application's help manager.
Use the help manager to register documentation sets.
*/
/*!
\fn QSettings *ICore::settings(QSettings::Scope scope = QSettings::UserScope)
\brief Returns the application's main settings object.
......
......@@ -95,7 +95,7 @@ public:
static QT_DEPRECATED ActionManager *actionManager(); // Use Actionmanager::... directly.
static QT_DEPRECATED DocumentManager *documentManager(); // Use DocumentManager::... directly.
static MessageManager *messageManager();
static QT_DEPRECATED MessageManager *messageManager(); // Use MessageManager::... directly.
static EditorManager *editorManager();
static ProgressManager *progressManager();
static ScriptManager *scriptManager();
......
......@@ -316,6 +316,8 @@ MainWindow::~MainWindow()
delete m_helpManager;
m_helpManager = 0;
delete m_variableManager;
m_variableManager = 0;
}
bool MainWindow::init(QString *errorMessage)
......@@ -355,7 +357,7 @@ void MainWindow::extensionsInitialized()
m_navigationWidget->setFactories(ExtensionSystem::PluginManager::getObjects<INavigationWidgetFactory>());
// reading the shortcut settings must be done after all shortcuts have been registered
m_actionManager->d->initialize();
m_actionManager->initialize();
readSettings();
updateContext();
......@@ -1004,7 +1006,7 @@ ScriptManager *MainWindow::scriptManager() const
VariableManager *MainWindow::variableManager() const
{
return m_variableManager.data();
return m_variableManager;
}
ModeManager *MainWindow::modeManager() const
......@@ -1168,7 +1170,7 @@ void MainWindow::writeSettings()
m_settings->endGroup();
DocumentManager::saveSettings();
m_actionManager->d->saveSettings(m_settings);
m_actionManager->saveSettings(m_settings);
m_editorManager->saveSettings();
m_navigationWidget->saveSettings(m_settings);
}
......@@ -1211,7 +1213,7 @@ void MainWindow::updateContext()
uniquecontexts.add(id);
}
m_actionManager->d->setContext(uniquecontexts);
m_actionManager->setContext(uniquecontexts);
emit m_coreImpl->contextChanged(m_activeContext, m_additionalContexts);
}
......
......@@ -184,7 +184,7 @@ private:
MessageManager *m_messageManager;
ProgressManagerPrivate *m_progressManager;
ScriptManager *m_scriptManager;
QScopedPointer<VariableManager> m_variableManager;
VariableManager *m_variableManager;
VcsManager *m_vcsManager;
StatusBarManager *m_statusBarManager;
ModeManager *m_modeManager;
......
......@@ -34,7 +34,8 @@
using namespace Core;
MessageManager *MessageManager::m_instance = 0;
static MessageManager *m_instance = 0;
MessageManager *MessageManager::instance() { return m_instance; }
MessageManager::MessageManager()
: m_messageOutputWindow(0)
......
......@@ -40,6 +40,7 @@ namespace Core {
namespace Internal {
class MessageOutputWindow;
class MainWindow;
}
class CORE_EXPORT MessageManager : public QObject
......@@ -47,12 +48,7 @@ class CORE_EXPORT MessageManager : public QObject
Q_OBJECT
public: