diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-13 12:41:29 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypickbot@codereview.qt-project.org> | 2020-05-13 21:14:17 +0000 |
commit | 62999f3f6d432de97f0aedaffeb54596a6544aae (patch) | |
tree | a59b55e46c74b90072bee611a241e780dbcc3e02 | |
parent | 469202bcce523ac613449b02cd82cfa73c025a1e (diff) |
Qt Designer/Active Qt plugin: Polish the code a bit
Use auto, raw string literals, member initialization and
streamline a bit.
Change-Id: I08c49c40e3636fe711568c10a8f4cae226700a87
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 2a05e4cc6eba5a74e12563e77afa18d4548c9a3b)
Reviewed-by: Qt Cherry-pick Bot
7 files changed, 69 insertions, 76 deletions
diff --git a/src/designer/src/plugins/activeqt/qaxwidgetplugin.cpp b/src/designer/src/plugins/activeqt/qaxwidgetplugin.cpp index a29ba2f77..89cf96c2a 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgetplugin.cpp +++ b/src/designer/src/plugins/activeqt/qaxwidgetplugin.cpp @@ -42,8 +42,7 @@ QT_BEGIN_NAMESPACE QAxWidgetPlugin::QAxWidgetPlugin(QObject *parent) : - QObject(parent), - m_core(0) + QObject(parent) { } @@ -85,8 +84,9 @@ bool QAxWidgetPlugin::isContainer() const QWidget *QAxWidgetPlugin::createWidget(QWidget *parent) { // Construction from Widget box or on a form? - const bool isFormEditor = parent != 0 && QDesignerFormWindowInterface::findFormWindow(parent) != 0; - QDesignerAxWidget *rc = new QDesignerAxPluginWidget(parent); + const bool isFormEditor = parent != nullptr + && QDesignerFormWindowInterface::findFormWindow(parent) != nullptr; + auto rc = new QDesignerAxPluginWidget(parent); if (!isFormEditor) rc->setDrawFlags(QDesignerAxWidget::DrawFrame|QDesignerAxWidget::DrawControl); return rc; @@ -94,12 +94,12 @@ QWidget *QAxWidgetPlugin::createWidget(QWidget *parent) bool QAxWidgetPlugin::isInitialized() const { - return m_core != 0; + return m_core != nullptr; } void QAxWidgetPlugin::initialize(QDesignerFormEditorInterface *core) { - if (m_core != 0) + if (m_core != nullptr) return; m_core = core; @@ -113,19 +113,18 @@ void QAxWidgetPlugin::initialize(QDesignerFormEditorInterface *core) QString QAxWidgetPlugin::domXml() const { - return QStringLiteral("\ -<ui language=\"c++\">\ - <widget class=\"QAxWidget\" name=\"axWidget\">\ - <property name=\"geometry\">\ - <rect>\ - <x>0</x>\ - <y>0</y>\ - <width>80</width>\ - <height>70</height>\ - </rect>\ - </property>\ - </widget>\ -</ui>"); + return QStringLiteral(R"(<ui language="c++"> + <widget class="QAxWidget" name="axWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>80</width> + <height>70</height> + </rect> + </property> + </widget> +</ui>)"); } QT_END_NAMESPACE diff --git a/src/designer/src/plugins/activeqt/qaxwidgetplugin.h b/src/designer/src/plugins/activeqt/qaxwidgetplugin.h index 23311e90b..2d0cef249 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgetplugin.h +++ b/src/designer/src/plugins/activeqt/qaxwidgetplugin.h @@ -42,7 +42,7 @@ class QAxWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidget" FILE "activeqt.json") Q_INTERFACES(QDesignerCustomWidgetInterface) public: - explicit QAxWidgetPlugin(QObject *parent = 0); + explicit QAxWidgetPlugin(QObject *parent = nullptr); QString name() const override; QString group() const override; @@ -57,7 +57,7 @@ public: QString domXml() const override; private: - QDesignerFormEditorInterface *m_core; + QDesignerFormEditorInterface *m_core = nullptr; }; QT_END_NAMESPACE diff --git a/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp b/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp index 960316cf2..e1236b274 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp +++ b/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp @@ -130,7 +130,7 @@ int QAxWidgetPropertySheet::indexOf(const QString &name) const return index; // Loading before recreation of sheet in timer slot: Add a fake property to store the value const QVariant dummValue(0); - QAxWidgetPropertySheet *that = const_cast<QAxWidgetPropertySheet *>(this); + auto that = const_cast<QAxWidgetPropertySheet *>(this); const int newIndex = that->createFakeProperty(name, dummValue); that->setPropertyGroup(newIndex, m_propertyGroup); return newIndex; @@ -142,7 +142,7 @@ void QAxWidgetPropertySheet::updatePropertySheet() struct SavedProperties tmp = m_currentProperties; QDesignerAxWidget *axw = axWidget(); QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(axw); - Q_ASSERT(formWin != 0); + Q_ASSERT(formWin != nullptr); tmp.widget = axw; tmp.clsid = axw->control(); // Delete the sheets as they cache the meta object and other information @@ -151,16 +151,18 @@ void QAxWidgetPropertySheet::updatePropertySheet() reloadPropertySheet(tmp, formWin); } -void QAxWidgetPropertySheet::reloadPropertySheet(const struct SavedProperties &properties, QDesignerFormWindowInterface *formWin) +void QAxWidgetPropertySheet::reloadPropertySheet(const struct SavedProperties &properties, + QDesignerFormWindowInterface *formWin) { QDesignerFormEditorInterface *core = formWin->core(); //Recreation of the property sheet - QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension *>(core->extensionManager(), properties.widget); + auto sheet = qt_extension<QDesignerPropertySheetExtension *>(core->extensionManager(), + properties.widget); bool foundGeometry = false; const QString geometryProperty = QLatin1String(geometryPropertyC); - const SavedProperties::NamePropertyMap::const_iterator cend = properties.changedProperties.constEnd(); - for (SavedProperties::NamePropertyMap::const_iterator i = properties.changedProperties.constBegin(); i != cend; ++i) { + for (auto i = properties.changedProperties.cbegin(), cend = properties.changedProperties.cend(); + i != cend; ++i) { const QString name = i.key(); const int index = sheet->indexOf(name); if (index == -1) diff --git a/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp b/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp index 4e34f3872..ed94356ad 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp +++ b/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp @@ -86,8 +86,9 @@ bool SetControlCommand::apply(const QString &clsid) if (m_oldClsid == m_newClsid) return true; - QObject *ext = m_formWindow->core()->extensionManager()->extension(m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension)); - QAxWidgetPropertySheet *sheet = qobject_cast<QAxWidgetPropertySheet*>(ext); + QObject *ext = m_formWindow->core()->extensionManager()->extension( + m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension)); + auto sheet = qobject_cast<QAxWidgetPropertySheet *>(ext); if (!sheet) return false; @@ -113,9 +114,7 @@ QAxWidgetTaskMenu::QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent) m_taskActions.push_back(m_resetAction); } -QAxWidgetTaskMenu::~QAxWidgetTaskMenu() -{ -} +QAxWidgetTaskMenu::~QAxWidgetTaskMenu() = default; QList<QAction*> QAxWidgetTaskMenu::taskActions() const { @@ -127,48 +126,46 @@ QList<QAction*> QAxWidgetTaskMenu::taskActions() const void QAxWidgetTaskMenu::resetActiveXControl() { - QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); - Q_ASSERT(formWin != 0); + auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); + Q_ASSERT(formWin != nullptr); formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin)); } void QAxWidgetTaskMenu::setActiveXControl() { - QAxSelect *dialog = new QAxSelect(m_axwidget->topLevelWidget()); - if (dialog->exec()) { - QUuid clsid = dialog->clsid(); - QString key; - - IClassFactory2 *cf2 = 0; - CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2, (void**)&cf2); - - if (cf2) { - BSTR bKey; - HRESULT hres = cf2->RequestLicKey(0, &bKey); - if (hres == CLASS_E_NOTLICENSED) { - QMessageBox::warning(m_axwidget->topLevelWidget(), tr("Licensed Control"), - tr("The control requires a design-time license")); - clsid = QUuid(); - } else { - key = QString::fromWCharArray(bKey); - } - + QAxSelect dialog(m_axwidget->topLevelWidget()); + if (dialog.exec() != QDialog::Accepted) + return; + + QUuid clsid = dialog.clsid(); + QString key; + + IClassFactory2 *cf2 = nullptr; + CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2, reinterpret_cast<void **>(&cf2)); + + if (cf2) { + BSTR bKey; + HRESULT hres = cf2->RequestLicKey(0, &bKey); + if (hres == CLASS_E_NOTLICENSED) { + QMessageBox::warning(m_axwidget->topLevelWidget(), tr("Licensed Control"), + tr("The control requires a design-time license")); cf2->Release(); + return; } - if (!clsid.isNull()) { - QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); + key = QString::fromWCharArray(bKey); + cf2->Release(); + } - Q_ASSERT(formWin != 0); - QString value = clsid.toString(); - if (!key.isEmpty()) { - value += QLatin1Char(':'); - value += key; - } - formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin, value)); - } + auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); + + Q_ASSERT(formWin != nullptr); + QString value = clsid.toString(); + if (!key.isEmpty()) { + value += QLatin1Char(':'); + value += key; } - delete dialog; + formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin, value)); } QT_END_NAMESPACE diff --git a/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.h b/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.h index e1cf40af6..ea76dcd5a 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.h +++ b/src/designer/src/plugins/activeqt/qaxwidgettaskmenu.h @@ -41,7 +41,7 @@ class QAxWidgetTaskMenu: public QObject, public QDesignerTaskMenuExtension Q_OBJECT Q_INTERFACES(QDesignerTaskMenuExtension) public: - explicit QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent = 0); + explicit QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent = nullptr); virtual ~QAxWidgetTaskMenu(); QList<QAction*> taskActions() const override; diff --git a/src/designer/src/plugins/activeqt/qdesigneraxwidget.cpp b/src/designer/src/plugins/activeqt/qdesigneraxwidget.cpp index 9ce14ed81..d51e8cdf9 100644 --- a/src/designer/src/plugins/activeqt/qdesigneraxwidget.cpp +++ b/src/designer/src/plugins/activeqt/qdesigneraxwidget.cpp @@ -78,9 +78,6 @@ const char *widgetIconXPM[]={ QDesignerAxWidget::QDesignerAxWidget(QWidget *parent) : QWidget(parent), - m_defaultSize(80, 70), - m_drawFlags(DrawIndicator|DrawFrame|DrawControl), - m_axobject(0), m_axImage(widgetIcon()) { } @@ -117,7 +114,7 @@ void QDesignerAxWidget::resetControl() if (!m_axobject) return; delete m_axobject; - m_axobject = 0; + m_axobject = nullptr; update(); } @@ -131,7 +128,7 @@ bool QDesignerAxWidget::loadControl(const QString &clsid) if (!m_axobject->setControl(clsid)) { delete m_axobject; - m_axobject = 0; + m_axobject = nullptr; return false; } update(); @@ -190,9 +187,7 @@ QDesignerAxPluginWidget::QDesignerAxPluginWidget(QWidget *parent) : { } -QDesignerAxPluginWidget::~QDesignerAxPluginWidget() -{ -} +QDesignerAxPluginWidget::~QDesignerAxPluginWidget() = default; const QMetaObject *QDesignerAxPluginWidget::metaObject() const { diff --git a/src/designer/src/plugins/activeqt/qdesigneraxwidget.h b/src/designer/src/plugins/activeqt/qdesigneraxwidget.h index 3c15763da..8f74bfaea 100644 --- a/src/designer/src/plugins/activeqt/qdesigneraxwidget.h +++ b/src/designer/src/plugins/activeqt/qdesigneraxwidget.h @@ -84,9 +84,9 @@ protected: QAxWidget *axobject() const { return m_axobject; } private: - const QSize m_defaultSize; - unsigned m_drawFlags; - QAxWidget *m_axobject; + const QSize m_defaultSize { 80, 70 }; + unsigned m_drawFlags = DrawIndicator | DrawFrame | DrawControl; + QAxWidget *m_axobject = nullptr; QPixmap m_axImage; }; |