pipelinetreewidget.h 5.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef PIPELINETREEWIDGET_H__
#define PIPELINETREEWIDGET_H__

#include <QAbstractItemModel>
#include <QTreeWidget>
#include <QList>
#include <QVariant>

#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
#include <vector>

namespace TUMVis {

// = TreeModel items ==============================================================================

schultezub's avatar
schultezub committed
17
18
19
    /**
     * Abstract base class for TreeView items of the PipelineTreeWidget.
     */
20
21
    class TreeItem {
    public:
schultezub's avatar
schultezub committed
22
23
24
25
        /**
         * Creates a new TreeItem
         * \param   parent  Parent item, will take ownership of this TreeItem.
         */
26
        TreeItem(TreeItem* parent = 0);
schultezub's avatar
schultezub committed
27
28
29
30

        /**
         * Destuctor, also deletes all child items.
         */
31
32
        virtual ~TreeItem();

schultezub's avatar
schultezub committed
33
34
35
36
        /**
         * Return the of this item at the column \a column.
         * To be overwritten by subclasses.
         * \param   column  Column
schultezub's avatar
schultezub committed
37
         * \param   role    Access role (Use Qt::DisplayRole for string representation, Qt::UserRole for the internal data)
schultezub's avatar
schultezub committed
38
39
         * \return  The data of this item at \a column.
         */
40
        virtual QVariant getData(int column, int role) const = 0;
41

schultezub's avatar
schultezub committed
42
43
44
45
        /**
         * Returns the parent TreeItem
         * \return _parent
         */
46
        TreeItem* getParent();
schultezub's avatar
schultezub committed
47
48
49
50
51
52

        /**
         * Returns the \a row-th child TreeItem.
         * \param   row     Number of the child to return.
         * \return  _children[row]
         */
53
        TreeItem* getChild(int row);
schultezub's avatar
schultezub committed
54
55
56
57
58

        /**
         * Returns the row of this TreeItem.
         * \return _parent._children.indexOf(this)
         */
59
        int getRow();
schultezub's avatar
schultezub committed
60
61
62
63
64

        /**
         * Returns the number of children.
         * \return  _children.size();
         */
65
66
67
        int getChildCount();

    private:
schultezub's avatar
schultezub committed
68
69
        TreeItem* _parent;              ///< Parent TreeItem.
        QList<TreeItem*> _children;     ///< Collection of all child items.
70
71
    };

schultezub's avatar
schultezub committed
72
73
74
    /**
     * Specialization for root TreeItems.
     */
75
76
77
78
79
    class RootTreeItem : public TreeItem {
    public:
        RootTreeItem(TreeItem* parent = 0);
        virtual ~RootTreeItem();

schultezub's avatar
schultezub committed
80
        /// \see TreeItem::getData()
81
        virtual QVariant getData(int column, int role) const;
82
83
    };

schultezub's avatar
schultezub committed
84
85
86
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
87
88
89
90
91
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

schultezub's avatar
schultezub committed
92
        /// \see TreeItem::getData()
93
        virtual QVariant getData(int column, int role) const;
94
95

    private:
schultezub's avatar
schultezub committed
96
        AbstractPipeline* _pipeline;        ///< Base pipeline
97
98
    };

schultezub's avatar
schultezub committed
99
100
101
    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
102
103
104
105
106
    class ProcessorTreeItem : public TreeItem {
    public:
        ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent);
        virtual ~ProcessorTreeItem();

schultezub's avatar
schultezub committed
107
        /// \see TreeItem::getData()
108
        virtual QVariant getData(int column, int role) const;
109
110

    private:
schultezub's avatar
schultezub committed
111
        AbstractProcessor* _processor;      ///< Base processor
112
113
114
115
    };

// = TreeModel ====================================================================================

schultezub's avatar
schultezub committed
116
117
118
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    class PipelineTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
        PipelineTreeModel(QObject *parent = 0);
        ~PipelineTreeModel();

        void setData(const std::vector<AbstractPipeline*>& pipelines);

        QVariant data(const QModelIndex &index, int role) const;
        Qt::ItemFlags flags(const QModelIndex &index) const;
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
        QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
        QModelIndex parent(const QModelIndex &index) const;

        int rowCount(const QModelIndex &parent = QModelIndex()) const;
        int columnCount(const QModelIndex &parent = QModelIndex()) const;

    private:
        TreeItem* _rootItem;
    };

// = Widget =======================================================================================

schultezub's avatar
schultezub committed
143
144
145
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
146
147
148
149
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
schultezub's avatar
schultezub committed
150
151
152
153
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
154
155
        PipelineTreeWidget(QWidget* parent = 0);

schultezub's avatar
schultezub committed
156
157
158
        /**
         * Destructor
         */
159
160
161
162
        virtual ~PipelineTreeWidget();


    public slots:
schultezub's avatar
schultezub committed
163
164
165
166
        /**
         * Updates the data in the tree view by the given collection of pipelines \a pipelines.
         * \param   pipelines   
         */
167
168
169
170
        void update(const std::vector<AbstractPipeline*>& pipelines);


    private:
schultezub's avatar
schultezub committed
171
172
173
        /**
         * Sets up the widget.
         */
174
175
        void setupWidget();

schultezub's avatar
schultezub committed
176
        PipelineTreeModel* _treeModel;      ///< Data model for the TreeView.
177
178
179
180
181
182


    };
}

#endif // PIPELINETREEWIDGET_H__