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
4#include <QtGui/qaction.h>
5
8
9#include <iconloader_p.h>
10
11#include <QtDesigner/abstractformwindow.h>
12#include <QtDesigner/abstractformwindowmanager.h>
13#include <QtDesigner/abstractformeditor.h>
14
16
17using namespace Qt::StringLiterals;
18
19namespace qdesigner_internal {
20
21BuddyEditorPlugin::BuddyEditorPlugin() = default;
22
24
26{
27 return m_initialized;
28}
29
30void BuddyEditorPlugin::initialize(QDesignerFormEditorInterface *core)
31{
32 Q_ASSERT(!isInitialized());
33
34 m_action = new QAction(tr("Edit Buddies"), this);
35 m_action->setObjectName(u"__qt_edit_buddies_action"_s);
36 m_action->setIcon(createIconSet("buddytool.png"_L1));
37 m_action->setEnabled(false);
38
39 setParent(core);
40 m_core = core;
41 m_initialized = true;
42
43 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::formWindowAdded,
44 this, &BuddyEditorPlugin::addFormWindow);
45
46 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::formWindowRemoved,
47 this, &BuddyEditorPlugin::removeFormWindow);
48
49 connect(core->formWindowManager(), &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
50 this, &BuddyEditorPlugin::activeFormWindowChanged);
51}
52
53QDesignerFormEditorInterface *BuddyEditorPlugin::core() const
54{
55 return m_core;
56}
57
58void BuddyEditorPlugin::addFormWindow(QDesignerFormWindowInterface *formWindow)
59{
60 Q_ASSERT(formWindow != nullptr);
61 Q_ASSERT(m_tools.contains(formWindow) == false);
62
63 BuddyEditorTool *tool = new BuddyEditorTool(formWindow, this);
64 m_tools[formWindow] = tool;
65 connect(m_action, &QAction::triggered, tool->action(), &QAction::trigger);
66 formWindow->registerTool(tool);
67}
68
69void BuddyEditorPlugin::removeFormWindow(QDesignerFormWindowInterface *formWindow)
70{
71 Q_ASSERT(formWindow != nullptr);
72 Q_ASSERT(m_tools.contains(formWindow) == true);
73
74 BuddyEditorTool *tool = m_tools.value(formWindow);
75 m_tools.remove(formWindow);
76 disconnect(m_action, &QAction::triggered, tool->action(), &QAction::trigger);
77 // ### FIXME disable the tool
78
79 delete tool;
80}
81
82QAction *BuddyEditorPlugin::action() const
83{
84 return m_action;
85}
86
87void BuddyEditorPlugin::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
88{
89 m_action->setEnabled(formWindow != nullptr);
90}
91
92} // namespace qdesigner_internal
93
94QT_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.
Auxiliary methods to store/retrieve settings.