QExtensionManager Class
QExtensionManager クラスはQt Widgets Designer の拡張機能管理機能を提供します。詳細...
ヘッダー | #include <QExtensionManager> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Designer) target_link_libraries(mytarget PRIVATE Qt6::Designer) |
qmake: | QT += designer |
を継承する: | QObject そしてQAbstractExtensionManager |
パブリック関数
QExtensionManager(QObject *parent = nullptr) | |
virtual | ~QExtensionManager() |
再実装されたパブリック関数
virtual QObject * | extension(QObject *object, const QString &iid) const override |
virtual void | registerExtensions(QAbstractExtensionFactory *factory, const QString &iid = QString()) override |
virtual void | unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid = QString()) override |
関連する非メンバー
T | qt_extension(QAbstractExtensionManager *manager, QObject *object) |
マクロ
Q_DECLARE_EXTENSION_INTERFACE(ExtensionName, Identifier) |
詳細説明
Qt Widgets Designerでは、エクステンションは必要になるまで作成されません。そのため、エクステンションを実装する場合は、QExtensionFactory 、つまりエクステンションのインスタンスを作成できるクラスを作成し、Qt Widgets Designerのエクステンションマネージャを使用して登録する必要があります。
拡張機能ファクトリの登録は通常、QDesignerCustomWidgetInterface::initialize() 関数で行います:
void MyPlugin::initialize(QDesignerFormEditorInterface *formEditor) { if (initialized) return; auto *manager = formEditor->extensionManager(); Q_ASSERT(manager != nullptr); manager->registerExtensions(new MyExtensionFactory(manager), Q_TYPEID(QDesignerTaskMenuExtension)); initialized = true; }
QExtensionManagerは直接インスタンス化することを意図していません。QDesignerFormEditorInterface::extensionManager() 関数を使用して、Qt Widgets Designer の拡張機能マネージャへのインターフェイスを取得できます。Qt Widgets Designerの現在のQDesignerFormEditorInterface オブジェクト(上記の例ではformEditor
)へのポインタは、QDesignerCustomWidgetInterface::initialize ()関数のパラメータで提供されます。カスタムウィジェットプラグインを実装する場合、QDesignerCustomWidgetInterface をサブクラス化してプラグインをQt Widgets Designer に公開する必要があります。
その後、拡張機能が必要になると、Qt Widgets Designer の拡張機能マネージャは、選択されたオブジェクトに対して要求された拡張機能を作成できる最初のファクトリが見つかるまで、登録されているすべてのファクトリに対してQExtensionFactory::createExtension() を呼び出します。このファクトリがエクステンションのインスタンスを作成します。
Qt Widgets Designerでは4種類のエクステンションを使用できます: QDesignerContainerExtension QDesignerMemberSheetExtension ,QDesignerPropertySheetExtension およびQDesignerTaskMenuExtension 。 Qt Widgets Designerの動作は、要求されたエクステンションがコンテナ、メンバーシート、プロパティシート、タスクメニューのいずれに関連付けられていても同じです。
QExtensionManager クラスを使用した完全な例については、タスク・メニュー拡張の例を参照してください。この例では、Qt Designer のカスタムウィジェットプラグインを作成する方法と、QDesignerTaskMenuExtension クラスを使用してQt Widgets Designer のタスクメニューにカスタム項目を追加する方法を示します。
QExtensionFactory およびQAbstractExtensionManagerも参照して ください。
メンバ関数のドキュメント
[explicit]
QExtensionManager::QExtensionManager(QObject *parent = nullptr)
与えられたparent で拡張マネージャを構築します。
[virtual noexcept]
QExtensionManager::~QExtensionManager()
拡張機能マネージャーを破壊する
[override virtual]
QObject *QExtensionManager::extension(QObject *object, const QString &iid) const
再実装:QAbstractExtensionManager::extension(QObject *object, const QString &iid) const.
与えられたobject に対して、iid で指定された拡張子を返します。
[override virtual]
void QExtensionManager::registerExtensions(QAbstractExtensionFactory *factory, const QString &iid = QString())
再実装:QAbstractExtensionManager::registerExtensions(QAbstractExtensionFactory *factory, const QString &iid)。
与えられたfactory と拡張機能識別子iid で指定された拡張機能を登録します。
[override virtual]
void QExtensionManager::unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid = QString())
再実装:QAbstractExtensionManager::unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid)。
与えられたfactory と拡張識別子iid で指定された拡張機能の登録を解除します。
関連する非会員
template <typename T> T qt_extension(QAbstractExtensionManager *manager, QObject *object)
オブジェクトが T 型(またはサブクラス)の場合、与えられたobject を T 型にキャストした拡張子を返し、そうでない場合は 0 を返します。拡張子は、与えられた拡張子manager を使用して取得されます。
auto *manager = formEditor->extensionManager(); auto *propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget); if(propertySheet) {...}
カスタムウィジェットプラグインを実装する場合、Qt Widgets Designer の現在のQDesignerFormEditorInterface オブジェクト (formEditor
) へのポインタは、QDesignerCustomWidgetInterface::initialize() 関数のパラメータで提供されます。
上記の例のウィジェットにQDesignerPropertySheetExtension が定義されていない場合、propertySheet
は NULL ポインタになります。
マクロ・ドキュメント
Q_DECLARE_EXTENSION_INTERFACE(ExtensionName, Identifier)
与えられたIdentifier (文字列リテラル)をExtensionName という拡張クラスに関連付けます。Identifier は一意でなければなりません。例えば
Q_DECLARE_EXTENSION_INTERFACE(MyExtension, "com.mycompany.myproduct.myextension")
識別子の一意性を保証するには、会社名と商品名を使用するのがよい方法です。
カスタム拡張クラスを実装する場合は、Q_DECLARE_EXTENSION_INTERFACE() を使用してqt_extension() 関数を使用できるようにする必要があります。このマクロは通常、関連するヘッダー・ファイルのExtensionName のクラス定義の直後にあります。
Q_DECLARE_INTERFACE()も参照してください 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.