Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdMediator.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 "CmdFactory.h"
9#include "CmdMediator.h"
10#include "Document.h"
11#include "DocumentSerialize.h"
12#include "EngaugeAssert.h"
13#include "Logger.h"
14#include "LoggerUpload.h"
15#include "MainWindow.h"
16#include "Point.h"
17#include <QDomNode>
18#include <QImage>
19#include <QUndoCommand>
20#include <QXmlStreamReader>
21#include <QXmlStreamWriter>
22#include "Transformation.h"
23#include "Xml.h"
24
26 const QImage &image) :
27 m_document (image)
28{
29 LOG4CPP_INFO_S ((*mainCat)) << "CmdMediator::CmdMediator image=" << image.width() << "x" << image.height ();
30
31 connectSignals(mainWindow);
32}
33
35 const QString &fileName) :
36 m_document (fileName)
37{
38 LOG4CPP_INFO_S ((*mainCat)) << "CmdMediator::CmdMediator filename=" << fileName.toLatin1().data();
39
40 connectSignals(mainWindow);
41}
42
46
47void CmdMediator::connectSignals (MainWindow &mainWindow)
48{
49 connect (this, SIGNAL (cleanChanged (bool)), &mainWindow, SLOT (slotCleanChanged (bool)));
50}
51
53{
54 return m_document.coordSystem();
55}
56
58{
59 return m_document.curveAxes ();
60}
61
63{
64 return m_document.curvesGraphsNames();
65}
66
67int CmdMediator::curvesGraphsNumPoints (const QString &curveName) const
68{
69 return m_document.curvesGraphsNumPoints(curveName);
70}
71
73{
74 return m_document;
75}
76
78{
79 return m_document;
80}
81
83{
84 return !isClean();
85}
86
87void CmdMediator::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
88{
89 m_document.iterateThroughCurvePointsAxes (ftorWithCallback);
90}
91
92void CmdMediator::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
93{
94 m_document.iterateThroughCurvePointsAxes (ftorWithCallback);
95}
96
97void CmdMediator::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
98{
99 return m_document.iterateThroughCurvesPointsGraphs (ftorWithCallback);
100}
101
102QPixmap CmdMediator::pixmap () const
103{
104 ENGAUGE_ASSERT (m_document.successfulRead ());
105
106 return m_document.pixmap ();
107}
108
110{
111 return m_document.reasonForUnsuccessfulRead ();
112}
113
114void CmdMediator::saveXml(QXmlStreamWriter &writer) const
115{
116 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD_MEDIATOR);
117
118 for (int i = 0; i < index(); i++) {
119
120 const CmdAbstract *cmd = dynamic_cast<const CmdAbstract *>(command(i));
121 cmd->saveXml (writer);
122 }
123
124 writer.writeEndElement();
125}
126
128{
129 return m_document.selectedCurveName ();
130}
131
133{
134 m_document.setDocumentAxesPointsRequired (documentAxesPointsRequired);
135}
136
138{
139 m_document.setSelectedCurveName (selectedCurveName);
140}
141
143{
144 return m_document.successfulRead();
145}
const QString DOCUMENT_SERIALIZE_CMD_MEDIATOR
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:24
virtual void saveXml(QXmlStreamWriter &writer) const =0
Save commands as xml for later uploading.
~CmdMediator()
Destructor.
const Curve & curveAxes() const
See Document::curveAxes.
QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow.
QString reasonForUnsuccessfulRead() const
See Document::reasonForUnsuccessfulRead.
QPixmap pixmap() const
See Document::pixmap.
bool isModified() const
Dirty flag.
void saveXml(QXmlStreamWriter &writer) const
Serialize to xml.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
void setSelectedCurveName(const QString &selectedCurveName)
Save curve name that is selected for the current coordinate system, for the next time the coordinate ...
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
const CoordSystem & coordSystem() const
Provide the current CoordSystem to commands with read-only access, primarily for undo/redo processing...
CmdMediator(MainWindow &mainWindow, const QImage &image)
Constructor for imported images and dragged images. Only one coordinate system is created but others ...
int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
bool successfulRead() const
Wrapper for Document::successfulRead.
void setDocumentAxesPointsRequired(DocumentAxesPointsRequired documentAxesPointsRequired)
Set the number of axes points required.
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the single axes curve.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Storage of data belonging to one coordinate system.
Definition CoordSystem.h:44
Container for one set of digitized Points.
Definition Curve.h:34
Storage of one imported image and the data attached to that image.
Definition Document.h:44
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