pipelinetreewidget.h 6.33 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
38
39
#ifndef PIPELINETREEWIDGET_H__
#define PIPELINETREEWIDGET_H__

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

#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
40
#include "application/tools/treeitem.h"
41
42
#include <vector>

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

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

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

schultezub's avatar
schultezub committed
59
60
61
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
62
63
64
65
66
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

schultezub's avatar
schultezub committed
67
        /// \see TreeItem::getData()
68
        virtual QVariant getData(int column, int role) const;
69

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

73
    private:
schultezub's avatar
schultezub committed
74
        AbstractPipeline* _pipeline;        ///< Base pipeline
75
76
    };

schultezub's avatar
schultezub committed
77
78
79
    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
80
81
82
83
84
    class ProcessorTreeItem : public TreeItem {
    public:
        ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent);
        virtual ~ProcessorTreeItem();

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

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

91
    private:
schultezub's avatar
schultezub committed
92
        AbstractProcessor* _processor;      ///< Base processor
93
94
95
96
    };

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

schultezub's avatar
schultezub committed
97
98
99
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
100
101
102
103
    class PipelineTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
104
        explicit PipelineTreeModel(QObject *parent = 0);
105
106
107
108
109
        ~PipelineTreeModel();

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

        QVariant data(const QModelIndex &index, int role) const;
110
111
112
113
114
115
116
117
118

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

119
120
121
122
123
124
125
126
127
128
129
130
131
132
        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
133
134
135
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
136
137
138
139
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
schultezub's avatar
schultezub committed
140
141
142
143
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
144
        explicit PipelineTreeWidget(QWidget* parent = 0);
145

schultezub's avatar
schultezub committed
146
147
148
        /**
         * Destructor
         */
149
150
        virtual ~PipelineTreeWidget();

151
152
153
154
155
156
157
158
        /**
         * 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;

159
160

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


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

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

    };
}

#endif // PIPELINETREEWIDGET_H__