Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Document
DocumentModelGeneral.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 "
DocumentModelGeneral.h
"
9
#include "
DocumentSerialize.h
"
10
#include "
Logger.h
"
11
#include <QObject>
12
#include <QSettings>
13
#include <QTextStream>
14
#include "
QtToString.h
"
15
#include <QXmlStreamWriter>
16
#include "
Settings.h
"
17
#include "
Xml.h
"
18
19
const
int
DEFAULT_CURSOR_SIZE
= 3;
20
const
int
DEFAULT_EXTRA_PRECISION
= 1;
21
22
DocumentModelGeneral::DocumentModelGeneral
() :
23
m_cursorSize (
DEFAULT_CURSOR_SIZE
),
24
m_extraPrecision (
DEFAULT_EXTRA_PRECISION
)
25
{
26
QSettings settings (
SETTINGS_ENGAUGE
,
SETTINGS_DIGITIZER
);
27
settings.beginGroup (
SETTINGS_GROUP_GENERAL
);
28
29
m_cursorSize = settings.value (
SETTINGS_GENERAL_CURSOR_SIZE
,
30
QVariant (
DEFAULT_CURSOR_SIZE
)).toInt();
31
m_extraPrecision = settings.value (
SETTINGS_GENERAL_EXTRA_PRECISION
,
32
QVariant (
DEFAULT_EXTRA_PRECISION
)).toInt();
33
settings.endGroup ();
34
}
35
36
DocumentModelGeneral::DocumentModelGeneral
(
const
Document
&document) :
37
m_cursorSize (document.modelGeneral().
cursorSize
()),
38
m_extraPrecision (document.modelGeneral().
extraPrecision
())
39
{
40
}
41
42
DocumentModelGeneral::DocumentModelGeneral
(
const
DocumentModelGeneral
&other) :
43
m_cursorSize (other.
cursorSize
()),
44
m_extraPrecision (other.
extraPrecision
())
45
{
46
}
47
48
DocumentModelGeneral
&
DocumentModelGeneral::operator=
(
const
DocumentModelGeneral
&other)
49
{
50
m_cursorSize = other.
cursorSize
();
51
m_extraPrecision = other.
extraPrecision
();
52
53
return
*
this
;
54
}
55
56
int
DocumentModelGeneral::cursorSize
()
const
57
{
58
return
m_cursorSize;
59
}
60
61
int
DocumentModelGeneral::extraPrecision
()
const
62
{
63
return
m_extraPrecision;
64
}
65
66
void
DocumentModelGeneral::loadXml
(QXmlStreamReader &reader)
67
{
68
qCInfo(ENGAUGE_LOG) <<
"DocumentModelGeneral::loadXml"
;
69
70
bool
success =
true
;
71
72
QXmlStreamAttributes attributes = reader.attributes();
73
74
if
(attributes.hasAttribute(
DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE
) &&
75
attributes.hasAttribute(
DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION
)) {
76
77
setCursorSize
(attributes.value(
DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE
).toInt());
78
setExtraPrecision
(attributes.value(
DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION
).toInt());
79
80
// Read until end of this subtree
81
while
((reader.tokenType() != QXmlStreamReader::EndElement) ||
82
(reader.name() !=
DOCUMENT_SERIALIZE_GENERAL
&&
83
reader.name() !=
DOCUMENT_SERIALIZE_COMMON
)){
84
loadNextFromReader
(reader);
85
if
(reader.atEnd()) {
86
success =
false
;
87
break
;
88
}
89
}
90
}
91
92
if
(!success) {
93
reader.raiseError (QObject::tr (
"Cannot read general data"
));
94
}
95
}
96
97
void
DocumentModelGeneral::printStream
(QString indentation,
98
QTextStream &str)
const
99
{
100
str << indentation <<
"DocumentModelGeneral\n"
;
101
102
indentation +=
INDENTATION_DELTA
;
103
104
str << indentation <<
"cursorSize="
<< m_cursorSize <<
"\n"
;
105
str << indentation <<
"extraPrecision="
<< m_extraPrecision <<
"\n"
;
106
}
107
108
void
DocumentModelGeneral::saveXml
(QXmlStreamWriter &writer)
const
109
{
110
qCInfo(ENGAUGE_LOG) <<
"DocumentModelGeneral::saveXml"
;
111
112
writer.writeStartElement(
DOCUMENT_SERIALIZE_GENERAL
);
113
writer.writeAttribute(
DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE
, QString::number (m_cursorSize));
114
writer.writeAttribute(
DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION
, QString::number (m_extraPrecision));
115
writer.writeEndElement();
116
}
117
118
void
DocumentModelGeneral::setCursorSize
(
int
cursorSize
)
119
{
120
m_cursorSize =
cursorSize
;
121
}
122
123
void
DocumentModelGeneral::setExtraPrecision
(
int
extraPrecision
)
124
{
125
m_extraPrecision =
extraPrecision
;
126
}
CmdMediator.h
DEFAULT_CURSOR_SIZE
const CursorSize DEFAULT_CURSOR_SIZE
Definition
DocumentModelDigitizeCurve.cpp:19
DEFAULT_EXTRA_PRECISION
const int DEFAULT_EXTRA_PRECISION
Definition
DocumentModelGeneral.cpp:20
DocumentModelGeneral.h
DocumentSerialize.h
DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE
const QString DOCUMENT_SERIALIZE_GENERAL_CURSOR_SIZE
DOCUMENT_SERIALIZE_COMMON
const QString DOCUMENT_SERIALIZE_COMMON
DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION
const QString DOCUMENT_SERIALIZE_GENERAL_EXTRA_PRECISION
DOCUMENT_SERIALIZE_GENERAL
const QString DOCUMENT_SERIALIZE_GENERAL
Logger.h
INDENTATION_DELTA
const QString INDENTATION_DELTA
QtToString.h
Settings.h
SETTINGS_ENGAUGE
const QString SETTINGS_ENGAUGE
SETTINGS_GROUP_GENERAL
const QString SETTINGS_GROUP_GENERAL
SETTINGS_GENERAL_CURSOR_SIZE
const QString SETTINGS_GENERAL_CURSOR_SIZE
SETTINGS_GENERAL_EXTRA_PRECISION
const QString SETTINGS_GENERAL_EXTRA_PRECISION
SETTINGS_DIGITIZER
const QString SETTINGS_DIGITIZER
loadNextFromReader
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition
Xml.cpp:14
Xml.h
DocumentModelGeneral::saveXml
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Definition
DocumentModelGeneral.cpp:108
DocumentModelGeneral::setCursorSize
void setCursorSize(int cursorSize)
Set method for effective cursor size.
Definition
DocumentModelGeneral.cpp:118
DocumentModelGeneral::loadXml
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
Definition
DocumentModelGeneral.cpp:66
DocumentModelGeneral::setExtraPrecision
void setExtraPrecision(int extraPrecision)
Set method for extra digits of precision.
Definition
DocumentModelGeneral.cpp:123
DocumentModelGeneral::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
DocumentModelGeneral.cpp:97
DocumentModelGeneral::operator=
DocumentModelGeneral & operator=(const DocumentModelGeneral &other)
Assignment constructor.
Definition
DocumentModelGeneral.cpp:48
DocumentModelGeneral::DocumentModelGeneral
DocumentModelGeneral()
Default constructor.
Definition
DocumentModelGeneral.cpp:22
DocumentModelGeneral::extraPrecision
int extraPrecision() const
Get method for extra digits of precsion.
Definition
DocumentModelGeneral.cpp:61
DocumentModelGeneral::cursorSize
int cursorSize() const
Get method for effective cursor size.
Definition
DocumentModelGeneral.cpp:56
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