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{
42 {
43 Q_OBJECT
44 public:
45 DesignObjectComboWidget(QWidget* parent = nullptr)
46 : QCustomComboBox(parent)
47 , m_property(DesignObject::e_design_property_size)
48 {
49 connect(this, &QCustomComboBox::edited, this, &DesignObjectComboWidget::sendCommand);
50 }
52 {
54 }
56 {
57 setTarget(object);
58 setDesignProperty(property);
59 }
61 {
62 if (m_target == object)
63 return;
64 if (!m_target.isNull())
65 {
66 disconnect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectComboWidget::onObjectUpdatedSlot);
67 disconnect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectComboWidget::onObjectDeletedSlot);
68 }
69 m_target = object;
70 if (!m_target.isNull())
71 {
72 connect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectComboWidget::onObjectUpdatedSlot);
73 connect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectComboWidget::onObjectDeletedSlot);
74 }
75 setEnabled(!m_target.isNull());
76 onObjectUpdatedSlot();
77 }
79 {
80 m_property = property;
81 if (m_title.translation().size() == 0)
82 {
83 if (property == DesignObject::DesignProperty::e_meta_data)
84 setWindowTitle(m_meta_data_title.formatTitleString().getAs<QString>());
85 else
86 setWindowTitle(String(property).formatTitleString().getAs<QString>());
87 }
88 QCustomValidator validator = customValidator();
89 onObjectUpdatedSlot();
90 switch (property)
91 {
92 case DesignObject::DesignProperty::e_file:
93 validator.setRegex(RegexFunctions::FileRegex());
94 break;
95 default:
96 //validator.setRegex("^[a-zA-Z0-9_\\s-]+$");
97 break;
98 }
99 setCustomValidator(validator);
100 }
101 void setupForMetadata(const String& metadata)
102 {
103 m_meta_data_title = metadata;
104 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
105 }
106 void setTitle(const TranslatedString& title)
107 {
108 m_title = title;
109 if (m_title.translation().size() == 0)
110 {
111 if (m_property == DesignObject::DesignProperty::e_meta_data)
112 setWindowTitle(m_meta_data_title.formatTitleString().getAs<QString>());
113 else
114 setWindowTitle(String(m_property).formatTitleString().getAs<QString>());
115 }
116 else
117 {
118 setWindowTitle(m_title.translation().getAs<QString>());
119 }
120 }
121 protected slots:
123 {
125 }
127 {
128 if (m_target.isNull())
129 return;
130 String name = getAs<String>();
131 if (m_property == DesignObject::DesignProperty::e_meta_data)
132 {
133 m_target->postCommand(ManagedDesignCommand::SetMetadata(m_meta_data_title, name));
134 }
135 else
136 {
137 if (name != m_target->getAs<DesignObject>().getProperty<String>(m_property))
138 m_target->postCommand(ManagedDesignCommand::SetProperty(m_property, name));
139 }
140 }
142 {
143 if (!m_target.isNull() && m_property != DesignObject::e_design_property_size)
144 {
145 String object_name;
146 if (m_property == DesignObject::e_meta_data)
147 {
148 if (m_target->get().hasMetaData(m_meta_data_title))
149 object_name = m_target->get().metaData(m_meta_data_title).getAs<String>();
150 }
151 else
152 {
153 object_name = m_target->getProperty<String>(m_property);
154 }
155 if (object_name.size() != 0)
156 {
157 setValue(object_name);
158 }
159 }
160 }
161 protected:
166 };
167}
168
#define NDEVR_API
Definition DLLInfo.h:67
constexpr t_index_type size() const
Definition Buffer.hpp:1461
decltype(auto) get(t_index_type index)
Definition Buffer.hpp:857
Definition DesignObjectComboWidget.h:42
DesignObject::DesignProperty m_property
Definition DesignObjectComboWidget.h:162
DynamicPointer< QTDesignObject > m_target
Definition DesignObjectComboWidget.h:163
void sendCommand()
Definition DesignObjectComboWidget.h:126
void setDesignProperty(DesignObject::DesignProperty property)
Definition DesignObjectComboWidget.h:78
void setTitle(const TranslatedString &title)
Definition DesignObjectComboWidget.h:106
void onObjectDeletedSlot()
Definition DesignObjectComboWidget.h:122
TranslatedString m_title
Definition DesignObjectComboWidget.h:165
void clearTarget()
Definition DesignObjectComboWidget.h:51
DesignObjectComboWidget(QWidget *parent=nullptr)
Definition DesignObjectComboWidget.h:45
void onObjectUpdatedSlot()
Definition DesignObjectComboWidget.h:141
void setupForMetadata(const String &metadata)
Definition DesignObjectComboWidget.h:101
String m_meta_data_title
Definition DesignObjectComboWidget.h:164
void setTarget(const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectComboWidget.h:60
void setTarget(DesignObject::DesignProperty property, const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectComboWidget.h:55
Definition DesignObject.h:66
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:263
DesignProperty
Definition DesignObject.h:94
Definition Pointer.hpp:303
Definition QCustomCombobox.h:47
Definition QCustomValidator.h:43
void setRegex(const String &regex)
Definition QCustomValidator.cpp:296
Definition String.h:40
t_type getAs() const
Definition String.h:334
Definition TranslatedString.h:9
Definition ACIColor.h:37