abstracttimelinemodel.cpp 7.57 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
static const int DefaultRowHeight = 30;
36
37
38
39

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

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

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

67
68
QString AbstractTimelineModel::name() const
{
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
117
118
    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);
119
120
}

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

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
int AbstractTimelineModel::rowHeight(int rowNumber) const
{
    Q_D(const AbstractTimelineModel);
    if (!expanded())
        return DefaultRowHeight;

    if (d->rowOffsets.length() > rowNumber)
        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;

    if (d->rowOffsets.length() >= rowNumber)
        return d->rowOffsets[rowNumber - 1];
    if (!d->rowOffsets.empty())
        return d->rowOffsets.last() + (rowNumber - 1 - d->rowOffsets.length()) * DefaultRowHeight;
    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();
    while (d->rowOffsets.length() <= rowNumber)
        d->rowOffsets << (nextOffset += DefaultRowHeight);
    int difference = height - d->rowOffsets[rowNumber] +
            (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
    if (difference != 0) {
        for (; rowNumber < d->rowOffsets.length(); ++rowNumber) {
            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;

    return d->rowOffsets.last() + (depth - d->rowOffsets.length()) * DefaultRowHeight;
}

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

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

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

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

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

214
int AbstractTimelineModel::getEventIdForTypeIndex(int typeIndex) const
215
{
216
    Q_UNUSED(typeIndex);
217
218
219
220
221
222
223
224
225
    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
226
227
228
229
230
231
232
233
}

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

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

240
241
void AbstractTimelineModel::dataChanged()
{
242
243
    Q_D(AbstractTimelineModel);
    switch (d->modelManager->state()) {
244
    case QmlProfilerDataState::ProcessingData:
245
246
        loadData();
        break;
247
    case QmlProfilerDataState::ClearingData:
248
249
250
251
252
        clear();
        break;
    default:
        break;
    }
253
254

    d->rowOffsets.clear();
255
256
}

257
bool AbstractTimelineModel::eventAccepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{
    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
283
284

}