pipelinetreewidget.h 7.88 KB
Newer Older
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
// ================================================================================================
// 
// This file is part of the TUMVis Visualization Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge (christian.szb@in.tum.de)
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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
45
46
47
    /**
     * Abstract base class for TreeView items of the PipelineTreeWidget.
     */
48
49
    class TreeItem {
    public:
schultezub's avatar
schultezub committed
50
51
52
53
        /**
         * Creates a new TreeItem
         * \param   parent  Parent item, will take ownership of this TreeItem.
         */
54
        TreeItem(TreeItem* parent = 0);
schultezub's avatar
schultezub committed
55
56
57
58

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

schultezub's avatar
schultezub committed
61
62
63
64
        /**
         * Return the of this item at the column \a column.
         * To be overwritten by subclasses.
         * \param   column  Column
schultezub's avatar
schultezub committed
65
         * \param   role    Access role (Use Qt::DisplayRole for string representation, Qt::UserRole for the internal data)
schultezub's avatar
schultezub committed
66
67
         * \return  The data of this item at \a column.
         */
68
        virtual QVariant getData(int column, int role) const = 0;
69

70
71
72
73
74
75
76
77
78
79
        /**
         * Sets the data at the given column to \a value using the given role.
         * Overwrite if needed, default implementation will only return false.
         * \param   column  Column
         * \param   role    Access role
         * \param   value   Value to set
         * \return  false
         */
        virtual bool setData(int column, int role, const QVariant& value) const;

schultezub's avatar
schultezub committed
80
81
82
83
        /**
         * Returns the parent TreeItem
         * \return _parent
         */
84
        TreeItem* getParent();
schultezub's avatar
schultezub committed
85
86
87
88
89
90

        /**
         * Returns the \a row-th child TreeItem.
         * \param   row     Number of the child to return.
         * \return  _children[row]
         */
91
        TreeItem* getChild(int row);
schultezub's avatar
schultezub committed
92
93
94
95
96

        /**
         * Returns the row of this TreeItem.
         * \return _parent._children.indexOf(this)
         */
97
        int getRow();
schultezub's avatar
schultezub committed
98
99
100
101
102

        /**
         * Returns the number of children.
         * \return  _children.size();
         */
103
104
105
        int getChildCount();

    private:
schultezub's avatar
schultezub committed
106
107
        TreeItem* _parent;              ///< Parent TreeItem.
        QList<TreeItem*> _children;     ///< Collection of all child items.
108
109
    };

schultezub's avatar
schultezub committed
110
111
112
    /**
     * Specialization for root TreeItems.
     */
113
114
115
116
117
    class RootTreeItem : public TreeItem {
    public:
        RootTreeItem(TreeItem* parent = 0);
        virtual ~RootTreeItem();

schultezub's avatar
schultezub committed
118
        /// \see TreeItem::getData()
119
        virtual QVariant getData(int column, int role) const;
120
121
    };

schultezub's avatar
schultezub committed
122
123
124
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
125
126
127
128
129
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

schultezub's avatar
schultezub committed
130
        /// \see TreeItem::getData()
131
        virtual QVariant getData(int column, int role) const;
132

133
134
135
        /// \see TreeItem::setData()
        virtual bool setData(int column, int role, const QVariant& value) const;

136
    private:
schultezub's avatar
schultezub committed
137
        AbstractPipeline* _pipeline;        ///< Base pipeline
138
139
    };

schultezub's avatar
schultezub committed
140
141
142
    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
143
144
145
146
147
    class ProcessorTreeItem : public TreeItem {
    public:
        ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent);
        virtual ~ProcessorTreeItem();

schultezub's avatar
schultezub committed
148
        /// \see TreeItem::getData()
149
        virtual QVariant getData(int column, int role) const;
150

151
152
153
        /// \see TreeItem::setData()
        virtual bool setData(int column, int role, const QVariant& value) const;

154
    private:
schultezub's avatar
schultezub committed
155
        AbstractProcessor* _processor;      ///< Base processor
156
157
158
159
    };

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

schultezub's avatar
schultezub committed
160
161
162
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
163
164
165
166
167
168
169
170
171
172
    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;
173
174
175
176
177
178
179
180
181

        /**
         * Sets the data at index \a index to \a value.
         * \param   index   position where to set data
         * \param   value   new data
         * \param   role    edit role
         **/
        bool setData(const QModelIndex& index, const QVariant& value, int role);

182
183
184
185
186
187
188
189
190
191
192
193
194
195
        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
196
197
198
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
199
200
201
202
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
schultezub's avatar
schultezub committed
203
204
205
206
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
207
208
        PipelineTreeWidget(QWidget* parent = 0);

schultezub's avatar
schultezub committed
209
210
211
        /**
         * Destructor
         */
212
213
214
215
        virtual ~PipelineTreeWidget();


    public slots:
schultezub's avatar
schultezub committed
216
217
218
219
        /**
         * Updates the data in the tree view by the given collection of pipelines \a pipelines.
         * \param   pipelines   
         */
220
221
222
223
        void update(const std::vector<AbstractPipeline*>& pipelines);


    private:
schultezub's avatar
schultezub committed
224
225
226
        /**
         * Sets up the widget.
         */
227
228
        void setupWidget();

schultezub's avatar
schultezub committed
229
        PipelineTreeModel* _treeModel;      ///< Data model for the TreeView.
230
231
232
233
234
235


    };
}

#endif // PIPELINETREEWIDGET_H__