API Documentation
Loading...
Searching...
No Matches
ModelChooserCombo.h
Go to the documentation of this file.
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{
39 {
40 Q_OBJECT
41 public:
42 ModelChooserCombo(QWidget* parent = nullptr);
43 void setIncludeParentName(bool include_parent_name, const String& parent_type = String());
44 void setIncludePath(bool include_parent_name, const String& parent_type = String());
45 void setManager(QTModelManager* manager);
46 bool canAddModel(const Model& model)
47 {
48 return !m_models.hasKey(model.uuid()) && isModelAllowed(model);
49 }
50 bool isModelAllowed(const Model& model);
51 void setModelFilter(const std::function<bool(const Model&)>& model_filter)
52 {
53 m_model_type.clear();
54 m_model_filter = model_filter;
55 }
56 void setModelType(const String& type);
57 void setIDs(const Buffer<UUID>& ids)
58 {
59 lib_assert(m_manager != nullptr, "Need to set Model Manager");
60 if (m_manager != nullptr)
61 setModels(m_manager->getModelsByID(ids));
62 }
63 void addID(const UUID& id);
64 void removeID(const UUID& id)
65 {
66 if (m_models.hasKey(id))
67 {
68 _removeID(id);
69 refreshWidget();
70 }
71 }
72 void setModels(const Buffer<Model>& models);
75 {
76
77 }
78 void setAllowNew(bool allow_new, const TranslatedString& new_title);
80 void setToNew()
81 {
82 lib_assert(m_allow_add_new, "Tried to set to new when new not enabled");
83 setValue(UUID::CreateUUID("New Model"));
84 }
85 bool isNewSelected() const
86 {
87 return getAs<UUID>() == UUID::CreateUUID("New Model");
88 }
89 void setExclusionList(const Buffer<UUID>& exclusion_list)
90 {
91 m_exclusion_list.clear();
92 for (uint04 i = 0; i < exclusion_list.size(); i++)
93 m_exclusion_list.insert(exclusion_list[i]);
94 }
96 {
97 UUID id = getAs<UUID>();
98 if (id == UUID::CreateUUID("New Model"))
100 return id;
101 }
102 virtual void onSorted(const Buffer<uint04>& sorted_indices);
103 void setDisplayNameCallback(std::function<TranslatedString(const Model&)>& callback)
104 {
105 m_display_name_callback = callback;
106 }
107 void setModelParentID(const UUID& parent);
108 signals:
111 protected slots:
114 void addModel(const Model& m)
115 {
116 if (canAddModel(m))
117 {
118 _addModel(m);
119 refreshWidget();
120 }
121 }
123 void onEdited();
124 private:
125 void _removeID(const UUID& id);
126 void _addModel(const Model& m);
127 protected:
136 std::function<bool(const Model&)> m_model_filter;
140 };
141}
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:68
#define NDEVR_API
Definition DLLInfo.h:67
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
constexpr t_index_type size() const
Definition Buffer.hpp:1374
UUID uuid() const
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:59
Definition ModelChooserCombo.h:39
void setToNew()
Definition ModelChooserCombo.h:80
void addID(const UUID &id)
TranslatedString displayName(const Model &m)
ModelChooserCombo(QWidget *parent=nullptr)
void setModelParentID(const UUID &parent)
void addModel(const Model &m)
Definition ModelChooserCombo.h:114
void onObjectUpdatedSlot(Buffer< UUID > ids)
bool isNewSelected() const
Definition ModelChooserCombo.h:85
void setDisplayNameCallback(std::function< TranslatedString(const Model &)> &callback)
Definition ModelChooserCombo.h:103
void setIncludePath(bool include_parent_name, const String &parent_type=String())
void setModels(const Buffer< Model > &models)
void setManager(QTModelManager *manager)
void setAllowNew(bool allow_new, const TranslatedString &new_title)
void setIDs(const Buffer< UUID > &ids)
Definition ModelChooserCombo.h:57
bool canAddModel(const Model &model)
Definition ModelChooserCombo.h:46
bool m_include_path
Definition ModelChooserCombo.h:139
bool m_include_parent_name
Definition ModelChooserCombo.h:138
virtual void onSorted(const Buffer< uint04 > &sorted_indices)
void setModelType(const String &type)
void removeID(const UUID &id)
Definition ModelChooserCombo.h:64
void refreshFromManager()
Definition ModelChooserCombo.h:74
void setExclusionList(const Buffer< UUID > &exclusion_list)
Definition ModelChooserCombo.h:89
Dictionary< UUID, Buffer< UUID > > m_model_parents
Definition ModelChooserCombo.h:131
std::function< TranslatedString(const Model &)> m_display_name_callback
Definition ModelChooserCombo.h:129
Dictionary< UUID, uint04 > m_models
Definition ModelChooserCombo.h:130
void modelSelectedSignal(UUID id)
void setCurrentSelection(UUID id)
void setModelFilter(const std::function< bool(const Model &)> &model_filter)
Definition ModelChooserCombo.h:51
std::function< bool(const Model &)> m_model_filter
Definition ModelChooserCombo.h:136
void setIncludeParentName(bool include_parent_name, const String &parent_type=String())
UUID selectedID() const
Definition ModelChooserCombo.h:95
bool isModelAllowed(const Model &model)
QTModelManager * m_manager
Definition ModelChooserCombo.h:135
void onObjectAddedSlot(const Buffer< UUID > &ids)
String m_parent_type
Definition ModelChooserCombo.h:134
String m_model_type
Definition ModelChooserCombo.h:133
bool m_allow_add_new
Definition ModelChooserCombo.h:137
Set< UUID > m_exclusion_list
Definition ModelChooserCombo.h:128
A core class that represents a node on model heirarchy. This node may contain a Geometry or.
Definition Model.h:58
A compact way to present a list of options to the user.
Definition QCustomCombobox.h:53
Definition QTModelManager.h:94
Container that stores unique elements in no particular order, and which allow for fast retrieval.
Definition Model.h:51
The core String class for the software.
Definition String.h:47
Any text displayed to the user should be defined as a TranslatedString which allows the.
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:62
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved.
Definition BaseValues.hpp:230