Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
newdynamicpropertydialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
6#include "ui_newdynamicpropertydialog.h"
7#include <abstractdialoggui_p.h>
8#include <qdesigner_propertysheet_p.h>
9
10#include <QtWidgets/qpushbutton.h>
11
12QT_BEGIN_NAMESPACE
13
14using namespace Qt::StringLiterals;
15
16namespace qdesigner_internal {
17
18NewDynamicPropertyDialog::NewDynamicPropertyDialog(QDesignerDialogGuiInterface *dialogGui,
19 QWidget *parent) :
20 QDialog(parent),
21 m_dialogGui(dialogGui),
22 m_ui(new QT_PREPEND_NAMESPACE(qdesigner_internal)::Ui::NewDynamicPropertyDialog)
23{
24 m_ui->setupUi(this);
25 connect(m_ui->m_lineEdit, &QLineEdit::textChanged, this, &NewDynamicPropertyDialog::nameChanged);
26 connect(m_ui->m_buttonBox, &QDialogButtonBox::clicked,
27 this, &NewDynamicPropertyDialog::buttonBoxClicked);
28
29 m_ui->m_comboBox->addItem(u"String"_s,
30 QVariant(QMetaType(QMetaType::QString)));
31 m_ui->m_comboBox->addItem(u"StringList"_s,
32 QVariant(QMetaType(QMetaType::QStringList)));
33 m_ui->m_comboBox->addItem(u"Char"_s,
34 QVariant(QMetaType(QMetaType::QChar)));
35 m_ui->m_comboBox->addItem(u"ByteArray"_s,
36 QVariant(QMetaType(QMetaType::QByteArray)));
37 m_ui->m_comboBox->addItem(u"Url"_s,
38 QVariant(QMetaType(QMetaType::QUrl)));
39 m_ui->m_comboBox->addItem(u"Bool"_s,
40 QVariant(QMetaType(QMetaType::Bool)));
41 m_ui->m_comboBox->addItem(u"Int"_s,
42 QVariant(QMetaType(QMetaType::Int)));
43 m_ui->m_comboBox->addItem(u"UInt"_s,
44 QVariant(QMetaType(QMetaType::UInt)));
45 m_ui->m_comboBox->addItem(u"LongLong"_s,
46 QVariant(QMetaType(QMetaType::LongLong)));
47 m_ui->m_comboBox->addItem(u"ULongLong"_s,
48 QVariant(QMetaType(QMetaType::ULongLong)));
49 m_ui->m_comboBox->addItem(u"Double"_s,
50 QVariant(QMetaType(QMetaType::Double)));
51 m_ui->m_comboBox->addItem(u"Size"_s,
52 QVariant(QMetaType(QMetaType::QSize)));
53 m_ui->m_comboBox->addItem(u"SizeF"_s,
54 QVariant(QMetaType(QMetaType::QSizeF)));
55 m_ui->m_comboBox->addItem(u"Point"_s,
56 QVariant(QMetaType(QMetaType::QPoint)));
57 m_ui->m_comboBox->addItem(u"PointF"_s,
58 QVariant(QMetaType(QMetaType::QPointF)));
59 m_ui->m_comboBox->addItem(u"Rect"_s,
60 QVariant(QMetaType(QMetaType::QRect)));
61 m_ui->m_comboBox->addItem(u"RectF"_s,
62 QVariant(QMetaType(QMetaType::QRectF)));
63 m_ui->m_comboBox->addItem(u"Date"_s,
64 QVariant(QMetaType(QMetaType::QDate)));
65 m_ui->m_comboBox->addItem(u"Time"_s,
66 QVariant(QMetaType(QMetaType::QTime)));
67 m_ui->m_comboBox->addItem(u"DateTime"_s,
68 QVariant(QMetaType(QMetaType::QDateTime)));
69 m_ui->m_comboBox->addItem(u"Font"_s,
70 QVariant(QMetaType(QMetaType::QFont)));
71 m_ui->m_comboBox->addItem(u"Palette"_s,
72 QVariant(QMetaType(QMetaType::QPalette)));
73 m_ui->m_comboBox->addItem(u"Color"_s,
74 QVariant(QMetaType(QMetaType::QColor)));
75 m_ui->m_comboBox->addItem(u"Pixmap"_s,
76 QVariant(QMetaType(QMetaType::QPixmap)));
77 m_ui->m_comboBox->addItem(u"Icon"_s,
78 QVariant(QMetaType(QMetaType::QIcon)));
79 m_ui->m_comboBox->addItem(u"Cursor"_s,
80 QVariant(QMetaType(QMetaType::QCursor)));
81 m_ui->m_comboBox->addItem(u"SizePolicy"_s,
82 QVariant(QMetaType(QMetaType::QSizePolicy)));
83 m_ui->m_comboBox->addItem(u"KeySequence"_s,
84 QVariant(QMetaType(QMetaType::QKeySequence)));
85
86 m_ui->m_comboBox->setCurrentIndex(0); // String
87 setOkButtonEnabled(false);
88}
89
90void NewDynamicPropertyDialog::setOkButtonEnabled(bool e)
91{
92 m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(e);
93}
94
99
100void NewDynamicPropertyDialog::setReservedNames(const QStringList &names)
101{
102 m_reservedNames = names;
103}
104
106{
107 const int index = m_ui->m_comboBox->findData(QVariant(QMetaType(t)));
108 if (index != -1)
109 m_ui->m_comboBox->setCurrentIndex(index);
110}
111
113{
114 return m_ui->m_lineEdit->text();
115}
116
118{
119 const int index = m_ui->m_comboBox->currentIndex();
120 if (index == -1)
121 return QVariant();
122 return m_ui->m_comboBox->itemData(index);
123}
124
125void NewDynamicPropertyDialog::information(const QString &message)
126{
127 m_dialogGui->message(this, QDesignerDialogGuiInterface::PropertyEditorMessage, QMessageBox::Information, tr("Set Property Name"), message);
128}
129
130void NewDynamicPropertyDialog::nameChanged(const QString &s)
131{
132 setOkButtonEnabled(!s.isEmpty());
133}
134
135bool NewDynamicPropertyDialog::validatePropertyName(const QString& name)
136{
137 if (m_reservedNames.contains(name)) {
138 information(tr("The current object already has a property named '%1'.\nPlease select another, unique one.").arg(name));
139 return false;
140 }
141 if (!QDesignerPropertySheet::internalDynamicPropertiesEnabled() && name.startsWith("_q_"_L1)) {
142 information(tr("The '_q_' prefix is reserved for the Qt library.\nPlease select another name."));
143 return false;
144 }
145 return true;
146}
147
148void NewDynamicPropertyDialog::buttonBoxClicked(QAbstractButton *btn)
149{
150 const int role = m_ui->m_buttonBox->buttonRole(btn);
151 switch (role) {
152 case QDialogButtonBox::RejectRole:
153 reject();
154 break;
155 case QDialogButtonBox::AcceptRole:
156 if (validatePropertyName(propertyName()))
157 accept();
158 break;
159 }
160}
161}
162
163QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
Auxiliary methods to store/retrieve settings.