2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

datacontainertreewidget.h 6.44 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-2014, 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
// 
// ================================================================================================

#ifndef DATACONTAINERTREEWIDGET_H__
#define DATACONTAINERTREEWIDGET_H__

#include <QAbstractItemModel>
#include <QTreeWidget>
#include <QList>
#include <QVariant>
32
#include <map>
33
34

#include "application/tools/treeitem.h"
35
#include "application/gui/qtdatahandle.h"
36

schultezub's avatar
schultezub committed
37
namespace campvis {
38
39
40
41
42
43
44
45
46
    class DataContainer;

// = TreeModel items ==============================================================================
    
    /**
     * Specialization for root TreeItems.
     */
    class DataContainerTreeRootItem : public TreeItem {
    public:
47
        explicit DataContainerTreeRootItem(TreeItem* parent = 0);
48
49
50
51
52
53
54
55
56
57
58
59
        virtual ~DataContainerTreeRootItem();

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

    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
    class DataHandleTreeItem : public TreeItem {
    public:
        /**
60
61
62
         * Creates a new TreeItem for a QtDataHandle
         * \param   dataHandle  The QtDataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
         * \param   name        Name of the QtDataHandle
63
64
         * \param   parent      Parent TreeItem
         */
65
        DataHandleTreeItem(QtDataHandle dataHandle, const std::string& name, TreeItem* parent);
66
67

        /**
68
         * Destructor, deletes the QtDataHandle
69
70
71
72
73
74
         */
        virtual ~DataHandleTreeItem();

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

75
        /**
76
         * Sets the QtDataHandle for this tree item.
77
         * \note    DataHandleTreeItem takes ownership of this pointer.
78
         * \param   dataHandle  The QtDataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
79
         */
80
        void setDataHandle(QtDataHandle dataHandle);
81

82
    private:
83
84
85
86
87
88
89
        /**
         * Updates this item's children.
         * In case of having a ImageSeries or RenderData as DataHandle, we are a collection of 
         * DataHandles ourself. Hence, we create child items for us.
         */
        void updateChildren();

90
91
        QtDataHandle _dataHandle;         ///< Base QtDataHandle
        std::string _name;              ///< Name of that QtDataHandle
92
93
94
95
96
97
98
99
100
101
102
    };

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

    /**
     * QItemModel for displaying a list of pipelines and their processors in the DataContainerTreeWidget.
     */
    class DataContainerTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
103
        explicit DataContainerTreeModel(QObject *parent = 0);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
        ~DataContainerTreeModel();

        void setData(const DataContainer* dataContainer);

        QVariant data(const QModelIndex &index, int role) const;

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

        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;

126
127
    public slots:
        /**
128
129
130
         * Slot being called when a QtDataHandle has been added to the DataContainer.
         * \param   key     Name of the QtDataHandle
         * \param   dh      The added QtDataHandle
131
         */
132
        void onDataContainerChanged(const QString& key, QtDataHandle dh);
133

134
135
    private:
        TreeItem* _rootItem;
136
        std::map<QString, DataHandleTreeItem*> _itemMap;  ///< Mapping the QtDataHandle Keys to the TreeItems
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    };

// = Widget =======================================================================================

    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
    class DataContainerTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
        /**
         * Creates a new DataContainerTreeWidget.
         * \param   parent  Parent widget
         */
152
        explicit DataContainerTreeWidget(QWidget* parent = 0);
153
154
155
156
157
158

        /**
         * Destructor
         */
        virtual ~DataContainerTreeWidget();

159
160
161
162
163
164
        /**
         * Returns the data model for the TreeView.
         * \return  _treeModel
         */
        DataContainerTreeModel* getTreeModel();

165
166
167
168
169
170
171
172
173

    public slots:
        /**
         * Updates the data in the tree view by the given collection of pipelines \a pipelines.
         * \param   pipelines   
         */
        void update(const DataContainer* dataContainer);


174

175
176
177
178
179
180
    private:
        /**
         * Sets up the widget.
         */
        void setupWidget();

181
        DataContainerTreeModel* _treeModel;     ///< Data model for the TreeView.
182
183
184
185
186
187

    };

}

#endif // DATACONTAINERTREEWIDGET_H__