8#include <QtDesigner/abstractformwindow.h>
9#include <QtDesigner/abstractformwindowcursor.h>
10#include <QtDesigner/abstractformeditor.h>
11#include <QtDesigner/qextensionmanager.h>
13#include <QtAxContainer/qaxselect.h>
15#include <QtWidgets/qmessagebox.h>
16#include <QtGui/qundostack.h>
18#include <QtGui/qaction.h>
20#include <QtCore/qt_windows.h>
21#include <QtCore/quuid.h>
27using namespace Qt::StringLiterals;
30
31
32
39 virtual void redo()
override { apply(m_newClsid); }
40 virtual void undo()
override { apply(m_oldClsid); }
43 bool apply(
const QString &clsid);
46 QDesignerFormWindowInterface *m_formWindow;
57 if (m_newClsid.isEmpty())
58 setText(QDesignerAxWidget::tr(
"Reset control"));
60 setText(QDesignerAxWidget::tr(
"Set control"));
65 if (m_oldClsid == m_newClsid)
68 QObject *ext = m_formWindow->core()->extensionManager()->extension(
69 m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension));
70 auto sheet = qobject_cast<QAxWidgetPropertySheet *>(ext);
74 const bool hasClsid = !clsid.isEmpty();
77 sheet->setProperty(index, clsid);
87 m_setAction(
new QAction(tr(
"Set Control"),
this)),
88 m_resetAction(
new QAction(tr(
"Reset Control"),
this))
90 connect(m_setAction, &QAction::triggered,
this, &QAxWidgetTaskMenu::setActiveXControl);
91 connect(m_resetAction, &QAction::triggered,
this, &QAxWidgetTaskMenu::resetActiveXControl);
92 m_taskActions.push_back(m_setAction);
93 m_taskActions.push_back(m_resetAction);
101 m_setAction->setEnabled(!loaded);
102 m_resetAction->setEnabled(loaded);
103 return m_taskActions;
108 auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
109 Q_ASSERT(formWin !=
nullptr);
115 QAxSelect dialog(m_axwidget->topLevelWidget());
116 if (dialog.exec() != QDialog::Accepted)
119 const auto clsid = QUuid::fromString(dialog.clsid());
122 IClassFactory2 *cf2 =
nullptr;
123 CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2,
reinterpret_cast<
void **>(&cf2));
127 HRESULT hres = cf2->RequestLicKey(0, &bKey);
128 if (hres == CLASS_E_NOTLICENSED) {
129 QMessageBox::warning(m_axwidget->topLevelWidget(), tr(
"Licensed Control"),
130 tr(
"The control requires a design-time license"));
135 key = QString::fromWCharArray(bKey);
139 auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
141 Q_ASSERT(formWin !=
nullptr);
142 QString value = clsid.toString();
145 formWin->commandHistory()->push(
new SetControlCommand(m_axwidget, formWin, value));
virtual void redo() override
Applies a change to the document.
virtual void undo() override
Reverts a change to the document.
SetControlCommand(QDesignerAxWidget *ax, QDesignerFormWindowInterface *core, const QString &newClsid=QString())
Combined button and popup list for selecting options.