pipelinetreewidget.h 6.94 KB
Newer Older
1 2 3 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
// ================================================================================================
// 
// This file is part of the TUMVis Visualization Framework.
// 
// 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.
// 
// ================================================================================================

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#ifndef PIPELINETREEWIDGET_H__
#define PIPELINETREEWIDGET_H__

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

#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
#include <vector>

namespace TUMVis {

// = TreeModel items ==============================================================================

schultezub's avatar
schultezub committed
45 46 47
    /**
     * Abstract base class for TreeView items of the PipelineTreeWidget.
     */
48 49
    class TreeItem {
    public:
schultezub's avatar
schultezub committed
50 51 52 53
        /**
         * Creates a new TreeItem
         * \param   parent  Parent item, will take ownership of this TreeItem.
         */
54
        TreeItem(TreeItem* parent = 0);
schultezub's avatar
schultezub committed
55 56 57 58

        /**
         * Destuctor, also deletes all child items.
         */
59 60
        virtual ~TreeItem();

schultezub's avatar
schultezub committed
61 62 63 64
        /**
         * Return the of this item at the column \a column.
         * To be overwritten by subclasses.
         * \param   column  Column
schultezub's avatar
schultezub committed
65
         * \param   role    Access role (Use Qt::DisplayRole for string representation, Qt::UserRole for the internal data)
schultezub's avatar
schultezub committed
66 67
         * \return  The data of this item at \a column.
         */
68
        virtual QVariant getData(int column, int role) const = 0;
69

schultezub's avatar
schultezub committed
70 71 72 73
        /**
         * Returns the parent TreeItem
         * \return _parent
         */
74
        TreeItem* getParent();
schultezub's avatar
schultezub committed
75 76 77 78 79 80

        /**
         * Returns the \a row-th child TreeItem.
         * \param   row     Number of the child to return.
         * \return  _children[row]
         */
81
        TreeItem* getChild(int row);
schultezub's avatar
schultezub committed
82 83 84 85 86

        /**
         * Returns the row of this TreeItem.
         * \return _parent._children.indexOf(this)
         */
87
        int getRow();
schultezub's avatar
schultezub committed
88 89 90 91 92

        /**
         * Returns the number of children.
         * \return  _children.size();
         */
93 94 95
        int getChildCount();

    private:
schultezub's avatar
schultezub committed
96 97
        TreeItem* _parent;              ///< Parent TreeItem.
        QList<TreeItem*> _children;     ///< Collection of all child items.
98 99
    };

schultezub's avatar
schultezub committed
100 101 102
    /**
     * Specialization for root TreeItems.
     */
103 104 105 106 107
    class RootTreeItem : public TreeItem {
    public:
        RootTreeItem(TreeItem* parent = 0);
        virtual ~RootTreeItem();

schultezub's avatar
schultezub committed
108
        /// \see TreeItem::getData()
109
        virtual QVariant getData(int column, int role) const;
110 111
    };

schultezub's avatar
schultezub committed
112 113 114
    /**
     * Specialization for TreeItems hosting an AbstracPipeline.
     */
115 116 117 118 119
    class PipelineTreeItem : public TreeItem {
    public:
        PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent);
        virtual ~PipelineTreeItem();

schultezub's avatar
schultezub committed
120
        /// \see TreeItem::getData()
121
        virtual QVariant getData(int column, int role) const;
122 123

    private:
schultezub's avatar
schultezub committed
124
        AbstractPipeline* _pipeline;        ///< Base pipeline
125 126
    };

schultezub's avatar
schultezub committed
127 128 129
    /**
     * Specialization for TreeItems hosting an AbstractProcessor.
     */
130 131 132 133 134
    class ProcessorTreeItem : public TreeItem {
    public:
        ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent);
        virtual ~ProcessorTreeItem();

schultezub's avatar
schultezub committed
135
        /// \see TreeItem::getData()
136
        virtual QVariant getData(int column, int role) const;
137 138

    private:
schultezub's avatar
schultezub committed
139
        AbstractProcessor* _processor;      ///< Base processor
140 141 142 143
    };

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

schultezub's avatar
schultezub committed
144 145 146
    /**
     * QItemModel for displaying a list of pipelines and their processors in the PipelineTreeWidget.
     */
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    class PipelineTreeModel : public QAbstractItemModel {
        Q_OBJECT

    public:
        PipelineTreeModel(QObject *parent = 0);
        ~PipelineTreeModel();

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

        QVariant data(const QModelIndex &index, int role) const;
        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
171 172 173
    /**
     * Qt widget for showing a list of pipelines and their processors in a QTreeView.
     */
174 175 176 177
    class PipelineTreeWidget : public QTreeView {
        Q_OBJECT;

    public:
schultezub's avatar
schultezub committed
178 179 180 181
        /**
         * Creates a new PipelineTreeWidget.
         * \param   parent  Parent widget
         */
182 183
        PipelineTreeWidget(QWidget* parent = 0);

schultezub's avatar
schultezub committed
184 185 186
        /**
         * Destructor
         */
187 188 189 190
        virtual ~PipelineTreeWidget();


    public slots:
schultezub's avatar
schultezub committed
191 192 193 194
        /**
         * Updates the data in the tree view by the given collection of pipelines \a pipelines.
         * \param   pipelines   
         */
195 196 197 198
        void update(const std::vector<AbstractPipeline*>& pipelines);


    private:
schultezub's avatar
schultezub committed
199 200 201
        /**
         * Sets up the widget.
         */
202 203
        void setupWidget();

schultezub's avatar
schultezub committed
204
        PipelineTreeModel* _treeModel;      ///< Data model for the TreeView.
205 206 207 208 209 210


    };
}

#endif // PIPELINETREEWIDGET_H__