Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CmdFactory.cpp
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 "CmdFactory.h"
16 #include "CmdMoveBy.h"
17 #include "CmdPaste.h"
18 #include "CmdRedoForTest.h"
19 #include "CmdSelectCoordSystem.h"
20 #include "CmdSettingsAxesChecker.h"
21 #include "CmdSettingsColorFilter.h"
22 #include "CmdSettingsCoords.h"
23 #include "CmdSettingsCurveAddRemove.h"
24 #include "CmdSettingsCurveProperties.h"
25 #include "CmdSettingsDigitizeCurve.h"
26 #include "CmdSettingsExportFormat.h"
27 #include "CmdSettingsGridRemoval.h"
28 #include "CmdSettingsPointMatch.h"
29 #include "CmdSettingsSegments.h"
30 #include "CmdUndoForTest.h"
31 #include "Document.h"
32 #include "DocumentSerialize.h"
33 #include "EngaugeAssert.h"
34 #include "MainWindow.h"
35 #include <QXmlStreamReader>
36 
38 {
39 }
40 
42  Document &document,
43  QXmlStreamReader &reader)
44 {
45  CmdAbstract *cmd = 0;
46 
47  QXmlStreamAttributes attributes = reader.attributes();
48  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_TYPE) ||
49  !attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION)) {
50 
51  // Invalid xml
52  ENGAUGE_ASSERT(false);
53 
54  }
55 
56  // Get common attributes
57  QString cmdType = attributes.value(DOCUMENT_SERIALIZE_CMD_TYPE).toString();
58  QString cmdDescription = attributes.value(DOCUMENT_SERIALIZE_CMD_DESCRIPTION).toString();
59 
60  if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINT_AXIS) {
61  cmd = new CmdAddPointAxis (mainWindow,
62  document,
63  cmdDescription,
64  reader);
65  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH) {
66  cmd = new CmdAddPointGraph (mainWindow,
67  document,
68  cmdDescription,
69  reader);
70  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH) {
71  cmd = new CmdAddPointsGraph (mainWindow,
72  document,
73  cmdDescription,
74  reader);
75  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_COPY) {
76  cmd = new CmdCopy (mainWindow,
77  document,
78  cmdDescription,
79  reader);
80  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_CUT) {
81  cmd = new CmdCut (mainWindow,
82  document,
83  cmdDescription,
84  reader);
85  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_DELETE) {
86  cmd = new CmdDelete (mainWindow,
87  document,
88  cmdDescription,
89  reader);
90  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS) {
91  cmd = new CmdEditPointAxis (mainWindow,
92  document,
93  cmdDescription,
94  reader);
95  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_MOVE_BY) {
96  cmd = new CmdMoveBy (mainWindow,
97  document,
98  cmdDescription,
99  reader);
100  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_PASTE) {
101  cmd = new CmdPaste (mainWindow,
102  document,
103  cmdDescription,
104  reader);
105  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST) {
106  cmd = new CmdRedoForTest (mainWindow,
107  document,
108  cmdDescription,
109  reader);
110  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM) {
111  cmd = new CmdSelectCoordSystem (mainWindow,
112  document,
113  cmdDescription,
114  reader);
115  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER) {
116  cmd = new CmdSettingsAxesChecker (mainWindow,
117  document,
118  cmdDescription,
119  reader);
120  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER) {
121  cmd = new CmdSettingsColorFilter (mainWindow,
122  document,
123  cmdDescription,
124  reader);
125  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS) {
126  cmd = new CmdSettingsCoords (mainWindow,
127  document,
128  cmdDescription,
129  reader);
130  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_ADD_REMOVE) {
131  cmd = new CmdSettingsCurveAddRemove (mainWindow,
132  document,
133  cmdDescription,
134  reader);
135  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_PROPERTIES) {
136  cmd = new CmdSettingsCurveProperties (mainWindow,
137  document,
138  cmdDescription,
139  reader);
140  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_DIGITIZE_CURVE) {
141  cmd = new CmdSettingsDigitizeCurve (mainWindow,
142  document,
143  cmdDescription,
144  reader);
145  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT) {
146  cmd = new CmdSettingsExportFormat (mainWindow,
147  document,
148  cmdDescription,
149  reader);
150  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL) {
151  cmd = new CmdSettingsGridRemoval (mainWindow,
152  document,
153  cmdDescription,
154  reader);
155  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH) {
156  cmd = new CmdSettingsPointMatch (mainWindow,
157  document,
158  cmdDescription,
159  reader);
160  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS) {
161  cmd = new CmdSettingsSegments (mainWindow,
162  document,
163  cmdDescription,
164  reader);
165  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST) {
166  cmd = new CmdUndoForTest (mainWindow,
167  document,
168  cmdDescription,
169  reader);
170  } else {
171 
172  // Invalid xml
173  ENGAUGE_ASSERT (false);
174 
175  }
176 
177  return cmd;
178 }
Command for cutting all selected Points.
Definition: CmdCut.h:18
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:19
Command for performing Undo during testing.
CmdFactory()
Single constructor.
Definition: CmdFactory.cpp:37
Command for performing Redo during testing.
Command for moving all selected Points by a specified translation.
Definition: CmdMoveBy.h:18
Command for DlgSettingsCurveProperties.
Command for DlgSettingsCurveAddRemove.
Command for DlgSettingsPointMatch.
Command for DlgSettingsCoords.
Command for DlgSettingsAxesChecker.
Command for adding one axis point.
Command for adding one or more graph points. This is for Segment Fill mode.
Command for adding one graph point.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
Command for deleting all selected Points.
Definition: CmdDelete.h:18
Command for DlgSettingsGridRemoval.
Command for DlgSettingsColorFilter.
Command for DlgSettingsSegments.
Command for DlgSettingsDigitizeCurve.
Command for editing the graph coordinates one axis point.
Command for moving all selected Points by a specified translation.
Definition: CmdCopy.h:18
Command for changing the currently selected CoordSystem.
Command for moving all selected Points by a specified translation.
Definition: CmdPaste.h:18
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:82
Command for DlgSettingsExportFormat.
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
Definition: CmdFactory.cpp:41