NDEVR
API Documentation
DesignTableModel.h
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;
46 constexpr int model_table_is_clicked_index = Qt::UserRole + 1;
47 constexpr int model_table_is_selected_index = Qt::UserRole + 2;
52 struct NDEVR_API ModelTableColumnSpec
53 {
63
80
109 bool is_clicked = false;
114 std::function<void(UUID)> callback;
117 public:
126 explicit ModelTableColumnSpec(const std::function<void(UUID)>& callback);
131 explicit ModelTableColumnSpec(const DesignParameter& parameter);
137 explicit ModelTableColumnSpec(const DesignParameter& parameter, Buffer<RelativePathObject> relative_mode);
149 ModelTableColumnSpec(const TranslatedString& text, const StringView& icon, const std::function<void(UUID)>& callback);
156 [[nodiscard]] DesignObject getTarget(const DesignObject& a, bool try_to_create) const;
162 [[nodiscard]] StringAllocatingView stringDisplayData(const DesignObject& obj) const;
169 [[nodiscard]] QVariant data(const DesignObject& obj, int role = Qt::DisplayRole) const;
177 [[nodiscard]] bool setData(const DesignObject& obj, const QVariant& value, int role);
182 [[nodiscard]] TranslatedString headerTitle() const;
187 [[nodiscard]] bool isValid() const;
192 [[nodiscard]] bool isTextEditable() const;
197 [[nodiscard]] bool isCheckEditable() const;
204 [[nodiscard]] bool isSortEqual(const DesignObject& a, const DesignObject& b) const;
211 [[nodiscard]] bool isSortLessThan(const DesignObject& a, const DesignObject& b) const;
212 protected:
219 [[nodiscard]] QVariant parameterData(const DesignObject& obj, int role) const;
220 };
221
225 class NDEVR_API DesignTableModel : public QAbstractTableModel
226 {
227 Q_OBJECT
228 public:
233 explicit DesignTableModel(QObject* parent = nullptr);
234 virtual ~DesignTableModel();
238 void setup();
244 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
250 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
255 void setList(const Buffer<UUID>& models);
262 [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
269 [[nodiscard]] QVariant userData(const QModelIndex& index, int role) const;
275 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
281 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
289 [[nodiscard]] bool setData(const QModelIndex& index, const QVariant& value, int role) override;
297 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
307 void setAddedFilter(const std::function<bool(const Model&)>& callback) { m_added_filter = callback; }
314 uint04 addColumn(NDPO property, bool is_editable);
321 uint04 addColumn(const DesignParameter& parameter, bool is_editable);
329 uint04 addColumn(const TranslatedString& name, const StringView& icon, const std::function<void(UUID)>& callback);
349 uint04 addParentDataColumn(const DesignParameter& param, bool is_editable, const TranslatedString& custom_column_name = TranslatedString());
362
368 [[nodiscard]] const ModelTableColumnSpec& getColumnSpec(uint04 column) const;
374 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
379 [[nodiscard]] QTModelManager* modelManager() const { return m_manager; };
385 [[nodiscard]] UUID getUUID(QModelIndex index) const;
392 [[nodiscard]] UUID getUUID(QModelIndex index, int row) const;
398 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index) const;
405 [[nodiscard]] DynamicPointer<QTDesignObject> getDesignObject(QModelIndex index, int row) const;
411 [[nodiscard]] Model getModel(QModelIndex index) const;
418 [[nodiscard]] DesignObject getObject(QModelIndex index, int row) const;
424 [[nodiscard]] DesignObject getObject(QModelIndex index) const;
430 void onSelected(QModelIndex index, const QRect& rect);
435 bool isEditable() const;
441 bool isObjectAllowed(const UUID& object) const;
447 bool canAddObject(const Model& object) const;
453 bool isObjectAllowed(const Model& object) const;
458 void setIsEditable(bool is_editable);
464 void setColumnEditable(uint04 column, bool is_editable);
465
474 virtual void objectAdded(const Buffer<UUID>& ids);
479 virtual void objectDeleted(const Buffer<UUID>& ids);
484 virtual void modelUpdated(const Buffer<UUID>& ids);
485 protected:
490 void updateColumn(uint04 index);
491 public slots:
507 protected:
510 std::function<bool(const Model&)> m_added_filter;
517 };
518
522 class NDEVR_API DesignSortFilterProxyModel : public QSortFilterProxyModel
523 {
524 Q_OBJECT
525 public:
531 explicit DesignSortFilterProxyModel(DesignTableModel* model, QObject* parent = nullptr);
536 void setSearchString(const StringView& search_string);
546 void sort(Qt::SortOrder order = Qt::DescendingOrder);
552 void sort(int column, Qt::SortOrder order = Qt::DescendingOrder) override;
558 void sortBy(NDPO property, Qt::SortOrder order = Qt::DescendingOrder);
564 void sortBy(ModelTableColumnSpec spec, Qt::SortOrder order = Qt::DescendingOrder);
570 void sortBy(const Buffer<ModelTableColumnSpec>& specs, Qt::SortOrder order = Qt::DescendingOrder);
576 void onSelected(const QModelIndex& index, const QRect& rect);
582 Model getModel(const QModelIndex& index);
588 UUID getUUID(const QModelIndex& index);
594 ModelTableColumnSpec columnSpec(const QModelIndex& index);
599 void setSearchParameter(const ModelTableColumnSpec& search_parameter);
610 [[nodiscard]] bool isMaterialIndex(const QModelIndex& index) const;
616 [[nodiscard]] bool isSpecialCallbackIndex(const QModelIndex& index) const;
621 bool isEditable() const;
626 void setIsEditable(bool is_editable);
632 void setColumnEditable(uint04 column, bool is_editable);
637 [[nodiscard]] QTModelManager* modelManager() const { return m_design_model->modelManager(); };
642 void setSelectedCallback(const std::function<void(Model, PopupInfo)>& callback) { m_selected_callback = callback; };
647 void setSortCallback(const std::function<bool(const Model& a, const Model& b)>& callback);
652 [[nodiscard]] const std::function<void(Model, PopupInfo)>& selectedCallback() const { return m_selected_callback; };
653 signals:
658 protected:
665 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
672 virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
684 protected:
686 std::function<void(Model, PopupInfo)> m_selected_callback;
687 std::function<bool(const Model& a, const Model& b)> m_sort_function;
692 };
693}
694
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
A definition of data that is logically stored in the Model hierarchy.
ModelTableColumnSpec columnSpec(const QModelIndex &index)
Returns the column specification for the given proxy index.
void sortBy(ModelTableColumnSpec spec, Qt::SortOrder order=Qt::DescendingOrder)
Sorts the table by a single column specification.
void sort(int column, Qt::SortOrder order=Qt::DescendingOrder) override
Sorts the table by the given column.
void setColumnEditable(uint04 column, bool is_editable)
Sets whether a specific column is editable.
TranslatedString searchByTitle() const
Returns the display title of the current search parameter.
QTModelManager * modelManager() const
Returns the model manager from the underlying table model.
void sort(Qt::SortOrder order=Qt::DescendingOrder)
Sorts the table using the current sort specifications.
ModelTableColumnSpec m_current_search_parameter
The currently active search parameter.
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns whether the row at the given source index passes the current filter.
DesignTableModel * model()
Returns the underlying DesignTableModel.
ModelTableColumnSpec m_search_parameter
The user-configured search parameter.
DesignSortFilterProxyModel(DesignTableModel *model, QObject *parent=nullptr)
Constructs a DesignSortFilterProxyModel wrapping the given table model.
Model getModel(const QModelIndex &index)
Returns the Model for the row of the given proxy index.
void setSearchString(const StringView &search_string)
Sets the search string used for filtering rows.
Buffer< ModelTableColumnSpec > m_sort_by
The column specifications used for sorting.
void sortBy(const Buffer< ModelTableColumnSpec > &specs, Qt::SortOrder order=Qt::DescendingOrder)
Sorts the table by multiple column specifications as tiebreakers.
String m_search_string
The current search/filter text.
bool isSpecialCallbackIndex(const QModelIndex &index) const
Returns whether the given proxy index represents a custom callback column.
void sortBy(NDPO property, Qt::SortOrder order=Qt::DescendingOrder)
Sorts the table by the given NDPO property.
std::function< void(Model, PopupInfo)> m_selected_callback
Callback invoked when a row is selected.
bool isEditable() const
Returns whether the table is currently editable.
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Compares two source model indices for sorting.
std::function< bool(const Model &a, const Model &b)> m_sort_function
Custom sort comparison function.
DesignTableModel * m_design_model
The underlying DesignTableModel.
bool modelIsShown(const DynamicPointer< QTDesignObject > &a) const
Returns whether the given design object should be shown after filtering.
void searchByParameterChangedSignal()
Emitted when the search-by parameter changes.
void setIsEditable(bool is_editable)
Sets whether the table is editable.
ModelTableColumnSpec currentSearchParameter() const
Returns the currently active search parameter column specification.
void setSortCallback(const std::function< bool(const Model &a, const Model &b)> &callback)
Sets a custom sort comparison callback for ordering rows.
const std::function< void(Model, PopupInfo)> & selectedCallback() const
Returns the current selection callback.
void setSearchParameter(const ModelTableColumnSpec &search_parameter)
Sets the column parameter used for search filtering.
void onSelected(const QModelIndex &index, const QRect &rect)
Handles a row selection event on the proxy model.
void setSelectedCallback(const std::function< void(Model, PopupInfo)> &callback)
Sets the callback invoked when a row is selected.
bool isMaterialIndex(const QModelIndex &index) const
Returns whether the given proxy index represents a material column.
UUID getUUID(const QModelIndex &index)
Returns the UUID for the row of the given proxy index.
Provides the ability to pull data from a DesignObjectLookup for display in tables within the NDEVR AP...
virtual void objectAdded(const Buffer< UUID > &ids)
Called when new design objects are added to the model manager.
bool isSpecialCallbackIndex(const QModelIndex &index) const
Returns whether the given index represents a custom callback column.
bool isObjectAllowed(const UUID &object) const
Returns whether the given object UUID passes the added filter.
void onSelected(QModelIndex index, const QRect &rect)
Handles a row selection event, invoking the selected callback.
void setup()
Performs initial setup, connecting to the model manager signals.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
const ModelTableColumnSpec & getColumnSpec(uint04 column) const
Returns the column specification for the given column index.
uint04 addGrandparentNameColumn(const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing the grandparent name of each object.
void setIsEditable(bool is_editable)
Sets whether the table is editable.
virtual void modelUpdated(const Buffer< UUID > &ids)
Called when existing design objects are updated.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data for the given index and role.
bool isMaterialIndex(const QModelIndex &index) const
Returns whether the given index represents a material column.
Buffer< BitFlag > m_callback_clicked
Tracks which callback buttons have been clicked per row.
QTModelManager * modelManager() const
Returns the model manager.
QTResourceListener * m_angle_listener
Listener for angle unit changes.
QTModelManager * m_manager
The model manager providing design objects.
void setColumnEditable(uint04 column, bool is_editable)
Sets whether a specific column is editable.
bool m_is_editable
Whether the table is currently editable.
QTResourceListener * m_orientation_listener
Listener for orientation unit changes.
Buffer< UUID > m_models
List of all model UUIDs displayed in the table.
void setList(const Buffer< UUID > &models)
Sets the list of object UUIDs to display as rows.
Model getModel(QModelIndex index) const
Returns the Model for the row of the given index.
uint04 addColumn(const TranslatedString &name, const StringView &icon, const std::function< void(UUID)> &callback)
Adds a button column with a label, icon, and click callback.
std::function< bool(const Model &)> m_added_filter
Filter callback for added/valid objects.
uint04 addColumn(const DesignParameter &parameter, bool is_editable)
Adds a column displaying the given design parameter.
QVariant userData(const QModelIndex &index, int role) const
Returns custom user-role data for the given index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows in the table.
uint04 addColumn(NDPO property, bool is_editable)
Adds a column displaying the given NDPO property.
void modelUpdatedSlot(const Buffer< UUID > &ids)
Slot connected to the model manager's model-updated signal.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets data at the given index for the specified role.
virtual void objectDeleted(const Buffer< UUID > &ids)
Called when design objects are deleted from the model manager.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the header data for the given section, orientation, and role.
void setModelManager(QTModelManager *manager)
Sets the model manager and connects its signals.
bool canAddObject(const Model &object) const
Returns whether the given Model can be added to the table.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns in the table.
void setAddedFilter(const std::function< bool(const Model &)> &callback)
Sets a filter callback applied when objects are added to the table.
DesignObject getObject(QModelIndex index, int row) const
Returns the DesignObject for the given row number.
UUID getUUID(QModelIndex index, int row) const
Returns the UUID for the given row number.
DesignObject getObject(QModelIndex index) const
Returns the DesignObject for the row of the given index.
DesignTableModel(QObject *parent=nullptr)
Constructs a DesignTableModel.
DynamicPointer< QTDesignObject > getDesignObject(QModelIndex index, int row) const
Returns the QTDesignObject for the given row number.
void objectDeletedSlot(const Buffer< UUID > &ids)
Slot connected to the model manager's object-deleted signal.
Buffer< ModelTableColumnSpec > m_columns
The column specifications for the table.
uint04 addColumn(const ModelTableColumnSpec &column)
Adds a column from a fully specified ModelTableColumnSpec.
QTResourceListener * m_coord_listener
Listener for coordinate unit changes.
UUID getUUID(QModelIndex index) const
Returns the UUID for the row of the given index.
bool isObjectAllowed(const Model &object) const
Returns whether the given Model passes the added filter.
uint04 addParentPathColumn(const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing the parent path of each object.
DynamicPointer< QTDesignObject > getDesignObject(QModelIndex index) const
Returns the QTDesignObject for the row of the given index.
void objectAddedSlot(const Buffer< UUID > &ids)
Slot connected to the model manager's object-added signal.
void refreshAll()
Forces a full refresh of all rows and columns.
bool isEditable() const
Returns whether the table is currently editable.
uint04 addMaterialDataColumn(const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing the material of each object.
uint04 addParentDataColumn(const DesignParameter &param, bool is_editable, const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing a parent design parameter value.
void updateColumn(uint04 index)
Updates a single column specification at the given index.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A core class that represents a node on model hierarchy.
Definition Model.h:292
A pointer to a DesignObject within a QTModelManager that receives and emits update signals based on t...
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
A ResourceListener which will always be executed on the main UI thread and can be tied to a Qt Object...
Definition QTTools.h:493
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
NDPO
NDPO - NDEVR Design Property Object: Values stored in the property database.
constexpr int model_table_is_selected_index
Custom role index indicating whether a row is selected.
constexpr int model_table_is_clicked_index
Custom role index indicating whether a cell button has been clicked.
STL namespace.
RelativePathObject(RelativePath path, StringView type)
Constructs a RelativePathObject with a path direction and type filter.
String type
Optional type filter for the target object.
RelativePath path
The direction to navigate.
RelativePathObject(RelativePath path)
Constructs a RelativePathObject with a path direction.
std::function< void(DesignObject &)> create_callback
A callback for creating the missing child, if it does not exist.
Provides the ability to pull specific data from a DesignObjectLookup for display in a column of a tab...
bool is_clicked
Whether the button in this column is currently in a clicked state.
StringAllocatingView stringDisplayData(const DesignObject &obj) const
Returns the string representation of the column data for the given object.
bool setData(const DesignObject &obj, const QVariant &value, int role)
Sets data on the given object for the specified role.
uint04 max_decimal_places
Maximum number of decimal places for numeric display.
RelativePath
Specifies a relative path from a design object to a related object in the hierarchy.
@ e_last_child
Navigate to the last child object.
@ e_child_5
Navigate to child at index 5.
@ e_child_7
Navigate to child at index 7.
@ e_child_2
Navigate to child at index 2.
@ e_child_3
Navigate to child at index 3.
@ e_parent
Navigate to the parent object.
@ e_child_6
Navigate to child at index 6.
@ e_child_1
Navigate to child at index 1.
@ e_child_0
Navigate to child at index 0.
@ e_child_4
Navigate to child at index 4.
@ e_child_index
Base index for child navigation by position.
bool isSortEqual(const DesignObject &a, const DesignObject &b) const
Returns whether two design objects have equal sort values for this column.
bool isTextEditable() const
Returns whether this column supports inline text editing.
bool isSortLessThan(const DesignObject &a, const DesignObject &b) const
Returns whether the first design object sorts before the second for this column.
ModelTableColumnSpec(const DesignParameter &parameter)
Constructs a design parameter column.
TranslatedString headerTitle() const
Returns the column header title.
DesignObject getTarget(const DesignObject &a, bool try_to_create) const
Resolves the target design object by following the relative path.
bool isValid() const
Returns whether this column specification is valid.
ModelTableType column_type
The type of data this column displays.
std::function< void(UUID)> callback
The callback invoked when a button column is clicked.
TranslatedString custom_column_name
Custom header name override.
QVariant data(const DesignObject &obj, int role=Qt::DisplayRole) const
Returns the data for the given object and role.
ModelTableColumnSpec(const TranslatedString &text, const StringView &icon, const std::function< void(UUID)> &callback)
Constructs a button column with a label, icon, and click callback.
ModelTableColumnSpec(const DesignParameter &parameter, Buffer< RelativePathObject > relative_mode)
Constructs a design parameter column with a relative path to the data source.
bool isCheckEditable() const
Returns whether this column supports checkbox editing.
QVariant parameterData(const DesignObject &obj, int role) const
Returns data from the design parameter for the given object and role.
TranslatedString custom_text
Custom display text for button columns.
ModelTableColumnSpec(const std::function< void(UUID)> &callback)
Constructs a custom callback column.
String custom_icon
Icon name for button columns.
bool is_currently_editable
Whether this column is currently in an editable state.
ModelTableType
The type of data a table column displays.
@ e_model_material
Column displays a material swatch.
@ e_custom_callback
Column displays a button that invokes a custom callback.
@ e_design_parameter
Column displays a design parameter value.
ModelTableColumnSpec()
Default constructor.
DesignParameter design_parameter
The design parameter displayed by this column.
uint04 min_decimal_places
Minimum number of decimal places for numeric display.
bool is_editable
Whether this column allows editing.
ModelTableColumnSpec(ModelTableType type)
Constructs a column of the specified type.
Buffer< RelativePathObject > relative_path
The relative path from the row object to the actual data source.
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16