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