Engauge Digitizer 2
Loading...
Searching...
No Matches
DocumentModelLoadViews.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2021 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 "Document.h"
9#include "DocumentSerialize.h"
10#include "EngaugeAssert.h"
11#include "Logger.h"
12#include <QObject>
13#include <QTextStream>
14#include "QtToString.h"
15#include <QXmlStreamWriter>
16#include "Xml.h"
17
19 m_gridlines (false),
20 m_guidelines (false)
21{
22}
23
25 m_gridlines (document.modelLoadViews().gridlines ()),
26 m_guidelines (document.modelLoadViews().guidelines ())
27{
28}
29
31 m_gridlines (other.gridlines ()),
32 m_guidelines (other.guidelines ())
33{
34}
35
37 bool guidelines) :
38 m_gridlines (gridlines),
39 m_guidelines (guidelines)
40{
41}
42
44{
45 m_gridlines = other.gridlines ();
46 m_guidelines = other.guidelines ();
47
48 return *this;
49}
50
52{
53 return m_gridlines;
54}
55
57{
58 return m_guidelines;
59}
60
61void DocumentModelLoadViews::loadXml(QXmlStreamReader &reader)
62{
63 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelLoadViews::loadXml";
64
65 bool success = true;
66
67 QXmlStreamAttributes attributes = reader.attributes();
68
69 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_LOAD_VIEWS_GRIDLINES) &&
70 attributes.hasAttribute(DOCUMENT_SERIALIZE_LOAD_VIEWS_GUIDELINES)) {
71
72 // Boolean values
73 QString stringGridlines = attributes.value (DOCUMENT_SERIALIZE_LOAD_VIEWS_GRIDLINES).toString();
74 QString stringGuidelines = attributes.value (DOCUMENT_SERIALIZE_LOAD_VIEWS_GUIDELINES).toString();
75
76 setGridlines (stringGridlines == DOCUMENT_SERIALIZE_BOOL_TRUE);
77 setGuidelines (stringGuidelines == DOCUMENT_SERIALIZE_BOOL_TRUE);
78
79 // Read until end of this subtree
80 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
81 (reader.name() != DOCUMENT_SERIALIZE_LOAD_VIEWS)){
82 loadNextFromReader(reader);
83 if (reader.atEnd()) {
84 success = false;
85 break;
86 }
87 }
88 }
89
90 if (!success) {
91 reader.raiseError (QObject::tr ("Cannot read settings for views loading"));
92 }
93}
94
95void DocumentModelLoadViews::printStream(QString indentation,
96 QTextStream &str) const
97{
98 str << indentation << "DocumentModelLoadViews\n";
99
100 indentation += INDENTATION_DELTA;
101
102 str << indentation << "gridlines=" << (m_gridlines ? "yes" : "no") << "\n";
103 str << indentation << "guidelines=" << (m_guidelines ? "yes" : "no") << "\n";
104}
105
106void DocumentModelLoadViews::saveXml(QXmlStreamWriter &writer) const
107{
108 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelLoadViews::saveXml";
109
110 writer.writeStartElement(DOCUMENT_SERIALIZE_LOAD_VIEWS);
111 writer.writeAttribute(DOCUMENT_SERIALIZE_LOAD_VIEWS_GRIDLINES, m_gridlines ?
114 writer.writeAttribute(DOCUMENT_SERIALIZE_LOAD_VIEWS_GUIDELINES, m_guidelines ?
117 writer.writeEndElement();
118}
119
121{
122 m_gridlines = gridlines;
123}
124
126{
127 m_guidelines = guidelines;
128}
const QString DOCUMENT_SERIALIZE_LOAD_VIEWS_GRIDLINES
const QString DOCUMENT_SERIALIZE_LOAD_VIEWS
const QString DOCUMENT_SERIALIZE_LOAD_VIEWS_GUIDELINES
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
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
bool gridlines() const
Get method for gridlines.
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 saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setGuidelines(bool guidelines)
Set method for guidelines.
bool guidelines() const
Get method for guidelines.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void setGridlines(bool gridlines)
Set method for gridlines.
DocumentModelLoadViews & operator=(const DocumentModelLoadViews &other)
Assignment constructor.
DocumentModelLoadViews()
Default constructor.
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