timelinemodelaggregator.cpp 11.4 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
** 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
Eike Ziller's avatar
Eike Ziller committed
13
14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
Christiaan Janssen's avatar
Christiaan Janssen committed
15
16
17
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Christiaan Janssen's avatar
Christiaan Janssen committed
24
25
26
27
28
29
30
31
32
**
** 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"

33
34
#include "qmlprofilerrangemodel.h"
#include "qmlprofileranimationsmodel.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
35
#include "qmlprofilerplugin.h"
36
#include "qmlprofilernotesmodel.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

#include <QStringList>
#include <QVariant>

namespace QmlProfiler {
namespace Internal {


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

    TimelineModelAggregator *q;

52
53
54
    // mapping of modelId assigned by manager to index in our list
    QList <int> modelManagerIndexMapping;

55
    QList <QmlProfilerTimelineModel *> modelList;
Christiaan Janssen's avatar
Christiaan Janssen committed
56
57
58
59
60
61
    QmlProfilerModelManager *modelManager;
};

TimelineModelAggregator::TimelineModelAggregator(QObject *parent)
    : QObject(parent), d(new TimelineModelAggregatorPrivate(this))
{
62
63
    connect(this,SIGNAL(modelsChanged(int,int)),this,SIGNAL(heightChanged()));
    connect(this,SIGNAL(stateChanged()),this,SIGNAL(heightChanged()));
Christiaan Janssen's avatar
Christiaan Janssen committed
64
65
66
67
68
69
70
}

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

71
72
int TimelineModelAggregator::height() const
{
73
    return modelOffset(d->modelList.length());
74
75
}

Christiaan Janssen's avatar
Christiaan Janssen committed
76
77
78
79
80
81
82
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
83
    foreach (QmlProfilerTimelineModel *timelineModel,
84
             QmlProfilerPlugin::instance->getModels(modelManager)) {
Christiaan Janssen's avatar
Christiaan Janssen committed
85
86
87
        addModel(timelineModel);
    }

88
    addModel(new QmlProfilerAnimationsModel(modelManager, this));
Christiaan Janssen's avatar
Christiaan Janssen committed
89

90
91
    for (int i = 0; i < QmlDebug::MaximumRangeType; ++i)
        addModel(new QmlProfilerRangeModel(modelManager, (QmlDebug::RangeType)i, this));
92
93
94

    // Connect this last so that it's executed after the models have updated their data.
    connect(modelManager->qmlModel(),SIGNAL(changed()),this,SIGNAL(stateChanged()));
95
96
    connect(modelManager->notesModel(), SIGNAL(changed(int,int,int)),
            this, SIGNAL(notesChanged(int,int,int)));
Christiaan Janssen's avatar
Christiaan Janssen committed
97
98
}

99
void TimelineModelAggregator::addModel(QmlProfilerTimelineModel *m)
Christiaan Janssen's avatar
Christiaan Janssen committed
100
{
101
102
103
    while (d->modelManagerIndexMapping.size() <= m->modelId())
        d->modelManagerIndexMapping.append(-1);
    d->modelManagerIndexMapping[m->modelId()] = d->modelList.size();
Christiaan Janssen's avatar
Christiaan Janssen committed
104
105
    d->modelList << m;
    connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged()));
106
    connect(m,SIGNAL(hiddenChanged()),this,SIGNAL(hiddenChanged()));
107
    connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged()));
108
    connect(m,SIGNAL(heightChanged()),this,SIGNAL(heightChanged()));
109
    d->modelManager->notesModel()->addTimelineModel(m);
110
    emit modelsChanged(d->modelList.length(), d->modelList.length());
111
112
}

113
const QmlProfilerTimelineModel *TimelineModelAggregator::model(int modelIndex) const
114
115
116
117
{
    return d->modelList[modelIndex];
}

118
119
120
QVariantList TimelineModelAggregator::models() const
{
    QVariantList ret;
121
    foreach (QmlProfilerTimelineModel *model, d->modelList)
122
123
        ret << QVariant::fromValue(model);
    return ret;
Christiaan Janssen's avatar
Christiaan Janssen committed
124
125
}

126
127
128
129
130
int TimelineModelAggregator::modelIndexFromManagerIndex(int modelManagerIndex) const
{
    return d->modelManagerIndexMapping[modelManagerIndex];
}

131
QmlProfilerNotesModel *TimelineModelAggregator::notes() const
132
133
134
135
{
    return d->modelManager->notesModel();
}

Christiaan Janssen's avatar
Christiaan Janssen committed
136
137
int TimelineModelAggregator::count(int modelIndex) const
{
138
    return d->modelList[modelIndex]->count();
Christiaan Janssen's avatar
Christiaan Janssen committed
139
140
141
142
}

bool TimelineModelAggregator::isEmpty() const
{
143
    foreach (const QmlProfilerTimelineModel *modelProxy, d->modelList)
Christiaan Janssen's avatar
Christiaan Janssen committed
144
145
146
147
148
        if (!modelProxy->isEmpty())
            return false;
    return true;
}

149
150
151
152
153
154
155
156
int TimelineModelAggregator::modelOffset(int modelIndex) const
{
    int ret = 0;
    for (int i = 0; i < modelIndex; ++i)
        ret += d->modelList[i]->height();
    return ret;
}

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
int TimelineModelAggregator::rowHeight(int modelIndex, int row) const
{
    return d->modelList[modelIndex]->rowHeight(row);
}

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

void TimelineModelAggregator::setRowHeight(int modelIndex, int row, int height)
{
    d->modelList[modelIndex]->setRowHeight(row, height);
}

172
bool TimelineModelAggregator::expanded(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
173
{
174
    return d->modelList[modelIndex]->expanded();
Christiaan Janssen's avatar
Christiaan Janssen committed
175
176
}

177
void TimelineModelAggregator::setExpanded(int modelIndex, bool expanded)
Christiaan Janssen's avatar
Christiaan Janssen committed
178
{
179
    d->modelList[modelIndex]->setExpanded(expanded);
Christiaan Janssen's avatar
Christiaan Janssen committed
180
181
}

182
183
184
185
186
187
188
189
190
191
bool TimelineModelAggregator::hidden(int modelIndex) const
{
    return d->modelList[modelIndex]->hidden();
}

void TimelineModelAggregator::setHidden(int modelIndex, bool hidden)
{
    d->modelList[modelIndex]->setHidden(hidden);
}

Christiaan Janssen's avatar
Christiaan Janssen committed
192
193
194
195
196
int TimelineModelAggregator::rowCount(int modelIndex) const
{
    return d->modelList[modelIndex]->rowCount();
}

197
QString TimelineModelAggregator::displayName(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
198
{
199
    return d->modelList[modelIndex]->displayName();
Christiaan Janssen's avatar
Christiaan Janssen committed
200
201
}

202
203
204
205
206
207
208
209
210
211
int TimelineModelAggregator::rowMinValue(int modelIndex, int row) const
{
    return d->modelList[modelIndex]->rowMinValue(row);
}

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

212
int TimelineModelAggregator::firstIndex(int modelIndex, qint64 startTime) const
Christiaan Janssen's avatar
Christiaan Janssen committed
213
{
214
    return d->modelList[modelIndex]->firstIndex(startTime);
Christiaan Janssen's avatar
Christiaan Janssen committed
215
216
}

217
int TimelineModelAggregator::firstIndexNoParents(int modelIndex, qint64 startTime) const
Christiaan Janssen's avatar
Christiaan Janssen committed
218
{
219
    return d->modelList[modelIndex]->firstIndexNoParents(startTime);
Christiaan Janssen's avatar
Christiaan Janssen committed
220
221
}

222
int TimelineModelAggregator::lastIndex(int modelIndex, qint64 endTime) const
Christiaan Janssen's avatar
Christiaan Janssen committed
223
{
224
    return d->modelList[modelIndex]->lastIndex(endTime);
Christiaan Janssen's avatar
Christiaan Janssen committed
225
226
}

227
int TimelineModelAggregator::row(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
228
{
229
    return d->modelList[modelIndex]->row(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
230
231
}

232
qint64 TimelineModelAggregator::duration(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
233
{
234
    return d->modelList[modelIndex]->duration(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
235
236
}

237
qint64 TimelineModelAggregator::startTime(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
238
{
239
    return d->modelList[modelIndex]->startTime(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
240
241
}

242
qint64 TimelineModelAggregator::endTime(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
243
{
244
    return d->modelList[modelIndex]->endTime(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
245
246
}

247
int TimelineModelAggregator::selectionId(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
248
{
249
    return d->modelList[modelIndex]->selectionId(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
250
251
}

252
253
254
255
256
int TimelineModelAggregator::typeId(int modelIndex, int index) const
{
    return d->modelList[modelIndex]->typeId(index);
}

257
int TimelineModelAggregator::bindingLoopDest(int modelIndex,int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
258
{
259
    return d->modelList[modelIndex]->bindingLoopDest(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
260
261
}

262
QColor TimelineModelAggregator::color(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
263
{
264
    return d->modelList[modelIndex]->color(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
265
266
}

267
float TimelineModelAggregator::relativeHeight(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
268
{
269
    return d->modelList[modelIndex]->relativeHeight(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
270
271
}

272
QVariantList TimelineModelAggregator::labels(int modelIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
273
{
274
    return d->modelList[modelIndex]->labels();
Christiaan Janssen's avatar
Christiaan Janssen committed
275
276
}

277
QVariantMap TimelineModelAggregator::details(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
278
{
279
    return d->modelList[modelIndex]->details(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
280
281
}

282
QVariantMap TimelineModelAggregator::location(int modelIndex, int index) const
Christiaan Janssen's avatar
Christiaan Janssen committed
283
{
284
    return d->modelList[modelIndex]->location(index);
Christiaan Janssen's avatar
Christiaan Janssen committed
285
286
}

287
bool TimelineModelAggregator::handlesTypeId(int modelIndex, int typeIndex) const
Christiaan Janssen's avatar
Christiaan Janssen committed
288
{
289
    return d->modelList[modelIndex]->handlesTypeId(typeIndex);
Christiaan Janssen's avatar
Christiaan Janssen committed
290
291
}

292
int TimelineModelAggregator::selectionIdForLocation(int modelIndex, const QString &filename,
293
                                                   int line, int column) const
Christiaan Janssen's avatar
Christiaan Janssen committed
294
{
295
    return d->modelList[modelIndex]->selectionIdForLocation(filename, line, column);
Christiaan Janssen's avatar
Christiaan Janssen committed
296
297
}

298
299
void TimelineModelAggregator::swapModels(int modelIndex1, int modelIndex2)
{
300
301
    QmlProfilerTimelineModel *&model1 = d->modelList[modelIndex1];
    QmlProfilerTimelineModel *&model2 = d->modelList[modelIndex2];
302
303
304
    std::swap(d->modelManagerIndexMapping[model1->modelId()],
              d->modelManagerIndexMapping[model2->modelId()]);
    std::swap(model1, model2);
305
306
307
    emit modelsChanged(modelIndex1, modelIndex2);
}

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
QString TimelineModelAggregator::noteText(int noteId) const
{
    return d->modelManager->notesModel()->text(noteId);
}

QString TimelineModelAggregator::noteText(int modelIndex, int index) const
{
    int managerId = d->modelList[modelIndex]->modelId();
    int noteId = d->modelManager->notesModel()->get(managerId, index);
    return noteId != -1 ? noteText(noteId) : QString();
}

void TimelineModelAggregator::setNoteText(int noteId, const QString &text)
{
    if (text.length() > 0) {
        notes()->update(noteId, text);
    } else {
        notes()->remove(noteId);
    }
}

void TimelineModelAggregator::setNoteText(int modelIndex, int index, const QString &text)
{
    int managerId = d->modelList[modelIndex]->modelId();
332
    QmlProfilerNotesModel *notesModel = notes();
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
    int noteId = notesModel->get(managerId, index);
    if (noteId == -1) {
        if (text.length() > 0)
            notesModel->add(managerId, index, text);
    } else {
        setNoteText(noteId, text);
    }
}

int TimelineModelAggregator::noteTimelineModel(int noteIndex) const
{
    return d->modelManagerIndexMapping[notes()->timelineModel(noteIndex)];
}

int TimelineModelAggregator::noteTimelineIndex(int noteIndex) const
{
    return notes()->timelineIndex(noteIndex);
}

QVariantList TimelineModelAggregator::notesByTimelineModel(int modelIndex) const
{
    int managerId = d->modelList[modelIndex]->modelId();
    return notes()->byTimelineModel(managerId);
}

QVariantList TimelineModelAggregator::notesByTypeId(int typeId) const
{
    return notes()->byTypeId(typeId);
}

int TimelineModelAggregator::noteCount() const
{
    return notes()->count();
}

Christiaan Janssen's avatar
Christiaan Janssen committed
368
369
370
371
372
373
374
375
376
377
378
379
380
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();
}

} // namespace Internal
} // namespace QmlProfiler