aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/timeline/timelinemodel.h
blob: 83ad4012ccb04d67bb2e3a32d15269227c080708 (plain)
1
2
3
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
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
119
120
121
122
123
124
125
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
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#ifndef TIMELINEMODEL_H
#define TIMELINEMODEL_H

#include "timeline_global.h"
#include "timelinerenderpass.h"
#include <QVariant>
#include <QColor>

namespace Timeline {

class TIMELINE_EXPORT TimelineModel : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int modelId READ modelId CONSTANT)
    Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
    Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
    Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
    Q_PROPERTY(bool expanded READ expanded WRITE setExpanded NOTIFY expandedChanged)
    Q_PROPERTY(int height READ height NOTIFY heightChanged)
    Q_PROPERTY(int expandedRowCount READ expandedRowCount NOTIFY expandedRowCountChanged)
    Q_PROPERTY(int collapsedRowCount READ collapsedRowCount NOTIFY collapsedRowCountChanged)
    Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
    Q_PROPERTY(QVariantList labels READ labels NOTIFY labelsChanged)
    Q_PROPERTY(int count READ count NOTIFY emptyChanged)
    Q_PROPERTY(int defaultRowHeight READ defaultRowHeight CONSTANT)

public:
    class TimelineModelPrivate;

    TimelineModel(int modelId, QObject *parent = 0);
    ~TimelineModel();

    // Methods implemented by the abstract model itself
    bool isEmpty() const;
    int modelId() const;

    Q_INVOKABLE int collapsedRowHeight(int rowNumber) const;
    Q_INVOKABLE int expandedRowHeight(int rowNumber) const;
    Q_INVOKABLE int rowHeight(int rowNumber) const;
    Q_INVOKABLE void setExpandedRowHeight(int rowNumber, int height);

    Q_INVOKABLE int collapsedRowOffset(int rowNumber) const;
    Q_INVOKABLE int expandedRowOffset(int rowNumber) const;
    Q_INVOKABLE int rowOffset(int rowNumber) const;

    int height() const;
    int count() const;
    Q_INVOKABLE qint64 duration(int index) const;
    Q_INVOKABLE qint64 startTime(int index) const;
    Q_INVOKABLE qint64 endTime(int index) const;
    Q_INVOKABLE int selectionId(int index) const;

    int firstIndex(qint64 startTime) const;
    int lastIndex(qint64 endTime) const;

    bool expanded() const;
    bool hidden() const;
    void setExpanded(bool expanded);
    void setHidden(bool hidden);
    void setDisplayName(const QString &displayName);
    QString displayName() const;
    int expandedRowCount() const;
    int collapsedRowCount() const;
    int rowCount() const;

    // Methods which can optionally be implemented by child models.
    Q_INVOKABLE virtual QColor color(int index) const;
    virtual QVariantList labels() const;
    Q_INVOKABLE virtual QVariantMap details(int index) const;
    Q_INVOKABLE virtual int expandedRow(int index) const;
    Q_INVOKABLE virtual int collapsedRow(int index) const;
    Q_INVOKABLE int row(int index) const;

    // returned map should contain "file", "line", "column" properties, or be empty
    Q_INVOKABLE virtual QVariantMap location(int index) const;
    Q_INVOKABLE virtual int typeId(int index) const;
    Q_INVOKABLE virtual bool handlesTypeId(int typeId) const;
    Q_INVOKABLE virtual int selectionIdForLocation(const QString &filename, int line,
                                                   int column) const;
    Q_INVOKABLE virtual float relativeHeight(int index) const;
    Q_INVOKABLE virtual int rowMinValue(int rowNumber) const;
    Q_INVOKABLE virtual int rowMaxValue(int rowNumber) const;

    Q_INVOKABLE int nextItemBySelectionId(int selectionId, qint64 time, int currentItem) const;
    Q_INVOKABLE int nextItemByTypeId(int typeId, qint64 time, int currentItem) const;
    Q_INVOKABLE int prevItemBySelectionId(int selectionId, qint64 time, int currentItem) const;
    Q_INVOKABLE int prevItemByTypeId(int typeId, qint64 time, int currentItem) const;

    static int defaultRowHeight();
    virtual QList<const TimelineRenderPass *> supportedRenderPasses() const;

signals:
    void expandedChanged();
    void hiddenChanged();
    void expandedRowHeightChanged(int row, int height);
    void emptyChanged();
    void heightChanged();
    void expandedRowCountChanged();
    void collapsedRowCountChanged();
    void rowCountChanged();
    void labelsChanged();
    void displayNameChanged();

protected:
    QColor colorBySelectionId(int index) const;
    QColor colorByFraction(double fraction) const;
    QColor colorByHue(int hue) const;

    int insert(qint64 startTime, qint64 duration, int selectionId);
    int insertStart(qint64 startTime, int selectionId);
    void insertEnd(int index, qint64 duration);
    void computeNesting();

    void setCollapsedRowCount(int rows);
    void setExpandedRowCount(int rows);

    virtual void clear();

    explicit TimelineModel(TimelineModelPrivate &dd, QObject *parent);
    TimelineModelPrivate *d_ptr;

private:
    Q_DECLARE_PRIVATE(TimelineModel)
};

} // namespace Timeline

#endif // TIMELINEMODEL_H