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