datacontainertreewidget.h 6.67 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Visualization Framework.
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
29
30
31
32
33
34
35
// 
// 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.
// 
// ================================================================================================

#ifndef DATACONTAINERTREEWIDGET_H__
#define DATACONTAINERTREEWIDGET_H__

#include <QAbstractItemModel>
#include <QTreeWidget>
#include <QList>
#include <QVariant>
36
#include <map>
37
38

#include "application/tools/treeitem.h"
39
#include "application/gui/qtdatahandle.h"
40

schultezub's avatar
schultezub committed
41
namespace campvis {
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    class DataContainer;

// = TreeModel items ==============================================================================
    
    /**
     * Specialization for root TreeItems.
     */
    class DataContainerTreeRootItem : public TreeItem {
    public:
        DataContainerTreeRootItem(TreeItem* parent = 0);
        virtual ~DataContainerTreeRootItem();

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

    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
    class DataHandleTreeItem : public TreeItem {
    public:
        /**
64
65
66
         * 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
67
68
         * \param   parent      Parent TreeItem
         */
69
        DataHandleTreeItem(const QtDataHandle& dataHandle, const std::string& name, TreeItem* parent);
70
71

        /**
72
         * Destructor, deletes the QtDataHandle
73
74
75
76
77
78
         */
        virtual ~DataHandleTreeItem();

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

79
        /**
80
         * Sets the QtDataHandle for this tree item.
81
         * \note    DataHandleTreeItem takes ownership of this pointer.
82
         * \param   dataHandle  The QtDataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
83
         */
84
        void setDataHandle(const QtDataHandle& dataHandle);
85

86
    private:
87
88
        QtDataHandle _dataHandle;         ///< Base QtDataHandle
        std::string _name;              ///< Name of that QtDataHandle
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    };

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

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

    public:
        DataContainerTreeModel(QObject *parent = 0);
        ~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;

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

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

// = 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
         */
        DataContainerTreeWidget(QWidget* parent = 0);

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

156
157
158
159
160
161
        /**
         * Returns the data model for the TreeView.
         * \return  _treeModel
         */
        DataContainerTreeModel* getTreeModel();

162
163
164
165
166
167
168
169
170

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


171

172
173
174
175
176
177
    private:
        /**
         * Sets up the widget.
         */
        void setupWidget();

178
        DataContainerTreeModel* _treeModel;     ///< Data model for the TreeView.
179
180
181
182
183
184

    };

}

#endif // DATACONTAINERTREEWIDGET_H__