Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DocumentModelSegments.cpp
1 #include "CmdMediator.h"
2 #include "DocumentModelSegments.h"
3 #include "DocumentSerialize.h"
4 #include "Logger.h"
5 #include <QTextStream>
6 #include <QXmlStreamWriter>
7 #include "Xml.h"
8 
9 const double DEFAULT_POINT_SEPARATION = 25;
10 const double DEFAULT_MIN_LENGTH = 2;
11 const double DEFAULT_LINE_WIDTH = 4;
12 const ColorPalette DEFAULT_LINE_COLOR (COLOR_PALETTE_GREEN);
13 
15  m_pointSeparation (DEFAULT_POINT_SEPARATION),
16  m_minLength (DEFAULT_MIN_LENGTH),
17  m_fillCorners (false),
18  m_lineWidth (DEFAULT_LINE_WIDTH),
19  m_lineColor (DEFAULT_LINE_COLOR)
20 {
21 }
22 
24  m_pointSeparation (document.modelSegments().pointSeparation()),
25  m_minLength (document.modelSegments().minLength()),
26  m_fillCorners (document.modelSegments().fillCorners()),
27  m_lineWidth (document.modelSegments().lineWidth()),
28  m_lineColor (document.modelSegments().lineColor())
29 {
30 }
31 
33  m_pointSeparation (other.pointSeparation()),
34  m_minLength (other.minLength()),
35  m_fillCorners (other.fillCorners ()),
36  m_lineWidth (other.lineWidth()),
37  m_lineColor (other.lineColor())
38 {
39 }
40 
42 {
43  m_pointSeparation = other.pointSeparation();
44  m_minLength = other.minLength();
45  m_fillCorners = other.fillCorners ();
46  m_lineWidth = other.lineWidth();
47  m_lineColor = other.lineColor();
48 
49  return *this;
50 }
51 
53 {
54  return m_fillCorners;
55 }
56 
58 {
59  return m_lineColor;
60 }
61 
63 {
64  return m_lineWidth;
65 }
66 
67 void DocumentModelSegments::loadXml(QXmlStreamReader &reader)
68 {
69  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::loadXml";
70 
71  bool success = true;
72 
73  // Read until end of this subtree
74  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
75  (reader.name() != DOCUMENT_SERIALIZE_SEGMENTS)){
76  loadNextFromReader(reader);
77  if (reader.atEnd()) {
78  success = false;
79  break;
80  }
81  }
82 
83  if (!success) {
84  reader.raiseError("Cannot read segment data");
85  }
86 }
87 
89 {
90  return m_minLength;
91 }
92 
94 {
95  return m_pointSeparation;
96 }
97 
98 void DocumentModelSegments::printStream(QString indentation,
99  QTextStream &str) const
100 {
101  str << indentation << "DocumentModelSegments\n";
102 
103  indentation += INDENTATION_DELTA;
104 
105  str << indentation << "pointSeparation=" << m_pointSeparation << "\n";
106  str << indentation << "minLength=" << m_minLength << "\n";
107  str << indentation << "fillCorners=" << (m_fillCorners ? "true" : "false") << "\n";
108  str << indentation << "lineWidth=" << m_lineWidth << "\n";
109  str << indentation << "lineColor=" << colorPaletteToString (m_lineColor) << "\n";
110 }
111 
112 void DocumentModelSegments::saveXml(QXmlStreamWriter &writer) const
113 {
114  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::saveXml";
115 
116  writer.writeStartElement(DOCUMENT_SERIALIZE_SEGMENTS);
117  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION, QString::number (m_pointSeparation));
118  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH, QString::number (m_minLength));
119  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS, m_fillCorners ?
120  DOCUMENT_SERIALIZE_BOOL_TRUE :
121  DOCUMENT_SERIALIZE_BOOL_FALSE);
122  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH, QString::number (m_lineWidth));
123  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR, QString::number (m_lineColor));
124  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING, colorPaletteToString (m_lineColor));
125  writer.writeEndElement();
126 }
127 
129 {
130  m_fillCorners = fillCorners;
131 }
132 
133 void DocumentModelSegments::setLineColor(ColorPalette lineColor)
134 {
135  m_lineColor = lineColor;
136 }
137 
139 {
140  m_lineWidth = lineWidth;
141 }
142 
144 {
145  m_minLength = minLength;
146 }
147 
148 void DocumentModelSegments::setPointSeparation(double pointSeparation)
149 {
150  m_pointSeparation = pointSeparation;
151 }
ColorPalette lineColor() const
Get method for line color.
void setLineColor(ColorPalette lineColor)
Set method for line color.
void setMinLength(double minLength)
Set method for min length.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
double pointSeparation() const
Get method for point separation.
void setLineWidth(double lineWidth)
Set method for line width.
void setFillCorners(bool fillCorners)
Set method for fill corners.
Storage of one imported image and the data attached to that image.
Definition: Document.h:29
double lineWidth() const
Get method for line width.
DocumentModelSegments()
Default constructor.
DocumentModelSegments & operator=(const DocumentModelSegments &other)
Assignment constructor.
double minLength() const
Get method for min length.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Model for DlgSettingsSegments and CmdSettingsSegments.
void setPointSeparation(double pointSeparation)
Set method for point separation.
bool fillCorners() const
Get method for fill corners.