Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Document
DocumentModelAxesChecker.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
"
8
#include "
DocumentModelAxesChecker.h
"
9
#include "
DocumentSerialize.h
"
10
#include "
Logger.h
"
11
#include <QObject>
12
#include <QTextStream>
13
#include "
QtToString.h
"
14
#include <QXmlStreamWriter>
15
#include "
Xml.h
"
16
17
const
int
DEFAULT_CHECKER_SECONDS
= 3;
18
19
// Color that should be easily visible against black axes lines. Red resonates with
20
// the default axes point color, and seems fairly bright when opacity is made transparent.
21
const
ColorPalette
DEFAULT_LINE_COLOR
=
COLOR_PALETTE_RED
;
22
23
DocumentModelAxesChecker::DocumentModelAxesChecker
() :
24
m_checkerMode (
CHECKER_MODE_N_SECONDS
),
25
m_checkerSeconds (
DEFAULT_CHECKER_SECONDS
),
26
m_lineColor (
DEFAULT_LINE_COLOR
)
27
{
28
}
29
30
DocumentModelAxesChecker::DocumentModelAxesChecker
(
const
Document
&document) :
31
m_checkerMode (document.modelAxesChecker().
checkerMode
()),
32
m_checkerSeconds (document.modelAxesChecker().
checkerSeconds
()),
33
m_lineColor (document.modelAxesChecker().
lineColor
())
34
{
35
}
36
37
DocumentModelAxesChecker::DocumentModelAxesChecker
(
const
DocumentModelAxesChecker
&other) :
38
m_checkerMode (other.
checkerMode
()),
39
m_checkerSeconds (other.
checkerSeconds
()),
40
m_lineColor (other.
lineColor
())
41
{
42
}
43
44
DocumentModelAxesChecker
&
DocumentModelAxesChecker::operator=
(
const
DocumentModelAxesChecker
&other)
45
{
46
m_checkerMode = other.
checkerMode
();
47
m_checkerSeconds = other.
checkerSeconds
();
48
m_lineColor = other.
lineColor
();
49
50
return
*
this
;
51
}
52
53
CheckerMode
DocumentModelAxesChecker::checkerMode
()
const
54
{
55
return
m_checkerMode;
56
}
57
58
int
DocumentModelAxesChecker::checkerSeconds
()
const
59
{
60
return
m_checkerSeconds;
61
}
62
63
ColorPalette
DocumentModelAxesChecker::lineColor
()
const
64
{
65
return
m_lineColor;
66
}
67
68
void
DocumentModelAxesChecker::loadXml
(QXmlStreamReader &reader)
69
{
70
qCInfo(ENGAUGE_LOG) <<
"DocumentModelAxesChecker::loadXml"
;
71
72
bool
success =
true
;
73
74
QXmlStreamAttributes attributes = reader.attributes();
75
76
if
(attributes.hasAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_MODE
) &&
77
attributes.hasAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_SECONDS
) &&
78
attributes.hasAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_LINE_COLOR
)) {
79
80
setCheckerMode
(
static_cast<
CheckerMode
>
(attributes.value(
DOCUMENT_SERIALIZE_AXES_CHECKER_MODE
).toInt()));
81
setCheckerSeconds
(attributes.value(
DOCUMENT_SERIALIZE_AXES_CHECKER_SECONDS
).toInt());
82
setLineColor
(
static_cast<
ColorPalette
>
(attributes.value(
DOCUMENT_SERIALIZE_AXES_CHECKER_LINE_COLOR
).toInt()));
83
84
// Read until end of this subtree
85
while
((reader.tokenType() != QXmlStreamReader::EndElement) ||
86
(reader.name() !=
DOCUMENT_SERIALIZE_AXES_CHECKER
)){
87
loadNextFromReader
(reader);
88
if
(reader.atEnd()) {
89
success =
false
;
90
break
;
91
}
92
}
93
}
94
95
if
(!success) {
96
reader.raiseError (QObject::tr (
"Cannot read axes checker data"
));
97
}
98
}
99
100
void
DocumentModelAxesChecker::printStream
(QString indentation,
101
QTextStream &str)
const
102
{
103
str << indentation <<
"DocumentModelAxesChecker\n"
;
104
105
indentation +=
INDENTATION_DELTA
;
106
107
str << indentation <<
"checkerMode="
<<
checkerModeToString
(m_checkerMode) <<
"\n"
;
108
str << indentation <<
"checkerSeconds="
<< m_checkerSeconds <<
"\n"
;
109
str << indentation <<
"color="
<<
colorPaletteToString
(m_lineColor) <<
"\n"
;
110
}
111
112
void
DocumentModelAxesChecker::saveXml
(QXmlStreamWriter &writer)
const
113
{
114
qCInfo(ENGAUGE_LOG) <<
"DocumentModelAxesChecker::saveXml"
;
115
116
writer.writeStartElement(
DOCUMENT_SERIALIZE_AXES_CHECKER
);
117
writer.writeAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_MODE
, QString::number (m_checkerMode));
118
writer.writeAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_SECONDS
, QString::number (m_checkerSeconds));
119
writer.writeAttribute(
DOCUMENT_SERIALIZE_AXES_CHECKER_LINE_COLOR
, QString::number (m_lineColor));
120
writer.writeEndElement();
121
}
122
123
void
DocumentModelAxesChecker::setCheckerMode
(
CheckerMode
checkerMode
)
124
{
125
m_checkerMode =
checkerMode
;
126
}
127
128
void
DocumentModelAxesChecker::setCheckerSeconds
(
int
seconds)
129
{
130
m_checkerSeconds = seconds;
131
}
132
133
void
DocumentModelAxesChecker::setLineColor
(
ColorPalette
lineColor
)
134
{
135
m_lineColor =
lineColor
;
136
}
checkerModeToString
QString checkerModeToString(CheckerMode checkerMode)
Definition
CheckerMode.cpp:10
CheckerMode
CheckerMode
Options for axes checker mode. Specifically, how long the checker is displayed after a change.
Definition
CheckerMode.h:14
CHECKER_MODE_N_SECONDS
@ CHECKER_MODE_N_SECONDS
Definition
CheckerMode.h:16
CmdMediator.h
colorPaletteToString
QString colorPaletteToString(ColorPalette colorPalette)
Definition
ColorPalette.cpp:9
ColorPalette
ColorPalette
Definition
ColorPalette.h:12
COLOR_PALETTE_RED
@ COLOR_PALETTE_RED
Definition
ColorPalette.h:19
DEFAULT_CHECKER_SECONDS
const int DEFAULT_CHECKER_SECONDS
Definition
DocumentModelAxesChecker.cpp:17
DEFAULT_LINE_COLOR
const ColorPalette DEFAULT_LINE_COLOR
Definition
DocumentModelAxesChecker.cpp:21
DocumentModelAxesChecker.h
DocumentSerialize.h
DOCUMENT_SERIALIZE_AXES_CHECKER
const QString DOCUMENT_SERIALIZE_AXES_CHECKER
DOCUMENT_SERIALIZE_AXES_CHECKER_LINE_COLOR
const QString DOCUMENT_SERIALIZE_AXES_CHECKER_LINE_COLOR
DOCUMENT_SERIALIZE_AXES_CHECKER_MODE
const QString DOCUMENT_SERIALIZE_AXES_CHECKER_MODE
DOCUMENT_SERIALIZE_AXES_CHECKER_SECONDS
const QString DOCUMENT_SERIALIZE_AXES_CHECKER_SECONDS
Logger.h
INDENTATION_DELTA
const QString INDENTATION_DELTA
QtToString.h
loadNextFromReader
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition
Xml.cpp:14
Xml.h
DocumentModelAxesChecker::printStream
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Definition
DocumentModelAxesChecker.cpp:100
DocumentModelAxesChecker::setLineColor
void setLineColor(ColorPalette lineColor)
Set method for line color.
Definition
DocumentModelAxesChecker.cpp:133
DocumentModelAxesChecker::saveXml
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Definition
DocumentModelAxesChecker.cpp:112
DocumentModelAxesChecker::lineColor
ColorPalette lineColor() const
Get method for line color.
Definition
DocumentModelAxesChecker.cpp:63
DocumentModelAxesChecker::checkerSeconds
int checkerSeconds() const
Get method for checker lifetime in seconds.
Definition
DocumentModelAxesChecker.cpp:58
DocumentModelAxesChecker::DocumentModelAxesChecker
DocumentModelAxesChecker()
Default constructor.
Definition
DocumentModelAxesChecker.cpp:23
DocumentModelAxesChecker::setCheckerSeconds
void setCheckerSeconds(int seconds)
Set method for checker lifetime in seconds.
Definition
DocumentModelAxesChecker.cpp:128
DocumentModelAxesChecker::checkerMode
CheckerMode checkerMode() const
Get method for checker lifetime mode.
Definition
DocumentModelAxesChecker.cpp:53
DocumentModelAxesChecker::loadXml
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
Definition
DocumentModelAxesChecker.cpp:68
DocumentModelAxesChecker::operator=
DocumentModelAxesChecker & operator=(const DocumentModelAxesChecker &other)
Assignment constructor.
Definition
DocumentModelAxesChecker.cpp:44
DocumentModelAxesChecker::setCheckerMode
void setCheckerMode(CheckerMode checkerMode)
Set method for checker mode.
Definition
DocumentModelAxesChecker.cpp:123
Document
Storage of one imported image and the data attached to that image.
Definition
Document.h:44
Generated on
for Engauge Digitizer by
1.17.0