pipelinetreewidget.h 7.04 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// 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.
// 
// ================================================================================================

30
31
32
33
34
35
36
37
#ifndef PIPELINETREEWIDGET_H__
#define PIPELINETREEWIDGET_H__

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

38
#include "core/datastructures/datacontainer.h"
39
40
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
41
#include "application/tools/treeitem.h"
42
43
#include <vector>

schultezub's avatar
schultezub committed
44
namespace campvis {
45
46

// = TreeModel items ==============================================================================
47
    
schultezub's avatar
schultezub committed
48
49
50
    /**
     * Specialization for root TreeItems.
     */
51
    class PipelineTreeRootItem : public TreeItem {
52
    public:
53
        explicit PipelineTreeRootItem(TreeItem* parent = 0);
54
        virtual ~PipelineTreeRootItem();
55

schultezub's avatar
schultezub committed
56
        /// \see TreeItem::getData()
57
        virtual QVariant getData(int column, int role) const;
58
59
    };

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    /**
     * 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
78
79
80
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
81
82
83
84
85
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

schultezub's avatar
schultezub committed
86
        /// \see TreeItem::getData()
87
        virtual QVariant getData(int column, int role) const;
88

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

92
    private:
schultezub's avatar
schultezub committed
93
        AbstractPipeline* _pipeline;        ///< Base pipeline
94
95
    };

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

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

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

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
    class PipelineTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
123
        explicit PipelineTreeModel(QObject *parent = 0);
124
125
        ~PipelineTreeModel();

126
        void setData(const std::vector<DataContainer*>& dataContainers, const std::vector<AbstractPipeline*>& pipelines);
127
128

        QVariant data(const QModelIndex &index, int role) const;
129
130
131
132
133
134
135
136
137

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

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

    public:
schultezub's avatar
schultezub committed
159
160
161
162
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
163
        explicit PipelineTreeWidget(QWidget* parent = 0);
164

schultezub's avatar
schultezub committed
165
166
167
        /**
         * Destructor
         */
168
169
        virtual ~PipelineTreeWidget();

170
171
172
173
174
175
176
177
        /**
         * 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;

178
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


    private:
schultezub's avatar
schultezub committed
188
189
190
        /**
         * Sets up the widget.
         */
191
192
        void setupWidget();

schultezub's avatar
schultezub committed
193
        PipelineTreeModel* _treeModel;      ///< Data model for the TreeView.
194
195
196
197
198

    };
}

#endif // PIPELINETREEWIDGET_H__