Debugger/Perspectives: Go back to QPointer<QObject>

Lifetime of the pointed-to object may end before that of
the plugin, so unique_ptr is the wrong choice.

This amends 01f2b982a2.

Change-Id: I76b9ac78348d2ae1e7eff0693b091dbe8475ab93
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-08-02 10:21:05 +02:00
parent b07c27b546
commit e9eb1a6437
5 changed files with 41 additions and 28 deletions

View File

@@ -203,7 +203,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
m_diagnosticFilterModel = new DiagnosticFilterModel(this); m_diagnosticFilterModel = new DiagnosticFilterModel(this);
m_diagnosticFilterModel->setSourceModel(m_diagnosticModel); m_diagnosticFilterModel->setSourceModel(m_diagnosticModel);
m_diagnosticView = std::make_unique<DiagnosticView>(); m_diagnosticView = new DiagnosticView;
initDiagnosticView(); initDiagnosticView();
m_diagnosticView->setModel(m_diagnosticFilterModel); m_diagnosticView->setModel(m_diagnosticFilterModel);
m_diagnosticView->setObjectName(QLatin1String("ClangTidyClazyIssuesView")); m_diagnosticView->setObjectName(QLatin1String("ClangTidyClazyIssuesView"));
@@ -226,7 +226,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::PREV_TOOLBAR.icon()); action->setIcon(Utils::Icons::PREV_TOOLBAR.icon());
action->setToolTip(tr("Go to previous diagnostic.")); action->setToolTip(tr("Go to previous diagnostic."));
connect(action, &QAction::triggered, m_diagnosticView.get(), &DetailedErrorView::goBack); connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goBack);
m_goBack = action; m_goBack = action;
// Go to next diagnostic // Go to next diagnostic
@@ -234,7 +234,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon()); action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon());
action->setToolTip(tr("Go to next diagnostic.")); action->setToolTip(tr("Go to next diagnostic."));
connect(action, &QAction::triggered, m_diagnosticView.get(), &DetailedErrorView::goNext); connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goNext);
m_goNext = action; m_goNext = action;
// Filter line edit // Filter line edit
@@ -254,7 +254,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
&ClangToolsDiagnosticModel::fixItsToApplyCountChanged, &ClangToolsDiagnosticModel::fixItsToApplyCountChanged,
[this](int c) { [this](int c) {
m_applyFixitsButton->setEnabled(c); m_applyFixitsButton->setEnabled(c);
static_cast<DiagnosticView *>(m_diagnosticView.get())->setSelectedFixItsCount(c); static_cast<DiagnosticView *>(m_diagnosticView.data())->setSelectedFixItsCount(c);
}); });
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() { connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
QVector<DiagnosticItem *> diagnosticItems; QVector<DiagnosticItem *> diagnosticItems;
@@ -270,7 +270,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
"Clang project to search for errors and warnings."); "Clang project to search for errors and warnings.");
auto perspective = new Perspective(tr("Clang-Tidy and Clazy")); auto perspective = new Perspective(tr("Clang-Tidy and Clazy"));
perspective->addWindow(m_diagnosticView.get(), Perspective::SplitVertical, nullptr); perspective->addWindow(m_diagnosticView, Perspective::SplitVertical, nullptr);
Debugger::registerPerspective(ClangTidyClazyPerspectiveId, perspective); Debugger::registerPerspective(ClangTidyClazyPerspectiveId, perspective);
action = new QAction(tr("Clang-Tidy and Clazy..."), this); action = new QAction(tr("Clang-Tidy and Clazy..."), this);

View File

@@ -98,7 +98,10 @@ ClangTool::ClangTool(const QString &name)
m_stopAction = Debugger::createStopAction(); m_stopAction = Debugger::createStopAction();
} }
ClangTool::~ClangTool() = default; ClangTool::~ClangTool()
{
delete m_diagnosticView;
}
FileInfos ClangTool::collectFileInfos(Project *project, bool askUserForFileSelection) const FileInfos ClangTool::collectFileInfos(Project *project, bool askUserForFileSelection) const
{ {

View File

@@ -72,7 +72,7 @@ protected:
void initDiagnosticView(); void initDiagnosticView();
ClangToolsDiagnosticModel *m_diagnosticModel = nullptr; ClangToolsDiagnosticModel *m_diagnosticModel = nullptr;
std::unique_ptr<Debugger::DetailedErrorView> m_diagnosticView; QPointer<Debugger::DetailedErrorView> m_diagnosticView;
QAction *m_startAction = nullptr; QAction *m_startAction = nullptr;
QAction *m_stopAction = nullptr; QAction *m_stopAction = nullptr;

View File

@@ -182,10 +182,10 @@ public:
QSortFilterProxyModel m_calleesProxy; QSortFilterProxyModel m_calleesProxy;
// Callgrind widgets // Callgrind widgets
std::unique_ptr<CostView> m_flatView; QPointer<CostView> m_flatView;
std::unique_ptr<CostView> m_callersView; QPointer<CostView> m_callersView;
std::unique_ptr<CostView> m_calleesView; QPointer<CostView> m_calleesView;
std::unique_ptr<Visualization> m_visualization; QPointer<Visualization> m_visualization;
// Navigation // Navigation
QAction *m_goBack = nullptr; QAction *m_goBack = nullptr;
@@ -307,15 +307,15 @@ CallgrindTool::CallgrindTool()
// //
// DockWidgets // DockWidgets
// //
m_visualization = std::make_unique<Visualization>(); m_visualization = new Visualization;
m_visualization->setFrameStyle(QFrame::NoFrame); m_visualization->setFrameStyle(QFrame::NoFrame);
m_visualization->setObjectName(QLatin1String("Valgrind.CallgrindTool.Visualisation")); m_visualization->setObjectName(QLatin1String("Valgrind.CallgrindTool.Visualisation"));
m_visualization->setWindowTitle(tr("Visualization")); m_visualization->setWindowTitle(tr("Visualization"));
m_visualization->setModel(&m_dataModel); m_visualization->setModel(&m_dataModel);
connect(m_visualization.get(), &Visualization::functionActivated, connect(m_visualization, &Visualization::functionActivated,
this, &CallgrindTool::visualisationFunctionSelected); this, &CallgrindTool::visualisationFunctionSelected);
m_callersView = std::make_unique<CostView>(); m_callersView = new CostView;
m_callersView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CallersView")); m_callersView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CallersView"));
m_callersView->setWindowTitle(tr("Callers")); m_callersView->setWindowTitle(tr("Callers"));
m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView"); m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView");
@@ -325,10 +325,10 @@ CallgrindTool::CallgrindTool()
m_callersProxy.setSourceModel(&m_callersModel); m_callersProxy.setSourceModel(&m_callersModel);
m_callersView->setModel(&m_callersProxy); m_callersView->setModel(&m_callersProxy);
m_callersView->hideColumn(CallModel::CalleeColumn); m_callersView->hideColumn(CallModel::CalleeColumn);
connect(m_callersView.get(), &QAbstractItemView::activated, connect(m_callersView, &QAbstractItemView::activated,
this, &CallgrindTool::callerFunctionSelected); this, &CallgrindTool::callerFunctionSelected);
m_calleesView = std::make_unique<CostView>(); m_calleesView = new CostView;
m_calleesView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CalleesView")); m_calleesView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CalleesView"));
m_calleesView->setWindowTitle(tr("Callees")); m_calleesView->setWindowTitle(tr("Callees"));
m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView"); m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView");
@@ -338,10 +338,10 @@ CallgrindTool::CallgrindTool()
m_calleesProxy.setSourceModel(&m_calleesModel); m_calleesProxy.setSourceModel(&m_calleesModel);
m_calleesView->setModel(&m_calleesProxy); m_calleesView->setModel(&m_calleesProxy);
m_calleesView->hideColumn(CallModel::CallerColumn); m_calleesView->hideColumn(CallModel::CallerColumn);
connect(m_calleesView.get(), &QAbstractItemView::activated, connect(m_calleesView, &QAbstractItemView::activated,
this, &CallgrindTool::calleeFunctionSelected); this, &CallgrindTool::calleeFunctionSelected);
m_flatView = std::make_unique<CostView>(); m_flatView = new CostView;
m_flatView->setObjectName(QLatin1String("Valgrind.CallgrindTool.FlatView")); m_flatView->setObjectName(QLatin1String("Valgrind.CallgrindTool.FlatView"));
m_flatView->setWindowTitle(tr("Functions")); m_flatView->setWindowTitle(tr("Functions"));
m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView"); m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView");
@@ -349,7 +349,7 @@ CallgrindTool::CallgrindTool()
m_flatView->setFrameStyle(QFrame::NoFrame); m_flatView->setFrameStyle(QFrame::NoFrame);
m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false); m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false);
m_flatView->setModel(&m_proxyModel); m_flatView->setModel(&m_proxyModel);
connect(m_flatView.get(), &QAbstractItemView::activated, connect(m_flatView, &QAbstractItemView::activated,
this, &CallgrindTool::dataFunctionSelected); this, &CallgrindTool::dataFunctionSelected);
updateCostFormat(); updateCostFormat();
@@ -507,10 +507,10 @@ CallgrindTool::CallgrindTool()
Debugger::registerToolbar(CallgrindPerspectiveId, toolbar); Debugger::registerToolbar(CallgrindPerspectiveId, toolbar);
auto perspective = new Perspective(tr("Callgrind")); auto perspective = new Perspective(tr("Callgrind"));
perspective->addWindow(m_flatView.get(), Perspective::SplitVertical, nullptr); perspective->addWindow(m_flatView, Perspective::SplitVertical, nullptr);
perspective->addWindow(m_calleesView.get(), Perspective::SplitVertical, nullptr); perspective->addWindow(m_calleesView, Perspective::SplitVertical, nullptr);
perspective->addWindow(m_callersView.get(), Perspective::SplitHorizontal, m_calleesView.get()); perspective->addWindow(m_callersView, Perspective::SplitHorizontal, m_calleesView);
perspective->addWindow(m_visualization.get(), Perspective::SplitVertical, nullptr, perspective->addWindow(m_visualization, Perspective::SplitVertical, nullptr,
false, Qt::RightDockWidgetArea); false, Qt::RightDockWidgetArea);
Debugger::registerPerspective(CallgrindPerspectiveId, perspective); Debugger::registerPerspective(CallgrindPerspectiveId, perspective);
@@ -521,6 +521,10 @@ CallgrindTool::CallgrindTool()
CallgrindTool::~CallgrindTool() CallgrindTool::~CallgrindTool()
{ {
qDeleteAll(m_textMarks); qDeleteAll(m_textMarks);
delete m_flatView;
delete m_callersView;
delete m_calleesView;
delete m_visualization;
} }
void CallgrindTool::doClear(bool clearParseData) void CallgrindTool::doClear(bool clearParseData)

View File

@@ -391,6 +391,7 @@ class MemcheckTool : public QObject
public: public:
MemcheckTool(); MemcheckTool();
~MemcheckTool();
void setupRunner(MemcheckToolRunner *runTool); void setupRunner(MemcheckToolRunner *runTool);
void loadShowXmlLogFile(const QString &filePath, const QString &exitMsg); void loadShowXmlLogFile(const QString &filePath, const QString &exitMsg);
@@ -424,7 +425,7 @@ private:
Valgrind::XmlProtocol::ErrorListModel m_errorModel; Valgrind::XmlProtocol::ErrorListModel m_errorModel;
MemcheckErrorFilterProxyModel m_errorProxyModel; MemcheckErrorFilterProxyModel m_errorProxyModel;
std::unique_ptr<MemcheckErrorView> m_errorView; QPointer<MemcheckErrorView> m_errorView;
QList<QAction *> m_errorFilterActions; QList<QAction *> m_errorFilterActions;
QAction *m_filterProjectAction; QAction *m_filterProjectAction;
@@ -539,7 +540,7 @@ MemcheckTool::MemcheckTool()
initKindFilterAction(a, { InvalidFree, MismatchedFree }); initKindFilterAction(a, { InvalidFree, MismatchedFree });
m_errorFilterActions.append(a); m_errorFilterActions.append(a);
m_errorView = std::make_unique<MemcheckErrorView>(); m_errorView = new MemcheckErrorView;
m_errorView->setObjectName(QLatin1String("MemcheckErrorView")); m_errorView->setObjectName(QLatin1String("MemcheckErrorView"));
m_errorView->setFrameStyle(QFrame::NoFrame); m_errorView->setFrameStyle(QFrame::NoFrame);
m_errorView->setAttribute(Qt::WA_MacShowFocusRect, false); m_errorView->setAttribute(Qt::WA_MacShowFocusRect, false);
@@ -556,7 +557,7 @@ MemcheckTool::MemcheckTool()
m_errorView->setWindowTitle(tr("Memory Issues")); m_errorView->setWindowTitle(tr("Memory Issues"));
auto perspective = new Perspective(tr("Memcheck")); auto perspective = new Perspective(tr("Memcheck"));
perspective->addWindow(m_errorView.get(), Perspective::SplitVertical, nullptr); perspective->addWindow(m_errorView, Perspective::SplitVertical, nullptr);
Debugger::registerPerspective(MemcheckPerspectiveId, perspective); Debugger::registerPerspective(MemcheckPerspectiveId, perspective);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
@@ -582,7 +583,7 @@ MemcheckTool::MemcheckTool()
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Icons::PREV_TOOLBAR.icon()); action->setIcon(Icons::PREV_TOOLBAR.icon());
action->setToolTip(tr("Go to previous leak.")); action->setToolTip(tr("Go to previous leak."));
connect(action, &QAction::triggered, m_errorView.get(), &MemcheckErrorView::goBack); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goBack);
m_goBack = action; m_goBack = action;
// Go to next leak. // Go to next leak.
@@ -590,7 +591,7 @@ MemcheckTool::MemcheckTool()
action->setDisabled(true); action->setDisabled(true);
action->setIcon(Icons::NEXT_TOOLBAR.icon()); action->setIcon(Icons::NEXT_TOOLBAR.icon());
action->setToolTip(tr("Go to next leak.")); action->setToolTip(tr("Go to next leak."));
connect(action, &QAction::triggered, m_errorView.get(), &MemcheckErrorView::goNext); connect(action, &QAction::triggered, m_errorView, &MemcheckErrorView::goNext);
m_goNext = action; m_goNext = action;
auto filterButton = new QToolButton; auto filterButton = new QToolButton;
@@ -697,6 +698,11 @@ MemcheckTool::MemcheckTool()
maybeActiveRunConfigurationChanged(); maybeActiveRunConfigurationChanged();
} }
MemcheckTool::~MemcheckTool()
{
delete m_errorView;
}
void MemcheckTool::heobAction() void MemcheckTool::heobAction()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN