1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "qmlprofilertimelinemodel.h"
27
28 namespace QmlProfiler {
29
QmlProfilerTimelineModel(QmlProfilerModelManager * modelManager,Message message,RangeType rangeType,ProfileFeature mainFeature,Timeline::TimelineModelAggregator * parent)30 QmlProfilerTimelineModel::QmlProfilerTimelineModel(QmlProfilerModelManager *modelManager,
31 Message message, RangeType rangeType,
32 ProfileFeature mainFeature,
33 Timeline::TimelineModelAggregator *parent) :
34 TimelineModel(parent), m_message(message), m_rangeType(rangeType), m_mainFeature(mainFeature),
35 m_modelManager(modelManager)
36 {
37 setDisplayName(tr(QmlProfilerModelManager::featureName(mainFeature)));
38 connect(modelManager, &QmlProfilerModelManager::typeDetailsFinished,
39 this, &Timeline::TimelineModel::labelsChanged);
40 connect(modelManager, &QmlProfilerModelManager::typeDetailsFinished,
41 this, &Timeline::TimelineModel::detailsChanged);
42 connect(modelManager, &QmlProfilerModelManager::visibleFeaturesChanged,
43 this, &QmlProfilerTimelineModel::onVisibleFeaturesChanged);
44
45 m_modelManager->registerFeatures(1ULL << m_mainFeature,
46 std::bind(&QmlProfilerTimelineModel::loadEvent, this,
47 std::placeholders::_1, std::placeholders::_2),
48 std::bind(&QmlProfilerTimelineModel::initialize, this),
49 std::bind(&QmlProfilerTimelineModel::finalize, this),
50 std::bind(&QmlProfilerTimelineModel::clear, this));
51 }
52
rangeType() const53 RangeType QmlProfilerTimelineModel::rangeType() const
54 {
55 return m_rangeType;
56 }
57
message() const58 Message QmlProfilerTimelineModel::message() const
59 {
60 return m_message;
61 }
62
mainFeature() const63 ProfileFeature QmlProfilerTimelineModel::mainFeature() const
64 {
65 return m_mainFeature;
66 }
67
handlesTypeId(int typeIndex) const68 bool QmlProfilerTimelineModel::handlesTypeId(int typeIndex) const
69 {
70 if (typeIndex < 0)
71 return false;
72
73 return modelManager()->eventType(typeIndex).feature() == m_mainFeature;
74 }
75
modelManager() const76 QmlProfilerModelManager *QmlProfilerTimelineModel::modelManager() const
77 {
78 return m_modelManager;
79 }
80
onVisibleFeaturesChanged(quint64 features)81 void QmlProfilerTimelineModel::onVisibleFeaturesChanged(quint64 features)
82 {
83 setHidden(!(features & (1ULL << m_mainFeature)));
84 }
85
locationFromTypeId(int index) const86 QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const
87 {
88 QVariantMap result;
89 int id = typeId(index);
90 if (id < 0)
91 return result;
92
93 const QmlProfilerModelManager *manager = modelManager();
94 if (id >= manager->numEventTypes())
95 return result;
96
97 QmlEventLocation location = manager->eventType(id).location();
98
99 result.insert(QStringLiteral("file"), location.filename());
100 result.insert(QStringLiteral("line"), location.line());
101 result.insert(QStringLiteral("column"), location.column());
102
103 return result;
104 }
105
initialize()106 void QmlProfilerTimelineModel::initialize()
107 {
108 setHidden(!(modelManager()->visibleFeatures() & (1ULL << m_mainFeature)));
109 }
110
finalize()111 void QmlProfilerTimelineModel::finalize()
112 {
113 emit contentChanged();
114 }
115
116 } // namespace QmlProfiler
117