Engauge Digitizer  2
DocumentModelPointMatch.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 "CmdMediator.h"
9 #include "DocumentSerialize.h"
10 #include "Logger.h"
11 #include <QObject>
12 #include <QTextStream>
13 #include <QXmlStreamWriter>
14 #include "Xml.h"
15 
16 const double DEFAULT_MIN_POINT_SEPARATION = 20;
17 const double DEFAULT_MAX_POINT_SIZE = 48;
21 
23  m_minPointSeparation (DEFAULT_MIN_POINT_SEPARATION),
24  m_maxPointSize (DEFAULT_MAX_POINT_SIZE),
25  m_paletteColorAccepted (DEFAULT_COLOR_ACCEPTED),
26  m_paletteColorCandidate (DEFAULT_COLOR_CANDIDATE),
27  m_paletteColorRejected (DEFAULT_COLOR_REJECTED)
28 {
29 }
30 
32  m_maxPointSize (document.modelPointMatch().maxPointSize()),
33  m_paletteColorAccepted (document.modelPointMatch().paletteColorAccepted()),
34  m_paletteColorCandidate (document.modelPointMatch().paletteColorCandidate()),
35  m_paletteColorRejected (document.modelPointMatch().paletteColorRejected())
36 {
37 }
38 
40  m_maxPointSize (other.maxPointSize()),
41  m_paletteColorAccepted (other.paletteColorAccepted()),
42  m_paletteColorCandidate (other.paletteColorCandidate()),
43  m_paletteColorRejected (other.paletteColorRejected())
44 {
45 }
46 
48 {
49  m_maxPointSize = other.maxPointSize();
50  m_paletteColorAccepted = other.paletteColorAccepted();
51  m_paletteColorCandidate = other.paletteColorCandidate();
52  m_paletteColorRejected = other.paletteColorRejected();
53 
54  return *this;
55 }
56 
57 void DocumentModelPointMatch::loadXml(QXmlStreamReader &reader)
58 {
59  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelPointMatch::loadXml";
60 
61  bool success = true;
62 
63  QXmlStreamAttributes attributes = reader.attributes();
64 
65  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE) &&
66  attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED) &&
67  attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE) &&
68  attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED)) {
69 
70  setMaxPointSize (attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE).toDouble());
74 
75  // Read until end of this subtree
76  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
77  (reader.name() != DOCUMENT_SERIALIZE_POINT_MATCH)){
78  loadNextFromReader(reader);
79  if (reader.atEnd()) {
80  success = false;
81  break;
82  }
83  }
84  }
85 
86  if (!success) {
87  reader.raiseError (QObject::tr ("Cannot read point match data"));
88  }
89 }
90 
92 {
93  return m_maxPointSize;
94 }
95 
97 {
98  return m_paletteColorAccepted;
99 }
100 
102 {
103  return m_paletteColorCandidate;
104 }
105 
107 {
108  return m_paletteColorRejected;
109 }
110 
111 void DocumentModelPointMatch::printStream(QString indentation,
112  QTextStream &str) const
113 {
114  str << indentation << "DocumentModelPointMatch\n";
115 
116  indentation += INDENTATION_DELTA;
117 
118  str << indentation << "minPointSeparation=" << m_minPointSeparation << "\n";
119  str << indentation << "maxPointSize=" << m_maxPointSize << "\n";
120  str << indentation << "colorAccepted=" << colorPaletteToString (m_paletteColorAccepted) << "\n";
121  str << indentation << "colorCandidate=" << colorPaletteToString (m_paletteColorCandidate) << "\n";
122  str << indentation << "colorRejected=" << colorPaletteToString (m_paletteColorRejected) << "\n";
123 }
124 
125 void DocumentModelPointMatch::saveXml(QXmlStreamWriter &writer) const
126 {
127  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelPointMatch::saveXml";
128 
129  writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_MATCH);
130  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE, QString::number (m_maxPointSize));
131  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED, QString::number (m_paletteColorAccepted));
132  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED_STRING, colorPaletteToString (m_paletteColorAccepted));
133  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE, QString::number (m_paletteColorCandidate));
134  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE_STRING, colorPaletteToString (m_paletteColorCandidate));
135  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED, QString::number (m_paletteColorRejected));
136  writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED_STRING, colorPaletteToString (m_paletteColorRejected));
137  writer.writeEndElement();
138 }
139 
141 {
142  m_maxPointSize = maxPointSize;
143 }
144 
146 {
147  m_paletteColorAccepted = paletteColorAccepted;
148 }
149 
151 {
152  m_paletteColorCandidate = paletteColorCandidate;
153 }
154 
156 {
157  m_paletteColorRejected = paletteColorRejected;
158 }
QString colorPaletteToString(ColorPalette colorPalette)
Definition: ColorPalette.cpp:9
ColorPalette
Definition: ColorPalette.h:12
@ COLOR_PALETTE_GREEN
Definition: ColorPalette.h:17
@ COLOR_PALETTE_RED
Definition: ColorPalette.h:19
@ COLOR_PALETTE_YELLOW
Definition: ColorPalette.h:20
const ColorPalette DEFAULT_COLOR_REJECTED
const ColorPalette DEFAULT_COLOR_ACCEPTED
const ColorPalette DEFAULT_COLOR_CANDIDATE
const double DEFAULT_MAX_POINT_SIZE
const double DEFAULT_MIN_POINT_SEPARATION
const QString DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE_STRING
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED_STRING
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED_STRING
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED
const QString DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE
const QString DOCUMENT_SERIALIZE_POINT_MATCH
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString INDENTATION_DELTA
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
void setMaxPointSize(double maxPointSize)
Set method for max point size.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void setPaletteColorCandidate(ColorPalette paletteColorCandidate)
Set method for candidate color.
ColorPalette paletteColorRejected() const
Get method for rejected color.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setPaletteColorAccepted(ColorPalette paletteColorAccepted)
Set method for accepted color.
ColorPalette paletteColorCandidate() const
Get method for candidate color.
DocumentModelPointMatch & operator=(const DocumentModelPointMatch &other)
Assignment constructor.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
double maxPointSize() const
Get method for max point size.
DocumentModelPointMatch()
Default constructor.
void setPaletteColorRejected(ColorPalette paletteColorRejected)
Set method for rejected color.
ColorPalette paletteColorAccepted() const
Get method for accepted color.
Storage of one imported image and the data attached to that image.
Definition: Document.h:42
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18