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