abstracttimelinemodel.cpp 7.72 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
** 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 "abstracttimelinemodel.h"
31
#include "abstracttimelinemodel_p.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
32
33
34

namespace QmlProfiler {

35
36
37
AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
        const QString &name, const QString &label, QmlDebug::Message message,
        QmlDebug::RangeType rangeType, QObject *parent) :
38
39
40
41
42
43
44
    QObject(parent), d_ptr(dd)
{
    Q_D(AbstractTimelineModel);
    d->q_ptr = this;
    d->name = name;
    d->modelId = 0;
    d->modelManager = 0;
45
46
47
48
    d->expanded = false;
    d->title = label;
    d->message = message;
    d->rangeType = rangeType;
49
}
Christiaan Janssen's avatar
Christiaan Janssen committed
50
51

AbstractTimelineModel::~AbstractTimelineModel()
52
53
54
55
{
    Q_D(AbstractTimelineModel);
    delete d;
}
Christiaan Janssen's avatar
Christiaan Janssen committed
56
57
58

void AbstractTimelineModel::setModelManager(QmlProfilerModelManager *modelManager)
{
59
60
    Q_D(AbstractTimelineModel);
    d->modelManager = modelManager;
61
    connect(d->modelManager->qmlModel(),SIGNAL(changed()),this,SLOT(dataChanged()));
62
    d->modelId = d->modelManager->registerModelProxy();
Christiaan Janssen's avatar
Christiaan Janssen committed
63
64
}

65
66
QString AbstractTimelineModel::name() const
{
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    Q_D(const AbstractTimelineModel);
    return d->name;
}

int AbstractTimelineModel::count() const
{
    Q_D(const AbstractTimelineModel);
    return d->count();
}

qint64 AbstractTimelineModel::lastTimeMark() const
{
    Q_D(const AbstractTimelineModel);
    return d->lastEndTime();
}

int AbstractTimelineModel::findFirstIndex(qint64 startTime) const
{
    Q_D(const AbstractTimelineModel);
    return d->findFirstIndex(startTime);
}

int AbstractTimelineModel::findFirstIndexNoParents(qint64 startTime) const
{
    Q_D(const AbstractTimelineModel);
    return d->findFirstIndexNoParents(startTime);
}

int AbstractTimelineModel::findLastIndex(qint64 endTime) const
{
    Q_D(const AbstractTimelineModel);
    return d->findLastIndex(endTime);
}

qint64 AbstractTimelineModel::getDuration(int index) const
{
    Q_D(const AbstractTimelineModel);
    return d->duration(index);
}

qint64 AbstractTimelineModel::getStartTime(int index) const
{
    Q_D(const AbstractTimelineModel);
    return d->startTime(index);
}

qint64 AbstractTimelineModel::getEndTime(int index) const
{
    Q_D(const AbstractTimelineModel);
    return d->startTime(index) + d->duration(index);
117
118
}

119
120
121
122
123
bool AbstractTimelineModel::isEmpty() const
{
    return count() == 0;
}

124
125
126
127
128
129
int AbstractTimelineModel::rowHeight(int rowNumber) const
{
    Q_D(const AbstractTimelineModel);
    if (!expanded())
        return DefaultRowHeight;

130
    if (d->rowOffsets.size() > rowNumber)
131
132
133
134
135
136
137
138
139
140
141
142
        return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
    return DefaultRowHeight;
}

int AbstractTimelineModel::rowOffset(int rowNumber) const
{
    Q_D(const AbstractTimelineModel);
    if (rowNumber == 0)
        return 0;
    if (!expanded())
        return DefaultRowHeight * rowNumber;

143
    if (d->rowOffsets.size() >= rowNumber)
144
145
        return d->rowOffsets[rowNumber - 1];
    if (!d->rowOffsets.empty())
146
        return d->rowOffsets.last() + (rowNumber - d->rowOffsets.size()) * DefaultRowHeight;
147
148
149
150
151
152
153
154
155
156
157
158
    return rowNumber * DefaultRowHeight;
}

void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
{
    Q_D(AbstractTimelineModel);
    if (!expanded())
        return;
    if (height < DefaultRowHeight)
        height = DefaultRowHeight;

    int nextOffset = d->rowOffsets.empty() ? 0 : d->rowOffsets.last();
159
    while (d->rowOffsets.size() <= rowNumber)
160
161
162
163
        d->rowOffsets << (nextOffset += DefaultRowHeight);
    int difference = height - d->rowOffsets[rowNumber] +
            (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
    if (difference != 0) {
164
        for (; rowNumber < d->rowOffsets.size(); ++rowNumber) {
165
166
167
168
169
170
171
172
173
174
175
176
177
            d->rowOffsets[rowNumber] += difference;
        }
        emit rowHeightChanged();
    }
}

int AbstractTimelineModel::height() const
{
    Q_D(const AbstractTimelineModel);
    int depth = rowCount();
    if (!expanded() || d->rowOffsets.empty())
        return depth * DefaultRowHeight;

178
    return d->rowOffsets.last() + (depth - d->rowOffsets.size()) * DefaultRowHeight;
179
180
}

Christiaan Janssen's avatar
Christiaan Janssen committed
181
182
qint64 AbstractTimelineModel::traceStartTime() const
{
183
184
    Q_D(const AbstractTimelineModel);
    return d->modelManager->traceTime()->startTime();
Christiaan Janssen's avatar
Christiaan Janssen committed
185
186
187
188
}

qint64 AbstractTimelineModel::traceEndTime() const
{
189
190
    Q_D(const AbstractTimelineModel);
    return d->modelManager->traceTime()->endTime();
Christiaan Janssen's avatar
Christiaan Janssen committed
191
192
193
194
}

qint64 AbstractTimelineModel::traceDuration() const
{
195
196
    Q_D(const AbstractTimelineModel);
    return d->modelManager->traceTime()->duration();
Christiaan Janssen's avatar
Christiaan Janssen committed
197
198
199
200
}

int AbstractTimelineModel::getState() const
{
201
202
203
204
205
206
207
208
209
210
211
    Q_D(const AbstractTimelineModel);
    return (int)d->modelManager->state();
}

const QVariantMap AbstractTimelineModel::getEventLocation(int index) const
{
    Q_UNUSED(index);
    QVariantMap map;
    return map;
}

212
int AbstractTimelineModel::getEventIdForTypeIndex(int typeIndex) const
213
{
214
    Q_UNUSED(typeIndex);
215
216
217
218
219
220
221
222
223
    return -1;
}

int AbstractTimelineModel::getEventIdForLocation(const QString &filename, int line, int column) const
{
    Q_UNUSED(filename);
    Q_UNUSED(line);
    Q_UNUSED(column);
    return -1;
Christiaan Janssen's avatar
Christiaan Janssen committed
224
225
226
227
228
229
230
231
}

int AbstractTimelineModel::getBindingLoopDest(int index) const
{
    Q_UNUSED(index);
    return -1;
}

232
233
234
235
236
237
float AbstractTimelineModel::getHeight(int index) const
{
    Q_UNUSED(index);
    return 1.0f;
}

238
239
240
241
242
243
244
245
246
247
248
249
int AbstractTimelineModel::rowMinValue(int rowNumber) const
{
    Q_UNUSED(rowNumber);
    return 0;
}

int AbstractTimelineModel::rowMaxValue(int rowNumber) const
{
    Q_UNUSED(rowNumber);
    return 0;
}

250
251
void AbstractTimelineModel::dataChanged()
{
252
253
    Q_D(AbstractTimelineModel);
    switch (d->modelManager->state()) {
254
    case QmlProfilerDataState::ProcessingData:
255
256
        loadData();
        break;
257
    case QmlProfilerDataState::ClearingData:
258
259
260
261
262
        clear();
        break;
    default:
        break;
    }
263
264

    d->rowOffsets.clear();
265
266
}

267
bool AbstractTimelineModel::eventAccepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
{
    Q_D(const AbstractTimelineModel);
    return (event.rangeType == d->rangeType && event.message == d->message);
}

bool AbstractTimelineModel::expanded() const
{
    Q_D(const AbstractTimelineModel);
    return d->expanded;
}

void AbstractTimelineModel::setExpanded(bool expanded)
{
    Q_D(AbstractTimelineModel);
    if (expanded != d->expanded) {
        d->expanded = expanded;
        emit expandedChanged();
    }
}

const QString AbstractTimelineModel::title() const
{
    Q_D(const AbstractTimelineModel);
    return d->title;
}
Christiaan Janssen's avatar
Christiaan Janssen committed
293
294

}