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;
49 {
51 {
52 e_design_parameter
53 , e_model_material
54 , e_custom_callback
55 };
57 {
58 e_parent
59 , e_last_child
60 , e_child_index = 10
61 , e_child_0 = e_child_index
62 , e_child_1
63 , e_child_2
64 , e_child_3
65 , e_child_4
66 , e_child_5
67 , e_child_6
68 , e_child_7
69 };
71 {
74 std::function<void(DesignObject&)> create_callback = nullptr;//A callback for creating the missing child, if it does not exist
76 : path(path)
77 {}
79 : path(path)
80 , type(std::move(type))
81 {}
82 };
87 bool is_clicked = false;
89 bool is_currently_editable = false;
92 std::function<void(UUID)> callback;
95 public:
97 explicit ModelTableColumnSpec(const std::function<void(UUID)>& callback);
98 explicit ModelTableColumnSpec(const DesignParameter& parameter);
99 explicit ModelTableColumnSpec(const DesignParameter& parameter, Buffer<RelativePathObject> relative_mode);
101 ModelTableColumnSpec(const TranslatedString& text, const String& icon, const std::function<void(UUID)>& callback);
102 [[nodiscard]] DesignObject getTarget(const DesignObject& a, bool try_to_create) const;
103 [[nodiscard]] String stringDisplayData(const DesignObject& obj) const;
104 [[nodiscard]] QVariant data(const DesignObject& obj, int role = Qt::DisplayRole) const;
105 [[nodiscard]] bool setData(const DesignObject& obj, const QVariant& value, int role);
106 [[nodiscard]] TranslatedString headerTitle() const;
107 [[nodiscard]] bool isValid() const;
108 [[nodiscard]] bool isTextEditable() const;
109 [[nodiscard]] bool isCheckEditable() const;
110 [[nodiscard]] bool isSortEqual(const DesignObject& a, const DesignObject& b) const;
111 [[nodiscard]] bool isSortLessThan(const DesignObject& a, const DesignObject& b) const;
112 protected:
113 [[nodiscard]] QVariant parameterData(const DesignObject& obj, int role) const;
114 };
115 class NDEVR_API DesignTableModel : public QAbstractTableModel
116 {
117 Q_OBJECT
118 public:
119 explicit DesignTableModel(QObject* parent = nullptr);
120 virtual ~DesignTableModel();
121 void setup();
122 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
123 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
124 void setList(const Buffer<UUID>& models);
125 [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
126 [[nodiscard]] QVariant userData(const QModelIndex& index, int role) const;
127 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
128 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
129 [[nodiscard]] bool setData(const QModelIndex& index, const QVariant& value, int role) override;
130 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
131 void setModelManager(QTModelManager* manager);
132 void setAddedFilter(const std::function<bool(const Model&)>& callback) { m_added_filter = callback; }
133 uint04 addColumn(DesignObject::DesignProperty property, bool is_editable);
134 uint04 addColumn(const DesignParameter& parameter, bool is_editable);
135 uint04 addColumn(const TranslatedString& name, const String& icon, const std::function<void(UUID)>& callback);
136 uint04 addColumn(const ModelTableColumnSpec& column);
137 uint04 addParentPathColumn(const TranslatedString& custom_column_name = TranslatedString());
138 uint04 addParentDataColumn(const DesignParameter& param, bool is_editable, const TranslatedString& custom_column_name = TranslatedString());
139 uint04 addGrandparentNameColumn(const TranslatedString& custom_column_name = TranslatedString());
140 uint04 addMaterialDataColumn(const TranslatedString& custom_column_name = TranslatedString());
141
142 [[nodiscard]] const ModelTableColumnSpec& getColumnSpec(uint04 column) const;
143 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
144 [[nodiscard]] QTModelManager* modelManager() const { return m_manager; };
145 [[nodiscard]] UUID getUUID(QModelIndex index) const;
146 [[nodiscard]] UUID getUUID(QModelIndex index, int row) const;
147 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index) const;
148 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index, int row) const;
149 [[nodiscard]] Model getModel(QModelIndex index) const;
150 [[nodiscard]] DesignObject getObject(QModelIndex index, int row) const;
151 [[nodiscard]] DesignObject getObject(QModelIndex index) const;
152 void onSelected(QModelIndex index, const QRect& rect);
153 bool isEditable() const;
154 bool isObjectAllowed(const UUID& object) const;
155 bool canAddObject(const Model& object) const;
156 bool isObjectAllowed(const Model& object) const;
157 void setIsEditable(bool is_editable);
158 void setColumnEditable(uint04 column, bool is_editable);
159
160 void refreshAll();
161 virtual void objectAdded(const Buffer<UUID>& ids);
162 virtual void objectDeleted(const Buffer<UUID>& ids);
163 virtual void modelUpdated(const Buffer<UUID>& ids);
164 protected:
165 void updateColumn(uint04 index);
166 public slots:
167 void objectAddedSlot(const Buffer<UUID>& ids);
168 void objectDeletedSlot(const Buffer<UUID>& ids);
169 void modelUpdatedSlot(const Buffer<UUID>& ids);
170 protected:
172 Buffer<UUID> m_models;//List of all models in the Table
173 std::function<bool(const Model&)> m_added_filter;//Filter for added/valid objects
177 QTResourceListener* m_coord_listener = nullptr;
178 QTResourceListener* m_orientation_listener = nullptr;
179 QTResourceListener* m_angle_listener = nullptr;
181 };
182
183 class NDEVR_API DesignSortFilterProxyModel : public QSortFilterProxyModel
184 {
185 Q_OBJECT
186 public:
187 explicit DesignSortFilterProxyModel(DesignTableModel* model, QObject* parent = nullptr);
188 void setSearchString(const String& search_string);
189 DesignTableModel* model();
190 void sort(Qt::SortOrder order = Qt::DescendingOrder);
191 void sort(int column, Qt::SortOrder order = Qt::DescendingOrder) override;
192 void sortBy(DesignObject::DesignProperty property, Qt::SortOrder order = Qt::DescendingOrder);
193 void sortBy(ModelTableColumnSpec spec, Qt::SortOrder order = Qt::DescendingOrder);
194 void sortBy(const Buffer<ModelTableColumnSpec>& specs, Qt::SortOrder order = Qt::DescendingOrder);
195 void onSelected(const QModelIndex& index, const QRect& rect);
196 Model getModel(const QModelIndex& index);
197 UUID getUUID(const QModelIndex& index);
198 ModelTableColumnSpec columnSpec(const QModelIndex& index);
199 void setSearchParameter(const ModelTableColumnSpec& search_parameter);
200 TranslatedString searchByTitle() const;
201 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
202 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
203 bool isEditable() const;
204 void setIsEditable(bool is_editable);
205 void setColumnEditable(uint04 column, bool is_editable);
206 [[nodiscard]] QTModelManager* modelManager() const { return m_design_model->modelManager(); };
207 void setSelectedCallback(const std::function<void(Model, PopupInfo)>& callback) { m_selected_callback = callback; };
208 void setSortCallback(const std::function<bool(const Model& a, const Model& b)>& callback);
209 [[nodiscard]] const std::function<void(Model, PopupInfo)>& selectedCallback() const { return m_selected_callback; };
210 signals:
212 protected:
213 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
214 virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
215 bool modelIsShown(const DynamicPointer<QTDesignObject>& a) const;
216 ModelTableColumnSpec currentSearchParameter() const;
217 protected:
219 std::function<void(Model, PopupInfo)> m_selected_callback;
220 std::function<bool(const Model& a, const Model& b)> m_sort_function;
225 };
226}
227
#define NDEVR_API
Definition DLLInfo.h:67
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition DesignObject.h:66
DesignProperty
Definition DesignObject.h:94
Definition DesignParameter.h:42
Definition DesignTableModel.h:184
DesignTableModel * m_design_model
Definition DesignTableModel.h:223
std::function< void(Model, PopupInfo)> m_selected_callback
Definition DesignTableModel.h:219
String m_search_string
Definition DesignTableModel.h:218
ModelTableColumnSpec m_search_parameter
Definition DesignTableModel.h:221
ModelTableColumnSpec m_current_search_parameter
Definition DesignTableModel.h:222
Buffer< ModelTableColumnSpec > m_sort_by
Definition DesignTableModel.h:224
const std::function< void(Model, PopupInfo)> & selectedCallback() const
Definition DesignTableModel.h:209
std::function< bool(const Model &a, const Model &b)> m_sort_function
Definition DesignTableModel.h:220
QTModelManager * modelManager() const
Definition DesignTableModel.h:206
void setSelectedCallback(const std::function< void(Model, PopupInfo)> &callback)
Definition DesignTableModel.h:207
Definition DesignTableModel.h:116
Buffer< UUID > m_models
Definition DesignTableModel.h:172
void setAddedFilter(const std::function< bool(const Model &)> &callback)
Definition DesignTableModel.h:132
std::function< bool(const Model &)> m_added_filter
Definition DesignTableModel.h:173
Buffer< TranslatedString > m_custom_column_titles
Definition DesignTableModel.h:175
Buffer< BitFlag > m_callback_clicked
Definition DesignTableModel.h:176
bool m_is_editable
Definition DesignTableModel.h:180
QTModelManager * m_manager
Definition DesignTableModel.h:171
QTModelManager * modelManager() const
Definition DesignTableModel.h:144
Buffer< ModelTableColumnSpec > m_columns
Definition DesignTableModel.h:174
Definition Pointer.hpp:303
Definition Model.h:54
Definition QTModelManager.h:94
Definition QTTools.h:183
Definition String.h:40
Definition TranslatedString.h:9
Definition UUID.h:66
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:120
Definition File.h:213
Definition DesignTableModel.h:71
String type
Definition DesignTableModel.h:73
RelativePathObject(RelativePath path, String type)
Definition DesignTableModel.h:78
RelativePathObject(RelativePath path)
Definition DesignTableModel.h:75
RelativePath path
Definition DesignTableModel.h:72
Definition DesignTableModel.h:49
uint04 min_decimal_places
Definition DesignTableModel.h:91
ModelTableType
Definition DesignTableModel.h:51
TranslatedString custom_column_name
Definition DesignTableModel.h:84
std::function< void(UUID)> callback
Definition DesignTableModel.h:92
bool is_editable
Definition DesignTableModel.h:88
String custom_icon
Definition DesignTableModel.h:86
TranslatedString custom_text
Definition DesignTableModel.h:85
DesignParameter design_parameter
Definition DesignTableModel.h:93
uint04 max_decimal_places
Definition DesignTableModel.h:90
ModelTableType column_type
Definition DesignTableModel.h:83
Buffer< RelativePathObject > relative_path
Definition DesignTableModel.h:94
RelativePath
Definition DesignTableModel.h:57
@ e_child_index
Definition DesignTableModel.h:60
Definition PopupInfo.h:10