1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author: Guillaume Boulant (EDF/R&D)
26 #include "TreeData.hxx"
28 #include <QAbstractItemModel>
29 #include <QModelIndex>
31 #include <QStringList>
33 #include "DataObject.hxx"
38 class TREEDATA_EXPORT TreeModel : public QAbstractItemModel
43 // In this implementation of QAbstractItemModel, a tree item is
44 // associated to the tree model it belongs to (it can request its
45 // model throw a pointer to this model). Then we declare the
46 // TreeItem as a friend class so that it can request the protected
47 // methods (for example beginInsertRows and endInsertRows, required
48 // to manage correctly the addition of an item in the model. An
49 // item can append a child to itself, so it needs to inform the
50 // model when it begins and when it ends).
51 friend class TreeItem;
52 friend class TreeView;
55 TreeModel(const QStringList &headers, QObject *parent = 0);
59 // =================================================================
60 // This part of the specification is the standard interface required
61 // for providing an operational TreeModel. These methods are used by
62 // the TreeView for display purpose. We just have to implement how
63 // we want the items to be displayed in the view.
64 // =================================================================
66 // MEM: note that these methods are not intended to be used
67 // directly. That's the job of the viewer to know how to use
68 // them. We just have to give the implementation for customizing the
69 // appearance of the tree. The implementation generally requests the
70 // items'data to set the appearance features.
71 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
72 QModelIndex parent(const QModelIndex &index) const;
73 int rowCount(const QModelIndex &parent = QModelIndex()) const;
74 int columnCount(const QModelIndex &parent = QModelIndex()) const;
75 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
76 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
77 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
78 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
79 Qt::ItemFlags flags(const QModelIndex &index) const;
82 // =================================================================
83 // This part is a specific behavior to get a TreeModel that can
84 // organize itself the tree hierarchy using data provided in a
85 // filesystem-like format:
87 // data="a/b/c" ==> creation/filling of the hierarchy a->b->c
88 // The "folder" categories are unique whereas the leaves may exists
89 // in multiple instances.
90 // =================================================================
92 bool addData(DataObject * dataObject);
93 bool addData(DataObject * dataObject, const QStringList &path);
95 // TODO: We should implement the delete and the update fucntions
96 bool removeData(DataObject * dataObject);
98 // This part contains helper functions for general purposes
99 TreeItem * getRootItem();
102 TreeItem *getItem(const QModelIndex &index = QModelIndex()) const;
103 TreeItem * _rootItem;
106 #endif // TREEMODEL_H