Engauge Digitizer  2
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 "CmdMoveBy.h"
18 #include "CmdRedoForTest.h"
19 #include "CmdSelectCoordSystem.h"
20 #include "CmdSettingsAxesChecker.h"
21 #include "CmdSettingsColorFilter.h"
22 #include "CmdSettingsCoords.h"
23 #include "CmdSettingsCurveList.h"
27 #include "CmdSettingsGeneral.h"
28 #include "CmdSettingsGridRemoval.h"
29 #include "CmdSettingsPointMatch.h"
30 #include "CmdSettingsSegments.h"
31 #include "CmdUndoForTest.h"
32 #include "Document.h"
33 #include "DocumentSerialize.h"
34 #include "EngaugeAssert.h"
35 #include "MainWindow.h"
36 #include <QXmlStreamReader>
37 
39 {
40 }
41 
43  Document &document,
44  QXmlStreamReader &reader)
45 {
46  CmdAbstract *cmd = nullptr;
47 
48  QXmlStreamAttributes attributes = reader.attributes();
49  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_TYPE) ||
50  !attributes.hasAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION)) {
51 
52  // Invalid xml
53  ENGAUGE_ASSERT(false);
54 
55  }
56 
57  // Get common attributes
58  QString cmdType = attributes.value(DOCUMENT_SERIALIZE_CMD_TYPE).toString();
59  QString cmdDescription = attributes.value(DOCUMENT_SERIALIZE_CMD_DESCRIPTION).toString();
60 
62  cmd = new CmdAddPointAxis (mainWindow,
63  document,
64  cmdDescription,
65  reader);
66  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH) {
67  cmd = new CmdAddPointGraph (mainWindow,
68  document,
69  cmdDescription,
70  reader);
71  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH) {
72  cmd = new CmdAddPointsGraph (mainWindow,
73  document,
74  cmdDescription,
75  reader);
76  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_COPY) {
77  cmd = new CmdCopy (mainWindow,
78  document,
79  cmdDescription,
80  reader);
81  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_CUT) {
82  cmd = new CmdCut (mainWindow,
83  document,
84  cmdDescription,
85  reader);
86  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_DELETE) {
87  cmd = new CmdDelete (mainWindow,
88  document,
89  cmdDescription,
90  reader);
91  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS) {
92  cmd = new CmdEditPointAxis (mainWindow,
93  document,
94  cmdDescription,
95  reader);
96  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH) {
97  cmd = new CmdEditPointGraph (mainWindow,
98  document,
99  cmdDescription,
100  reader);
101  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_MOVE_BY) {
102  cmd = new CmdMoveBy (mainWindow,
103  document,
104  cmdDescription,
105  reader);
106  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST) {
107  cmd = new CmdRedoForTest (mainWindow,
108  document,
109  cmdDescription,
110  reader);
111  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM) {
112  cmd = new CmdSelectCoordSystem (mainWindow,
113  document,
114  cmdDescription,
115  reader);
116  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER) {
117  cmd = new CmdSettingsAxesChecker (mainWindow,
118  document,
119  cmdDescription,
120  reader);
121  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER) {
122  cmd = new CmdSettingsColorFilter (mainWindow,
123  document,
124  cmdDescription,
125  reader);
126  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS) {
127  cmd = new CmdSettingsCoords (mainWindow,
128  document,
129  cmdDescription,
130  reader);
131  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST) {
132  cmd = new CmdSettingsCurveList (mainWindow,
133  document,
134  cmdDescription,
135  reader);
136  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_PROPERTIES) {
137  cmd = new CmdSettingsCurveProperties (mainWindow,
138  document,
139  cmdDescription,
140  reader);
141  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_DIGITIZE_CURVE) {
142  cmd = new CmdSettingsDigitizeCurve (mainWindow,
143  document,
144  cmdDescription,
145  reader);
146  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT) {
147  cmd = new CmdSettingsExportFormat (mainWindow,
148  document,
149  cmdDescription,
150  reader);
151  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GENERAL) {
152  cmd = new CmdSettingsGeneral (mainWindow,
153  document,
154  cmdDescription,
155  reader);
156  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL) {
157  cmd = new CmdSettingsGridRemoval (mainWindow,
158  document,
159  cmdDescription,
160  reader);
161  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH) {
162  cmd = new CmdSettingsPointMatch (mainWindow,
163  document,
164  cmdDescription,
165  reader);
166  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS) {
167  cmd = new CmdSettingsSegments (mainWindow,
168  document,
169  cmdDescription,
170  reader);
171  } else if (cmdType == DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST) {
172  cmd = new CmdUndoForTest (mainWindow,
173  document,
174  cmdDescription,
175  reader);
176  } else {
177 
178  // Invalid xml
179  ENGAUGE_ASSERT (false);
180 
181  }
182 
183  return cmd;
184 }
const QString DOCUMENT_SERIALIZE_CMD_MOVE_BY
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_PROPERTIES
const QString DOCUMENT_SERIALIZE_CMD_UNDO_FOR_TEST
const QString DOCUMENT_SERIALIZE_CMD_CUT
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:38
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_GENERAL
Command for editing the graph coordinates of one or more graph points.
Command for performing Redo during testing.
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_AXES_CHECKER
const QString DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM
Command for moving all selected Points by a specified translation.
Definition: CmdMoveBy.h:18
Command for DlgSettingsCurveProperties.
const QString DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_EXPORT
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_COLOR_FILTER
Command for DlgSettingsPointMatch.
Command for DlgSettingsGeneral.
Command for DlgSettingsCoords.
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINT_AXIS
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
Command for DlgSettingsAxesChecker.
Command for adding one axis point.
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_DIGITIZE_CURVE
Command for adding one or more graph points. This is for Segment Fill mode.
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS
Command for adding one graph point.
const QString DOCUMENT_SERIALIZE_CMD_COPY
const QString DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS
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
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH
Command for DlgSettingsGridRemoval.
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST
Command for DlgSettingsColorFilter.
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_GRID_REMOVAL
Command for DlgSettingsSegments.
Command for DlgSettingsDigitizeCurve.
const QString DOCUMENT_SERIALIZE_CMD_DELETE
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_SEGMENTS
Command for DlgSettingsCurveList.
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.
const QString DOCUMENT_SERIALIZE_CMD_REDO_FOR_TEST
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:91
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_POINT_MATCH
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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:42