timelinemodelaggregator.cpp 8.19 KB
Newer Older
Christiaan Janssen's avatar
Christiaan Janssen committed
1
2
/****************************************************************************
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
Christiaan Janssen's avatar
Christiaan Janssen committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "timelinemodelaggregator.h"

#include "qmlprofilertimelinemodelproxy.h"
#include "qmlprofilerpainteventsmodelproxy.h"
#include "qmlprofilerplugin.h"

#include <QStringList>
#include <QVariant>

namespace QmlProfiler {
namespace Internal {


class TimelineModelAggregator::TimelineModelAggregatorPrivate {
public:
    TimelineModelAggregatorPrivate(TimelineModelAggregator *qq):q(qq) {}
    ~TimelineModelAggregatorPrivate() {}

    TimelineModelAggregator *q;

    QList <AbstractTimelineModel *> modelList;
    QmlProfilerModelManager *modelManager;
};

TimelineModelAggregator::TimelineModelAggregator(QObject *parent)
    : QObject(parent), d(new TimelineModelAggregatorPrivate(this))
{
}

TimelineModelAggregator::~TimelineModelAggregator()
{
    delete d;
}

void TimelineModelAggregator::setModelManager(QmlProfilerModelManager *modelManager)
{
    d->modelManager = modelManager;
    connect(modelManager,SIGNAL(stateChanged()),this,SLOT(dataChanged()));
    connect(modelManager,SIGNAL(dataAvailable()),this,SIGNAL(dataAvailable()));

    // external models pushed on top
    foreach (AbstractTimelineModel *timelineModel, QmlProfilerPlugin::instance->getModels()) {
        timelineModel->setModelManager(modelManager);
        addModel(timelineModel);
    }

    PaintEventsModelProxy *paintEventsModelProxy = new PaintEventsModelProxy(this);
    paintEventsModelProxy->setModelManager(modelManager);
    addModel(paintEventsModelProxy);

80
81
82
83
84
    for (int i = 0; i < QmlDebug::MaximumRangeType; ++i) {
        RangeTimelineModel *rangeModel = new RangeTimelineModel((QmlDebug::RangeType)i, this);
        rangeModel->setModelManager(modelManager);
        addModel(rangeModel);
    }
85
86
87

    // Connect this last so that it's executed after the models have updated their data.
    connect(modelManager->qmlModel(),SIGNAL(changed()),this,SIGNAL(stateChanged()));
Christiaan Janssen's avatar
Christiaan Janssen committed
88
89
90
91
92
93
94
95
96
97
98
99
}

void TimelineModelAggregator::addModel(AbstractTimelineModel *m)
{
    d->modelList << m;
    connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged()));
}

QStringList TimelineModelAggregator::categoryTitles() const
{
    QStringList retString;
    foreach (const AbstractTimelineModel *modelProxy, d->modelList)
100
        retString << modelProxy->title();
Christiaan Janssen's avatar
Christiaan Janssen committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    return retString;
}

int TimelineModelAggregator::count(int modelIndex) const
{
    if (modelIndex == -1) {
        int totalCount = 0;
        foreach (const AbstractTimelineModel *modelProxy, d->modelList)
            totalCount += modelProxy->count();

        return totalCount;
    } else {
        return d->modelList[modelIndex]->count();
    }
}

bool TimelineModelAggregator::isEmpty() const
{
    foreach (const AbstractTimelineModel *modelProxy, d->modelList)
        if (!modelProxy->isEmpty())
            return false;
    return true;
}

125
bool TimelineModelAggregator::eventAccepted(const QmlProfilerDataModel::QmlEventData &/*event*/) const
Christiaan Janssen's avatar
Christiaan Janssen committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
    // accept all events
    return true;
}

qint64 TimelineModelAggregator::lastTimeMark() const
{
    qint64 mark = -1;
    foreach (const AbstractTimelineModel *modelProxy, d->modelList) {
        if (!modelProxy->isEmpty()) {
            qint64 mk = modelProxy->lastTimeMark();
            if (mark > mk)
                mark = mk;
        }
    }
    return mark;
}

144
bool TimelineModelAggregator::expanded(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
145
{
146
    return d->modelList[modelIndex]->expanded();
Christiaan Janssen's avatar
Christiaan Janssen committed
147
148
}

149
void TimelineModelAggregator::setExpanded(int modelIndex, bool expanded)
Christiaan Janssen's avatar
Christiaan Janssen committed
150
{
151
    d->modelList[modelIndex]->setExpanded(expanded);
Christiaan Janssen's avatar
Christiaan Janssen committed
152
153
154
155
156
157
158
}

int TimelineModelAggregator::rowCount(int modelIndex) const
{
    return d->modelList[modelIndex]->rowCount();
}

159
const QString TimelineModelAggregator::title(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
160
{
161
    return d->modelList[modelIndex]->title();
Christiaan Janssen's avatar
Christiaan Janssen committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
}

int TimelineModelAggregator::findFirstIndex(int modelIndex, qint64 startTime) const
{
    return d->modelList[modelIndex]->findFirstIndex(startTime);
}

int TimelineModelAggregator::findFirstIndexNoParents(int modelIndex, qint64 startTime) const
{
    return d->modelList[modelIndex]->findFirstIndexNoParents(startTime);
}

int TimelineModelAggregator::findLastIndex(int modelIndex, qint64 endTime) const
{
    return d->modelList[modelIndex]->findLastIndex(endTime);
}

int TimelineModelAggregator::getEventRow(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getEventRow(index);
}

qint64 TimelineModelAggregator::getDuration(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getDuration(index);
}

qint64 TimelineModelAggregator::getStartTime(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getStartTime(index);
}

qint64 TimelineModelAggregator::getEndTime(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getEndTime(index);
}

int TimelineModelAggregator::getEventId(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getEventId(index);
}

int TimelineModelAggregator::getBindingLoopDest(int modelIndex,int index) const
{
    return d->modelList[modelIndex]->getBindingLoopDest(index);
}

QColor TimelineModelAggregator::getColor(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getColor(index);
}

float TimelineModelAggregator::getHeight(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getHeight(index);
}

219
const QVariantList TimelineModelAggregator::getLabels(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
220
{
221
    return d->modelList[modelIndex]->getLabels();
Christiaan Janssen's avatar
Christiaan Janssen committed
222
223
224
225
226
227
228
229
230
231
232
233
}

const QVariantList TimelineModelAggregator::getEventDetails(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getEventDetails(index);
}

const QVariantMap TimelineModelAggregator::getEventLocation(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->getEventLocation(index);
}

234
int TimelineModelAggregator::getEventIdForTypeIndex(int modelIndex, int typeIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
235
{
236
    return d->modelList[modelIndex]->getEventIdForTypeIndex(typeIndex);
Christiaan Janssen's avatar
Christiaan Janssen committed
237
238
}

239
240
int TimelineModelAggregator::getEventIdForLocation(int modelIndex, const QString &filename,
                                                   int line, int column) const
Christiaan Janssen's avatar
Christiaan Janssen committed
241
{
242
    return d->modelList[modelIndex]->getEventIdForLocation(filename, line, column);
Christiaan Janssen's avatar
Christiaan Janssen committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
}

void TimelineModelAggregator::dataChanged()
{
    // this is a slot connected for every modelproxy
    // nothing to do here, each model will take care of itself
}

int TimelineModelAggregator::modelCount() const
{
    return d->modelList.count();
}

qint64 TimelineModelAggregator::traceStartTime() const
{
    return d->modelManager->traceTime()->startTime();
}

qint64 TimelineModelAggregator::traceEndTime() const
{
    return d->modelManager->traceTime()->endTime();
}

qint64 TimelineModelAggregator::traceDuration() const
{
    return d->modelManager->traceTime()->duration();
}

int TimelineModelAggregator::getState() const
{
    return (int)d->modelManager->state();
}


} // namespace Internal
} // namespace QmlProfiler