NDEVR
API Documentation
DesignObjectStringWidget.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: DesignObjectStringWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTDesignObject.h>
34#include <NDEVR/QCustomLineEdit.h>
35#include <NDEVR/RegexFunctions.h>
36namespace NDEVR
37{
43 {
44 Q_OBJECT
45 public:
50 DesignObjectStringWidget(QWidget* parent = nullptr)
51 : QCustomLineEdit(parent)
53 {
56 customValidator().setAllowEmpty(true);
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.toTitleString().getAs<QString>());
108 else
109 setWindowTitle(String::DisplayString(property).translation().toTitleString().getAs<QString>());
110 }
112 switch (property)
113 {
114 case NDPO::file:
116 break;
117 default:
118 //customValidator().setRegex(/*"^[\\.a-zA-Z0-9_\\s-]+$"*/);
119 break;
120 }
121 }
122
127 void setupForMetadata(TranslatedString title, const StringView& metadata)
128 {
129 m_title = title;
130 m_meta_data = metadata;
132 }
133
137 void setupForMetadata(const StringView& metadata)
138 {
139 m_meta_data = metadata;
141 }
142
146 void setTitle(const TranslatedString& title) override
147 {
148 m_title = title;
149 if (m_title.isEmpty() == 0)
150 {
153 else
155 }
156 else
157 {
159 }
160 }
161 protected slots:
169
177 protected:
181 };
182}
183
void setupForMetadata(TranslatedString title, const StringView &metadata)
Configures this widget to edit a specific metadata key with a custom title.
void clearTarget()
Clears the current target design object.
void setTitle(const TranslatedString &title) override
Sets the display title, falling back to the property or metadata name if empty.
void onObjectUpdatedSlot()
Slot called when the target design object is updated, refreshing the displayed value.
void setNDPO(NDPO property)
Sets the design object property to edit and updates validation rules accordingly.
void sendCommand()
Sends the edited value as a command to the target design object.
NDPO m_property
The design object property being edited.
String m_meta_data
The metadata key when editing metadata properties.
DesignObjectStringWidget(QWidget *parent=nullptr)
Constructs a DesignObjectStringWidget for editing a string property of a design object.
void setupForMetadata(const StringView &metadata)
Configures this widget to edit a specific metadata key.
void onObjectDeletedSlot()
Slot called when the target design object is deleted, clearing the target.
DynamicPointer< QTDesignObject > m_target
The target design object.
void setTarget(NDPO property, const DynamicPointer< QTDesignObject > &object)
Sets both the target design object and the property to edit.
void setTarget(const DynamicPointer< QTDesignObject > &object)
Sets the target design object, connecting update and deletion signals.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
TranslatedString m_title
The display title for the line edit.
virtual void setTitle(const TranslatedString &title)
Sets the display title for the line edit, used as a label or placeholder context.
void editingFinishedSignal()
Emitted when the user finishes editing (focus lost or enter pressed).
void setAllowPlaceholderAsValue(bool allow)
Sets whether the placeholder text should be treated as a valid value when the field is empty.
t_type getAs(bool allow_placeholder) const
Returns the current value converted to the requested type.
QCustomValidator & customValidator()
Returns a mutable reference to the custom validator used for input validation.
QCustomLineEdit(QWidget *parent=Q_NULLPTR)
Constructs a QCustomLineEdit with the given parent widget.
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
static TranslatedString DisplayString(const t_type &value)
Converts an object into a TranslatedString.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
static TranslatedString DirectString(const StringView &sub_string)
If a string does not have a translation (EG: reading from an already translated string) this operatio...
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.
@ meta_data
General-purpose metadata string for the object.