X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_DataModel.h;h=d08ccc42a8f301529b7d0e5f6352c3e1f6ac6b36;hb=ca05954b3f9fe2c1a21333df5d454eeccbd42224;hp=e1157ccb74cc74a68eca189a1cb873f273620132;hpb=3e3fc52de000b4d8e51fdcffe7f72f82237833ad;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index e1157ccb7..d08ccc42a 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -9,16 +9,36 @@ #define XGUI_DataModel_H #include "XGUI.h" +#include #include +#include #include +#include + #include -class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel +/**\class XGUI_DataModel + * \ingroup GUI + * \brief This is a data model for Object Browser (QTreeView). + * It uses XML file for definition of data tree. + * Some tips about organization of the model: + * - Non Valid Index - root index + * - An index with internal Id == -1 is a folder of root document + * - An index which contains internal pointer as ModelAPI_Object its the object + * - An index which contains internal pointer as ModelAPI_Document is a folder which belongs to this document + */ +class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener { Q_OBJECT public: + /// Constructor + /// \param theParent a parent object XGUI_DataModel(QObject* theParent); + /// Event Listener method + /// \param theMessage an event message + virtual void processEvent(const std::shared_ptr& theMessage); + //! Returns an object by the given Model index. //! Returns 0 if the given index is not index of an object virtual ObjectPtr object(const QModelIndex& theIndex) const; @@ -72,8 +92,59 @@ public: /// \param theParent a parent model index virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; + /// Inserts count rows into the model before the given row. + /// Items in the new row will be children of the item represented by the parent model index. + /// \param theRow a start row + /// \param theCount a nember of rows to insert + /// \param theParent a parent model index + virtual bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); + + /// Removes count rows starting with the given row under parent parent from the model. + /// \param theRow a start row + /// \param theCount a nember of rows to remove + /// \param theParent a parent model index + virtual bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); + + /// Returns the item flags for the given index. + /// \param theIndex a model index + virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const; + + /// Returns an index which is root of the given document + /// \param theDoc a document + QModelIndex documentRootIndex(DocumentPtr theDoc) const; + + /// Returns last history object index + virtual QModelIndex lastHistoryIndex() const; private: + /// Find a root index which contains objects of the given document + /// \param theDoc the document object + QModelIndex findDocumentRootIndex(const ModelAPI_Document* theDoc) const; + + /// Returns number of folders in document. Considered folders which has to be shown only if they are not empty. + /// \param theDoc document which has to be checked. If 0 then Root document will be considered + int foldersCount(ModelAPI_Document* theDoc = 0) const; + + /// Retrurns indexes of folders which can not be shown because they are empty + /// \param theDoc document which has to be checked. If 0 then Root document will be considered + QIntList missedFolderIndexes(ModelAPI_Document* theDoc = 0) const; + + /// Returns Id (row) of a folder taking into consideration folders which can not be shown non empty + /// \param theType Type of the folder + /// \param theDoc a document which contains this folder + int folderId(std::string theType, ModelAPI_Document* theDoc = 0); + + /// Removes a row from branch of tree + /// \param theStart - start row to update indexes + /// \param theSize - number of indexes in the folder + /// \param theParent - index of parent folder + void rebuildBranch(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); + + + /// Returns list of folders types which can not be shown empty + /// \param fromRoot - root document flag + QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const; + Config_DataModelReader myXMLReader; };