API Documentation
Loading...
Searching...
No Matches
DesignTableModel.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: DesignTableModel
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/DesignObject.h>
35#include <NDEVR/DesignParameter.h>
36#include <QSortFilterProxyModel>
37#include <QAbstractTableModel>
38#include <functional>
39namespace NDEVR
40{
41 class QTModelManager;
42 class Button;
43 class QTDesignObject;
44 struct PopupInfo;
45 class QTResourceListener;
46 constexpr int model_table_is_clicked_index = Qt::UserRole + 1;
47 constexpr int model_table_is_selected_index = Qt::UserRole + 2;
48 /**--------------------------------------------------------------------------------------------------
49 \brief Provides the ability to pull specific data from a DesignObjectLookup for display in a column
50 of a table.
51 **/
53 {
55 {
56 e_design_parameter
57 , e_model_material
58 , e_custom_callback
59 };
61 {
62 e_parent
63 , e_last_child
64 , e_child_index = 10
65 , e_child_0 = e_child_index
66 , e_child_1
67 , e_child_2
68 , e_child_3
69 , e_child_4
70 , e_child_5
71 , e_child_6
72 , e_child_7
73 };
75 {
78 std::function<void(DesignObject&)> create_callback = nullptr;//A callback for creating the missing child, if it does not exist
80 : path(path)
81 {}
83 : path(path)
84 , type(std::move(type))
85 {}
86 };
91 bool is_clicked = false;
93 bool is_currently_editable = false;
96 std::function<void(UUID)> callback;
99 public:
101 explicit ModelTableColumnSpec(const std::function<void(UUID)>& callback);
102 explicit ModelTableColumnSpec(const DesignParameter& parameter);
103 explicit ModelTableColumnSpec(const DesignParameter& parameter, Buffer<RelativePathObject> relative_mode);
105 ModelTableColumnSpec(const TranslatedString& text, const String& icon, const std::function<void(UUID)>& callback);
106 [[nodiscard]] DesignObject getTarget(const DesignObject& a, bool try_to_create) const;
107 [[nodiscard]] String stringDisplayData(const DesignObject& obj) const;
108 [[nodiscard]] QVariant data(const DesignObject& obj, int role = Qt::DisplayRole) const;
109 [[nodiscard]] bool setData(const DesignObject& obj, const QVariant& value, int role);
110 [[nodiscard]] TranslatedString headerTitle() const;
111 [[nodiscard]] bool isValid() const;
112 [[nodiscard]] bool isTextEditable() const;
113 [[nodiscard]] bool isCheckEditable() const;
114 [[nodiscard]] bool isSortEqual(const DesignObject& a, const DesignObject& b) const;
115 [[nodiscard]] bool isSortLessThan(const DesignObject& a, const DesignObject& b) const;
116 protected:
117 [[nodiscard]] QVariant parameterData(const DesignObject& obj, int role) const;
118 };
119 /**--------------------------------------------------------------------------------------------------
120 \brief Provides the ability to pull data from a DesignObjectLookup for display in tables within the
121 NDEVR API.
122 **/
123 class NDEVR_API DesignTableModel : public QAbstractTableModel
124 {
125 Q_OBJECT
126 public:
127 explicit DesignTableModel(QObject* parent = nullptr);
129 void setup();
130 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
131 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
132 void setList(const Buffer<UUID>& models);
133 [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
134 [[nodiscard]] QVariant userData(const QModelIndex& index, int role) const;
135 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
136 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
137 [[nodiscard]] bool setData(const QModelIndex& index, const QVariant& value, int role) override;
138 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
140 void setAddedFilter(const std::function<bool(const Model&)>& callback) { m_added_filter = callback; }
141 uint04 addColumn(DesignObject::DesignProperty property, bool is_editable);
142 uint04 addColumn(const DesignParameter& parameter, bool is_editable);
143 uint04 addColumn(const TranslatedString& name, const String& icon, const std::function<void(UUID)>& callback);
146 uint04 addParentDataColumn(const DesignParameter& param, bool is_editable, const TranslatedString& custom_column_name = TranslatedString());
149
150 [[nodiscard]] const ModelTableColumnSpec& getColumnSpec(uint04 column) const;
151 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
152 [[nodiscard]] QTModelManager* modelManager() const { return m_manager; };
153 [[nodiscard]] UUID getUUID(QModelIndex index) const;
154 [[nodiscard]] UUID getUUID(QModelIndex index, int row) const;
155 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index) const;
156 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index, int row) const;
157 [[nodiscard]] Model getModel(QModelIndex index) const;
158 [[nodiscard]] DesignObject getObject(QModelIndex index, int row) const;
159 [[nodiscard]] DesignObject getObject(QModelIndex index) const;
160 void onSelected(QModelIndex index, const QRect& rect);
161 bool isEditable() const;
162 bool isObjectAllowed(const UUID& object) const;
163 bool canAddObject(const Model& object) const;
164 bool isObjectAllowed(const Model& object) const;
165 void setIsEditable(bool is_editable);
166 void setColumnEditable(uint04 column, bool is_editable);
167
169 virtual void objectAdded(const Buffer<UUID>& ids);
170 virtual void objectDeleted(const Buffer<UUID>& ids);
171 virtual void modelUpdated(const Buffer<UUID>& ids);
172 protected:
173 void updateColumn(uint04 index);
174 public slots:
178 protected:
180 Buffer<UUID> m_models;//List of all models in the Table
181 std::function<bool(const Model&)> m_added_filter;//Filter for added/valid objects
185 QTResourceListener* m_coord_listener = nullptr;
186 QTResourceListener* m_orientation_listener = nullptr;
187 QTResourceListener* m_angle_listener = nullptr;
189 };
190 /**--------------------------------------------------------------------------------------------------
191 \brief Provides the ability to pull data from a DesignObjectLookup for display in tables within the
192 NDEVR API and filter and sort it.
193 **/
194 class NDEVR_API DesignSortFilterProxyModel : public QSortFilterProxyModel
195 {
196 Q_OBJECT
197 public:
198 explicit DesignSortFilterProxyModel(DesignTableModel* model, QObject* parent = nullptr);
199 void setSearchString(const String& search_string);
201 void sort(Qt::SortOrder order = Qt::DescendingOrder);
202 void sort(int column, Qt::SortOrder order = Qt::DescendingOrder) override;
203 void sortBy(DesignObject::DesignProperty property, Qt::SortOrder order = Qt::DescendingOrder);
204 void sortBy(ModelTableColumnSpec spec, Qt::SortOrder order = Qt::DescendingOrder);
205 void sortBy(const Buffer<ModelTableColumnSpec>& specs, Qt::SortOrder order = Qt::DescendingOrder);
206 void onSelected(const QModelIndex& index, const QRect& rect);
207 Model getModel(const QModelIndex& index);
208 UUID getUUID(const QModelIndex& index);
209 ModelTableColumnSpec columnSpec(const QModelIndex& index);
210 void setSearchParameter(const ModelTableColumnSpec& search_parameter);
212 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
213 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
214 bool isEditable() const;
215 void setIsEditable(bool is_editable);
216 void setColumnEditable(uint04 column, bool is_editable);
217 [[nodiscard]] QTModelManager* modelManager() const { return m_design_model->modelManager(); };
218 void setSelectedCallback(const std::function<void(Model, PopupInfo)>& callback) { m_selected_callback = callback; };
219 void setSortCallback(const std::function<bool(const Model& a, const Model& b)>& callback);
220 [[nodiscard]] const std::function<void(Model, PopupInfo)>& selectedCallback() const { return m_selected_callback; };
221 signals:
223 protected:
224 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
225 virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
228 protected:
230 std::function<void(Model, PopupInfo)> m_selected_callback;
231 std::function<bool(const Model& a, const Model& b)> m_sort_function;
236 };
237}
238
#define NDEVR_API
Definition DLLInfo.h:50
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
DesignProperty
Values stored in the property database.
Definition DesignObject.h:93
A definition of data that is logically stored in the Model heirarchy. Data could be a property of a M...
Definition DesignParameter.h:46
Provides the ability to pull data from a DesignObjectLookup for display in tables within the NDEVR AP...
Definition DesignTableModel.h:195
ModelTableColumnSpec currentSearchParameter() const
DesignTableModel * m_design_model
Definition DesignTableModel.h:234
void sortBy(const Buffer< ModelTableColumnSpec > &specs, Qt::SortOrder order=Qt::DescendingOrder)
void setSearchString(const String &search_string)
void onSelected(const QModelIndex &index, const QRect &rect)
DesignSortFilterProxyModel(DesignTableModel *model, QObject *parent=nullptr)
Model getModel(const QModelIndex &index)
bool isSpecialCallbackIndex(const QModelIndex &index) const
UUID getUUID(const QModelIndex &index)
void setSortCallback(const std::function< bool(const Model &a, const Model &b)> &callback)
std::function< void(Model, PopupInfo)> m_selected_callback
Definition DesignTableModel.h:230
String m_search_string
Definition DesignTableModel.h:229
TranslatedString searchByTitle() const
ModelTableColumnSpec m_search_parameter
Definition DesignTableModel.h:232
ModelTableColumnSpec m_current_search_parameter
Definition DesignTableModel.h:233
void sort(Qt::SortOrder order=Qt::DescendingOrder)
void sortBy(DesignObject::DesignProperty property, Qt::SortOrder order=Qt::DescendingOrder)
void setSearchParameter(const ModelTableColumnSpec &search_parameter)
bool isMaterialIndex(const QModelIndex &index) const
ModelTableColumnSpec columnSpec(const QModelIndex &index)
Buffer< ModelTableColumnSpec > m_sort_by
Definition DesignTableModel.h:235
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
void setIsEditable(bool is_editable)
void sortBy(ModelTableColumnSpec spec, Qt::SortOrder order=Qt::DescendingOrder)
void setColumnEditable(uint04 column, bool is_editable)
const std::function< void(Model, PopupInfo)> & selectedCallback() const
Definition DesignTableModel.h:220
std::function< bool(const Model &a, const Model &b)> m_sort_function
Definition DesignTableModel.h:231
QTModelManager * modelManager() const
Definition DesignTableModel.h:217
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
void setSelectedCallback(const std::function< void(Model, PopupInfo)> &callback)
Definition DesignTableModel.h:218
bool modelIsShown(const DynamicPointer< QTDesignObject > &a) const
void sort(int column, Qt::SortOrder order=Qt::DescendingOrder) override
Provides the ability to pull data from a DesignObjectLookup for display in tables within the NDEVR AP...
Definition DesignTableModel.h:124
uint04 addGrandparentNameColumn(const TranslatedString &custom_column_name=TranslatedString())
void onSelected(QModelIndex index, const QRect &rect)
Buffer< UUID > m_models
Definition DesignTableModel.h:180
uint04 addParentPathColumn(const TranslatedString &custom_column_name=TranslatedString())
void setList(const Buffer< UUID > &models)
DesignObject getObject(QModelIndex index) const
void setModelManager(QTModelManager *manager)
uint04 addColumn(const ModelTableColumnSpec &column)
bool canAddObject(const Model &object) const
void setAddedFilter(const std::function< bool(const Model &)> &callback)
Definition DesignTableModel.h:140
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
bool isSpecialCallbackIndex(const QModelIndex &index) const
void updateColumn(uint04 index)
QVariant userData(const QModelIndex &index, int role) const
uint04 addColumn(const DesignParameter &parameter, bool is_editable)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
virtual void modelUpdated(const Buffer< UUID > &ids)
virtual void objectAdded(const Buffer< UUID > &ids)
Qt::ItemFlags flags(const QModelIndex &index) const override
std::function< bool(const Model &)> m_added_filter
Definition DesignTableModel.h:181
Buffer< TranslatedString > m_custom_column_titles
Definition DesignTableModel.h:183
uint04 addColumn(const TranslatedString &name, const String &icon, const std::function< void(UUID)> &callback)
DynamicPointer< QTDesignObject > getDesignObject(QModelIndex index, int row) const
Model getModel(QModelIndex index) const
bool isObjectAllowed(const UUID &object) const
DynamicPointer< QTDesignObject > getDesignObject(QModelIndex index) const
virtual void objectDeleted(const Buffer< UUID > &ids)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool isMaterialIndex(const QModelIndex &index) const
UUID getUUID(QModelIndex index) const
DesignTableModel(QObject *parent=nullptr)
bool isObjectAllowed(const Model &object) const
Buffer< BitFlag > m_callback_clicked
Definition DesignTableModel.h:184
bool m_is_editable
Definition DesignTableModel.h:188
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
uint04 addParentDataColumn(const DesignParameter &param, bool is_editable, const TranslatedString &custom_column_name=TranslatedString())
void objectDeletedSlot(const Buffer< UUID > &ids)
void setIsEditable(bool is_editable)
void setColumnEditable(uint04 column, bool is_editable)
UUID getUUID(QModelIndex index, int row) const
DesignObject getObject(QModelIndex index, int row) const
uint04 addColumn(DesignObject::DesignProperty property, bool is_editable)
QTModelManager * m_manager
Definition DesignTableModel.h:179
void objectAddedSlot(const Buffer< UUID > &ids)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QTModelManager * modelManager() const
Definition DesignTableModel.h:152
Buffer< ModelTableColumnSpec > m_columns
Definition DesignTableModel.h:182
void modelUpdatedSlot(const Buffer< UUID > &ids)
const ModelTableColumnSpec & getColumnSpec(uint04 column) const
uint04 addMaterialDataColumn(const TranslatedString &custom_column_name=TranslatedString())
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
Definition QTModelManager.h:105
Definition QTTools.h:168
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
constexpr int model_table_is_selected_index
Definition DesignTableModel.h:47
constexpr int model_table_is_clicked_index
Definition DesignTableModel.h:46
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Definition File.h:211
Definition DesignTableModel.h:75
String type
Definition DesignTableModel.h:77
RelativePathObject(RelativePath path, String type)
Definition DesignTableModel.h:82
RelativePathObject(RelativePath path)
Definition DesignTableModel.h:79
RelativePath path
Definition DesignTableModel.h:76
Provides the ability to pull specific data from a DesignObjectLookup for display in a column of a tab...
Definition DesignTableModel.h:53
DesignObject getTarget(const DesignObject &a, bool try_to_create) const
uint04 min_decimal_places
Definition DesignTableModel.h:95
String stringDisplayData(const DesignObject &obj) const
ModelTableColumnSpec(const std::function< void(UUID)> &callback)
TranslatedString headerTitle() const
ModelTableColumnSpec(const DesignParameter &parameter, Buffer< RelativePathObject > relative_mode)
ModelTableType
Definition DesignTableModel.h:55
bool setData(const DesignObject &obj, const QVariant &value, int role)
TranslatedString custom_column_name
Definition DesignTableModel.h:88
bool isSortEqual(const DesignObject &a, const DesignObject &b) const
ModelTableColumnSpec(const TranslatedString &text, const String &icon, const std::function< void(UUID)> &callback)
QVariant data(const DesignObject &obj, int role=Qt::DisplayRole) const
std::function< void(UUID)> callback
Definition DesignTableModel.h:96
QVariant parameterData(const DesignObject &obj, int role) const
bool is_editable
Definition DesignTableModel.h:92
String custom_icon
Definition DesignTableModel.h:90
TranslatedString custom_text
Definition DesignTableModel.h:89
DesignParameter design_parameter
Definition DesignTableModel.h:97
uint04 max_decimal_places
Definition DesignTableModel.h:94
ModelTableColumnSpec(ModelTableType type)
ModelTableType column_type
Definition DesignTableModel.h:87
ModelTableColumnSpec(const DesignParameter &parameter)
Buffer< RelativePathObject > relative_path
Definition DesignTableModel.h:98
bool isSortLessThan(const DesignObject &a, const DesignObject &b) const
RelativePath
Definition DesignTableModel.h:61
@ e_child_index
Definition DesignTableModel.h:64
Class which is used to pass arguments and requests for creating a popup dialog or widget....
Definition PopupInfo.h:15