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#include "MainWindow.h"
18
22
24 Document &document,
25 double valueAfter,
26 const DocumentModelGuideline &modelGuidelineDocument,
27 const QString &identifier,
28 bool draggedOffscreen)
29{
30 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineDragCommandFactory::GuidelineDragCommandFactory";
31
32 GuidelineValues valuesXDocument = modelGuidelineDocument.valuesX ();
33 GuidelineValues valuesYDocument = modelGuidelineDocument.valuesY ();
34
35 // So which Guideline moved?
36 double valueBefore = valueForIdentifier (modelGuidelineDocument,
37 identifier);
38
39 // What type was the Guideline?
40 bool isXT = isXTForIdentifier (modelGuidelineDocument,
41 identifier);
42
43 CmdAbstract *cmd = nullptr;
44
45 if (draggedOffscreen) {
46
47 // Delete
48 if (isXT) {
49 cmd = new CmdGuidelineRemoveXT(mainWindow,
50 document,
51 identifier,
52 valueBefore);
53 } else {
54 cmd = new CmdGuidelineRemoveYR(mainWindow,
55 document,
56 identifier,
57 valueBefore);
58 }
59 } else {
60
61 // Move
62 if (isXT) {
63 cmd = new CmdGuidelineMoveXT(mainWindow,
64 document,
65 identifier,
66 valueBefore,
67 valueAfter);
68 } else {
69 cmd = new CmdGuidelineMoveYR(mainWindow,
70 document,
71 identifier,
72 valueBefore,
73 valueAfter);
74 }
75 }
76
77 return cmd;
78}
79
80bool GuidelineDragCommandFactory::isXTForIdentifier (const DocumentModelGuideline &modelGuideline,
81 const QString &identifierWanted) const
82{
83 GuidelineValues::const_iterator itr;
84
85 const GuidelineValues &valuesX = modelGuideline.valuesX();
86 for (itr = valuesX.begin(); itr != valuesX.end(); itr++) {
87 QString identifierGot = itr.key();
88 if (identifierWanted == identifierGot) {
89 return true;
90 }
91 }
92
93 return false;
94}
95
96double GuidelineDragCommandFactory::valueForIdentifier (const DocumentModelGuideline &modelGuideline,
97 const QString &identifierWanted) const
98{
99 GuidelineValues::const_iterator itr;
100
101 const GuidelineValues &valuesX = modelGuideline.valuesX();
102 for (itr = valuesX.begin(); itr != valuesX.end(); itr++) {
103 QString identifierGot = itr.key();
104 if (identifierWanted == identifierGot) {
105 return itr.value ();
106 }
107 }
108
109 const GuidelineValues &valuesY = modelGuideline.valuesY();
110 for (itr = valuesY.begin(); itr != valuesY.end(); itr++) {
111 QString identifierGot = itr.key();
112 if (identifierWanted == identifierGot) {
113 return itr.value ();
114 }
115 }
116
117 LOG4CPP_ERROR_S ((*mainCat)) << "GuidelineDragCommandFactory::valueForIdentifier identifier "
118 << identifierWanted.toLatin1().data() << " was not found";
119
120 return 0.0;
121}
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:24
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 valuesY() const
Get method for y/r values.
GuidelineValues valuesX() const
Get method for x/t 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 DocumentModelGuideline &modelGuidelineDocument, 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:95
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12