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