pipelinetreewidget.h 5.11 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
37
38
        /**
         * Return the of this item at the column \a column.
         * To be overwritten by subclasses.
         * \param   column  Column
         * \return  The data of this item at \a column.
         */
39
        virtual QVariant getData(int column, int role) const = 0;
40

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

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

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

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

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

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

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

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

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

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

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

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

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

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

schultezub's avatar
schultezub committed
115
116
117
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    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
142
143
144
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
145
146
147
148
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

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

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


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


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

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


    };
}

#endif // PIPELINETREEWIDGET_H__