Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAbstract.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 "DataKey.h"
9#include "Document.h"
10#include "GraphicsItemType.h"
11#include "GraphicsScene.h"
12#include "GraphicsView.h"
13#include "Logger.h"
14#include "MainWindow.h"
15#include "Point.h"
16#include <QGraphicsItem>
17
19 Document &document,
20 const QString &cmdDescription) :
21 QUndoCommand (cmdDescription),
22 m_mainWindow (mainWindow),
23 m_document (document),
24 m_isFirstRedo (true)
25{
26 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::CmdAbstract";
27}
28
29CmdAbstract::~CmdAbstract()
30{
31}
32
34{
35 return m_document;
36}
37
39{
40 return m_document;
41}
42
44{
45 return m_mainWindow;
46}
47
48void CmdAbstract::redo ()
49{
50 // Note that m_identifierIndexBeforeRedo and m_identifierIndexAfterRedo are not set until below (at which point they are logged)
51 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo";
52
53 if (m_isFirstRedo) {
54
55 m_identifierIndexBeforeRedo = Point::identifierIndex ();
56
57 } else {
58
59 // Reset state. The first time this is called, this is a noop since m_identifierIndex was just set to
60 // GraphicsPointAbstractBase::identifierIndex in the constructor of this class
61 Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
62
63 }
64
65 // Invoke the leaf class redo method
66 cmdRedo ();
67
68 if (m_isFirstRedo) {
69
70 m_isFirstRedo = false;
71 m_identifierIndexAfterRedo = Point::identifierIndex();
72
73 }
74
75 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo identifierIndex=" << m_identifierIndexBeforeRedo << "->"
76 << m_identifierIndexAfterRedo;
77}
78
79void CmdAbstract::resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
80{
81 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::resetSelection";
82
83 QList<QGraphicsItem *> items = mainWindow().view().items();
84 QList<QGraphicsItem *>::iterator itrS;
85 for (itrS = items.begin (); itrS != items.end (); itrS++) {
86
87 QGraphicsItem *item = *itrS;
88 bool selected = false;
89 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
90
91 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
92
93 selected = pointIdentifiersToSelect.contains (pointIdentifier);
94 }
95
96 item->setSelected (selected);
97 }
98}
99
100void CmdAbstract::undo ()
101{
102 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::undo identifierIndex=" << m_identifierIndexAfterRedo << "->"
103 << m_identifierIndexBeforeRedo;
104
105 Point::setIdentifierIndex (m_identifierIndexAfterRedo);
106
107 // Invoke the leaf class undo method
108 cmdUndo ();
109
110 Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
111}
Document & document()
Return the Document that this command will modify during redo and undo.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
virtual void cmdUndo()=0
Undo method that is called when QUndoStack is moved one command backward.
void resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
Since the set of selected points has probably changed, changed that set back to the specified set.
CmdAbstract(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
virtual void cmdRedo()=0
Redo method that is called when QUndoStack is moved one command forward.
Storage of one imported image and the data attached to that image.
Definition Document.h:41
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
Hash table class that tracks point identifiers as the key, with a corresponding boolean value.
bool contains(const QString &pointIdentifier) const
True if specified entry exists in the table.
static unsigned int identifierIndex()
Return the current index for storage in case we need to reset it later while performing a Redo.
Definition Point.cpp:261
static void setIdentifierIndex(unsigned int identifierIndex)
Reset the current index while performing a Redo.
Definition Point.cpp:460