TreeModel.hh 4.35 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




#ifndef TREEMODEL_H
#define TREEMODEL_H

#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>

#include <OpenFlipper/common/Types.hh>

class TreeItem;

class TreeModel : public QAbstractItemModel
{
    Q_OBJECT

public:
Dirk Wilden's avatar
Dirk Wilden committed
51
52

    /// Constructor
Jan Möbius's avatar
 
Jan Möbius committed
53
    TreeModel(QObject *_parent = 0);
Dirk Wilden's avatar
Dirk Wilden committed
54
55

    /// Destructor
Jan Möbius's avatar
 
Jan Möbius committed
56
57
58
59
    ~TreeModel();

    /// Get the data of the corresponding entry
    QVariant data(const QModelIndex &index, int role) const;
Dirk Wilden's avatar
Dirk Wilden committed
60

Jan Möbius's avatar
 
Jan Möbius committed
61
62
    /// return the types of the corresponding entry
    Qt::ItemFlags flags(const QModelIndex &index) const;
Dirk Wilden's avatar
Dirk Wilden committed
63

Jan Möbius's avatar
 
Jan Möbius committed
64
65
66
67
    /// return the header data of the model
    QVariant headerData(int section, 
                        Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
Dirk Wilden's avatar
Dirk Wilden committed
68
69

    /// Get the ModelIndex at given row,column
Jan Möbius's avatar
 
Jan Möbius committed
70
71
    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const;
Dirk Wilden's avatar
Dirk Wilden committed
72
73

    /// Get the parent ModelIndex
Jan Möbius's avatar
 
Jan Möbius committed
74
    QModelIndex parent(const QModelIndex &index) const;
Dirk Wilden's avatar
Dirk Wilden committed
75
76

    /// get the number of rows
Jan Möbius's avatar
 
Jan Möbius committed
77
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
Dirk Wilden's avatar
Dirk Wilden committed
78
79

    /// get the number of columns
Jan Möbius's avatar
 
Jan Möbius committed
80
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
Dirk Wilden's avatar
Dirk Wilden committed
81

Jan Möbius's avatar
 
Jan Möbius committed
82
83
    /// The object with the given id has been updated. Check if model has to be changed
    void updatedObject(int id_);
Dirk Wilden's avatar
Dirk Wilden committed
84

Jan Möbius's avatar
 
Jan Möbius committed
85
86
    /// Set the data at the given index
    bool setData(const QModelIndex &index, const QVariant &value , int role);
Dirk Wilden's avatar
Dirk Wilden committed
87
88

    /// Get the BaseObject corresponding to a given ModelIndex
Jan Möbius's avatar
 
Jan Möbius committed
89
    BaseObject *getItem(const QModelIndex &index) const;
90

Dirk Wilden's avatar
Dirk Wilden committed
91
    /// Return the ModelIndex corresponding to a given BaseObject and Column
92
    QModelIndex getModelIndex(BaseObject* _object, int _column );
Dirk Wilden's avatar
Dirk Wilden committed
93

Jan Möbius's avatar
 
Jan Möbius committed
94
    /// Check if the given item is the root item
Dirk Wilden's avatar
Dirk Wilden committed
95
96
97
    bool isRoot(BaseObject* _item);

    /// Get the name of a given object
Jan Möbius's avatar
 
Jan Möbius committed
98
    bool getObjectName(BaseObject* _object , QString& _name);
99

Dirk Wilden's avatar
Dirk Wilden committed
100
101
102
103
104
105
106

//===========================================================================
/** @name Drag and Drop
  * @{ */
//===========================================================================

    /// supported drag & Drop actions
107
108
    Qt::DropActions supportedDropActions() const;

Dirk Wilden's avatar
Dirk Wilden committed
109
    /// stores the mimeType for Drag & Drop
110
111
    QStringList mimeTypes() const;

Dirk Wilden's avatar
Dirk Wilden committed
112
    /// get the mimeData for a given ModelIndex
113
114
    QMimeData* mimeData(const QModelIndexList& indexes) const;

Dirk Wilden's avatar
Dirk Wilden committed
115
    /// Called when mimeData is dropped somewhere
116
117
    bool dropMimeData(const QMimeData *data,
     Qt::DropAction action, int row, int column, const QModelIndex &parent);
Dirk Wilden's avatar
Dirk Wilden committed
118
119
120

/** @} */

Jan Möbius's avatar
 
Jan Möbius committed
121
122
123
124
125
126
127
128
129
130
private:
    /// Rootitem of the tree
    BaseObject* rootItem_;
    
    /** Mapping of the group ids to their parent
     * Use this to check if a group with the given id exists and which item 
     * represents this group
     */
    std::map< int, TreeItem* > map_;

131
132
133
134
    /// Recursively update source,target selection up to the root of the tree
    void updateSourceSelection(BaseObject* _obj );
    void updateTargetSelection(BaseObject* _obj );

Jan Möbius's avatar
 
Jan Möbius committed
135
136
137
138
139
140
141
142
143
};

///@todo : Save group names on exit
///@todo : Load group names
///@todo : emit update objects in the right place
///@todo : emit dataChanged instead of reset();

#endif