NDEVR
API Documentation
QTModelManagerView.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: QTModelManagerView
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTModelManager.h>
34
35#include <NDEVR/Model.h>
36#include <QAbstractItemModel>
37#include <QIcon>
38namespace NDEVR
39{
43 class NDEVR_API QTModelManagerView final : public QAbstractItemModel
44 {
45 Q_OBJECT
46 protected:
52 {
53 uint04 cache_index = Constant<uint04>::Invalid;
55 UUID material = Constant<UUID>::Invalid;
56 UUID parent = Constant<UUID>::Invalid;
57 QString name;
58 QString material_name;
61 QString tooltip;
62 RGBColor icon_color = Constant<RGBColor>::Invalid;
63 bool is_visible = true;
65 bool is_selected = false;
66 };
67 public:
68 friend class ProxyModelViewFilter;
74 QTModelManagerView(QTModelManager* manager, QObject *parent = nullptr);
75
76 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
77 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
78 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
79 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
80 Qt::ItemFlags flags(const QModelIndex& index) const override;
81 QVariant headerData(int column, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
82 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
83 QModelIndex parent(const QModelIndex& index) const override;
84
90 virtual ~QTModelManagerView() = default;
95 void setRootModels(const Buffer<UUID>& roots);
100 const Buffer<UUID>& rootModels() const { return m_root_models; }
105 void setIsRootFilter(const std::function<bool(const Model&)>& filter) { m_root_filter = filter; }
106 protected slots:
108 void clearAll();
119 void objectSelected(Buffer<UUID> id, bool selected);
125 void modelFocussed(UUID id, bool selected);
135 void modelUpdatedSlot(const Buffer<UUID>& updated_ids);
140 void materialUpdatedSlot(const Buffer<UUID>& updated_ids);
151 protected:
159 QVariant data(const UUID& id, int role, int column) const;
165 bool hasCached(const UUID& id) const;
172 QModelIndex getIndex(const Model& model, int column) const;
179 QModelIndex getIndex(const UUID& id, int column) const;
185 QIcon::Mode iconMode(const QModelIndex& index) const;
194 ModelCache createCache(const Model& model, bool recursive, bool parent_visible, bool add_id) const;
195
201 UUID getModelID(const QModelIndex& model_index) const;
207 UUID getMaterialID(const QModelIndex& model_index) const;
213 Model model(const QModelIndex& model_index) const;
220 Model model(uint04 row, const QModelIndex& parent) const;
221
229 void setupCache(const Model& model, bool recursive, bool parent_visible, bool add_id) const;
235 void updateModel3DVisible(const UUID& id, bool visible);
240 void recursiveCacheRemove(const UUID& id);
241
246 void addModel(UUID id);
254 void emitIndexUpdated(const UUID& id, const QList<int>& roles = QList<int>());
259 void postMaterialImageRequest(const UUID& id) const;
260 protected:
267 std::function<bool(const Model&)> m_root_filter;
271 };
272}
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
ModelCache createCache(const Model &model, bool recursive, bool parent_visible, bool add_id) const
Creates a cache entry for a model.
void postMaterialImageRequest(const UUID &id) const
Posts a request to generate a material preview image.
Buffer< UUID > m_index_ids
Flat list mapping cache indices to UUIDs.
void modelDeleted(Buffer< UUID > id)
Handles model deletion events.
const Buffer< UUID > & rootModels() const
Retrieves the current root model UUIDs.
Buffer< UUID > m_root_models
UUIDs of the root models displayed in the view.
UUID m_tree_capture_id
UUID of the tree capture request.
void modelAdded(Buffer< UUID > id)
Handles model addition events.
bool hasCached(const UUID &id) const
Checks whether cached data exists for a given model UUID.
QTModelManager & manager()
Retrieves the underlying model manager.
Model model(uint04 row, const QModelIndex &parent) const
Retrieves a Model object by row and parent index.
void setupCache(const Model &model, bool recursive, bool parent_visible, bool add_id) const
Populates the cache for a model and optionally its children.
void updateModel3DVisible(const UUID &id, bool visible)
Updates the 3D visibility state of a cached model.
Dictionary< UUID, QIcon > m_cached_material_images
Cached material preview icons.
QVariant data(const UUID &id, int role, int column) const
Retrieves display data for a specific model by UUID, role, and column.
void clearAll()
Clears all cached data and resets the view.
void modelUpdatedSlot(const Buffer< UUID > &updated_ids)
Handles model update events.
void emitIndexUpdated(const UUID &id, const QList< int > &roles=QList< int >())
Emits data-changed signals for a specific model index.
QTModelManager * m_manager
The underlying model manager.
void addModel(UUID id)
Adds a model to the view and cache.
Dictionary< UUID, ModelCache > m_cached_model_indices
Cached display data per model.
void modelFocussed(UUID id, bool selected)
Handles model focus change events.
void materialUpdatedSlot(const Buffer< UUID > &updated_ids)
Handles material update events.
QTModelManagerView(QTModelManager *manager, QObject *parent=nullptr)
Constructs a model manager view for the given manager.
void topLevelChanged(Buffer< UUID > id)
Handles top-level parent change events for models.
UUID m_project_id
UUID of the currently active project.
void refreshAll()
Refreshes the entire view by rebuilding all caches.
void objectSelected(Buffer< UUID > id, bool selected)
Handles object selection change events.
Model model(const QModelIndex &model_index) const
Retrieves a Model object for a given QModelIndex.
QIcon::Mode iconMode(const QModelIndex &index) const
Determines the icon display mode for the given index.
QModelIndex getIndex(const UUID &id, int column) const
Retrieves the QModelIndex for a model UUID at a specific column.
void setRootModels(const Buffer< UUID > &roots)
Sets the root models displayed in the view.
Dictionary< UUID, Set< UUID > > m_cached_material_indices
Map of materials to the models using them.
QModelIndex getIndex(const Model &model, int column) const
Retrieves the QModelIndex for a model at a specific column.
void setIsRootFilter(const std::function< bool(const Model &)> &filter)
Sets a filter function that determines which models are treated as roots.
void recursiveCacheRemove(const UUID &id)
Recursively removes a model and its children from the cache.
void projectChanged(UUID id)
Handles project change events.
UUID getMaterialID(const QModelIndex &model_index) const
Retrieves the material UUID for a given QModelIndex.
bool m_include_materials
Whether to show materials as child items.
std::function< bool(const Model &)> m_root_filter
Optional filter for determining root models.
UUID getModelID(const QModelIndex &model_index) const
Retrieves the model UUID for a given QModelIndex.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The core String class for the NDEVR API.
Definition String.h:95
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...
Cached data for a single model entry in the tree view, storing display properties to avoid repeated l...
bool is_selected
Whether this model is currently selected.
String icon
Icon identifier for the model.
QString material_name
Display name of the associated material.
bool is_visible
Whether this model is individually visible.
bool is_visible_recursive
Whether this model is visible considering parent visibility.
uint04 cache_index
Index into the flat index ID list.
Buffer< UUID > children
UUIDs of child models.
QString tooltip
Tooltip text for the model.
String material_icon
Icon identifier for the material.
UUID material
UUID of the associated material.
RGBColor icon_color
Tint color for the icon.
UUID parent
UUID of the parent model.
QString name
Display name of the model.