NDEVR
API Documentation
DesignPropertyTable.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: DesignPropertyTable
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/DesignTableModel.h>
35#include <NDEVR/Button.h>
36#include <NDEVR/Translator.h>
37#include <QWidget>
38#include <QTableView>
39#include <functional>
40#include <QItemDelegate>
41class QHBoxLayout;
42namespace NDEVR
43{
44 class QTModelManager;
47 class MaterialWidget;
51 class ModelTableDelegate : public QItemDelegate
52 {
53 Q_OBJECT
54 public:
60 explicit ModelTableDelegate(DesignSortFilterProxyModel* model, QObject* parent = nullptr);
67 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
76 bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
82 protected:
86 };
87
90 class DesignPropertyTableView : public QTableView
91 {
92 public:
97 explicit DesignPropertyTableView(QWidget* parent = nullptr);
107 [[nodiscard]] DesignTableModel* model() const { return m_table_model->model(); }
112 QSize minimumSizeHint() const override;
122 protected:
129 void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) override;
136 void rowsInserted(const QModelIndex& parent, int start, int end) override;
137 protected:
139 };
140
143 class NDEVR_API DesignPropertyTable : public QWidget
144 {
145 Q_OBJECT
146 public:
151 explicit DesignPropertyTable(QWidget* parent = nullptr);
157 explicit DesignPropertyTable(QTModelManager* manager, QWidget* parent = nullptr);
158 virtual ~DesignPropertyTable();
162 void setup();
172 void setList(const Buffer<UUID>& ids);
177 void addListItem(const UUID& id);
182 void setModels(const Buffer<Model>& models);
192 bool event(QEvent* event) override;
197 void updateRow(uint04 row);
202 void setTypeAddedFilter(const String& type);
207 void setAddedFilter(const std::function<bool(const Model&)>& callback);
215 Button* addNewButton(std::function<void(Button*)> callback, const TranslatedString& new_title = _t("Add New"), const StringView& add_icon = "plus");
222 void addOpenButton(std::function<void(Button*)> callback, const TranslatedString& new_title = _t("Open"), const StringView& add_icon = "open");
227 void addWidget(QWidget* widget);
232 virtual void setModelManager(QTModelManager* manager);
238 void setColumnVisible(uint04 column, bool visible);
245 uint04 addColumn(NDPO property, bool is_editable = true);
252 uint04 addColumn(const DesignParameter& parameter, bool is_editable = true);
260 uint04 addColumn(const TranslatedString& custom_column_name, const DesignParameter& parameter, bool is_editable = true);
280 uint04 addColumn(const TranslatedString& name, const StringView& icon, const std::function<void(UUID)>& callback);
291 void showSearch(bool show_search);
296 void setEditable(bool editable);
302 void setColumnEditable(uint04 column, bool editable);
317 void setSelectedCallback(const std::function<void(Model, PopupInfo)>& callback) { m_sort_model->setSelectedCallback(callback); };
322 void setSortCallback(const std::function<bool(const Model& a, const Model& b)>& callback);
327 const std::function<void(Model, PopupInfo)>& selectedCallback() const { return m_sort_model->selectedCallback(); };
328 signals:
333 protected slots:
338 void selected(QModelIndex index);
343 void contextMenu(const QPoint &pos);
344 protected:
353 };
354}
355
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
Allows the user to enter search terms for filtering out tables or other views.
A definition of data that is logically stored in the Model hierarchy.
A QTableView for showing Model or DesignObject properties.
DesignSortFilterProxyModel * m_table_model
The proxy model providing sorted/filtered data.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles) override
Handles data changes to auto-resize affected columns.
void refreshAll()
Refreshes all rows and columns in the table view.
void setProxyModel(DesignSortFilterProxyModel *model)
Sets the sort/filter proxy model for this table view.
QSize minimumSizeHint() const override
Returns the minimum size hint for this table view.
DesignTableModel * model() const
Returns the underlying DesignTableModel.
void rowsInserted(const QModelIndex &parent, int start, int end) override
Handles row insertions to auto-resize columns.
DesignPropertyTableView(QWidget *parent=nullptr)
Constructs a DesignPropertyTableView.
Buffer< UUID > selectedIDs() const
Returns the UUIDs of the currently selected rows.
uint04 addMaterialDataColumn(const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing material data for each design object.
DesignPropertyTableView * m_table_view
The table view displaying design object properties.
void setup()
Performs initial setup of the table layout, search bar, and edit button.
void viewSettingsSignal()
Emitted when the view settings should be shown or updated.
void addOpenButton(std::function< void(Button *)> callback, const TranslatedString &new_title=_t("Open"), const StringView &add_icon="open")
Adds an "Open" button to the bottom button bar.
void setSelectedCallback(const std::function< void(Model, PopupInfo)> &callback)
Sets the callback invoked when a row is selected.
void filterAndSetList(Buffer< UUID > ids)
Applies the current search filter and sets the list of objects to display.
void contextMenu(const QPoint &pos)
Slot called to display a context menu at the given position.
const std::function< void(Model, PopupInfo)> & selectedCallback() const
Returns the current selection callback.
uint04 addColumn(const TranslatedString &custom_column_name, const DesignParameter &parameter, bool is_editable=true)
Adds a column with a custom name displaying the given design parameter.
Button * m_edit_button
The button for toggling edit mode.
Buffer< UUID > selectedIDs() const
Returns the UUIDs of the currently selected rows.
void setEditable(bool editable)
Sets whether the entire table is editable.
DesignTableModel * m_view_model
The underlying table model.
QTModelManager * m_manager
The model manager providing design objects.
DesignSortFilterProxyModel * m_sort_model
The sort/filter proxy model.
void addWidget(QWidget *widget)
Adds a custom widget to the bottom button bar.
uint04 addColumn(NDPO property, bool is_editable=true)
Adds a column displaying the given NDPO property.
void addListItem(const UUID &id)
Adds a single object to the table.
uint04 addColumn(const TranslatedString &name, const StringView &icon, const std::function< void(UUID)> &callback)
Adds a button column with a custom icon and click callback.
void setAddedFilter(const std::function< bool(const Model &)> &callback)
Sets a custom filter callback applied when objects are added.
uint04 addColumn(const ModelTableColumnSpec &column)
Adds a column from a fully specified ModelTableColumnSpec.
void selected(QModelIndex index)
Slot called when a table row is selected.
bool isEditable()
Returns whether the table is currently editable.
void showSearch(bool show_search)
Shows or hides the search bar.
void setTypeAddedFilter(const String &type)
Sets a type-based filter so only objects of the given type appear when added.
bool event(QEvent *event) override
Handles events, including custom polish events for deferred setup.
QHBoxLayout * m_bottom_button_layout
The layout for buttons at the bottom of the table.
void setupTable()
Sets up the table view, proxy model, and delegate.
void setList(const Buffer< UUID > &ids)
Sets the list of objects to display in the table.
Button * addNewButton(std::function< void(Button *)> callback, const TranslatedString &new_title=_t("Add New"), const StringView &add_icon="plus")
Adds an "Add New" button to the bottom button bar.
void setSortCallback(const std::function< bool(const Model &a, const Model &b)> &callback)
Sets a custom sort comparison callback for ordering rows.
void setColumnEditable(uint04 column, bool editable)
Sets whether a specific column is editable.
DesignPropertyTable(QTModelManager *manager, QWidget *parent=nullptr)
Constructs a DesignPropertyTable with a model manager.
void setColumnVisible(uint04 column, bool visible)
Shows or hides a specific column.
virtual void setModelManager(QTModelManager *manager)
Sets the model manager and connects it to the table model.
uint04 addParentPathColumn(const TranslatedString &custom_column_name=TranslatedString())
Adds a column showing the parent path of each design object.
DesignPropertyTable(QWidget *parent=nullptr)
Constructs a DesignPropertyTable without a model manager.
void updateRow(uint04 row)
Updates the data display for a specific row.
uint04 addColumn(const DesignParameter &parameter, bool is_editable=true)
Adds a column displaying the given design parameter.
QWidget * m_search_widget
The container widget for the search bar.
void setModels(const Buffer< Model > &models)
Sets the table contents from a buffer of Models.
DesignObjectSearchWidget * m_search_text
The search text input widget.
Provides the ability to pull data from a DesignObjectLookup for display in tables within the NDEVR AP...
Provides the ability to pull data from a DesignObjectLookup for display in tables within the NDEVR AP...
A simple widget showing some visual properties of a Material or Model.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Paints a cell in the table, including custom rendering for material properties.
ModelTableDelegate(DesignSortFilterProxyModel *model, QObject *parent=nullptr)
Constructs a ModelTableDelegate for the given proxy model.
MaterialWidget * m_click_material_widget
Reusable widget for handling material cell clicks.
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Handles editor events such as clicks on material cells.
DesignSortFilterProxyModel * m_table_model
The proxy model providing data for this delegate.
MaterialWidget * m_draw_material_widget
Reusable widget for painting material cells.
void setModel(DesignSortFilterProxyModel *model)
Sets the proxy model used by this delegate.
A core class that represents a node on model hierarchy.
Definition Model.h:292
Provides a standard way to show table data within the application.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
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.
Provides the ability to pull specific data from a DesignObjectLookup for display in a column of a tab...
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16