pipelinetreewidget.h 6.71 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

25
26
27
28
29
30
31
32
#ifndef PIPELINETREEWIDGET_H__
#define PIPELINETREEWIDGET_H__

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

33
#include "core/datastructures/datacontainer.h"
34
35
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
36
#include "application/tools/treeitem.h"
37
38
#include <vector>

schultezub's avatar
schultezub committed
39
namespace campvis {
40
41

// = TreeModel items ==============================================================================
42
    
schultezub's avatar
schultezub committed
43
44
45
    /**
     * Specialization for root TreeItems.
     */
46
    class PipelineTreeRootItem : public TreeItem {
47
    public:
48
        explicit PipelineTreeRootItem(TreeItem* parent = 0);
49
        virtual ~PipelineTreeRootItem();
50

schultezub's avatar
schultezub committed
51
        /// \see TreeItem::getData()
52
        virtual QVariant getData(int column, int role) const;
53
54
    };

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
    class DataContainerTreeItem : public TreeItem {
    public:
        DataContainerTreeItem(DataContainer* dc, TreeItem* parent);
        virtual ~DataContainerTreeItem();

        /// \see TreeItem::getData()
        virtual QVariant getData(int column, int role) const;

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

    private:
        DataContainer* _dataContainer;        ///< Base DataContainer
    };

schultezub's avatar
schultezub committed
73
74
75
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
76
77
78
79
80
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

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

84
85
86
        /// \see TreeItem::setData()
        virtual bool setData(int column, int role, const QVariant& value) const;

87
    private:
schultezub's avatar
schultezub committed
88
        AbstractPipeline* _pipeline;        ///< Base pipeline
89
90
    };

schultezub's avatar
schultezub committed
91
92
93
    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
94
95
96
97
98
    class ProcessorTreeItem : public TreeItem {
    public:
        ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent);
        virtual ~ProcessorTreeItem();

schultezub's avatar
schultezub committed
99
        /// \see TreeItem::getData()
100
        virtual QVariant getData(int column, int role) const;
101

102
103
104
        /// \see TreeItem::setData()
        virtual bool setData(int column, int role, const QVariant& value) const;

105
    private:
schultezub's avatar
schultezub committed
106
        AbstractProcessor* _processor;      ///< Base processor
107
108
109
110
    };

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

schultezub's avatar
schultezub committed
111
112
113
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
114
115
116
117
    class PipelineTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
118
        explicit PipelineTreeModel(QObject *parent = 0);
119
120
        ~PipelineTreeModel();

121
        void setData(const std::vector<DataContainer*>& dataContainers, const std::vector<AbstractPipeline*>& pipelines);
122
123

        QVariant data(const QModelIndex &index, int role) const;
124
125
126
127
128
129
130
131
132

        /**
         * 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);

133
134
135
136
137
138
139
140
141
142
143
144
145
146
        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
147
148
149
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
150
151
152
153
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
schultezub's avatar
schultezub committed
154
155
156
157
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
158
        explicit PipelineTreeWidget(QWidget* parent = 0);
159

schultezub's avatar
schultezub committed
160
161
162
        /**
         * Destructor
         */
163
164
        virtual ~PipelineTreeWidget();

165
166
167
168
169
170
171
172
        /**
         * Return the recommended size for the widget.
         *
         * This method tries to calculate a sensible height for the wigdet, while still reusing QTreeView's hardcoded
         * width.
         */
        virtual QSize sizeHint() const;

173

174
175
176
177
178
    signals:
        /// Emitted whenever the currently selected item changes
        void itemChanged(const QModelIndex& index);


179
    public slots:
schultezub's avatar
schultezub committed
180
181
182
183
        /**
         * Updates the data in the tree view by the given collection of pipelines \a pipelines.
         * \param   pipelines   
         */
184
        void update(const std::vector<DataContainer*>& dataContainers, const std::vector<AbstractPipeline*>& pipelines);
185
186


187
188
189
190
    protected:

        virtual void selectionChanged(const QItemSelection& selected, const QItemSelection &deselected);

191
    private:
schultezub's avatar
schultezub committed
192
193
194
        /**
         * Sets up the widget.
         */
195
196
        void setupWidget();

schultezub's avatar
schultezub committed
197
        PipelineTreeModel* _treeModel;      ///< Data model for the TreeView.
198
199
200
201
202

    };
}

#endif // PIPELINETREEWIDGET_H__