NDEVR
API Documentation
DesignObjectComboWidget.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: DesignObjectComboWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTDesignObject.h>
34#include <NDEVR/QCustomComboBox.h>
35#include <NDEVR/QCustomValidator.h>
36#include <NDEVR/ManagedDesignCommand.h>
37#include <NDEVR/JSONNode.h>
38#include <NDEVR/RegexFunctions.h>
39namespace NDEVR
40{
45 {
46 Q_OBJECT
47 public:
52 DesignObjectComboWidget(QWidget* parent = nullptr)
53 : QCustomComboBox(parent)
55 {
57 }
58
65
70 void setTarget(NDPO property, const DynamicPointer<QTDesignObject>& object)
71 {
72 setTarget(object);
73 setNDPO(property);
74 }
75
80 {
81 if (m_target == object)
82 return;
83 if (!m_target.isNull())
84 {
87 }
88 m_target = object;
89 if (!m_target.isNull())
90 {
93 }
94 setEnabled(!m_target.isNull());
96 }
97
101 void setNDPO(NDPO property)
102 {
103 m_property = property;
104 if (m_title.isEmpty())
105 {
106 if (property == NDPO::meta_data)
107 setWindowTitle(m_meta_data_title.toTitleString().getAs<QString>());
108 else
109 setWindowTitle(String(property).toTitleString().getAs<QString>());
110 }
111 QCustomValidator validator = customValidator();
113 switch (property)
114 {
115 case NDPO::file:
117 break;
118 default:
119 //validator.setRegex("^[a-zA-Z0-9_\\s-]+$");
120 break;
121 }
122 setCustomValidator(validator);
123 }
124
128 void setupForMetadata(const StringView& metadata)
129 {
130 m_meta_data_title = metadata;
132 }
133
137 void setTitle(const TranslatedString& title)
138 {
139 m_title = title;
140 if (m_title.translation().size() == 0)
141 {
143 setWindowTitle(m_meta_data_title.toTitleString().getAs<QString>());
144 else
145 setWindowTitle(String(m_property).toTitleString().getAs<QString>());
146 }
147 else
148 {
149 setWindowTitle(m_title.translation().getAs<QString>());
150 }
151 }
152 protected slots:
160
164 {
165 if (m_target.isNull())
166 return;
169 {
171 }
172 else
173 {
176 }
177 }
178
182 {
183 if (!m_target.isNull() && m_property != NDPO::property_size)
184 {
185 String object_name;
187 {
189 object_name = m_target->getAs<DesignObject>().metaData(m_meta_data_title).getAs<String>();
190 }
191 else
192 {
193 object_name = m_target->get<StringView>(m_property);
194 }
195 if (object_name.size() != 0)
196 {
197 setValue(object_name);
198 }
199 }
200 }
201 protected:
206 };
207}
208
TranslatedString m_title
The custom display title, if set.
void setNDPO(NDPO property)
Sets the design object property that this combo box reads and writes.
NDPO m_property
The design object property this combo box is bound to.
void setTarget(NDPO property, const DynamicPointer< QTDesignObject > &object)
Sets the target design object and the property to display.
DynamicPointer< QTDesignObject > m_target
The target design object.
DesignObjectComboWidget(QWidget *parent=nullptr)
Constructs a DesignObjectComboWidget.
void setupForMetadata(const StringView &metadata)
Configures this combo box to read and write a metadata key on the target object.
void sendCommand()
Sends a command to update the target object property with the current combo value.
void setTitle(const TranslatedString &title)
Sets the display title for this combo box.
void onObjectDeletedSlot()
Slot called when the target design object is deleted.
String m_meta_data_title
The metadata key name when bound to metadata.
void clearTarget()
Clears the current target design object.
void setTarget(const DynamicPointer< QTDesignObject > &object)
Sets the target design object and connects update/delete signals.
void onObjectUpdatedSlot()
Slot called when the target object is updated.
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
bool hasMetaData(const StringView &index) const
Checks whether a metadata entry exists for the given key.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
static DynamicPointer< ManagedDesignCommand > SetProperty(NDPO design_property, const t_type &value)
Creates a command to set a design-level property to the given value.
static DynamicPointer< ManagedDesignCommand > SetMetadata(const String &label, const String &value)
Creates a command to set a metadata key-value pair on target objects.
void setCustomValidator(const QCustomValidator &validator)
Sets the custom validator used for input validation and formatting.
void edited()
Emitted when the combo box value is edited by the user.
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.
t_type getAs() const
Returns the current value converted to the requested type.
const QCustomValidator & customValidator() const
Returns a const reference to the custom validator used for input validation.
Responsible on most user input fields for correcting the input when possible or allerting the user th...
void setRegex(const StringView &regex)
Sets a regular expression pattern that the input must match.
void updatedSignal(UUID id)
Emitted when this object is updated.
void deletedSignal(UUID id)
Emitted when this object is deleted.
static const char * FileRegex()
Gets a regex pattern for validating file paths.
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...
The primary namespace for the NDEVR SDK.
NDPO
NDPO - NDEVR Design Property Object: Values stored in the property database.
@ property_size
Sentinel value representing the total number of properties (always last).
@ file
The source file path associated with this object.
@ name
The display name of the object.
@ meta_data
General-purpose metadata string for the object.