Analyzer: Do not make each tool current on startup.

Avoid adding all dock widgets of all tools to the mainwindow
to save the default settings during initialization.
This commit is contained in:
Friedemann Kleint
2011-05-06 14:02:03 +02:00
parent 0c27e12824
commit 74d65c7e18
4 changed files with 73 additions and 47 deletions

View File

@@ -165,6 +165,15 @@ public:
} }
}; };
struct ToolDockWidgetData
{
ToolDockWidgetData(Qt::DockWidgetArea a, QDockWidget *w, QDockWidget *t) :
area(a), widget(w), tabifyTo(t) {}
Qt::DockWidgetArea area;
QDockWidget *widget;
QDockWidget *tabifyTo;
};
} // namespace Internal } // namespace Internal
} // namespace Analyzer } // namespace Analyzer
@@ -212,12 +221,11 @@ public:
QStackedWidget *m_controlsWidget; QStackedWidget *m_controlsWidget;
ActionContainer *m_viewsMenu; ActionContainer *m_viewsMenu;
Utils::StatusLabel *m_statusLabel; Utils::StatusLabel *m_statusLabel;
typedef QPair<Qt::DockWidgetArea, QDockWidget *> ToolWidgetPair; typedef QMap<IAnalyzerTool *, FancyMainWindowSettings> MainWindowSettingsMap;
typedef QList<ToolWidgetPair> ToolWidgetPairList; QMap<IAnalyzerTool *, QList<ToolDockWidgetData> > m_toolWidgets;
QMap<IAnalyzerTool *, ToolWidgetPairList> m_toolWidgets;
DockWidgetEventFilter *m_resizeEventFilter; DockWidgetEventFilter *m_resizeEventFilter;
QMap<IAnalyzerTool *, FancyMainWindowSettings> m_defaultSettings; MainWindowSettingsMap m_defaultSettings;
// list of dock widgets to prevent memory leak // list of dock widgets to prevent memory leak
typedef QWeakPointer<QDockWidget> DockPtr; typedef QWeakPointer<QDockWidget> DockPtr;
@@ -225,6 +233,7 @@ public:
bool m_restartOnStop; bool m_restartOnStop;
bool m_initialized; bool m_initialized;
IAnalyzerTool *m_currentTool;
}; };
AnalyzerManager::AnalyzerManagerPrivate::AnalyzerManagerPrivate(AnalyzerManager *qq): AnalyzerManager::AnalyzerManagerPrivate::AnalyzerManagerPrivate(AnalyzerManager *qq):
@@ -245,7 +254,8 @@ AnalyzerManager::AnalyzerManagerPrivate::AnalyzerManagerPrivate(AnalyzerManager
m_statusLabel(new Utils::StatusLabel), m_statusLabel(new Utils::StatusLabel),
m_resizeEventFilter(new DockWidgetEventFilter(qq)), m_resizeEventFilter(new DockWidgetEventFilter(qq)),
m_restartOnStop(false), m_restartOnStop(false),
m_initialized(false) m_initialized(false),
m_currentTool(0)
{ {
m_toolBox->setObjectName(QLatin1String("AnalyzerManagerToolBox")); m_toolBox->setObjectName(QLatin1String("AnalyzerManagerToolBox"));
m_runControlFactory = new AnalyzerRunControlFactory(); m_runControlFactory = new AnalyzerRunControlFactory();
@@ -640,37 +650,49 @@ void AnalyzerManager::selectTool(IAnalyzerTool *tool)
void AnalyzerManager::toolSelected(int idx) void AnalyzerManager::toolSelected(int idx)
{ {
static bool selectingTool = false; static bool selectingTool = false;
if (selectingTool)
return;
selectingTool = true;
IAnalyzerTool *oldTool = currentTool(); IAnalyzerTool *oldTool = currentTool();
IAnalyzerTool *newTool = d->m_tools.at(idx);
if (selectingTool || oldTool == newTool)
return;
selectingTool = true;
if (oldTool != 0) { if (oldTool != 0) {
saveToolSettings(oldTool); saveToolSettings(oldTool);
ActionManager *am = ICore::instance()->actionManager(); ActionManager *am = ICore::instance()->actionManager();
foreach(const AnalyzerManagerPrivate::ToolWidgetPair &widget, d->m_toolWidgets.value(oldTool)) { foreach (const ToolDockWidgetData &widget, d->m_toolWidgets.value(oldTool)) {
QAction *toggleViewAction = widget.second->toggleViewAction(); QAction *toggleViewAction = widget.widget->toggleViewAction();
am->unregisterAction(toggleViewAction, QString("Analyzer." + widget.second->objectName())); am->unregisterAction(toggleViewAction, QString("Analyzer." + widget.widget->objectName()));
d->m_mainWindow->removeDockWidget(widget.second); d->m_mainWindow->removeDockWidget(widget.widget);
///NOTE: QMainWindow (and FancyMainWindow) just look at @c findChildren<QDockWidget*>() ///NOTE: QMainWindow (and FancyMainWindow) just look at @c findChildren<QDockWidget*>()
///if we don't do this, all kind of havoc might happen, including: ///if we don't do this, all kind of havoc might happen, including:
///- improper saveState/restoreState ///- improper saveState/restoreState
///- improper list of qdockwidgets in popup menu ///- improper list of qdockwidgets in popup menu
///- ... ///- ...
widget.second->setParent(0); widget.widget->setParent(0);
} }
} }
d->m_currentTool = newTool;
d->m_toolGroup->actions().at(idx)->setChecked(true); d->m_toolGroup->actions().at(idx)->setChecked(true);
d->m_toolBox->setCurrentIndex(idx); d->m_toolBox->setCurrentIndex(idx);
d->m_controlsWidget->setCurrentIndex(idx); d->m_controlsWidget->setCurrentIndex(idx);
IAnalyzerTool *newTool = currentTool(); const bool firstTime = !d->m_defaultSettings.contains(newTool);
foreach (const AnalyzerManagerPrivate::ToolWidgetPair &widget, d->m_toolWidgets.value(newTool)) { foreach (const ToolDockWidgetData &widget, d->m_toolWidgets.value(newTool)) {
d->addDock(newTool, widget.first, widget.second); d->addDock(newTool, widget.area, widget.widget);
if (firstTime && widget.tabifyTo)
d->m_mainWindow->tabifyDockWidget(widget.tabifyTo, widget.widget);
} }
if (firstTime) // Save default settings first time
d->m_defaultSettings.insert(newTool, d->m_mainWindow->saveSettings());
loadToolSettings(newTool); loadToolSettings(newTool);
d->m_outputpane->setTool(newTool); d->m_outputpane->setTool(newTool);
@@ -694,6 +716,7 @@ void AnalyzerManager::addTool(IAnalyzerTool *tool)
QAction *action = new QAction(tool->displayName(), d->m_toolGroup); QAction *action = new QAction(tool->displayName(), d->m_toolGroup);
action->setData(d->m_tools.count()); action->setData(d->m_tools.count());
action->setCheckable(true); action->setCheckable(true);
action->setChecked(false);
ActionManager *am = Core::ICore::instance()->actionManager(); ActionManager *am = Core::ICore::instance()->actionManager();
@@ -703,24 +726,26 @@ void AnalyzerManager::addTool(IAnalyzerTool *tool)
d->m_toolGroup->setVisible(d->m_toolGroup->actions().count() > 1); d->m_toolGroup->setVisible(d->m_toolGroup->actions().count() > 1);
d->m_tools.append(tool); d->m_tools.append(tool);
d->m_toolBox->addItem(tool->displayName());
const bool blocked = d->m_toolBox->blockSignals(true); // Do not make current.
d->m_toolBox->addItem(tool->displayName());
d->m_toolBox->blockSignals(blocked);
// Populate output pane
d->m_outputpane->setTool(tool);
// populate controls widget // populate controls widget
QWidget *controlWidget = tool->createControlWidget(); // might be 0 QWidget *controlWidget = tool->createControlWidget(); // might be 0
d->m_controlsWidget->addWidget(controlWidget ? controlWidget : AnalyzerUtils::createDummyWidget()); d->m_controlsWidget->addWidget(controlWidget ? controlWidget : AnalyzerUtils::createDummyWidget());
d->m_toolBox->setEnabled(d->m_toolBox->count() > 1); d->m_toolBox->setEnabled(d->m_toolBox->count() > 1);
if (currentTool() != tool)
selectTool(tool); // the first tool gets selected automatically due to signal emission from toolbox
tool->initialize(plugin); tool->initialize(plugin);
d->m_defaultSettings.insert(tool, d->m_mainWindow->saveSettings());
loadToolSettings(tool);
} }
QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, const QString &title, QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, const QString &title,
QWidget *widget, Qt::DockWidgetArea area) QWidget *widget, Qt::DockWidgetArea area,
QDockWidget *tabifyTo)
{ {
QTC_ASSERT(!widget->objectName().isEmpty(), return 0;); QTC_ASSERT(!widget->objectName().isEmpty(), return 0;);
@@ -728,19 +753,14 @@ QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, const QStrin
d->m_dockWidgets << AnalyzerManagerPrivate::DockPtr(dockWidget); d->m_dockWidgets << AnalyzerManagerPrivate::DockPtr(dockWidget);
dockWidget->setWindowTitle(title); dockWidget->setWindowTitle(title);
d->m_toolWidgets[tool] << qMakePair(area, dockWidget); d->m_toolWidgets[tool].push_back(ToolDockWidgetData(area, dockWidget, tabifyTo));
dockWidget->installEventFilter(d->m_resizeEventFilter); dockWidget->installEventFilter(d->m_resizeEventFilter);
d->addDock(tool, area, dockWidget);
return dockWidget; return dockWidget;
} }
IAnalyzerTool *AnalyzerManager::currentTool() const IAnalyzerTool *AnalyzerManager::currentTool() const
{ {
if (const QAction *ca = d->m_toolGroup->checkedAction()) return d->m_currentTool;
return d->m_tools.value(ca->data().toInt());
return 0;
} }
QList<IAnalyzerTool *> AnalyzerManager::tools() const QList<IAnalyzerTool *> AnalyzerManager::tools() const

View File

@@ -89,7 +89,8 @@ public:
// dockwidgets are registered to the main window // dockwidgets are registered to the main window
QDockWidget *createDockWidget(IAnalyzerTool *tool, const QString &title, QWidget *widget, QDockWidget *createDockWidget(IAnalyzerTool *tool, const QString &title, QWidget *widget,
Qt::DockWidgetArea area = Qt::TopDockWidgetArea); Qt::DockWidgetArea area = Qt::TopDockWidgetArea,
QDockWidget *tabifyTo = 0);
Utils::FancyMainWindow *mainWindow() const; Utils::FancyMainWindow *mainWindow() const;

View File

@@ -129,19 +129,24 @@ void AnalyzerPlugin::extensionsInitialized()
// plugins that depend on it are completely initialized." // plugins that depend on it are completely initialized."
// notify tools about the extensions initialized state // notify tools about the extensions initialized state
foreach(IAnalyzerTool *tool, d->m_manager->tools()) { const QList<IAnalyzerTool *> tools = d->m_manager->tools();
if (tools.isEmpty())
return;
const QSettings *settings = Core::ICore::instance()->settings();
const QString lastActiveToolId = settings->value(QLatin1String(lastActiveToolC), QString()).toString();
IAnalyzerTool *lastActiveTool = 0;
foreach (IAnalyzerTool *tool, tools) {
tool->extensionsInitialized(); tool->extensionsInitialized();
if (tool->id() == lastActiveToolId)
lastActiveTool = tool;
} }
// load the last active tool if (!lastActiveTool)
QSettings *settings = Core::ICore::instance()->settings(); lastActiveTool = tools.back();
const QString lastActiveTool = settings->value(lastActiveToolC, QString()).toString(); if (lastActiveTool)
foreach(IAnalyzerTool *tool, d->m_manager->tools()) { d->m_manager->selectTool(lastActiveTool);
if (tool->id() == lastActiveTool) {
d->m_manager->selectTool(tool);
break;
}
}
} }
ExtensionSystem::IPlugin::ShutdownFlag AnalyzerPlugin::aboutToShutdown() ExtensionSystem::IPlugin::ShutdownFlag AnalyzerPlugin::aboutToShutdown()

View File

@@ -164,16 +164,16 @@ void CallgrindTool::initialize(ExtensionSystem::IPlugin */*plugin*/)
CallgrindWidgetHandler *handler = new CallgrindWidgetHandler(am->mainWindow()); CallgrindWidgetHandler *handler = new CallgrindWidgetHandler(am->mainWindow());
m_callgrindWidgetHandler = handler; m_callgrindWidgetHandler = handler;
QDockWidget *visDock = am->createDockWidget(this, tr("Visualisation"),
handler->visualisation(), Qt::LeftDockWidgetArea);
QDockWidget *calleesDock = am->createDockWidget(this, tr("Callees"),
handler->calleesView(), Qt::BottomDockWidgetArea);
QDockWidget *callersDock = am->createDockWidget(this, tr("Callers"), QDockWidget *callersDock = am->createDockWidget(this, tr("Callers"),
handler->callersView(), Qt::BottomDockWidgetArea); handler->callersView(), Qt::BottomDockWidgetArea);
am->mainWindow()->tabifyDockWidget(callersDock, calleesDock); QDockWidget *calleesDock = am->createDockWidget(this, tr("Callees"),
am->mainWindow()->tabifyDockWidget(calleesDock, visDock); handler->calleesView(), Qt::BottomDockWidgetArea,
callersDock);
am->createDockWidget(this, tr("Visualisation"),
handler->visualisation(), Qt::LeftDockWidgetArea,
calleesDock);
connect(m_callgrindWidgetHandler, SIGNAL(functionSelected(const Valgrind::Callgrind::Function*)), connect(m_callgrindWidgetHandler, SIGNAL(functionSelected(const Valgrind::Callgrind::Function*)),
this, SLOT(slotFunctionSelected(const Valgrind::Callgrind::Function*))); this, SLOT(slotFunctionSelected(const Valgrind::Callgrind::Function*)));