NDEVR
API Documentation
DesignObjectToggleWidget.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: 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{
43 class NDEVR_API DesignObjectToggleWidget : public Toggle
44 {
45 Q_OBJECT
46 public:
51 DesignObjectToggleWidget(QWidget* parent = nullptr)
52 : Toggle(parent)
54 {
55 setFunction([this](Button*)
56 {
58 });
59 }
60
67
72 void setTarget(NDPO property, const DynamicPointer<QTDesignObject>& object)
73 {
74 setTarget(object);
75 setNDPO(property);
76 }
77
82 {
83 if (m_target == object)
84 return;
85 if (!m_target.isNull())
86 {
89 }
90 m_target = object;
91 if (!m_target.isNull())
92 {
95 }
96 setEnabled(!m_target.isNull());
98 }
99
103 void setNDPO(NDPO property)
104 {
105 m_property = property;
106 if (m_title.isEmpty())
107 {
108 if (property == NDPO::meta_data)
109 setTitle(TranslatedString(m_meta_data.toTitleString()));
110 else
112 }
114 }
115
126
130 void setupForMetadata(const String& metadata)
131 {
132 m_meta_data = metadata;
134 }
135 protected slots:
143
147 {
148 bool toggle = isChecked();
150 {
152 }
153 else
154 {
155 if (toggle != m_target->getAs<DesignObject>().get<bool>(m_property))
157 }
158 }
159
163 {
164 if (!m_target.isNull() && m_property != NDPO::property_size)
165 {
166 bool checked = false;
168 {
170 checked = m_target->getAs<DesignObject>().metaData(m_meta_data).getAs<bool>();
171 }
172 else
173 {
174 checked = m_target->get<bool>(m_property);
175 }
176 setChecked(checked);
177 }
178 }
179 protected:
184 };
185}
186
A core widget that allows the user to click one of many button types.
Definition Button.h:68
const TranslatedString & title() const
Returns the translated title of the button.
void setFunction(const std::function< void(Button *)> &on_click)
Sets the callback function invoked when the button is clicked.
Definition Button.h:260
void setChecked(bool checked)
Sets the checked state of the button.
void setTitle(const TranslatedString &title)
Sets the display title of the button.
void sendCommand()
Sends the current toggle state as a command to the target design object.
String m_meta_data
The metadata key when toggling metadata properties.
DesignObjectToggleWidget(QWidget *parent=nullptr)
Constructs a DesignObjectToggleWidget for toggling a boolean property of a design object.
NDPO m_property
The design object property being toggled.
void onObjectUpdatedSlot()
Slot called when the target design object is updated, refreshing the toggle state.
void onObjectDeletedSlot()
Slot called when the target design object is deleted, clearing the target.
void setupForMetadata(const TranslatedString &title, String meta_data)
Configures this widget to toggle a specific metadata key with a custom title.
DynamicPointer< QTDesignObject > m_target
The target design object.
void setupForMetadata(const String &metadata)
Configures this widget to toggle a specific metadata key.
void setTarget(NDPO property, const DynamicPointer< QTDesignObject > &object)
Sets both the target design object and the boolean property to toggle.
void setNDPO(NDPO property)
Sets the design object property to toggle and updates the title accordingly.
void setTarget(const DynamicPointer< QTDesignObject > &object)
Sets the target design object, connecting update and deletion signals.
void clearTarget()
Clears the current target design object.
TranslatedString m_title
The custom display title, if set.
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
bool hasMetaData(const StringView &index) const
Checks whether a metadata entry exists for the given key.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
static DynamicPointer< ManagedDesignCommand > SetProperty(NDPO design_property, const t_type &value)
Creates a command to set a design-level property to the given value.
static DynamicPointer< ManagedDesignCommand > SetMetadata(const String &label, const String &value)
Creates a command to set a metadata key-value pair on target objects.
void updatedSignal(UUID id)
Emitted when this object is updated.
void deletedSignal(UUID id)
Emitted when this object is deleted.
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.
Toggle(QWidget *parent=nullptr)
Constructs a Toggle with an optional parent widget.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
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).
@ meta_data
General-purpose metadata string for the object.