Changeset View
Changeset View
Standalone View
Standalone View
plugins/formulashape/KoFormulaTool.cpp
Show All 32 Lines | |||||
33 | #include <KoIcon.h> | 33 | #include <KoIcon.h> | ||
34 | 34 | | |||
35 | #include <klocalizedstring.h> | 35 | #include <klocalizedstring.h> | ||
36 | 36 | | |||
37 | #include <QKeyEvent> | 37 | #include <QKeyEvent> | ||
38 | #include <QAction> | 38 | #include <QAction> | ||
39 | #include <QPainter> | 39 | #include <QPainter> | ||
40 | #include <QFile> | 40 | #include <QFile> | ||
41 | #include <QSignalMapper> | | |||
42 | #include <QFileDialog> | 41 | #include <QFileDialog> | ||
43 | 42 | | |||
44 | #include <KoShapeSavingContext.h> | 43 | #include <KoShapeSavingContext.h> | ||
45 | #include <KoShapeLoadingContext.h> | 44 | #include <KoShapeLoadingContext.h> | ||
46 | #include <KoOdfLoadingContext.h> | 45 | #include <KoOdfLoadingContext.h> | ||
47 | #include <KoOdfStylesReader.h> | 46 | #include <KoOdfStylesReader.h> | ||
48 | #include "FormulaCommand.h" | 47 | #include "FormulaCommand.h" | ||
49 | #include "FormulaCommandUpdate.h" | 48 | #include "FormulaCommandUpdate.h" | ||
50 | #include <KoXmlReader.h> | 49 | #include <KoXmlReader.h> | ||
51 | #include <KoXmlWriter.h> | 50 | #include <KoXmlWriter.h> | ||
52 | #include <KoGenStyles.h> | 51 | #include <KoGenStyles.h> | ||
53 | #include <KoEmbeddedDocumentSaver.h> | 52 | #include <KoEmbeddedDocumentSaver.h> | ||
54 | #include "FormulaRenderer.h" | 53 | #include "FormulaRenderer.h" | ||
55 | #include <QClipboard> | 54 | #include <QClipboard> | ||
56 | 55 | | |||
57 | 56 | | |||
58 | 57 | | |||
59 | KoFormulaTool::KoFormulaTool( KoCanvasBase* canvas ) : KoToolBase( canvas ), | 58 | KoFormulaTool::KoFormulaTool( KoCanvasBase* canvas ) : KoToolBase( canvas ), | ||
60 | m_formulaShape( 0 ), | 59 | m_formulaShape( 0 ), | ||
61 | m_formulaEditor( 0 ) | 60 | m_formulaEditor( 0 ) | ||
62 | { | 61 | { | ||
63 | m_signalMapper = new QSignalMapper(this); | | |||
64 | setupActions(); | 62 | setupActions(); | ||
65 | setTextMode(true); | 63 | setTextMode(true); | ||
66 | } | 64 | } | ||
67 | 65 | | |||
68 | KoFormulaTool::~KoFormulaTool() | 66 | KoFormulaTool::~KoFormulaTool() | ||
69 | { | 67 | { | ||
70 | if( m_formulaEditor ) { | 68 | if( m_formulaEditor ) { | ||
71 | m_cursorList.removeAll(m_formulaEditor); | 69 | m_cursorList.removeAll(m_formulaEditor); | ||
Show All 37 Lines | 96 | if (editor->formulaData() == formulaData) { | |||
109 | delete editor; | 107 | delete editor; | ||
110 | } | 108 | } | ||
111 | } | 109 | } | ||
112 | if (m_formulaEditor==0) { | 110 | if (m_formulaEditor==0) { | ||
113 | //TODO: there should be a extra constructor for this | 111 | //TODO: there should be a extra constructor for this | ||
114 | m_formulaEditor = new FormulaEditor( m_formulaShape->formulaData()); | 112 | m_formulaEditor = new FormulaEditor( m_formulaShape->formulaData()); | ||
115 | } | 113 | } | ||
116 | connect(m_formulaShape->formulaData(), SIGNAL(dataChanged(FormulaCommand*,bool)), this, SLOT(updateCursor(FormulaCommand*,bool))); | 114 | connect(m_formulaShape->formulaData(), SIGNAL(dataChanged(FormulaCommand*,bool)), this, SLOT(updateCursor(FormulaCommand*,bool))); | ||
117 | connect(m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(insert(QString))); | 115 | for (const TemplateAction &templateAction : qAsConst(m_templateActions)) { | ||
116 | connect(templateAction.action, &QAction::triggered, this, [this, templateAction] { insert(templateAction.data); }); | ||||
117 | } | ||||
dfaure: `qAsConst(m_templateActions)` to avoid a detach | |||||
118 | //Only for debugging: | 118 | //Only for debugging: | ||
119 | connect(action("write_elementTree"),SIGNAL(triggered(bool)), m_formulaShape->formulaData(), SLOT(writeElementTree())); | 119 | connect(action("write_elementTree"),SIGNAL(triggered(bool)), m_formulaShape->formulaData(), SLOT(writeElementTree())); | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | void KoFormulaTool::deactivate() | 122 | void KoFormulaTool::deactivate() | ||
123 | { | 123 | { | ||
124 | for (const TemplateAction &templateAction : qAsConst(m_templateActions)) { | ||||
dfaure: same here | |||||
125 | disconnect(templateAction.action, &QAction::triggered, this, nullptr); | ||||
126 | } | ||||
124 | disconnect(m_formulaShape->formulaData(),0,this,0); | 127 | disconnect(m_formulaShape->formulaData(),0,this,0); | ||
125 | disconnect(m_signalMapper,0,this,0); | | |||
126 | if (canvas()) { | 128 | if (canvas()) { | ||
127 | m_cursorList.append(m_formulaEditor); | 129 | m_cursorList.append(m_formulaEditor); | ||
128 | debugFormula << "Appending cursor"; | 130 | debugFormula << "Appending cursor"; | ||
129 | } | 131 | } | ||
130 | if (m_cursorList.count() > 20) { // don't let it grow indefinitely | 132 | if (m_cursorList.count() > 20) { // don't let it grow indefinitely | ||
131 | //TODO: is this save? | 133 | delete m_cursorList.takeAt(0); | ||
completely unrelated : this those two lines could be combined into delete m_cursorList.takeAt(0);, and the comment removed. dfaure: completely unrelated : this those two lines could be combined into `delete m_cursorList.takeAt… | |||||
132 | delete m_cursorList[0]; | | |||
133 | m_cursorList.removeAt(0); | | |||
134 | } | 134 | } | ||
135 | m_formulaShape = 0; | 135 | m_formulaShape = 0; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | 138 | | |||
139 | void KoFormulaTool::updateCursor(FormulaCommand* command, bool undo) | 139 | void KoFormulaTool::updateCursor(FormulaCommand* command, bool undo) | ||
140 | { | 140 | { | ||
141 | if (command!=0) { | 141 | if (command!=0) { | ||
▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Line(s) | 409 | { | |||
476 | action->setIcon(koIcon("remcol")); | 476 | action->setIcon(koIcon("remcol")); | ||
477 | 477 | | |||
478 | } | 478 | } | ||
479 | 479 | | |||
480 | 480 | | |||
481 | void KoFormulaTool::addTemplateAction(const QString &caption, const QString &name, const QString &data, | 481 | void KoFormulaTool::addTemplateAction(const QString &caption, const QString &name, const QString &data, | ||
482 | const char *iconName) | 482 | const char *iconName) | ||
483 | { | 483 | { | ||
484 | QAction * action; | 484 | QAction *action = new QAction( caption, this ); | ||
485 | action = new QAction( caption, this ); | | |||
486 | m_signalMapper->setMapping(action, data); | | |||
487 | addAction( name , action ); | 485 | addAction(name , action); | ||
488 | action->setIcon(QIcon::fromTheme(QLatin1String(iconName))); | 486 | action->setIcon(QIcon::fromTheme(QLatin1String(iconName))); | ||
489 | connect( action, SIGNAL(triggered()), m_signalMapper, SLOT(map())); | 487 | m_templateActions.push_back(TemplateAction { action, data }); | ||
488 | // the connection takes place when this KoToolBase is activated | ||||
490 | } | 489 | } | ||
491 | 490 | | |||
492 | 491 | | |||
493 | void KoFormulaTool::copy() const | 492 | void KoFormulaTool::copy() const | ||
494 | { | 493 | { | ||
495 | QApplication::clipboard()->setText("test"); | 494 | QApplication::clipboard()->setText("test"); | ||
496 | } | 495 | } | ||
497 | 496 | | |||
Show All 27 Lines |
qAsConst(m_templateActions) to avoid a detach