API Documentation
Loading...
Searching...
No Matches
DesignObjectToggleWidget.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: DesignObjectToggleWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTDesignObject.h>
34#include <NDEVR/Toggle.h>
35#include <NDEVR/ManagedDesignCommand.h>
36#include <NDEVR/JSONNode.h>
37namespace NDEVR
38{
40 {
41 Q_OBJECT
42 public:
43 DesignObjectToggleWidget(QWidget* parent = nullptr)
44 : Toggle(parent)
45 , m_property(DesignObject::e_design_property_size)
46 {
47 setFunction([this](Button*)
48 {
49 sendCommand();
50 });
51 }
53 {
55 }
57 {
58 setTarget(object);
59 setDesignProperty(property);
60 }
62 {
63 if (m_target == object)
64 return;
65 if (!m_target.isNull())
66 {
67 disconnect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectToggleWidget::onObjectUpdatedSlot);
68 disconnect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectToggleWidget::onObjectDeletedSlot);
69 }
70 m_target = object;
71 if (!m_target.isNull())
72 {
73 connect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectToggleWidget::onObjectUpdatedSlot);
74 connect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectToggleWidget::onObjectDeletedSlot);
75 }
76 setEnabled(!m_target.isNull());
77 onObjectUpdatedSlot();
78 }
80 {
81 m_property = property;
82 if (m_title.isEmpty())
83 {
84 if (property == DesignObject::DesignProperty::e_meta_data)
85 setTitle(TranslatedString(m_meta_data.formatTitleString()));
86 else
87 setTitle(String::DisplayString(property));
88 }
89 onObjectUpdatedSlot();
90 }
91 void setupForMetadata(const TranslatedString& title, String meta_data)
92 {
93 m_title = title;
94 m_meta_data = meta_data;
95 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
96 }
97 void setupForMetadata(const String& metadata)
98 {
99 m_meta_data = metadata;
100 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
101 }
102 protected slots:
104 {
106 }
108 {
109 bool toggle = isChecked();
110 if (m_property == DesignObject::DesignProperty::e_meta_data)
111 {
112 m_target->postCommand(ManagedDesignCommand::SetMetadata(m_meta_data, String(toggle)));
113 }
114 else
115 {
116 if (toggle != m_target->getAs<DesignObject>().getProperty<bool>(m_property))
117 m_target->postCommand(ManagedDesignCommand::SetProperty(m_property, toggle));
118 }
119 }
121 {
122 if (!m_target.isNull() && m_property != DesignObject::e_design_property_size)
123 {
124 bool checked = false;
125 if (m_property == DesignObject::e_meta_data)
126 {
127 if (m_target->get().hasMetaData(m_meta_data))
128 checked = m_target->get().metaData(m_meta_data).getAs<bool>();
129 }
130 else
131 {
132 checked = m_target->getProperty<bool>(m_property);
133 }
134 setChecked(checked);
135 }
136 }
137 protected:
142 };
143}
144
#define NDEVR_API
Definition DLLInfo.h:67
Definition Button.h:60
Definition DesignObject.h:66
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:263
DesignProperty
Definition DesignObject.h:94
Definition DesignObjectToggleWidget.h:40
DesignObject::DesignProperty m_property
Definition DesignObjectToggleWidget.h:138
DynamicPointer< QTDesignObject > m_target
Definition DesignObjectToggleWidget.h:139
void sendCommand()
Definition DesignObjectToggleWidget.h:107
void setDesignProperty(DesignObject::DesignProperty property)
Definition DesignObjectToggleWidget.h:79
DesignObjectToggleWidget(QWidget *parent=nullptr)
Definition DesignObjectToggleWidget.h:43
void onObjectDeletedSlot()
Definition DesignObjectToggleWidget.h:103
TranslatedString m_title
Definition DesignObjectToggleWidget.h:140
void clearTarget()
Definition DesignObjectToggleWidget.h:52
void onObjectUpdatedSlot()
Definition DesignObjectToggleWidget.h:120
String m_meta_data
Definition DesignObjectToggleWidget.h:141
void setupForMetadata(const String &metadata)
Definition DesignObjectToggleWidget.h:97
void setTarget(const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectToggleWidget.h:61
void setTarget(DesignObject::DesignProperty property, const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectToggleWidget.h:56
void setupForMetadata(const TranslatedString &title, String meta_data)
Definition DesignObjectToggleWidget.h:91
Definition Pointer.hpp:303
Definition String.h:40
Definition Toggle.h:45
Definition TranslatedString.h:9
Definition ACIColor.h:37