NDEVR
API Documentation
ProxyModelViewFilter.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: ProxyModelViewFilter
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/QTModelManager.h>
35#include <NDEVR/QTModelManagerView.h>
36#include <QDate>
37#include <QSortFilterProxyModel>
38
39namespace NDEVR
40{
41 class Model;
45
46 class NDEVR_API ProxyModelViewFilter : public QSortFilterProxyModel
47 {
48 Q_OBJECT
49 public:
55 explicit ProxyModelViewFilter(QTModelManager* manager, QObject* parent = nullptr);
61 explicit ProxyModelViewFilter(QTModelManagerView* view, QObject* parent = nullptr);
72 UUID getModelID(const QModelIndex& index) const;
78 UUID getMaterialID(const QModelIndex& index) const;
84 Model model(const QModelIndex& index) const;
91 QModelIndex getIndex(const Model& model, int column) const;
98 QModelIndex getIndex(const UUID& id, int column) const;
103 void setVisibleFilter(const std::function<bool(const Model&)>& filter);
108 void setIsRootFilter(const std::function<bool(const Model&)>& filter);
114 QIcon::Mode iconMode(const QModelIndex& index) const;
119 void setRootModels(const Buffer<UUID>& ids);
124 void setAllowEdits(bool allow);
129 void setGreyHidden(bool grey_hidden);
134 void setShowSelected(bool show_selected);
143 void setShowMaterials(bool show_materials);
149 void setCustomHeader(const TranslatedString& header_title, const StringView& header_icon);
155 Qt::CheckState checkState(const Model& model) const;
160 void setAllowSelections(bool allow);
161 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
162 Qt::ItemFlags flags(const QModelIndex& index) const override;
163 QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const override;
164 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
170 void setCheckState(const Model& model, Qt::CheckState check_state);
180 void setSelectedModelRoots(const Buffer<UUID>& roots, bool only_visible_children);
186 void setCheckStateRecursive(const Model& model, Qt::CheckState check_state);
191 void setCheckStateAll(Qt::CheckState check_state);
197 void setCheckStateAll(GeometryType type, Qt::CheckState check_state);
204 void setCheckStateAll(const String& model_type, GeometryType type, Qt::CheckState check_state);
210 void setCheckStateAll(const String& model_type, Qt::CheckState check_state);
216 void setCheckStateAll(const std::function<bool(const Model& model)>& model_type, Qt::CheckState check_state);
227 virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
233 bool hasIndex(const UUID& id) const;
234 private slots:
236 void modelUpdatedSlot(const Buffer<UUID>& updated_ids);
237 private:
238 void _autosetCheckState(const Model& parent, Qt::CheckState default_check_state);
239 bool filterAcceptsRow(int row, const QModelIndex& parent) const override;
240 bool filterAcceptsColumn(int row, const QModelIndex& parent) const override;
241 bool isTreeVisible(const Model& m) const;
242 bool calculateTreeVisible(const Model& m) const;
243 private:
244 std::function<bool(const Model&)> m_visible_filter;
245 mutable Dictionary<UUID, Qt::CheckState> m_check_states;
246 mutable Dictionary<UUID, bool> m_visible_states;
247 QTModelManagerView* m_view;
248 TranslatedString m_custom_header_title;
249 String m_custom_header_icon;
250 bool m_allow_selections;
251 bool m_allow_edits;
252 bool m_grey_hidden;
253 bool m_show_selected;
254 bool m_show_materials;
255 };
256
257}
258
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
A core class that represents a node on model hierarchy.
Definition Model.h:292
bool hasIndex(const UUID &id) const
Checks whether the given UUID exists in the proxy model.
QTModelManager & manager() const
Gets the model manager associated with this filter.
void setIsRootFilter(const std::function< bool(const Model &)> &filter)
Sets a filter function that determines whether a model is treated as a root.
void setCheckStateRecursive(const Model &model, Qt::CheckState check_state)
Sets the check state of a model and all its descendants recursively.
void selectAllVisible()
Sets all currently visible models to checked.
void setCheckState(const Model &model, Qt::CheckState check_state)
Sets the check state of a single model.
void setAllowSelections(bool allow)
Sets whether checkbox selection is allowed.
void setCheckStateAll(Qt::CheckState check_state)
Sets the check state of all models.
Model model(const QModelIndex &index) const
Gets the Model object at the given proxy index.
void setCheckStateAll(GeometryType type, Qt::CheckState check_state)
Sets the check state of all models matching the given geometry type.
void invalidate()
Invalidates the current filter and triggers re-evaluation.
void setRootModels(const Buffer< UUID > &ids)
Sets the root model UUIDs to display in the filtered view.
void setCheckStateAll(const String &model_type, Qt::CheckState check_state)
Sets the check state of all models matching the given model type.
QIcon::Mode iconMode(const QModelIndex &index) const
Gets the icon mode for the given proxy index based on the model state.
void setShowSelected(bool show_selected)
Sets whether to visually indicate selected models.
ProxyModelViewFilter(QTModelManagerView *view, QObject *parent=nullptr)
Constructs a proxy filter using a model manager view as the data source.
void setCheckStateAll(const String &model_type, GeometryType type, Qt::CheckState check_state)
Sets the check state of all models matching a model type and geometry type.
void clearCheckStates()
Clears all check states to unchecked.
void setGreyHidden(bool grey_hidden)
Sets whether hidden models should be displayed with greyed-out icons.
void setCustomHeader(const TranslatedString &header_title, const StringView &header_icon)
Sets a custom header title and icon for the view.
void setShowMaterials(bool show_materials)
Sets whether material entries are shown in the view.
void setSelectedModelRoots(const Buffer< UUID > &roots, bool only_visible_children)
Sets check states based on model root UUIDs with optional child visibility filtering.
UUID getModelID(const QModelIndex &index) const
Gets the model UUID at the given proxy index.
Qt::CheckState checkState(const Model &model) const
Gets the check state of the given model.
void setCheckStateAll(const std::function< bool(const Model &model)> &model_type, Qt::CheckState check_state)
Sets the check state of all models matching a custom predicate.
void setVisibleFilter(const std::function< bool(const Model &)> &filter)
Sets a custom filter function that determines whether a model is visible.
UUID getMaterialID(const QModelIndex &index) const
Gets the material UUID at the given proxy index.
QModelIndex getIndex(const UUID &id, int column) const
Gets the proxy index for the given UUID and column.
void setAllowEdits(bool allow)
Sets whether editing model names is allowed in the view.
Buffer< UUID > getSelectedModelRoots() const
Gets the UUIDs of all checked root models.
void refreshAll()
Forces a complete refresh of all filtered data.
Buffer< UUID > getModelRoots() const
Gets the UUIDs of all root models in the view.
QModelIndex getIndex(const Model &model, int column) const
Gets the proxy index for the given model and column.
ProxyModelViewFilter(QTModelManager *manager, QObject *parent=nullptr)
Constructs a proxy filter using a model manager as the data source.
A Qt compatible ItemModel for interfacing with a DesignObjectLookup.
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.
GeometryType
Describes the high-level geometric topology of a Geometry object.