QmlProfiler: Add qml, register types via qt_add_qml_module

Use the CMake-based qml API to create the "QtCreator.QmlProfiler"
module.
This uses qt_add_qml_module, which was introduced with Qt 6.2.

For Qt 6.1 and below, everything compiles and runs like before this
change.

Change-Id: If381059bbf2a0a2b92c7f62e6da3142036ac6bbc
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Alessandro Portale
2021-06-24 23:15:42 +02:00
parent 3ebe5dbb99
commit 9624d2cd69
6 changed files with 104 additions and 59 deletions

View File

@@ -1,15 +1,38 @@
add_qtc_plugin(QmlProfiler if(WITH_TESTS)
CONDITION TARGET Tracing set(TEST_SOURCES
DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets tests/debugmessagesmodel_test.cpp tests/debugmessagesmodel_test.h
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor tests/fakedebugserver.cpp tests/fakedebugserver.h
SOURCES tests/flamegraphmodel_test.cpp tests/flamegraphmodel_test.h
tests/flamegraphview_test.cpp tests/flamegraphview_test.h
tests/inputeventsmodel_test.cpp tests/inputeventsmodel_test.h
tests/localqmlprofilerrunner_test.cpp tests/localqmlprofilerrunner_test.h
tests/memoryusagemodel_test.cpp tests/memoryusagemodel_test.h
tests/pixmapcachemodel_test.cpp tests/pixmapcachemodel_test.h
tests/qmlevent_test.cpp tests/qmlevent_test.h
tests/qmleventlocation_test.cpp tests/qmleventlocation_test.h
tests/qmleventtype_test.cpp tests/qmleventtype_test.h
tests/qmlnote_test.cpp tests/qmlnote_test.h
tests/qmlprofileranimationsmodel_test.cpp tests/qmlprofileranimationsmodel_test.h
tests/qmlprofilerattachdialog_test.cpp tests/qmlprofilerattachdialog_test.h
tests/qmlprofilerbindingloopsrenderpass_test.cpp tests/qmlprofilerbindingloopsrenderpass_test.h
tests/qmlprofilerclientmanager_test.cpp tests/qmlprofilerclientmanager_test.h
tests/qmlprofilerdetailsrewriter_test.cpp tests/qmlprofilerdetailsrewriter_test.h
tests/qmlprofilertool_test.cpp tests/qmlprofilertool_test.h
tests/qmlprofilertraceclient_test.cpp tests/qmlprofilertraceclient_test.h
tests/qmlprofilertraceview_test.cpp tests/qmlprofilertraceview_test.h
tests/tests.qrc
)
else()
set(TEST_SOURCES "")
endif()
set(QMLPROFILER_CPP_SOURCES
debugmessagesmodel.cpp debugmessagesmodel.h debugmessagesmodel.cpp debugmessagesmodel.h
flamegraphmodel.cpp flamegraphmodel.h flamegraphmodel.cpp flamegraphmodel.h
flamegraphview.cpp flamegraphview.h flamegraphview.cpp flamegraphview.h
inputeventsmodel.cpp inputeventsmodel.h inputeventsmodel.cpp inputeventsmodel.h
memoryusagemodel.cpp memoryusagemodel.h memoryusagemodel.cpp memoryusagemodel.h
pixmapcachemodel.cpp pixmapcachemodel.h pixmapcachemodel.cpp pixmapcachemodel.h
qml/qmlprofiler.qrc
qmlevent.cpp qmlevent.h qmlevent.cpp qmlevent.h
qmleventlocation.cpp qmleventlocation.h qmleventlocation.cpp qmleventlocation.h
qmleventtype.cpp qmleventtype.h qmleventtype.cpp qmleventtype.h
@@ -46,28 +69,43 @@ add_qtc_plugin(QmlProfiler
scenegraphtimelinemodel.cpp scenegraphtimelinemodel.h scenegraphtimelinemodel.cpp scenegraphtimelinemodel.h
) )
extend_qtc_plugin(QmlProfiler add_qtc_plugin(QmlProfiler
CONDITION WITH_TESTS DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor
SOURCES SOURCES
tests/debugmessagesmodel_test.cpp tests/debugmessagesmodel_test.h ${TEST_SOURCES}
tests/fakedebugserver.cpp tests/fakedebugserver.h
tests/flamegraphmodel_test.cpp tests/flamegraphmodel_test.h
tests/flamegraphview_test.cpp tests/flamegraphview_test.h
tests/inputeventsmodel_test.cpp tests/inputeventsmodel_test.h
tests/localqmlprofilerrunner_test.cpp tests/localqmlprofilerrunner_test.h
tests/memoryusagemodel_test.cpp tests/memoryusagemodel_test.h
tests/pixmapcachemodel_test.cpp tests/pixmapcachemodel_test.h
tests/qmlevent_test.cpp tests/qmlevent_test.h
tests/qmleventlocation_test.cpp tests/qmleventlocation_test.h
tests/qmleventtype_test.cpp tests/qmleventtype_test.h
tests/qmlnote_test.cpp tests/qmlnote_test.h
tests/qmlprofileranimationsmodel_test.cpp tests/qmlprofileranimationsmodel_test.h
tests/qmlprofilerattachdialog_test.cpp tests/qmlprofilerattachdialog_test.h
tests/qmlprofilerbindingloopsrenderpass_test.cpp tests/qmlprofilerbindingloopsrenderpass_test.h
tests/qmlprofilerclientmanager_test.cpp tests/qmlprofilerclientmanager_test.h
tests/qmlprofilerdetailsrewriter_test.cpp tests/qmlprofilerdetailsrewriter_test.h
tests/qmlprofilertool_test.cpp tests/qmlprofilertool_test.h
tests/qmlprofilertraceclient_test.cpp tests/qmlprofilertraceclient_test.h
tests/qmlprofilertraceview_test.cpp tests/qmlprofilertraceview_test.h
tests/tests.qrc
) )
if(${Qt5_VERSION} VERSION_LESS "6.2.0")
extend_qtc_plugin(QmlProfiler
SOURCES
${QMLPROFILER_CPP_SOURCES}
qml/qmlprofiler.qrc
)
else() # < Qt 6.2
set(QMLPROFILER_QML_FILES
qml/QmlProfilerFlameGraphView.qml
)
set(QMLPROFILER_QML_RESOURCES
qml/bindingloops.frag
qml/bindingloops.vert
)
foreach(file IN LISTS QMLPROFILER_QML_FILES QMLPROFILER_QML_RESOURCES)
get_filename_component(fileName "${file}" NAME)
set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}")
endforeach()
qt_add_qml_module(QmlProfiler
URI "QtCreator.QmlProfiler"
VERSION "1.0"
NO_CREATE_PLUGIN_TARGET
QML_FILES
${QMLPROFILER_QML_FILES}
RESOURCES
${QMLPROFILER_QML_RESOURCES}
SOURCES
${QMLPROFILER_CPP_SOURCES}
)
endif() # < Qt 6.2

View File

@@ -55,6 +55,10 @@ struct FlameGraphData {
class FlameGraphModel : public QAbstractItemModel class FlameGraphModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
QML_NAMED_ELEMENT(QmlProfilerFlameGraphModel)
QML_UNCREATABLE("use the context property")
#endif // Qt >= 6.2
public: public:
enum Role { enum Role {
TypeIdRole = Qt::UserRole + 1, // Sort by data, not by displayed string TypeIdRole = Qt::UserRole + 1, // Sort by data, not by displayed string

View File

@@ -48,15 +48,16 @@ FlameGraphView::FlameGraphView(QmlProfilerModelManager *manager, QWidget *parent
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
qmlRegisterType<FlameGraph::FlameGraph>("QtCreator.Tracing", 1, 0, "FlameGraph"); qmlRegisterType<FlameGraph::FlameGraph>("QtCreator.Tracing", 1, 0, "FlameGraph");
#endif // Qt < 6.2
qmlRegisterUncreatableType<FlameGraphModel>("QtCreator.QmlProfiler", 1, 0, qmlRegisterUncreatableType<FlameGraphModel>("QtCreator.QmlProfiler", 1, 0,
"QmlProfilerFlameGraphModel", "QmlProfilerFlameGraphModel",
QLatin1String("use the context property")); QLatin1String("use the context property"));
#endif // Qt < 6.2
Timeline::TimelineTheme::setupTheme(m_content->engine()); Timeline::TimelineTheme::setupTheme(m_content->engine());
m_content->rootContext()->setContextProperty(QStringLiteral("flameGraphModel"), m_model); m_content->rootContext()->setContextProperty(QStringLiteral("flameGraphModel"), m_model);
m_content->setSource(QUrl(QStringLiteral("qrc:/qmlprofiler/QmlProfilerFlameGraphView.qml"))); m_content->setSource(
QUrl(QStringLiteral("qrc:/QtCreator/QmlProfiler/QmlProfilerFlameGraphView.qml")));
m_content->setClearColor(Utils::creatorTheme()->color(Utils::Theme::Timeline_BackgroundColor1)); m_content->setClearColor(Utils::creatorTheme()->color(Utils::Theme::Timeline_BackgroundColor1));
m_content->setResizeMode(QQuickWidget::SizeRootObjectToView); m_content->setResizeMode(QQuickWidget::SizeRootObjectToView);

View File

@@ -24,7 +24,7 @@
****************************************************************************/ ****************************************************************************/
import QtCreator.QmlProfiler 1.0 import QtCreator.QmlProfiler 1.0
import "../QtCreator/Tracing/" // TODO: Turn into module import when possible import "../Tracing" // TODO: Turn into module import when possible
FlameGraphView { FlameGraphView {
id: root id: root

View File

@@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/qmlprofiler"> <qresource prefix="/QtCreator/QmlProfiler">
<file>bindingloops.vert</file> <file>bindingloops.vert</file>
<file>bindingloops.frag</file> <file>bindingloops.frag</file>
<file>QmlProfilerFlameGraphView.qml</file> <file>QmlProfilerFlameGraphView.qml</file>

View File

@@ -317,11 +317,13 @@ BindingLoopMaterialShader::BindingLoopMaterialShader()
: QSGMaterialShader() : QSGMaterialShader()
{ {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qmlprofiler/bindingloops.vert")); setShaderSourceFile(QOpenGLShader::Vertex,
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qmlprofiler/bindingloops.frag")); QStringLiteral(":/QtCreator/QmlProfiler/bindingloops.vert"));
setShaderSourceFile(QOpenGLShader::Fragment,
QStringLiteral(":/QtCreator/QmlProfiler/bindingloops.frag"));
#else // < Qt 6 #else // < Qt 6
setShaderFileName(VertexStage, ":/qmlprofiler/bindingloops.vert"); setShaderFileName(VertexStage, ":/QtCreator/QmlProfiler/bindingloops.vert");
setShaderFileName(FragmentStage, ":/qmlprofiler/bindingloops.frag"); setShaderFileName(FragmentStage, ":/QtCreator/QmlProfiler/bindingloops.frag");
#endif // < Qt 6 #endif // < Qt 6
} }