9#include <QtDesigner/abstractformwindow.h>
10#include <QtDesigner/abstractformwindowcursor.h>
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/qextensionmanager.h>
14#include <QtAxContainer/qaxselect.h>
16#include <QtWidgets/qmessagebox.h>
17#include <QtGui/qundostack.h>
19#include <QtGui/qaction.h>
21#include <QtCore/qt_windows.h>
22#include <QtCore/quuid.h>
28using namespace Qt::StringLiterals;
31
32
33
40 virtual void redo()
override { apply(m_newClsid); }
41 virtual void undo()
override { apply(m_oldClsid); }
44 bool apply(
const QString &clsid);
47 QDesignerFormWindowInterface *m_formWindow;
58 if (m_newClsid.isEmpty())
59 setText(QDesignerAxWidget::tr(
"Reset control"));
61 setText(QDesignerAxWidget::tr(
"Set control"));
66 if (m_oldClsid == m_newClsid)
69 QObject *ext = m_formWindow->core()->extensionManager()->extension(
70 m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension));
71 auto sheet = qobject_cast<QAxWidgetPropertySheet *>(ext);
75 const bool hasClsid = !clsid.isEmpty();
78 sheet->setProperty(index, clsid);
88 m_setAction(
new QAction(tr(
"Set Control"),
this)),
89 m_resetAction(
new QAction(tr(
"Reset Control"),
this))
91 connect(m_setAction, &QAction::triggered,
this, &QAxWidgetTaskMenu::setActiveXControl);
92 connect(m_resetAction, &QAction::triggered,
this, &
QAxWidgetTaskMenu::resetActiveXControl);
93 m_taskActions.push_back(m_setAction);
94 m_taskActions.push_back(m_resetAction);
102 m_setAction->setEnabled(!loaded);
103 m_resetAction->setEnabled(loaded);
104 return m_taskActions;
109 auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
110 Q_ASSERT(formWin !=
nullptr);
116 QAxSelect dialog(m_axwidget->topLevelWidget());
117 if (dialog.exec() != QDialog::Accepted)
120 const auto clsid = QUuid::fromString(dialog.clsid());
123 IClassFactory2 *cf2 =
nullptr;
124 CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2,
reinterpret_cast<
void **>(&cf2));
128 HRESULT hres = cf2->RequestLicKey(0, &bKey);
129 if (hres == CLASS_E_NOTLICENSED) {
130 QMessageBox::warning(m_axwidget->topLevelWidget(), tr(
"Licensed Control"),
131 tr(
"The control requires a design-time license"));
136 key = QString::fromWCharArray(bKey);
140 auto formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
142 Q_ASSERT(formWin !=
nullptr);
143 QString value = clsid.toString();
146 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.