1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "signalsloteditor_plugin.h"
30#include "signalsloteditor_tool.h"
31
32#include <QtDesigner/abstractformeditor.h>
33#include <QtDesigner/abstractformwindowmanager.h>
34
35#include <QtWidgets/qaction.h>
36
37QT_BEGIN_NAMESPACE
38
39using namespace qdesigner_internal;
40
41SignalSlotEditorPlugin::SignalSlotEditorPlugin() = default;
42
43SignalSlotEditorPlugin::~SignalSlotEditorPlugin() = default;
44
45bool SignalSlotEditorPlugin::isInitialized() const
46{
47 return m_initialized;
48}
49
50void SignalSlotEditorPlugin::initialize(QDesignerFormEditorInterface *core)
51{
52 Q_ASSERT(!isInitialized());
53
54 m_action = new QAction(tr(s: "Edit Signals/Slots"), this);
55 m_action->setObjectName(QStringLiteral("__qt_edit_signals_slots_action"));
56 m_action->setShortcut(tr(s: "F4"));
57 QIcon icon = QIcon::fromTheme(QStringLiteral("designer-edit-signals"),
58 fallback: QIcon(core->resourceLocation() + QStringLiteral("/signalslottool.png")));
59 m_action->setIcon(icon);
60 m_action->setEnabled(false);
61
62 setParent(core);
63 m_core = core;
64 m_initialized = true;
65
66 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::formWindowAdded,
67 receiver: this, slot: &SignalSlotEditorPlugin::addFormWindow);
68
69 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::formWindowRemoved,
70 receiver: this, slot: &SignalSlotEditorPlugin::removeFormWindow);
71
72 connect(sender: core->formWindowManager(), signal: &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
73 receiver: this, slot: &SignalSlotEditorPlugin::activeFormWindowChanged);
74}
75
76QDesignerFormEditorInterface *SignalSlotEditorPlugin::core() const
77{
78 return m_core;
79}
80
81void SignalSlotEditorPlugin::addFormWindow(QDesignerFormWindowInterface *formWindow)
82{
83 Q_ASSERT(formWindow != nullptr);
84 Q_ASSERT(m_tools.contains(formWindow) == false);
85
86 SignalSlotEditorTool *tool = new SignalSlotEditorTool(formWindow, this);
87 connect(sender: m_action, signal: &QAction::triggered, receiver: tool->action(), slot: &QAction::trigger);
88 m_tools[formWindow] = tool;
89 formWindow->registerTool(tool);
90}
91
92void SignalSlotEditorPlugin::removeFormWindow(QDesignerFormWindowInterface *formWindow)
93{
94 Q_ASSERT(formWindow != nullptr);
95 Q_ASSERT(m_tools.contains(formWindow) == true);
96
97 SignalSlotEditorTool *tool = m_tools.value(akey: formWindow);
98 m_tools.remove(akey: formWindow);
99 disconnect(sender: m_action, signal: &QAction::triggered, receiver: tool->action(), slot: &QAction::trigger);
100 // ### FIXME disable the tool
101
102 delete tool;
103}
104
105QAction *SignalSlotEditorPlugin::action() const
106{
107 return m_action;
108}
109
110void SignalSlotEditorPlugin::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
111{
112 m_action->setEnabled(formWindow != nullptr);
113}
114
115QT_END_NAMESPACE
116

source code of qttools/src/designer/src/components/signalsloteditor/signalsloteditor_plugin.cpp