Engauge Digitizer  2
DocumentModelSegments.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_POINT_SEPARATION = 25;
17 const double DEFAULT_MIN_LENGTH = 2;
18 const double DEFAULT_LINE_WIDTH = 4;
20 
22  m_pointSeparation (DEFAULT_POINT_SEPARATION),
23  m_minLength (DEFAULT_MIN_LENGTH),
24  m_fillCorners (false),
25  m_lineWidth (DEFAULT_LINE_WIDTH),
26  m_lineColor (DEFAULT_LINE_COLOR)
27 {
28 }
29 
31  m_pointSeparation (document.modelSegments().pointSeparation()),
32  m_minLength (document.modelSegments().minLength()),
33  m_fillCorners (document.modelSegments().fillCorners()),
34  m_lineWidth (document.modelSegments().lineWidth()),
35  m_lineColor (document.modelSegments().lineColor())
36 {
37 }
38 
40  m_pointSeparation (other.pointSeparation()),
41  m_minLength (other.minLength()),
42  m_fillCorners (other.fillCorners ()),
43  m_lineWidth (other.lineWidth()),
44  m_lineColor (other.lineColor())
45 {
46 }
47 
49 {
50  m_pointSeparation = other.pointSeparation();
51  m_minLength = other.minLength();
52  m_fillCorners = other.fillCorners ();
53  m_lineWidth = other.lineWidth();
54  m_lineColor = other.lineColor();
55 
56  return *this;
57 }
58 
60 {
61  return m_fillCorners;
62 }
63 
65 {
66  return m_lineColor;
67 }
68 
70 {
71  return m_lineWidth;
72 }
73 
74 void DocumentModelSegments::loadXml(QXmlStreamReader &reader)
75 {
76  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::loadXml";
77 
78  bool success = true;
79 
80  // Read until end of this subtree
81  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
82  (reader.name() != DOCUMENT_SERIALIZE_SEGMENTS)){
83  loadNextFromReader(reader);
84  if (reader.atEnd()) {
85  success = false;
86  break;
87  }
88  }
89 
90  if (!success) {
91  reader.raiseError(QObject::tr ("Cannot read segment data"));
92  }
93 }
94 
96 {
97  return m_minLength;
98 }
99 
101 {
102  return m_pointSeparation;
103 }
104 
105 void DocumentModelSegments::printStream(QString indentation,
106  QTextStream &str) const
107 {
108  str << indentation << "DocumentModelSegments\n";
109 
110  indentation += INDENTATION_DELTA;
111 
112  str << indentation << "pointSeparation=" << m_pointSeparation << "\n";
113  str << indentation << "minLength=" << m_minLength << "\n";
114  str << indentation << "fillCorners=" << (m_fillCorners ? "true" : "false") << "\n";
115  str << indentation << "lineWidth=" << m_lineWidth << "\n";
116  str << indentation << "lineColor=" << colorPaletteToString (m_lineColor) << "\n";
117 }
118 
119 void DocumentModelSegments::saveXml(QXmlStreamWriter &writer) const
120 {
121  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::saveXml";
122 
123  writer.writeStartElement(DOCUMENT_SERIALIZE_SEGMENTS);
124  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION, QString::number (m_pointSeparation));
125  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH, QString::number (m_minLength));
126  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS, m_fillCorners ?
129  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH, QString::number (m_lineWidth));
130  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR, QString::number (m_lineColor));
131  writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING, colorPaletteToString (m_lineColor));
132  writer.writeEndElement();
133 }
134 
136 {
137  m_fillCorners = fillCorners;
138 }
139 
141 {
142  m_lineColor = lineColor;
143 }
144 
146 {
147  m_lineWidth = lineWidth;
148 }
149 
151 {
152  m_minLength = minLength;
153 }
154 
155 void DocumentModelSegments::setPointSeparation(double pointSeparation)
156 {
157  m_pointSeparation = pointSeparation;
158 }
const QString DOCUMENT_SERIALIZE_SEGMENTS
const QString DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
double pointSeparation() const
Get method for point separation.
void setLineColor(ColorPalette lineColor)
Set method for line color.
QString colorPaletteToString(ColorPalette colorPalette)
Definition: ColorPalette.cpp:9
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH
const QString INDENTATION_DELTA
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setMinLength(double minLength)
Set method for min length.
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR
double lineWidth() const
Get method for line width.
const double DEFAULT_POINT_SEPARATION
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
double minLength() const
Get method for min length.
bool fillCorners() const
Get method for fill corners.
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void setLineWidth(double lineWidth)
Set method for line width.
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
void setFillCorners(bool fillCorners)
Set method for fill corners.
const double DEFAULT_LINE_WIDTH
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
DocumentModelSegments()
Default constructor.
DocumentModelSegments & operator=(const DocumentModelSegments &other)
Assignment constructor.
const ColorPalette DEFAULT_LINE_COLOR(COLOR_PALETTE_GREEN)
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const double DEFAULT_MIN_LENGTH
ColorPalette lineColor() const
Get method for line color.
Model for DlgSettingsSegments and CmdSettingsSegments.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
const QString DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH
void setPointSeparation(double pointSeparation)
Set method for point separation.
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING
ColorPalette
Definition: ColorPalette.h:12