Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineDragCommandFactory.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2019 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"
13#include "EngaugeAssert.h"
15#include "Guidelines.h"
16#include "Logger.h"
17
21
23 Document &document,
24 double valueAfter,
25 const DocumentModelGuidelines &modelGuidelinesDocument,
26 const QString &identifier,
27 bool draggedOffscreen)
28{
29 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineDragCommandFactory::GuidelineDragCommandFactory";
30
31 GuidelineValues valuesXDocument = modelGuidelinesDocument.valuesX ();
32 GuidelineValues valuesYDocument = modelGuidelinesDocument.valuesY ();
33
34 // So which Guideline moved?
35 double valueBefore = valueForIdentifier (modelGuidelinesDocument,
36 identifier);
37
38 // What type was the Guideline?
39 bool isXT = isXTForIdentifier (modelGuidelinesDocument,
40 identifier);
41
42 CmdAbstract *cmd = nullptr;
43
44 if (draggedOffscreen) {
45
46 // Delete
47 if (isXT) {
48 cmd = new CmdGuidelineRemoveXT(mainWindow,
49 document,
50 identifier,
51 valueBefore);
52 } else {
53 cmd = new CmdGuidelineRemoveYR(mainWindow,
54 document,
55 identifier,
56 valueBefore);
57 }
58 } else {
59
60 // Move
61 if (isXT) {
62 cmd = new CmdGuidelineMoveXT(mainWindow,
63 document,
64 identifier,
65 valueBefore,
66 valueAfter);
67 } else {
68 cmd = new CmdGuidelineMoveYR(mainWindow,
69 document,
70 identifier,
71 valueBefore,
72 valueAfter);
73 }
74 }
75
76 return cmd;
77}
78
79bool GuidelineDragCommandFactory::isXTForIdentifier (const DocumentModelGuidelines &modelGuidelines,
80 const QString &identifierWanted) const
81{
82 GuidelineValues::const_iterator itr;
83
84 const GuidelineValues &valuesX = modelGuidelines.valuesX();
85 for (itr = valuesX.begin(); itr != valuesX.end(); itr++) {
86 QString identifierGot = itr.key();
87 if (identifierWanted == identifierGot) {
88 return true;
89 }
90 }
91
92 return false;
93}
94
95double GuidelineDragCommandFactory::valueForIdentifier (const DocumentModelGuidelines &modelGuidelines,
96 const QString &identifierWanted) const
97{
98 GuidelineValues::const_iterator itr;
99
100 const GuidelineValues &valuesX = modelGuidelines.valuesX();
101 for (itr = valuesX.begin(); itr != valuesX.end(); itr++) {
102 QString identifierGot = itr.key();
103 if (identifierWanted == identifierGot) {
104 return itr.value ();
105 }
106 }
107
108 const GuidelineValues &valuesY = modelGuidelines.valuesY();
109 for (itr = valuesY.begin(); itr != valuesY.end(); itr++) {
110 QString identifierGot = itr.key();
111 if (identifierWanted == identifierGot) {
112 return itr.value ();
113 }
114 }
115
116 LOG4CPP_ERROR_S ((*mainCat)) << "GuidelineDragCommandFactory::valueForIdentifier identifier "
117 << identifierWanted.toLatin1().data() << " was not found";
118
119 return 0.0;
120}
QMap< QString, double > GuidelineValues
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 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.
Model for managing the coordinate values corresponding Guidelines.
GuidelineValues valuesX() const
Get method for x/t values.
GuidelineValues valuesY() const
Get method for y/r values.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
CmdAbstract * createAfterDrag(MainWindow &mainWindow, Document &document, double newValue, const DocumentModelGuidelines &modelGuidelinesDocument, const QString &identifier, bool draggedOffscreen)
Create delete or move Cmd.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:96
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12