API Documentation
Loading...
Searching...
No Matches
DesignObjectComboWidget.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: 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{
41 /**--------------------------------------------------------------------------------------------------
42 \brief Shows a filtered list of models in a combobox that the user can use to select a desired Model
43 **/
45 {
46 Q_OBJECT
47 public:
48 DesignObjectComboWidget(QWidget* parent = nullptr)
49 : QCustomComboBox(parent)
50 , m_property(DesignObject::e_design_property_size)
51 {
52 connect(this, &QCustomComboBox::edited, this, &DesignObjectComboWidget::sendCommand);
53 }
55 {
57 }
59 {
60 setTarget(object);
61 setDesignProperty(property);
62 }
64 {
65 if (m_target == object)
66 return;
67 if (!m_target.isNull())
68 {
69 disconnect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectComboWidget::onObjectUpdatedSlot);
70 disconnect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectComboWidget::onObjectDeletedSlot);
71 }
72 m_target = object;
73 if (!m_target.isNull())
74 {
75 connect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectComboWidget::onObjectUpdatedSlot);
76 connect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectComboWidget::onObjectDeletedSlot);
77 }
78 setEnabled(!m_target.isNull());
79 onObjectUpdatedSlot();
80 }
82 {
83 m_property = property;
84 if (m_title.isEmpty())
85 {
86 if (property == DesignObject::DesignProperty::e_meta_data)
87 setWindowTitle(String(m_meta_data_title).formatAsTitleString().getAs<QString>());
88 else
89 setWindowTitle(String(property).formatAsTitleString().getAs<QString>());
90 }
91 QCustomValidator validator = customValidator();
92 onObjectUpdatedSlot();
93 switch (property)
94 {
95 case DesignObject::DesignProperty::e_file:
96 validator.setRegex(RegexFunctions::FileRegex());
97 break;
98 default:
99 //validator.setRegex("^[a-zA-Z0-9_\\s-]+$");
100 break;
101 }
102 setCustomValidator(validator);
103 }
104 void setupForMetadata(const String& metadata)
105 {
106 m_meta_data_title = metadata;
107 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
108 }
109 void setTitle(const TranslatedString& title)
110 {
111 m_title = title;
112 if (m_title.translation().size() == 0)
113 {
114 if (m_property == DesignObject::DesignProperty::e_meta_data)
115 setWindowTitle(String(m_meta_data_title).formatAsTitleString().getAs<QString>());
116 else
117 setWindowTitle(String(m_property).formatAsTitleString().getAs<QString>());
118 }
119 else
120 {
121 setWindowTitle(m_title.translation().getAs<QString>());
122 }
123 }
124 protected slots:
126 {
128 }
130 {
131 if (m_target.isNull())
132 return;
133 String name = getAs<String>();
134 if (m_property == DesignObject::DesignProperty::e_meta_data)
135 {
136 m_target->postCommand(ManagedDesignCommand::SetMetadata(m_meta_data_title, name));
137 }
138 else
139 {
140 if (name != m_target->getAs<DesignObject>().getProperty<String>(m_property))
141 m_target->postCommand(ManagedDesignCommand::SetProperty(m_property, name));
142 }
143 }
145 {
146 if (!m_target.isNull() && m_property != DesignObject::e_design_property_size)
147 {
148 String object_name;
149 if (m_property == DesignObject::e_meta_data)
150 {
151 if (m_target->get().hasMetaData(m_meta_data_title))
152 object_name = m_target->get().metaData(m_meta_data_title).getAs<String>();
153 }
154 else
155 {
156 object_name = m_target->getProperty<String>(m_property);
157 }
158 if (object_name.size() != 0)
159 {
160 setValue(object_name);
161 }
162 }
163 }
164 protected:
169 };
170}
171
#define NDEVR_API
Definition DLLInfo.h:50
constexpr t_index_type size() const
Definition Buffer.hpp:823
decltype(auto) get(t_index_type index)
Definition Buffer.hpp:541
Shows a filtered list of models in a combobox that the user can use to select a desired Model.
Definition DesignObjectComboWidget.h:45
DesignObject::DesignProperty m_property
Definition DesignObjectComboWidget.h:165
DynamicPointer< QTDesignObject > m_target
Definition DesignObjectComboWidget.h:166
void sendCommand()
Definition DesignObjectComboWidget.h:129
void setDesignProperty(DesignObject::DesignProperty property)
Definition DesignObjectComboWidget.h:81
void setTitle(const TranslatedString &title)
Definition DesignObjectComboWidget.h:109
void onObjectDeletedSlot()
Definition DesignObjectComboWidget.h:125
TranslatedString m_title
Definition DesignObjectComboWidget.h:168
void clearTarget()
Definition DesignObjectComboWidget.h:54
DesignObjectComboWidget(QWidget *parent=nullptr)
Definition DesignObjectComboWidget.h:48
void onObjectUpdatedSlot()
Definition DesignObjectComboWidget.h:144
void setupForMetadata(const String &metadata)
Definition DesignObjectComboWidget.h:104
String m_meta_data_title
Definition DesignObjectComboWidget.h:167
void setTarget(const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectComboWidget.h:63
void setTarget(DesignObject::DesignProperty property, const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectComboWidget.h:58
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:256
DesignProperty
Values stored in the property database.
Definition DesignObject.h:93
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A compact way to present a list of options to the user.
Definition QCustomCombobox.h:53
Responsible on most user input fields for correcting the input when possible or allerting the user th...
Definition QCustomValidator.h:47
void setRegex(const String &regex)
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37