Engauge Digitizer 2
Loading...
Searching...
No Matches
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 "InactiveOpacity.h"
11#include "Logger.h"
12#include <QObject>
13#include <QTextStream>
14#include <QXmlStreamWriter>
15#include "Xml.h"
16
17const double DEFAULT_POINT_SEPARATION = 25;
18const double DEFAULT_MIN_LENGTH = 2;
19const double DEFAULT_LINE_WIDTH_ACTIVE = 6; // Highlight is slightly bigger
22const InactiveOpacity DEFAULT_INACTIVE_OPACITY = INACTIVE_OPACITY_128; // Highlight is slightly brighter as INACTIVE_OPACITY_256
23
25 m_pointSeparation (DEFAULT_POINT_SEPARATION),
26 m_minLength (DEFAULT_MIN_LENGTH),
27 m_fillCorners (false),
28 m_lineWidthActive (DEFAULT_LINE_WIDTH_ACTIVE),
29 m_lineWidthInactive (DEFAULT_LINE_WIDTH_INACTIVE),
30 m_lineColor (DEFAULT_LINE_COLOR),
31 m_inactiveOpacity (DEFAULT_INACTIVE_OPACITY)
32{
33}
34
36 m_pointSeparation (document.modelSegments().pointSeparation()),
37 m_minLength (document.modelSegments().minLength()),
38 m_fillCorners (document.modelSegments().fillCorners()),
39 m_lineWidthActive (document.modelSegments().lineWidthActive()),
40 m_lineWidthInactive (document.modelSegments().lineWidthInactive()),
41 m_lineColor (document.modelSegments().lineColor()),
42 m_inactiveOpacity (document.modelSegments().inactiveOpacity())
43{
44}
45
47 m_pointSeparation (other.pointSeparation()),
48 m_minLength (other.minLength()),
49 m_fillCorners (other.fillCorners ()),
50 m_lineWidthActive (other.lineWidthActive()),
51 m_lineWidthInactive (other.lineWidthInactive()),
52 m_lineColor (other.lineColor()),
53 m_inactiveOpacity (other.inactiveOpacity())
54{
55}
56
58{
59 m_pointSeparation = other.pointSeparation();
60 m_minLength = other.minLength();
61 m_fillCorners = other.fillCorners ();
62 m_lineWidthActive = other.lineWidthActive();
63 m_lineWidthInactive = other.lineWidthInactive();
64 m_lineColor = other.lineColor();
65 m_inactiveOpacity = other.inactiveOpacity();
66
67 return *this;
68}
69
71{
72 return m_fillCorners;
73}
74
76{
77 return m_inactiveOpacity;
78}
79
81{
82 return m_lineColor;
83}
84
86{
87 return m_lineWidthActive;
88}
89
91{
92 return m_lineWidthInactive;
93}
94
95void DocumentModelSegments::loadXml(QXmlStreamReader &reader)
96{
97 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::loadXml";
98
99 bool success = true;
100
101 QXmlStreamAttributes attributes = reader.attributes ();
102
103 // Entries that are optional since they were removed in version 13
104 // DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH
105 // Entries that are optional since they were added in version 13
106 // DOCUMENT_SERIALIZE_SEGMENTS_INACTIVE_OPACITY
107 // DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_ACTIVE
108 // DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_ACTIVE_STRING
109 // DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_INACTIVE
110 // DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_INACTIVE_STRING
111 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION) &&
112 attributes.hasAttribute(DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH) &&
113 attributes.hasAttribute(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS) &&
114 attributes.hasAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH) &&
115 attributes.hasAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR)) {
116
117 // Boolean values
118 QString fillCorners = attributes.value(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS).toString();
119
121 setMinLength (attributes.value (DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH).toDouble());
123 setLineColor (static_cast<ColorPalette> (attributes.value (DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR).toInt()));
124
125 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_SEGMENTS_INACTIVE_OPACITY)) {
126 setInactiveOpacity (static_cast<InactiveOpacity> (attributes.value (DOCUMENT_SERIALIZE_SEGMENTS_INACTIVE_OPACITY).toInt ()));
127 } else{
129 }
130
131 // For line widths, first look for single value (corresponding to versions before 13), then look
132 // for two values (corresponding to version 13+)
135 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH)) {
136 lineWidthActive = attributes.value (DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH).toInt ();
137 lineWidthInactive = attributes.value (DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH).toInt ();
138 } else if (attributes.hasAttribute (DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_ACTIVE) &&
139 attributes.hasAttribute (DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_INACTIVE)) {
142 }
145
146 // Read until end of this subtree
147 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
148 (reader.name() != DOCUMENT_SERIALIZE_SEGMENTS)){
149 loadNextFromReader(reader);
150 if (reader.atEnd()) {
151 success = false;
152 break;
153 }
154 }
155 }
156
157 if (!success) {
158 reader.raiseError(QObject::tr ("Cannot read segment data"));
159 }
160}
161
163{
164 return m_minLength;
165}
166
168{
169 return m_pointSeparation;
170}
171
172void DocumentModelSegments::printStream(QString indentation,
173 QTextStream &str) const
174{
175 str << indentation << "DocumentModelSegments\n";
176
177 indentation += INDENTATION_DELTA;
178
179 str << indentation << "pointSeparation=" << m_pointSeparation << "\n";
180 str << indentation << "minLength=" << m_minLength << "\n";
181 str << indentation << "fillCorners=" << (m_fillCorners ? "true" : "false") << "\n";
182 str << indentation << "lineWidthActive=" << m_lineWidthActive << "\n";
183 str << indentation << "lineWidthInactive=" << m_lineWidthInactive << "\n";
184 str << indentation << "lineColor=" << colorPaletteToString (m_lineColor) << "\n";
185 str << indentation << "inactiveOpacity=" << m_inactiveOpacity << "\n";
186}
187
188void DocumentModelSegments::saveXml(QXmlStreamWriter &writer) const
189{
190 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::saveXml";
191
192 writer.writeStartElement(DOCUMENT_SERIALIZE_SEGMENTS);
193 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION, QString::number (m_pointSeparation));
194 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH, QString::number (m_minLength));
195 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS, m_fillCorners ?
198 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_ACTIVE, QString::number (m_lineWidthActive));
199 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_INACTIVE, QString::number (m_lineWidthInactive));
200 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR, QString::number (m_lineColor));
201 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING, colorPaletteToString (m_lineColor));
202 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_INACTIVE_OPACITY, QString::number (m_inactiveOpacity));
203 writer.writeEndElement();
204}
205
207{
208 m_fillCorners = fillCorners;
209}
210
215
220
222{
223 m_lineWidthActive = lineWidthActive;
224}
225
230
232{
233 m_minLength = minLength;
234}
235
237{
238 m_pointSeparation = pointSeparation;
239}
QString colorPaletteToString(ColorPalette colorPalette)
ColorPalette
@ COLOR_PALETTE_GREEN
const ColorPalette DEFAULT_LINE_COLOR
const double DEFAULT_LINE_WIDTH_ACTIVE
const double DEFAULT_LINE_WIDTH_INACTIVE
const double DEFAULT_MIN_LENGTH
const double DEFAULT_POINT_SEPARATION
const InactiveOpacity DEFAULT_INACTIVE_OPACITY
const QString DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_INACTIVE
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR
const QString DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION
const QString DOCUMENT_SERIALIZE_SEGMENTS
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING
const QString DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS
const QString DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH_ACTIVE
const QString DOCUMENT_SERIALIZE_SEGMENTS_INACTIVE_OPACITY
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
InactiveOpacity
Enum for opacity/alpha values used for segments that are not currently under hover.
@ INACTIVE_OPACITY_128
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
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
DocumentModelSegments()
Default constructor.
void setFillCorners(bool fillCorners)
Set method for fill corners.
void setLineWidthActive(double lineWidth)
Set method for line width when active.
double lineWidthInactive() const
Get method for line width when inactive.
double lineWidthActive() const
Get method for line width when active.
void setInactiveOpacity(InactiveOpacity inactiveOpacity)
Set method for inactive opacity.
void setPointSeparation(double pointSeparation)
Set method for point separation.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
InactiveOpacity inactiveOpacity() const
Get method for inactive opacity.
void setLineWidthInactive(double lineWidth)
Set method for line width when inactive.
DocumentModelSegments & operator=(const DocumentModelSegments &other)
Assignment constructor.
ColorPalette lineColor() const
Get method for line color.
double minLength() const
Get method for min length.
void setLineColor(ColorPalette lineColor)
Set method for line color.
bool fillCorners() const
Get method for fill corners.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
double pointSeparation() const
Get method for point separation.
void setMinLength(double minLength)
Set method for min length.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18