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
qaxwidgetpropertysheet.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <QtDesigner/membersheet.h>
9#include <QtDesigner/abstractformwindow.h>
10#include <QtDesigner/abstractformeditor.h>
11#include <QtDesigner/abstractpropertyeditor.h>
12
13#include <QtDesigner/qextensionmanager.h>
14#include <private/qdesigner_utils_p.h>
15#include <QtCore/qdebug.h>
16#include <QtCore/qtimer.h>
17
19
20using namespace Qt::StringLiterals;
21
22const char *QAxWidgetPropertySheet::controlPropertyName = "control";
23
24static QString designerPropertyToString(const QVariant &value)
25{
26 return value.canConvert<qdesigner_internal::PropertySheetStringValue>() ?
27 qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value).value() :
28 value.toString();
29}
30
31QAxWidgetPropertySheet::QAxWidgetPropertySheet(QDesignerAxWidget *object, QObject *parent) :
32 QDesignerPropertySheet(object, parent),
33 m_controlProperty(controlPropertyName),
34 m_propertyGroup(u"QAxWidget"_s)
35{
36 if (!axWidget()->loaded()) { // For some obscure reason....
37 const int controlIndex = QDesignerPropertySheet::indexOf(m_controlProperty);
38 setPropertyGroup(controlIndex, m_propertyGroup);
39 }
40}
41
42bool QAxWidgetPropertySheet::isEnabled(int index) const
43{
44 if (propertyName(index) == m_controlProperty)
45 return false;
46 return QDesignerPropertySheet::isEnabled(index);
47}
48
49bool QAxWidgetPropertySheet::isVisible(int index) const
50{
51 // classContext is ulong, which the property editor does not support
52 return propertyName(index) != "classContext"_L1;
53}
54
56{
57 return false;
58}
59
61{
62 return static_cast<QDesignerAxWidget*>(object());
63}
64
65// Reload as the meta object changes.
67{
68 const QString name = propertyName(index);
69 const auto it = m_currentProperties.changedProperties.find(name);
70 if (it != m_currentProperties.changedProperties.end())
71 m_currentProperties.changedProperties.erase(it);
72 if (name != m_controlProperty)
73 return QDesignerPropertySheet::reset(index);
74 axWidget()->resetControl();
75 QTimer::singleShot(0, this, &QAxWidgetPropertySheet::updatePropertySheet);
76 return true;
77}
78
80{
81 // QTBUG-34592, accessing the 'control' property via meta object system
82 // may cause crashes during loading for some controls.
83 return propertyName(index) == m_controlProperty ?
84 QVariant(axWidget()->control()) :
85 QDesignerPropertySheet::property(index);
86}
87
88void QAxWidgetPropertySheet::setProperty(int index, const QVariant &value)
89{
90
91 // take care of all changed properties
92 const QString name = propertyName(index);
93 m_currentProperties.changedProperties[name] = value;
94 if (name != m_controlProperty) {
95 QDesignerPropertySheet::setProperty(index, value);
96 return;
97 }
98 // Loading forms: Reload
99 if (name == m_controlProperty) {
100 const QString clsid = designerPropertyToString(value);
101 if (clsid.isEmpty() || !axWidget()->loadControl(clsid))
102 reset(index);
103 else
104 QTimer::singleShot(100, this, &QAxWidgetPropertySheet::updatePropertySheet);
105 }
106}
107
108int QAxWidgetPropertySheet::indexOf(const QString &name) const
109{
110 const int index = QDesignerPropertySheet::indexOf(name);
111 if (index != -1)
112 return index;
113 // Loading before recreation of sheet in timer slot: Add a fake property to store the value
114 const QVariant dummValue(0);
115 auto that = const_cast<QAxWidgetPropertySheet *>(this);
116 const int newIndex = that->createFakeProperty(name, dummValue);
117 that->setPropertyGroup(newIndex, m_propertyGroup);
118 return newIndex;
119}
120
121void QAxWidgetPropertySheet::updatePropertySheet()
122{
123 // refresh the property sheet (we are deleting m_currentProperties)
124 struct SavedProperties tmp = m_currentProperties;
125 QDesignerAxWidget *axw = axWidget();
126 QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(axw);
127 Q_ASSERT(formWin != nullptr);
128 tmp.widget = axw;
129 tmp.clsid = axw->control();
130 // Delete the sheets as they cache the meta object and other information
131 delete this;
132 delete qt_extension<QDesignerMemberSheetExtension *>(formWin->core()->extensionManager(), axw);
133 reloadPropertySheet(tmp, formWin);
134}
135
136void QAxWidgetPropertySheet::reloadPropertySheet(const struct SavedProperties &properties,
137 QDesignerFormWindowInterface *formWin)
138{
139 QDesignerFormEditorInterface *core = formWin->core();
140 //Recreation of the property sheet
141 auto sheet = qt_extension<QDesignerPropertySheetExtension *>(core->extensionManager(),
142 properties.widget);
143
144 bool foundGeometry = false;
145 const QString geometryProperty = "geometry"_L1;
146 for (auto i = properties.changedProperties.cbegin(), cend = properties.changedProperties.cend();
147 i != cend; ++i) {
148 const QString name = i.key();
149 const int index = sheet->indexOf(name);
150 if (index == -1)
151 continue;
152 // filter out geometry as this will resize the control
153 // to is default size even if it is attached to an layout
154 // but set the changed flag to work around preview bug...
155 if (name == geometryProperty) {
156 sheet->setChanged(index, true);
157 foundGeometry = true;
158 continue;
159 }
160 if (name == QLatin1String(controlPropertyName)) {
161 sheet->setChanged(index, !designerPropertyToString(i.value()).isEmpty());
162 continue;
163 }
164 sheet->setChanged(index, true);
165 sheet->setProperty(index, i.value());
166 }
167
168 if (!foundGeometry) // Make sure geometry is always changed in Designer
169 sheet->setChanged(sheet->indexOf(geometryProperty), true);
170
171 if (core->propertyEditor()->object() == properties.widget) {
172 formWin->clearSelection(true);
173 formWin->selectWidget(properties.widget);
174 }
175}
176
177QT_END_NAMESPACE
int indexOf(const QString &name) const override
void setProperty(int index, const QVariant &value) override
bool reset(int index) override
bool dynamicPropertiesAllowed() const override
bool isEnabled(int index) const override
QVariant property(int index) const override
static const char * controlPropertyName
bool isVisible(int index) const override
Combined button and popup list for selecting options.
static QString designerPropertyToString(const QVariant &value)