Changeset View
Changeset View
Standalone View
Standalone View
words/plugins/scripting/Tool.h
Show All 16 Lines | |||||
17 | * You should have received a copy of the GNU Library General Public License | 17 | * You should have received a copy of the GNU Library General Public License | ||
18 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef SCRIPTING_TOOL_H | 22 | #ifndef SCRIPTING_TOOL_H | ||
23 | #define SCRIPTING_TOOL_H | 23 | #define SCRIPTING_TOOL_H | ||
24 | 24 | | |||
25 | #include <QSignalMapper> | | |||
26 | #include <QAction> | 25 | #include <QAction> | ||
27 | 26 | | |||
28 | #include <kdebug.h> | 27 | #include <kdebug.h> | ||
29 | #include <KoToolManager.h> | 28 | #include <KoToolManager.h> | ||
30 | #include <KoToolProxy.h> | 29 | #include <KoToolProxy.h> | ||
31 | #include <KoTextEditor.h> | 30 | #include <KoTextEditor.h> | ||
32 | #include <KWView.h> | 31 | #include <KWView.h> | ||
33 | #include <KoCanvasBase.h> | 32 | #include <KoCanvasBase.h> | ||
Show All 26 Lines | |||||
60 | { | 59 | { | ||
61 | Q_OBJECT | 60 | Q_OBJECT | ||
62 | public: | 61 | public: | ||
63 | explicit Tool(Module* module) : QObject(module), m_module(module) { | 62 | explicit Tool(Module* module) : QObject(module), m_module(module) { | ||
64 | KWView* v = dynamic_cast< KWView* >(m_module->view()); | 63 | KWView* v = dynamic_cast< KWView* >(m_module->view()); | ||
65 | KoCanvasBase* c = v ? v->canvasBase() : 0; | 64 | KoCanvasBase* c = v ? v->canvasBase() : 0; | ||
66 | m_toolproxy = c ? c->toolProxy() : 0; | 65 | m_toolproxy = c ? c->toolProxy() : 0; | ||
67 | 66 | | |||
68 | m_signalMapper = new QSignalMapper(this); | | |||
69 | QHash<QString, QAction*> actionhash = actions(); | 67 | QHash<QString, QAction*> actionhash = actions(); | ||
70 | for (QHash<QString, QAction*>::const_iterator it = actionhash.constBegin(); it != actionhash.constEnd(); ++it) { | 68 | for (QHash<QString, QAction*>::const_iterator it = actionhash.constBegin(); it != actionhash.constEnd(); ++it) { | ||
71 | connect(it.value(), SIGNAL(triggered()), m_signalMapper, SLOT(map())); | 69 | QString key = it.key(); | ||
72 | m_signalMapper->setMapping(it.value() , it.key()); | 70 | connect(it.value(), &QAction::triggered, this, [this, key] { actionTriggered(key); }); | ||
dfaure: Better capture a local variable called `key` by value.
Iterators get invalidated when… | |||||
73 | } | 71 | } | ||
74 | connect(m_signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(actionTriggered(QString))); | | |||
75 | 72 | | |||
76 | connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), this, SIGNAL(changedTool())); | 73 | connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), this, SIGNAL(changedTool())); | ||
77 | } | 74 | } | ||
78 | virtual ~Tool() {} | 75 | virtual ~Tool() {} | ||
79 | 76 | | |||
80 | KoToolSelection* toolSelection() const { | 77 | KoToolSelection* toolSelection() const { | ||
81 | return m_toolproxy ? m_toolproxy->selection() : 0; | 78 | return m_toolproxy ? m_toolproxy->selection() : 0; | ||
82 | } | 79 | } | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 144 | Q_SIGNALS: | |||
150 | void actionTriggered(const QString& actionname); | 147 | void actionTriggered(const QString& actionname); | ||
151 | 148 | | |||
152 | /** This signal got emitted if the tool changed. */ | 149 | /** This signal got emitted if the tool changed. */ | ||
153 | void changedTool(); | 150 | void changedTool(); | ||
154 | 151 | | |||
155 | private: | 152 | private: | ||
156 | Module* m_module; | 153 | Module* m_module; | ||
157 | KoToolProxy* m_toolproxy; | 154 | KoToolProxy* m_toolproxy; | ||
158 | QSignalMapper* m_signalMapper; | | |||
159 | }; | 155 | }; | ||
160 | 156 | | |||
161 | } | 157 | } | ||
162 | 158 | | |||
163 | #endif | 159 | #endif |
Better capture a local variable called key by value.
Iterators get invalidated when containers change.