Engauge Digitizer  2
MainWindowModel.cpp
1 #include "CmdMediator.h"
2 #include "DocumentSerialize.h"
3 #include "Logger.h"
4 #include "MainWindowModel.h"
5 #include <QLocale>
6 #include <QTextStream>
7 #include "QtToString.h"
8 #include <QXmlStreamWriter>
9 #include "Xml.h"
10 #include "ZoomFactorInitial.h"
11 
13  m_zoomControl (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS),
14  m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL)
15 {
16  // Locale member variable m_locale is initialized to default locale when default constructor is called
17 }
18 
20  m_locale (other.locale()),
21  m_zoomControl (other.zoomControl()),
22  m_zoomFactorInitial (other.zoomFactorInitial())
23 {
24 }
25 
27 {
28  m_locale = other.locale();
29  m_zoomControl = other.zoomControl();
30  m_zoomFactorInitial = other.zoomFactorInitial();
31 
32  return *this;
33 }
34 
35 void MainWindowModel::loadXml(QXmlStreamReader &reader)
36 {
37  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
38 
39  bool success = true;
40 
41  // Read until end of this subtree
42  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
43  (reader.name() != DOCUMENT_SERIALIZE_MAIN_WINDOW)){
44  loadNextFromReader(reader);
45  if (reader.atEnd()) {
46  success = false;
47  break;
48  }
49  }
50 
51  if (!success) {
52  reader.raiseError ("Cannot read main window data");
53  }
54 }
55 
56 QLocale MainWindowModel::locale () const
57 {
58  return m_locale;
59 }
60 
61 void MainWindowModel::printStream(QString indentation,
62  QTextStream &str) const
63 {
64  str << indentation << "MainWindowModel\n";
65 
66  indentation += INDENTATION_DELTA;
67 
68  str << indentation << "locale=" << m_locale.name() << "\n";
69  str << indentation << "zoomControl=" << m_zoomControl << "\n";
70  str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
71 }
72 
73 void MainWindowModel::saveXml(QXmlStreamWriter &writer) const
74 {
75  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
76 
77  writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
78  writer.writeEndElement();
79 }
80 
81 void MainWindowModel::setLocale (QLocale::Language language,
82  QLocale::Country country)
83 {
84  QLocale locale (language,
85  country);
86 
87  m_locale = locale;
88 }
89 
90 void MainWindowModel::setLocale (const QLocale &locale)
91 {
92  m_locale = locale;
93 }
94 
95 void MainWindowModel::setZoomControl (ZoomControl zoomControl)
96 {
97  m_zoomControl = zoomControl;
98 }
99 
100 void MainWindowModel::setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
101 {
102  m_zoomFactorInitial = zoomFactorInitial;
103 }
104 
105 ZoomControl MainWindowModel::zoomControl () const
106 {
107  return m_zoomControl;
108 }
109 
110 ZoomFactorInitial MainWindowModel::zoomFactorInitial() const
111 {
112  return m_zoomFactorInitial;
113 }
MainWindowModel & operator=(const MainWindowModel &other)
Assignment constructor.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
MainWindowModel()
Default constructor.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
ZoomControl zoomControl() const
Get method for zoom control.
Model for DlgSettingsMainWindow and CmdSettingsMainWindow.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setZoomControl(ZoomControl zoomControl)
Set method for zoom control.
void setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
Set method for initial zoom factor.
ZoomFactorInitial zoomFactorInitial() const
Get method for initial zoom factor.
QLocale locale() const
Get method for locale.