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"
25#include "CmdMoveBy.h"
26#include "CmdRedoForTest.h"
30#include "CmdSettingsCoords.h"
35#include "CmdSettingsGeneral.h"
38#include "CmdSettingsSegments.h"
39#include "CmdUndoForTest.h"
40#include "Document.h"
41#include "DocumentSerialize.h"
42#include "EngaugeAssert.h"
43#include "Logger.h"
44#include "MainWindow.h"
45#include <QXmlStreamReader>
46
50
52 Document &document,
53 QXmlStreamReader &reader)
54{
55 CmdAbstract *cmd = nullptr;
56
57 QXmlStreamAttributes attributes = reader.attributes();
58 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_TYPE) ||
59 !attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION)) {
60
61 // Invalid xml
62 LOG4CPP_ERROR_S ((*mainCat)) << "CmdFactory::createCmd missing " << DOCUMENT_SERIALIZE_CMD_TYPE.toLatin1().data()
63 << " or " << DOCUMENT_SERIALIZE_CMD_DESCRIPTION.toLatin1().data();
64 ENGAUGE_ASSERT(false);
65
66 }
67
68 // Get common attributes
69 QString cmdType = attributes.value(DOCUMENT_SERIALIZE_CMD_TYPE).toString();
70 QString cmdDescription = attributes.value(DOCUMENT_SERIALIZE_CMD_DESCRIPTION).toString();
71
73 cmd = new CmdAddPointAxis (mainWindow,
74 document,
75 cmdDescription,
76 reader);
77 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH) {
78 cmd = new CmdAddPointGraph (mainWindow,
79 document,
80 cmdDescription,
81 reader);
82 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH) {
83 cmd = new CmdAddPointsGraph (mainWindow,
84 document,
85 cmdDescription,
86 reader);
87 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_COPY) {
88 cmd = new CmdCopy (mainWindow,
89 document,
90 cmdDescription,
91 reader);
92 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_CUT) {
93 cmd = new CmdCut (mainWindow,
94 document,
95 cmdDescription,
96 reader);
97 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_DELETE) {
98 cmd = new CmdDelete (mainWindow,
99 document,
100 cmdDescription,
101 reader);
102 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS) {
103 cmd = new CmdEditPointAxis (mainWindow,
104 document,
105 cmdDescription,
106 reader);
107 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH) {
108 cmd = new CmdEditPointGraph (mainWindow,
109 document,
110 cmdDescription,
111 reader);
112 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GONG) {
113 cmd = new CmdGong (mainWindow,
114 document,
115 cmdDescription,
116 reader);
117 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_X_T) {
118 cmd = new CmdGuidelineAddXT (mainWindow,
119 document,
120 cmdDescription,
121 reader);
122 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_ADD_Y_R) {
123 cmd = new CmdGuidelineAddYR (mainWindow,
124 document,
125 cmdDescription,
126 reader);
127 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_X_T) {
128 cmd = new CmdGuidelineMoveXT (mainWindow,
129 document,
130 cmdDescription,
131 reader);
132 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_Y_R) {
133 cmd = new CmdGuidelineMoveYR (mainWindow,
134 document,
135 cmdDescription,
136 reader);
137 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_X_T) {
138 cmd = new CmdGuidelineRemoveXT (mainWindow,
139 document,
140 cmdDescription,
141 reader);
142 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_REMOVE_Y_R) {
143 cmd = new CmdGuidelineRemoveYR (mainWindow,
144 document,
145 cmdDescription,
146 reader);
147 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_GUIDELINE_VIEW_STATE) {
148 cmd = new CmdGuidelineViewState (mainWindow,
149 document,
150 cmdDescription,
151 reader);
152 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_MOVE_BY) {
153 cmd = new CmdMoveBy (mainWindow,
154 document,
155 cmdDescription,
156 reader);
157 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST) {
158 cmd = new CmdRedoForTest (mainWindow,
159 document,
160 cmdDescription,
161 reader);
162 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM) {
163 cmd = new CmdSelectCoordSystem (mainWindow,
164 document,
165 cmdDescription,
166 reader);
167 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER) {
168 cmd = new CmdSettingsAxesChecker (mainWindow,
169 document,
170 cmdDescription,
171 reader);
172 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER) {
173 cmd = new CmdSettingsColorFilter (mainWindow,
174 document,
175 cmdDescription,
176 reader);
177 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS) {
178 cmd = new CmdSettingsCoords (mainWindow,
179 document,
180 cmdDescription,
181 reader);
182 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST) {
183 cmd = new CmdSettingsCurveList (mainWindow,
184 document,
185 cmdDescription,
186 reader);
188 cmd = new CmdSettingsCurveProperties (mainWindow,
189 document,
190 cmdDescription,
191 reader);
193 cmd = new CmdSettingsDigitizeCurve (mainWindow,
194 document,
195 cmdDescription,
196 reader);
197 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT) {
198 cmd = new CmdSettingsExportFormat (mainWindow,
199 document,
200 cmdDescription,
201 reader);
202 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GENERAL) {
203 cmd = new CmdSettingsGeneral (mainWindow,
204 document,
205 cmdDescription,
206 reader);
207 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL) {
208 cmd = new CmdSettingsGridRemoval (mainWindow,
209 document,
210 cmdDescription,
211 reader);
212 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH) {
213 cmd = new CmdSettingsPointMatch (mainWindow,
214 document,
215 cmdDescription,
216 reader);
217 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS) {
218 cmd = new CmdSettingsSegments (mainWindow,
219 document,
220 cmdDescription,
221 reader);
222 } else if (cmdType == DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST) {
223 cmd = new CmdUndoForTest (mainWindow,
224 document,
225 cmdDescription,
226 reader);
227 } else {
228
229 // Invalid xml
230 LOG4CPP_ERROR_S ((*mainCat)) << "CmdFactory::createCmd invalid command type " << cmdType.toLatin1().data();
231 ENGAUGE_ASSERT (false);
232
233 }
234
235 return cmd;
236}
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_GUIDELINE_VIEW_STATE
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.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:20
Command for adding one axis point.
Command for adding one graph point.
Command for adding one or more graph points. This is for Segment Fill mode.
Command for copying all selected Points to the clipboard.
Definition CmdCopy.h:19
Command for cutting all selected Points.
Definition CmdCut.h:19
Command for deleting all selected Points.
Definition CmdDelete.h:19
Command for editing the graph coordinates one axis point.
Command for editing the graph coordinates of one or more graph points.
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
CmdFactory()
Single constructor.
Command for sending a satisfying signal to the unit test framework to indicate completion of queued c...
Definition CmdGong.h:16
Command for adding one X/T Guideline value.
Command for adding one Y/R Guideline value.
Command for moving one X/T Guideline value.
Command for moving one Y/R Guideline value.
Command for removing one X/T Guideline value.
Command for removing one Y/R Guideline value.
Command for changing the View / Guidelines state.
Command for moving all selected Points by a specified translation.
Definition CmdMoveBy.h:19
Command for performing Redo during testing.
Command for changing the currently selected CoordSystem.
Command for DlgSettingsAxesChecker.
Command for DlgSettingsColorFilter.
Command for DlgSettingsCoords.
Command for DlgSettingsCurveList.
Command for DlgSettingsCurveProperties.
Command for DlgSettingsDigitizeCurve.
Command for DlgSettingsExportFormat.
Command for DlgSettingsGeneral.
Command for DlgSettingsGridRemoval.
Command for DlgSettingsPointMatch.
Command for DlgSettingsSegments.
Command for performing Undo during testing.
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:96
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12