API Documentation
Loading...
Searching...
No Matches
DesignObjectStringWidget.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: DesignObjectStringWidget
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/QTDesignObject.h>
34#include <NDEVR/QCustomLineEdit.h>
35#include <NDEVR/RegexFunctions.h>
36namespace NDEVR
37{
38 /**--------------------------------------------------------------------------------------------------
39 \brief A widget allowing easy access to change the properties of a designObject by taking user
40 string input.
41 **/
43 {
44 Q_OBJECT
45 public:
46 DesignObjectStringWidget(QWidget* parent = nullptr)
47 : QCustomLineEdit(parent)
48 , m_property(DesignObject::e_design_property_size)
49 {
50 connect(this, &QCustomLineEdit::editingFinishedSignal, this, &DesignObjectStringWidget::sendCommand);
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, &DesignObjectStringWidget::onObjectUpdatedSlot);
68 disconnect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectStringWidget::onObjectDeletedSlot);
69 }
70 m_target = object;
71 if (!m_target.isNull())
72 {
73 connect(&m_target.get(), &QTDesignObject::updatedSignal, this, &DesignObjectStringWidget::onObjectUpdatedSlot);
74 connect(&m_target.get(), &QTDesignObject::deletedSignal, this, &DesignObjectStringWidget::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 setWindowTitle(String(m_meta_data).formatAsTitleString().getAs<QString>());
86 else
87 setWindowTitle(String(String::DisplayString(property).translation()).formatAsTitleString().getAs<QString>());
88 }
89 onObjectUpdatedSlot();
90 switch (property)
91 {
92 case DesignObject::DesignProperty::e_file:
93 customValidator().setRegex(RegexFunctions::FileRegex());
94 break;
95 default:
96 //customValidator().setRegex(/*"^[\\.a-zA-Z0-9_\\s-]+$"*/);
97 break;
98 }
99 }
100 void setupForMetadata(TranslatedString title, const String& metadata)
101 {
102 m_title = title;
103 m_meta_data = metadata;
104 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
105 }
106 void setupForMetadata(const String& metadata)
107 {
108 m_meta_data = metadata;
109 setDesignProperty(DesignObject::DesignProperty::e_meta_data);
110 }
111 void setTitle(const TranslatedString& title) override
112 {
113 m_title = title;
114 if (m_title.isEmpty() == 0)
115 {
116 if (m_property == DesignObject::DesignProperty::e_meta_data)
117 QCustomLineEdit::setTitle(TranslatedString(String(m_meta_data).formatAsTitleString()));
118 else
119 QCustomLineEdit::setTitle(String::DisplayString(m_property));
120 }
121 else
122 {
123 QCustomLineEdit::setTitle(title);
124 }
125 }
126 protected slots:
128 {
130 }
133 protected:
137 };
138}
139
#define NDEVR_API
Definition DLLInfo.h:50
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
DesignProperty
Values stored in the property database.
Definition DesignObject.h:93
A widget allowing easy access to change the properties of a designObject by taking user string input.
Definition DesignObjectStringWidget.h:43
void setupForMetadata(TranslatedString title, const String &metadata)
Definition DesignObjectStringWidget.h:100
DesignObject::DesignProperty m_property
Definition DesignObjectStringWidget.h:134
DynamicPointer< QTDesignObject > m_target
Definition DesignObjectStringWidget.h:135
void setDesignProperty(DesignObject::DesignProperty property)
Definition DesignObjectStringWidget.h:79
void onObjectDeletedSlot()
Definition DesignObjectStringWidget.h:127
void setTitle(const TranslatedString &title) override
Definition DesignObjectStringWidget.h:111
void clearTarget()
Definition DesignObjectStringWidget.h:52
String m_meta_data
Definition DesignObjectStringWidget.h:136
DesignObjectStringWidget(QWidget *parent=nullptr)
Definition DesignObjectStringWidget.h:46
void setupForMetadata(const String &metadata)
Definition DesignObjectStringWidget.h:106
void setTarget(const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectStringWidget.h:61
void setTarget(DesignObject::DesignProperty property, const DynamicPointer< QTDesignObject > &object)
Definition DesignObjectStringWidget.h:56
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Definition QCustomLineEdit.h:56
The core String class for the NDEVR API.
Definition String.h:69
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