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{
39 /**--------------------------------------------------------------------------------------------------
40 \brief A widget allowing easy access to change the properties of a designObject by showing a toggle
41 to the user.
42 **/
44 {
45 Q_OBJECT
46 public:
47 DesignObjectToggleWidget(QWidget* parent = nullptr)
48 : Toggle(parent)
49 , m_property(DesignObject::e_design_property_size)
50 {
51 setFunction([this](Button*)
52 {
53 sendCommand();
54 });
55 }
57 {
59 }
61 {
62 setTarget(object);
63 setDesignProperty(property);
64 }
66 {
67 if (m_target == object)
68 return;
69 if (!m_target.isNull())
70 {
71 disconnect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectToggleWidget::onObjectUpdatedSlot);
72 disconnect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectToggleWidget::onObjectDeletedSlot);
73 }
74 m_target = object;
75 if (!m_target.isNull())
76 {
77 connect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectToggleWidget::onObjectUpdatedSlot);
78 connect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectToggleWidget::onObjectDeletedSlot);
79 }
80 setEnabled(!m_target.isNull());
81 onObjectUpdatedSlot();
82 }
84 {
85 m_property = property;
86 if (m_title.isEmpty())
87 {
88 if (property == DesignObject::DesignProperty::e_meta_data)
89 setTitle(TranslatedString(String(m_meta_data).formatAsTitleString()));
90 else
91 setTitle(String::DisplayString(property));
92 }
93 onObjectUpdatedSlot();
94 }
95 void setupForMetadata(const TranslatedString& title, String meta_data)
96 {
97 m_title = title;
98 m_meta_data = meta_data;
99 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
100 }
101 void setupForMetadata(const String& metadata)
102 {
103 m_meta_data = metadata;
104 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
105 }
106 protected slots:
108 {
110 }
112 {
113 bool toggle = isChecked();
114 if (m_property == DesignObject::DesignProperty::e_meta_data)
115 {
116 m_target->postCommand(ManagedDesignCommand::SetMetadata(m_meta_data, String(toggle)));
117 }
118 else
119 {
120 if (toggle != m_target->getAs<DesignObject>().getProperty<bool>(m_property))
121 m_target->postCommand(ManagedDesignCommand::SetProperty(m_property, toggle));
122 }
123 }
125 {
126 if (!m_target.isNull() && m_property != DesignObject::e_design_property_size)
127 {
128 bool checked = false;
129 if (m_property == DesignObject::e_meta_data)
130 {
131 if (m_target->get().hasMetaData(m_meta_data))
132 checked = m_target->get().metaData(m_meta_data).getAs<bool>();
133 }
134 else
135 {
136 checked = m_target->getProperty<bool>(m_property);
137 }
138 setChecked(checked);
139 }
140 }
141 protected:
146 };
147}
148
#define NDEVR_API
Definition DLLInfo.h:50
A core widget that allows the user to click one of many button types.
Definition Button.h:66
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
A widget allowing easy access to change the properties of a designObject by showing a toggle to the u...
Definition DesignObjectToggleWidget.h:44
DesignObject::DesignProperty m_property
Definition DesignObjectToggleWidget.h:142
DynamicPointer< QTDesignObject > m_target
Definition DesignObjectToggleWidget.h:143
void sendCommand()
Definition DesignObjectToggleWidget.h:111
void setDesignProperty(DesignObject::DesignProperty property)
Definition DesignObjectToggleWidget.h:83
DesignObjectToggleWidget(QWidget *parent=nullptr)
Definition DesignObjectToggleWidget.h:47
void onObjectDeletedSlot()
Definition DesignObjectToggleWidget.h:107
TranslatedString m_title
Definition DesignObjectToggleWidget.h:144
void clearTarget()
Definition DesignObjectToggleWidget.h:56
void onObjectUpdatedSlot()
Definition DesignObjectToggleWidget.h:124
String m_meta_data
Definition DesignObjectToggleWidget.h:145
void setupForMetadata(const String &metadata)
Definition DesignObjectToggleWidget.h:101
void setTarget(const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectToggleWidget.h:65
void setTarget(DesignObject::DesignProperty property, const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectToggleWidget.h:60
void setupForMetadata(const TranslatedString &title, String meta_data)
Definition DesignObjectToggleWidget.h:95
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
The core String class for the NDEVR API.
Definition String.h:69
A Button that toggles between on and off. In desktop mode this looks like a checkbox and in touch mod...
Definition Toggle.h:49
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