1 // Created on: 2020-01-25
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2020 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef TreeModel_ItemProperties_H
17 #define TreeModel_ItemProperties_H
19 #include <Standard.hxx>
20 #include <Standard_Dump.hxx>
21 #include <Standard_Handle.hxx>
22 #include <Standard_Macro.hxx>
23 #include <Standard_Type.hxx>
24 #include <Standard_Transient.hxx>
26 #include <NCollection_IndexedDataMap.hxx>
27 #include <NCollection_IndexedMap.hxx>
28 #include <NCollection_List.hxx>
30 #include <TCollection_AsciiString.hxx>
32 #include <inspector/TreeModel_ItemBase.hxx>
33 #include <inspector/ViewControl_EditType.hxx>
35 #include <Standard_WarningsDisable.hxx>
36 #include <QAbstractTableModel>
39 #include <QModelIndexList>
41 #include <Standard_WarningsRestore.hxx>
43 //! \class TreeModel_ItemProperties
44 //! Class to manipulate properties of tree item. The properties are organized in table structure
45 class TreeModel_ItemProperties : public Standard_Transient
47 //! enum defined the dimension type
48 enum TreeModel_DimType
50 TreeModel_DimType_Rows, //!< defines number of rows
51 TreeModel_DimType_Columns //!< defines number of columns
54 //! container of values in a row of property table
55 struct TreeModel_RowValue
57 TreeModel_RowValue (const Standard_Integer theValueStartPosition, const QVariant& theKey, QVariant theValue)
58 : ValueStartPosition (theValueStartPosition), Key (theKey), Value (theValue) {}
60 Standard_Integer ValueStartPosition; //!< start position of the key
61 QVariant Key; //!< value in the first column
62 QVariant Value; //!< value in the second column
63 QMap<int, QVariant> CustomValues; //!< custom values, e.g. key is Background, value is a defined color
68 TreeModel_ItemProperties() {}
71 ~TreeModel_ItemProperties() {}
73 //! Sets the current item
74 void SetItem (const TreeModel_ItemBasePtr& theItem) { myItem = theItem; }
76 //! Returns the current item
77 TreeModel_ItemBasePtr Item() const { return myItem; }
79 //! Fills internal containers by item stream values
80 Standard_EXPORT void Init();
82 //! If the item has internal values, they should be reset here.
83 Standard_EXPORT virtual void Reset();
85 //! Returns number of table rows
86 //! \return an integer value
87 Standard_EXPORT int RowCount() const;
89 //! Returns number of table columns
90 //! \return an integer value
91 int ColumnCount() const { return 2; }
93 //! Returns content of the model index for the given role, it is obtained from internal container of values
94 //! \param theRow a model index row
95 //! \param theColumn a model index column
96 //! \param theRole a view role
97 //! \return value interpreted depending on the given role
98 Standard_EXPORT QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const;
100 //! Returns type of edit control for the model index. By default, it is an empty control
101 //! \param theRow a model index row
102 //! \param theColumn a model index column
103 //! \return edit type
104 Standard_EXPORT ViewControl_EditType EditType (const int theRow, const int theColumn) const;
106 //! Sets content of the model index for the given role, it is applied to internal container of values
107 //! \param theRow a model index row
108 //! \param theColumn a model index column
109 //! \param theRole a view role
110 //! \return true if the value is changed
111 Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue,
112 int theRole = Qt::DisplayRole);
114 //! Returns presentation of the attribute to be visualized in the view
115 //! \thePresentations [out] container of presentation handles to be visualized
116 Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
118 //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable.
119 //! Additional flag for the column 1 is Qt::ItemIsEditable.
120 //! \param theIndex a model index
122 Standard_EXPORT virtual Qt::ItemFlags TableFlags (const int theRow, const int theColumn) const;
124 //! Returns stream value of the item to fulfill property panel.
125 //! \return stream value or dummy
126 Standard_EXPORT void ChildStream (const int theRowId,
127 TCollection_AsciiString& theKey,
128 Standard_DumpValue& theValue) const;
130 //! Returns data object of the item.
131 //! \return object key
132 const TCollection_AsciiString& Key() const { return myKey; }
134 //! Returns stream value of the item.
136 const TCollection_AsciiString& StreamValue() const { return myStreamValue.myValue; }
138 //! Returns children stream values
139 //const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Values() const { initItem(); return myValues; }
141 //! Returns children stream values
142 const NCollection_IndexedDataMap<Standard_Integer, TreeModel_RowValue>& RowValues() const { initItem(); return myRowValues; }
144 //! Returns children stream values
145 const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Children() const { initItem(); return myChildren; }
147 DEFINE_STANDARD_RTTIEXT (TreeModel_ItemProperties, Standard_Transient)
150 //! Initializes the current item. It creates a backup of the specific item information
151 Standard_EXPORT void initItem() const;
154 TreeModel_ItemBasePtr myItem; //!< current item
156 TCollection_AsciiString myKey; //!< the item key
157 Standard_DumpValue myStreamValue; //!< the stream value
158 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue> myChildren; //!< the children
159 NCollection_IndexedDataMap<Standard_Integer, TreeModel_RowValue> myRowValues; //!< the values