+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
#ifndef XGUI_PartDataModel_H
#define XGUI_PartDataModel_H
-#include <QAbstractItemModel>
-
-class ModelAPI_Feature;
-class ModelAPI_Document;
+#include "XGUI.h"
+#include "XGUI_DataTreeModel.h"
/**\class XGUI_TopDataModel
* \ingroup GUI
* \brief This is a data model for Object Browser (QTreeView).
* It represents only upper part of data tree (non-parts tree items)
*/
-class XGUI_TopDataModel : public QAbstractItemModel
+class XGUI_EXPORT XGUI_TopDataModel : public XGUI_FeaturesModel
{
- Q_OBJECT
-public:
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent a parent object
XGUI_TopDataModel(QObject* theParent);
virtual ~XGUI_TopDataModel();
-
- //! Set a document object
- virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc)
- {
- myDocument = theDoc;
- }
-
- // Reimplementation from QAbstractItemModel
- virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
- virtual QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ // Reimpl from QAbstractItemModel
- virtual QModelIndex index(int theRow, int theColumn,
- const QModelIndex& theParent = QModelIndex()) const;
+ /// Returns the data stored under the given role for the item referred to by the index.
+ /// \param theIndex a model index
+ /// \param theRole a data role (see Qt::ItemDataRole)
+ virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
+ /// Returns the data for the given role and section in the header with the specified orientation.
+ /// \param theSection a section
+ /// \param theOrient an orientation
+ /// \param theRole a data role (see Qt::ItemDataRole)
+ virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
+ int theRole = Qt::DisplayRole) const;
+
+ /// Returns the number of rows under the given parent. When the parent is valid it means that
+ /// rowCount is returning the number of children of parent.
+ /// \param theParent a parent model index
+ virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
+
+ /// Returns the number of columns for the children of the given parent.
+ /// It has a one column
+ /// \param theParent a parent model index
+ virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
+
+
+ /// Returns the index of the item in the model specified by the given row, column and parent index.
+ /// \param theRow a row
+ /// \param theColumn a column
+ /// \param theParent a parent model index
+ virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
+ QModelIndex()) const;
+
+ /// Returns the parent of the model item with the given index.
+ /// If the item has no parent, an invalid QModelIndex is returned.
+ /// \param theIndex a model index
virtual QModelIndex parent(const QModelIndex& theIndex) const;
+ /// Returns true if parent has any children; otherwise returns false.
+ /// \param theParent a parent model index
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
-private:
+ //! Returns object by the given Model index.
+ //! Returns 0 if the given index is not index of a object
+ virtual ObjectPtr object(const QModelIndex& theIndex) const;
+
+ //! Returns QModelIndex which corresponds to the given object
+ //! If the object is not found then index is not valid
+ virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
+
+ //! Returns parent index of the given object
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const;
+
+ //! Returns index corresponded to the group
+ virtual QModelIndex findGroup(const std::string& theGroup) const;
+
+ private:
//! Types of QModelIndexes
- enum DataIds {
+ enum DataIds
+ {
ParamsFolder,
ParamObject,
ConstructFolder,
ConstructObject
+ //GroupsFolder,
+ //GroupObject
};
- //! Document object
- std::shared_ptr<ModelAPI_Document> myDocument;
};
-
/**\class XGUI_PartDataModel
* \ingroup GUI
* \brief This is a data model for Object Browser (QTreeView).
* It represents data tree only of a one part
*/
-class XGUI_PartDataModel : public QAbstractItemModel
+class XGUI_PartDataModel : public XGUI_PartModel
{
- Q_OBJECT
-public:
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent a parent object
XGUI_PartDataModel(QObject* theParent);
virtual ~XGUI_PartDataModel();
- //! Set a document object and Id of a part in the document
- virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc, int theId)
- {
- myDocument = theDoc;
- myId = theId;
- }
+ // Reimpl from QAbstractItemModel
- // Reimplementation from QAbstractItemModel
+ /// Returns the data stored under the given role for the item referred to by the index.
+ /// \param theIndex a model index
+ /// \param theRole a data role (see Qt::ItemDataRole)
virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
- virtual QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
-
- virtual QModelIndex index(int theRow, int theColumn,
- const QModelIndex& theParent = QModelIndex()) const;
+ /// Returns the data for the given role and section in the header with the specified orientation.
+ /// \param theSection a section
+ /// \param theOrient an orientation
+ /// \param theRole a data role (see Qt::ItemDataRole)
+ virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
+ int theRole = Qt::DisplayRole) const;
+
+ /// Returns the number of rows under the given parent. When the parent is valid it means that
+ /// rowCount is returning the number of children of parent.
+ /// \param theParent a parent model index
+ virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
+
+ /// Returns the number of columns for the children of the given parent.
+ /// It has a one column
+ /// \param theParent a parent model index
+ virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
+
+ /// Returns the index of the item in the model specified by the given row, column and parent index.
+ /// \param theRow a row
+ /// \param theColumn a column
+ /// \param theParent a parent model index
+ virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
+ QModelIndex()) const;
+
+ /// Returns the parent of the model item with the given index.
+ /// If the item has no parent, an invalid QModelIndex is returned.
+ /// \param theIndex a model index
virtual QModelIndex parent(const QModelIndex& theIndex) const;
+ /// Returns true if parent has any children; otherwise returns false.
+ /// \param theParent a parent model index
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
-private:
- std::shared_ptr<ModelAPI_Document> featureDocument() const;
+ //! Returns object by the given Model index.
+ //! Returns 0 if the given index is not index of a object
+ virtual ObjectPtr object(const QModelIndex& theIndex) const;
+
+ //! Returns QModelIndex which corresponds to the given object
+ //! If the object is not found then index is not valid
+ virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
+
+ //! Returns true if the given document is a sub-document of this tree
+ virtual bool hasDocument(const DocumentPtr& theDoc) const;
+
+ //! Returns parent index of the given object
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const;
+
+ //! Returns index corresponded to the group
+ virtual QModelIndex findGroup(const std::string& theGroup) const;
+
+ //! Return a Part object
+ virtual ResultPartPtr part() const;
+
+ private:
+
+ //! Returns document of the current part
+ DocumentPtr partDocument() const;
+
+ //! Returns defult number of rows
+ int getRowsNumber() const;
//! Types of QModelIndexes
- enum DataIds {
+ enum DataIds
+ {
MyRoot,
ParamsFolder,
ParamObject,
ConstructFolder,
- ConstructObject
+ ConstructObject,
+ BodiesFolder,
+ BodiesObject,
+ GroupsFolder,
+ GroupObject,
+ HistoryObject
};
- //! Document object
- std::shared_ptr<ModelAPI_Document> myDocument;
-
- //! Id of the current part object in the document
- int myId;
};
-#endif
\ No newline at end of file
+#endif