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
buddyeditor_plugin.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
5#include <QtGui/qaction.h>
6
9
10#include <iconloader_p.h>
11
12#include <QtDesigner/abstractformwindow.h>
13#include <QtDesigner/abstractformwindowmanager.h>
14#include <QtDesigner/abstractformeditor.h>
15
17
18using namespace Qt::StringLiterals;
19
20namespace qdesigner_internal {
21
22BuddyEditorPlugin::BuddyEditorPlugin() = default;
23
25
27{
28 return m_initialized;
29}
30
31void BuddyEditorPlugin::initialize(QDesignerFormEditorInterface *core)
32{
33 Q_ASSERT(!isInitialized());
34
35 m_action = new QAction(tr("Edit Buddies"), this);
36 m_action->setObjectName(u"__qt_edit_buddies_action"_s);
37 m_action->setIcon(createIconSet("buddytool.png"_L1));
38 m_action->setEnabled(false);
39
40 setParent(core);
41 m_core = core;
42 m_initialized = true;
43
44 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::formWindowAdded,
45 this, &BuddyEditorPlugin::addFormWindow);
46
47 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::formWindowRemoved,
48 this, &BuddyEditorPlugin::removeFormWindow);
49
50 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
51 this, &BuddyEditorPlugin::activeFormWindowChanged);
52}
53
54QDesignerFormEditorInterface *BuddyEditorPlugin::core() const
55{
56 return m_core;
57}
58
59void BuddyEditorPlugin::addFormWindow(QDesignerFormWindowInterface *formWindow)
60{
61 Q_ASSERT(formWindow != nullptr);
62 Q_ASSERT(m_tools.contains(formWindow) == false);
63
64 BuddyEditorTool *tool = new BuddyEditorTool(formWindow, this);
65 m_tools[formWindow] = tool;
66 connect(m_action, &QAction::triggered, tool->action(), &QAction::trigger);
67 formWindow->registerTool(tool);
68}
69
70void BuddyEditorPlugin::removeFormWindow(QDesignerFormWindowInterface *formWindow)
71{
72 Q_ASSERT(formWindow != nullptr);
73 Q_ASSERT(m_tools.contains(formWindow) == true);
74
75 BuddyEditorTool *tool = m_tools.value(formWindow);
76 m_tools.remove(formWindow);
77 disconnect(m_action, &QAction::triggered, tool->action(), &QAction::trigger);
78 // ### FIXME disable the tool
79
80 delete tool;
81}
82
83QAction *BuddyEditorPlugin::action() const
84{
85 return m_action;
86}
87
88void BuddyEditorPlugin::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
89{
90 m_action->setEnabled(formWindow != nullptr);
91}
92
93} // namespace qdesigner_internal
94
95QT_END_NAMESPACE
bool isInitialized() const override
Returns true if the plugin interface is initialized; otherwise returns false.
QDesignerFormEditorInterface * core() const override
Returns the core form editor interface associated with this component.
QAction * action() const override
Returns the action associated with this interface.
QAction * action() const override
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.