NDEVR
API Documentation
ModelChooserCombo.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: ModelChooserCombo
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTModelManager.h>
34#include <NDEVR/QCustomComboBox.h>
35#include <NDEVR/Set.h>
36namespace NDEVR
37{
42 class NDEVR_API ModelChooserCombo : public QCustomComboBox
43 {
44 Q_OBJECT
45 public:
50 ModelChooserCombo(QWidget* parent = nullptr);
56 void setIncludeParentName(bool include_parent_name, const StringView& parent_type = String());
62 void setIncludePath(bool include_parent_name, const StringView& parent_type = String());
72 QTModelManager* manager() const { return m_manager; }
78 bool canAddModel(const Model& model)
79 {
80 return !m_models.hasKey(model.get<NDPO::guid>()) && isModelAllowed(model);
81 }
82
87 bool isModelAllowed(const Model& model);
92 void setModelFilter(const std::function<bool(const Model&)>& model_filter)
93 {
94 m_model_types.clear();
95 m_model_filter = model_filter;
96 }
97
101 void setModelType(const StringView& type);
106 void addModelType(const StringView& type);
111 void setIDs(const Buffer<UUID>& ids)
112 {
113 lib_assert(m_manager != nullptr, "Need to set Model Manager");
114 if (m_manager != nullptr)
115 setModels(m_manager->getModelsByID(ids));
116 }
117
121 void addID(const UUID& id);
126 void removeID(const UUID& id)
127 {
128 if (m_models.hasKey(id))
129 {
130 _removeID(id);
132 }
133 }
134
138 void setModels(const Buffer<Model>& models);
143 void addModels(const Buffer<Model>& models);
154 {
155
156 }
157
162 void setAllowNew(bool allow_new, const TranslatedString& new_title);
171 void setToNew()
172 {
173 lib_assert(m_allow_add_new, "Tried to set to new when new not enabled");
174 setValue(UUID::CreateUUID("New Model"));
175 }
176
180 bool isNewSelected() const
181 {
182 return getAs<UUID>() == UUID::CreateUUID("New Model");
183 }
184
188 void setExclusionList(const Buffer<UUID>& exclusion_list)
189 {
190 m_exclusion_list.clear();
191 for (uint04 i = 0; i < exclusion_list.size(); i++)
192 m_exclusion_list.insert(exclusion_list[i]);
193 }
194
199 {
200 UUID id = getAs<UUID>();
201 if (id == UUID::CreateUUID("New Model"))
202 id = Constant<UUID>::Invalid;
203 return id;
204 }
205
209 virtual void onSorted(const Buffer<uint04>& sorted_indices);
214 void setDisplayNameCallback(std::function<TranslatedString(const Model&)>& callback)
215 {
216 m_display_name_callback = callback;
217 }
218
222 void setModelParentID(const UUID& parent);
223 signals:
233 protected slots:
247 void addModel(const Model& m)
248 {
249 if (canAddModel(m))
250 {
251 _addModel(m);
253 }
254 }
255
263 void onEdited();
264 private:
269 void _removeID(const UUID& id);
274 void _addModel(const Model& m);
275 protected:
280 UUID m_model_parent = Constant<UUID>::Invalid;
284 std::function<bool(const Model&)> m_model_filter;
288 };
289}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
void addModel(const Model &m)
Adds a model to the combo box if it passes the current filters.
bool m_include_path
Whether to include the full path in display labels.
bool isNewSelected() const
Checks whether the "New Model" entry is currently selected.
QTModelManager * manager() const
Returns the model manager associated with this combo box.
bool isModelAllowed(const Model &model)
Checks whether the model passes the current type and custom filters.
Dictionary< UUID, Buffer< UUID > > m_model_parents
Maps model UUIDs to their parent chain.
void removeID(const UUID &id)
Removes a model identified by UUID from the combo box.
Buffer< String > m_model_types
Model type names used for filtering.
std::function< TranslatedString(const Model &)> m_display_name_callback
Custom callback for generating display names.
void modelSelectedSignal(UUID id)
Emitted when a model is selected in the combo box.
void onObjectAddedSlot(const Buffer< UUID > &ids)
Slot called when objects are added to the scene, potentially adding them to the combo box.
bool m_include_parent_name
Whether to include the parent name in display labels.
void refreshFromManager()
Refreshes the combo box contents from the model manager.
void setToNew()
Sets the combo box selection to the "New Model" entry.
String m_parent_type
Parent type name used for display name generation.
void setAllowNew(bool allow_new, const TranslatedString &new_title)
Enables or disables a "New Model" entry in the combo box.
void setModelParentID(const UUID &parent)
Filters the combo box to only show children of the specified parent model.
ModelChooserCombo(QWidget *parent=nullptr)
Constructs the model chooser combo box.
void addID(const UUID &id)
Adds a model identified by UUID to the combo box.
void onObjectsDeletedSlot()
Slot called when objects are deleted from the scene, removing them from the combo box.
virtual void onSorted(const Buffer< uint04 > &sorted_indices)
Called when the combo box items are sorted, to update internal state.
void setDisplayNameCallback(std::function< TranslatedString(const Model &)> &callback)
Sets a custom callback for generating model display names.
void onEdited()
Slot called when the user edits the combo box selection.
void setExclusionList(const Buffer< UUID > &exclusion_list)
Sets a list of model UUIDs to exclude from the combo box.
Set< UUID > m_exclusion_list
Set of model UUIDs excluded from the combo box.
void setCurrentSelection(UUID id)
Sets the current combo box selection to the model with the given UUID.
void setModelFilter(const std::function< bool(const Model &)> &model_filter)
Sets a custom filter function for determining which models to include.
void newModelSelectedSignal()
Emitted when the "New Model" entry is selected.
void onObjectUpdatedSlot(Buffer< UUID > ids)
Slot called when objects are updated, refreshing their display names.
void setModelType(const StringView &type)
Sets a single model type filter, replacing any existing type filters.
void setIncludeParentName(bool include_parent_name, const StringView &parent_type=String())
Configures whether the parent model name is shown in display labels.
void setIDs(const Buffer< UUID > &ids)
Populates the combo box with models identified by the given UUIDs.
UUID selectedID() const
Returns the UUID of the currently selected model, or Invalid if "New Model" is selected.
QTModelManager * m_manager
The model manager providing scene data.
void setModels(const Buffer< Model > &models)
Replaces the combo box contents with the given models.
Dictionary< UUID, uint04 > m_models
Maps model UUIDs to their combo box indices.
bool m_allow_add_new
Whether the "New Model" entry is enabled.
void addModels(const Buffer< Model > &models)
Adds multiple models to the combo box.
void setIncludePath(bool include_parent_name, const StringView &parent_type=String())
Configures whether the full model path is shown in display labels.
void setManager(QTModelManager *manager)
Sets the model manager used to query models for the combo box.
TranslatedString displayName(const Model &m)
Returns the translated display name for the given model.
bool canAddModel(const Model &model)
Checks whether a model can be added to the combo box.
void addModelType(const StringView &type)
Adds an additional model type to the type filter list.
UUID m_model_parent
Optional parent model UUID for filtering.
std::function< bool(const Model &)> m_model_filter
Custom filter predicate for model inclusion.
A core class that represents a node on model hierarchy.
Definition Model.h:292
void setValue(const t_type &t_value)
Sets the current value of the combo box.
QCustomComboBox(QWidget *parent=nullptr)
Constructs a QCustomComboBox with the given parent widget.
void refreshWidget()
Rebuilds the widget contents from the internal value and display buffers.
t_type getAs() const
Returns the current value converted to the requested type.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
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
static UUID CreateUUID()
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...
@ guid
A 128-bit globally unique identifier for the object.