diff --git a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp index e1bca5391d2..e3a2a1aa3ff 100644 --- a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp @@ -91,11 +91,7 @@ public: bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString) { Q_UNUSED(arguments) - - if (!Utils::HostOsInfo::canCreateOpenGLContext(errorString)) - return false; - - return true; + return Utils::HostOsInfo::canCreateOpenGLContext(errorString); } void QmlProfilerPlugin::extensionsInitialized() diff --git a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp index c590df0d50c..6d7b69eb453 100644 --- a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp @@ -52,11 +52,14 @@ void QmlProfilerTextMark::addTypeId(int typeId) void QmlProfilerTextMark::paintIcon(QPainter *painter, const QRect &paintRect) const { + const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView(); + QTC_ASSERT(statisticsView, return); + painter->save(); painter->setPen(Qt::black); painter->fillRect(paintRect, Qt::white); painter->drawRect(paintRect); - painter->drawText(paintRect, m_viewManager->statisticsView()->summary(m_typeIds), + painter->drawText(paintRect, statisticsView->summary(m_typeIds), Qt::AlignRight | Qt::AlignVCenter); painter->restore(); } @@ -133,10 +136,13 @@ void QmlProfilerTextMarkModel::hideTextMarks() bool QmlProfilerTextMark::addToolTipContent(QLayout *target) const { + const QmlProfilerStatisticsView *statisticsView = m_viewManager->statisticsView(); + QTC_ASSERT(statisticsView, return false); + auto layout = new QGridLayout; layout->setHorizontalSpacing(10); for (int row = 0, rowEnd = m_typeIds.length(); row != rowEnd; ++row) { - const QStringList typeDetails = m_viewManager->statisticsView()->details(m_typeIds[row]); + const QStringList typeDetails = statisticsView->details(m_typeIds[row]); for (int column = 0, columnEnd = typeDetails.length(); column != columnEnd; ++column) { QLabel *label = new QLabel; label->setAlignment(column == columnEnd - 1 ? Qt::AlignRight : Qt::AlignLeft); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index ba1e17cd134..1196429d7dc 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -195,9 +195,12 @@ QmlProfilerTool::QmlProfilerTool() d->m_searchButton = new QToolButton; d->m_searchButton->setIcon(Utils::Icons::ZOOM_TOOLBAR.icon()); d->m_searchButton->setToolTip(tr("Search timeline event notes.")); + d->m_searchButton->setEnabled(false); connect(d->m_searchButton, &QToolButton::clicked, this, &QmlProfilerTool::showTimeLineSearch); - d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable()); + connect(d->m_viewContainer, &QmlProfilerViewManager::viewsCreated, this, [this]() { + d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable()); + }); d->m_displayFeaturesButton = new QToolButton; d->m_displayFeaturesButton->setIcon(Utils::Icons::FILTER.icon()); @@ -451,6 +454,7 @@ void QmlProfilerTool::updateTimeDisplay() void QmlProfilerTool::showTimeLineSearch() { QmlProfilerTraceView *traceView = d->m_viewContainer->traceView(); + QTC_ASSERT(traceView, return); QTC_ASSERT(qobject_cast(traceView->parentWidget()), return); traceView->parentWidget()->raise(); traceView->setFocus(); @@ -482,7 +486,8 @@ void QmlProfilerTool::setButtonsEnabled(bool enable) { d->m_clearButton->setEnabled(enable); d->m_displayFeaturesButton->setEnabled(enable); - d->m_searchButton->setEnabled(d->m_viewContainer->traceView()->isUsable() && enable); + const QmlProfilerTraceView *traceView = d->m_viewContainer->traceView(); + d->m_searchButton->setEnabled(traceView && traceView->isUsable() && enable); d->m_recordFeaturesMenu->setEnabled(enable); } diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp index a5f07a63f2e..9432407d7b6 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp @@ -51,6 +51,12 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, QTC_ASSERT(m_profilerModelManager, return); QTC_ASSERT(m_profilerState, return); + m_perspective = new Utils::Perspective(Constants::QmlProfilerPerspectiveId, tr("QML Profiler")); + m_perspective->setAboutToActivateCallback([this]() { createViews(); }); +} + +void QmlProfilerViewManager::createViews() +{ m_traceView = new QmlProfilerTraceView(nullptr, this, m_profilerModelManager); connect(m_traceView, &QmlProfilerTraceView::gotoSourceLocation, this, &QmlProfilerViewManager::gotoSourceLocation); @@ -61,8 +67,6 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, new QmlProfilerStateWidget(m_profilerState, m_profilerModelManager, m_traceView); - m_perspective = new Utils::Perspective(Constants::QmlProfilerPerspectiveId, tr("QML Profiler")); - auto prepareEventsView = [this](QmlProfilerEventsView *view) { connect(view, &QmlProfilerEventsView::typeSelected, this, &QmlProfilerViewManager::typeSelected); @@ -93,6 +97,8 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, } m_perspective->addWindow(m_statisticsView, Perspective::AddToTab, anchorDock); m_perspective->addWindow(anchorDock, Perspective::Raise, nullptr); + m_perspective->setAboutToActivateCallback(Perspective::Callback()); + emit viewsCreated(); } QmlProfilerViewManager::~QmlProfilerViewManager() @@ -105,7 +111,8 @@ QmlProfilerViewManager::~QmlProfilerViewManager() void QmlProfilerViewManager::clear() { - m_traceView->clear(); + if (m_traceView) + m_traceView->clear(); } } // namespace Internal diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h index f03f3032ff3..d65f3c4965a 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h @@ -58,8 +58,11 @@ public: signals: void typeSelected(int typeId); void gotoSourceLocation(QString,int,int); + void viewsCreated(); private: + void createViews(); + QmlProfilerTraceView *m_traceView = nullptr; QmlProfilerStatisticsView *m_statisticsView = nullptr; FlameGraphView *m_flameGraphView = nullptr;