Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdFactory.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdAbstract.h"
8#include "CmdAddPointAxis.h"
9#include "CmdAddPointGraph.h"
10#include "CmdAddPointsGraph.h"
11#include "CmdCopy.h"
12#include "CmdCut.h"
13#include "CmdDelete.h"
14#include "CmdEditPointAxis.h"
15#include "CmdEditPointGraph.h"
16#include "CmdFactory.h"
17#include "CmdGong.h"
18#include "CmdGuidelineAddXT.h"
19#include "CmdGuidelineAddYR.h"
20#include "CmdGuidelineMoveXT.h"
21#include "CmdGuidelineMoveYR.h"
24#include "CmdMoveBy.h"
25#include "CmdRedoForTest.h"
29#include "CmdSettingsCoords.h"
34#include "CmdSettingsGeneral.h"
37#include "CmdSettingsSegments.h"
38#include "CmdUndoForTest.h"
39#include "Document.h"
40#include "DocumentSerialize.h"
41#include "EngaugeAssert.h"
42#include "Logger.h"
43#include "MainWindow.h"
44#include <QXmlStreamReader>
45
49
51 Document &document,
52 QXmlStreamReader &reader)
53{
54 CmdAbstract *cmd = nullptr;
55
56 QXmlStreamAttributes attributes = reader.attributes();
57 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_TYPE) ||
58 !attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION)) {
59
60 // Invalid xml
61 qCCritical(ENGAUGE_LOG) << "CmdFactory::createCmd missing " << DOCUMENT_SERIALIZE_CMD_TYPE.toLatin1().data()
62 << " or " << DOCUMENT_SERIALIZE_CMD_DESCRIPTION.toLatin1().data();
63 ENGAUGE_ASSERT(false);
64
65 }
66
67 // Get common attributes
68 QString cmdType = attributes.value(DOCUMENT_SERIALIZE_CMD_TYPE).toString();
69 QString cmdDescription = attributes.value(DOCUMENT_SERIALIZE_CMD_DESCRIPTION).toString();
70
72 cmd = new CmdAddPointAxis (mainWindow,
73 document,
74 cmdDescription,
75 reader);
76 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH) {
77 cmd = new CmdAddPointGraph (mainWindow,
78 document,
79 cmdDescription,
80 reader);
81 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH) {
82 cmd = new CmdAddPointsGraph (mainWindow,
83 document,
84 cmdDescription,
85 reader);
86 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_COPY) {
87 cmd = new CmdCopy (mainWindow,
88 document,
89 cmdDescription,
90 reader);
91 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_CUT) {
92 cmd = new CmdCut (mainWindow,
93 document,
94 cmdDescription,
95 reader);
96 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_DELETE) {
97 cmd = new CmdDelete (mainWindow,
98 document,
99 cmdDescription,
100 reader);
101 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS) {
102 cmd = new CmdEditPointAxis (mainWindow,
103 document,
104 cmdDescription,
105 reader);
106 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH) {
107 cmd = new CmdEditPointGraph (mainWindow,
108 document,
109 cmdDescription,
110 reader);
111 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GONG) {
112 cmd = new CmdGong (mainWindow,
113 document,
114 cmdDescription,
115 reader);
116 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_X_T) {
117 cmd = new CmdGuidelineAddXT (mainWindow,
118 document,
119 cmdDescription,
120 reader);
121 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_Y_R) {
122 cmd = new CmdGuidelineAddYR (mainWindow,
123 document,
124 cmdDescription,
125 reader);
126 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_X_T) {
127 cmd = new CmdGuidelineMoveXT (mainWindow,
128 document,
129 cmdDescription,
130 reader);
131 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_Y_R) {
132 cmd = new CmdGuidelineMoveYR (mainWindow,
133 document,
134 cmdDescription,
135 reader);
136 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_X_T) {
137 cmd = new CmdGuidelineRemoveXT (mainWindow,
138 document,
139 cmdDescription,
140 reader);
141 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_Y_R) {
142 cmd = new CmdGuidelineRemoveYR (mainWindow,
143 document,
144 cmdDescription,
145 reader);
146 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_MOVE_BY) {
147 cmd = new CmdMoveBy (mainWindow,
148 document,
149 cmdDescription,
150 reader);
151 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST) {
152 cmd = new CmdRedoForTest (mainWindow,
153 document,
154 cmdDescription,
155 reader);
156 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM) {
157 cmd = new CmdSelectCoordSystem (mainWindow,
158 document,
159 cmdDescription,
160 reader);
161 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER) {
162 cmd = new CmdSettingsAxesChecker (mainWindow,
163 document,
164 cmdDescription,
165 reader);
166 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER) {
167 cmd = new CmdSettingsColorFilter (mainWindow,
168 document,
169 cmdDescription,
170 reader);
171 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS) {
172 cmd = new CmdSettingsCoords (mainWindow,
173 document,
174 cmdDescription,
175 reader);
176 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST) {
177 cmd = new CmdSettingsCurveList (mainWindow,
178 document,
179 cmdDescription,
180 reader);
182 cmd = new CmdSettingsCurveProperties (mainWindow,
183 document,
184 cmdDescription,
185 reader);
187 cmd = new CmdSettingsDigitizeCurve (mainWindow,
188 document,
189 cmdDescription,
190 reader);
191 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT) {
192 cmd = new CmdSettingsExportFormat (mainWindow,
193 document,
194 cmdDescription,
195 reader);
196 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GENERAL) {
197 cmd = new CmdSettingsGeneral (mainWindow,
198 document,
199 cmdDescription,
200 reader);
201 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL) {
202 cmd = new CmdSettingsGridRemoval (mainWindow,
203 document,
204 cmdDescription,
205 reader);
206 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH) {
207 cmd = new CmdSettingsPointMatch (mainWindow,
208 document,
209 cmdDescription,
210 reader);
211 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS) {
212 cmd = new CmdSettingsSegments (mainWindow,
213 document,
214 cmdDescription,
215 reader);
216 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST) {
217 cmd = new CmdUndoForTest (mainWindow,
218 document,
219 cmdDescription,
220 reader);
221 } else {
222
223 // Invalid xml
224 qCCritical(ENGAUGE_LOG) << "CmdFactory::createCmd invalid command type " << cmdType.toLatin1().data();
225 ENGAUGE_ASSERT (false);
226
227 }
228
229 return cmd;
230}
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINT_AXIS
const QString DOCUMENT_SERIALIZE_CMD_MOVE_BY
const QString DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_PROPERTIES
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_Y_R
const QString DOCUMENT_SERIALIZE_CMD_GONG
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_Y_R
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_X_T
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_X_T
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_Y_R
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER
const QString DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_GENERAL
const QString DOCUMENT_SERIALIZE_CMD_CUT
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_DIGITIZE_CURVE
const QString DOCUMENT_SERIALIZE_CMD_DELETE
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_X_T
const QString DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS
const QString DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT
const QString DOCUMENT_SERIALIZE_CMD_COPY
const QString DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:24
CmdAddPointAxis(MainWindow &mainWindow, Document &document, const QPointF &posScreen, const QPointF &posGraph, double ordinal, bool isXOnly)
Constructor for normal creation.
CmdAddPointGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QPointF &posScreen, double ordinal)
Constructor for normal creation.
CmdAddPointsGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QList< QPoint > &points, const QList< double > &ordinals)
Constructor for normal creation.
CmdCopy(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdCopy.cpp:27
CmdCut(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdCut.cpp:27
CmdDelete(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdDelete.cpp:25
CmdEditPointAxis(MainWindow &mainWindow, Document &document, const QString &pointIdentifier, const QPointF &posGraphBefore, const QPointF &posGraphAfter, bool isXOnly)
Constructor for normal creation.
CmdEditPointGraph(MainWindow &mainWindow, Document &document, const QStringList &pointIdentifiers, bool isX, bool isY, double x, double y)
Constructor for normal creation.
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
CmdFactory()
Single constructor.
CmdGong(MainWindow &mainWindow, Document &document)
Constructor for normal creation.
Definition CmdGong.cpp:15
CmdGuidelineAddXT(MainWindow &mainWindow, Document &document, double value)
Constructor for normal creation.
CmdGuidelineAddYR(MainWindow &mainWindow, Document &document, double value)
Constructor for normal creation.
CmdGuidelineMoveXT(MainWindow &mainWindow, Document &document, const QString &identifier, double valueBefore, double valueAfter)
Constructor for normal creation.
CmdGuidelineMoveYR(MainWindow &mainWindow, Document &document, const QString &identifier, double valueBefore, double valueAfter)
Constructor for normal creation.
CmdGuidelineRemoveXT(MainWindow &mainWindow, Document &document, const QString &identifier, double valueBefore)
Constructor for normal creation.
CmdGuidelineRemoveYR(MainWindow &mainWindow, Document &document, const QString &identifier, double oldBefore)
Constructor for normal creation.
CmdMoveBy(MainWindow &mainWindow, Document &document, const QPointF &deltaScreen, const QString &moveText, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdMoveBy.cpp:21
CmdRedoForTest(MainWindow &mainWindow, Document &document)
Constructor for normal creation.
CmdSelectCoordSystem(MainWindow &mainWindow, Document &document, CoordSystemIndex coordSystem)
Constructor for normal creation.
CmdSettingsAxesChecker(MainWindow &mainWindow, Document &document, const DocumentModelAxesChecker &modelAxesCheckerBefore, const DocumentModelAxesChecker &modelAxesCheckerAfter)
Constructor for normal creation.
CmdSettingsColorFilter(MainWindow &mainWindow, Document &document, const DocumentModelColorFilter &modelColorFilterBefore, const DocumentModelColorFilter &modelColorFilterAfter)
Constructor for normal creation.
CmdSettingsCoords(MainWindow &mainWindow, Document &document, const DocumentModelCoords &modelCoordsBefore, const DocumentModelCoords &modelCoordsAfter)
Constructor for normal creation.
CmdSettingsCurveList(MainWindow &mainWindow, Document &document, const CurveNameList &modelCurves)
Constructor for normal creation.
CmdSettingsCurveProperties(MainWindow &mainWindow, Document &document, const CurveStyles &modelCurveStylesBefore, const CurveStyles &modelCurveStylesAfter)
Constructor for normal creation.
CmdSettingsDigitizeCurve(MainWindow &mainWindow, Document &document, const DocumentModelDigitizeCurve &modelDigitizeCurveBefore, const DocumentModelDigitizeCurve &modelDigitizeCurveAfter)
Constructor for normal creation.
CmdSettingsExportFormat(MainWindow &mainWindow, Document &document, const DocumentModelExportFormat &modelExportBefore, const DocumentModelExportFormat &modelExportAfter)
Constructor for normal creation.
CmdSettingsGeneral(MainWindow &mainWindow, Document &document, const DocumentModelGeneral &modelGeneralBefore, const DocumentModelGeneral &modelGeneralAfter)
Constructor for normal creation.
CmdSettingsGridRemoval(MainWindow &mainWindow, Document &document, const DocumentModelGridRemoval &modelGridRemovalBefore, const DocumentModelGridRemoval &modelGridRemovalAfter)
Constructor for normal creation.
CmdSettingsPointMatch(MainWindow &mainWindow, Document &document, const DocumentModelPointMatch &modelPointMatchBefore, const DocumentModelPointMatch &modelPointMatchAfter)
Constructor for normal creation.
CmdSettingsSegments(MainWindow &mainWindow, Document &document, const DocumentModelSegments &modelSegmentsBefore, const DocumentModelSegments &modelSegmentsAfter)
Constructor for normal creation.
CmdUndoForTest(MainWindow &mainWindow, Document &document)
Constructor for normal creation.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95