Engauge Digitizer  2
MainWindowModel.cpp
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 "DocumentSerialize.h"
9 #include "GraphicsPoint.h"
10 #include "GridLineLimiter.h"
11 #include "ImportCroppingUtilBase.h"
12 #include "Logger.h"
13 #include "MainWindowModel.h"
14 #include "PdfResolution.h"
15 #include <QLocale>
16 #include <QObject>
17 #include <QTextStream>
18 #include "QtToString.h"
19 #include <QXmlStreamWriter>
20 #include "Xml.h"
21 #include "ZoomFactorInitial.h"
22 
23 // Prevent comma ambiguity with group separator commas and field delimiting commas
24 const QLocale::NumberOption HIDE_GROUP_SEPARATOR = QLocale::OmitGroupSeparator;
25 
26 bool DEFAULT_SMALL_DIALOGS = false;
27 
29  m_zoomControl (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS),
30  m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL),
31  m_mainTitleBarFormat (MAIN_TITLE_BAR_FORMAT_PATH),
32  m_pdfResolution (DEFAULT_IMPORT_PDF_RESOLUTION),
33  m_importCropping (DEFAULT_IMPORT_CROPPING),
34  m_maximumGridLines (DEFAULT_MAXIMUM_GRID_LINES),
35  m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
36  m_smallDialogs (DEFAULT_SMALL_DIALOGS)
37 {
38  // Locale member variable m_locale is initialized to default locale when default constructor is called
39 }
40 
42  m_locale (other.locale()),
43  m_zoomControl (other.zoomControl()),
44  m_zoomFactorInitial (other.zoomFactorInitial()),
45  m_mainTitleBarFormat (other.mainTitleBarFormat()),
46  m_pdfResolution (other.pdfResolution()),
47  m_importCropping (other.importCropping()),
48  m_maximumGridLines (other.maximumGridLines()),
49  m_highlightOpacity (other.highlightOpacity()),
50  m_smallDialogs (other.smallDialogs())
51 {
52 }
53 
55 {
56  m_locale = other.locale();
57  m_zoomControl = other.zoomControl();
58  m_zoomFactorInitial = other.zoomFactorInitial();
59  m_mainTitleBarFormat = other.mainTitleBarFormat();
60  m_pdfResolution = other.pdfResolution();
61  m_importCropping = other.importCropping();
62  m_maximumGridLines = other.maximumGridLines();
63  m_highlightOpacity = other.highlightOpacity();
64  m_smallDialogs = other.smallDialogs();
65 
66  return *this;
67 }
68 
70 {
71  return m_highlightOpacity;
72 }
73 
74 ImportCropping MainWindowModel::importCropping() const
75 {
76  return m_importCropping;
77 }
78 
79 void MainWindowModel::loadXml(QXmlStreamReader &reader)
80 {
81  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
82 
83  bool success = true;
84 
85  // Read until end of this subtree
86  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
87  (reader.name() != DOCUMENT_SERIALIZE_MAIN_WINDOW)){
88  loadNextFromReader(reader);
89  if (reader.atEnd()) {
90  success = false;
91  break;
92  }
93  }
94 
95  if (!success) {
96  reader.raiseError (QObject::tr ("Cannot read main window data"));
97  }
98 }
99 
100 QLocale MainWindowModel::locale () const
101 {
102  return m_locale;
103 }
104 
105 MainTitleBarFormat MainWindowModel::mainTitleBarFormat() const
106 {
107  return m_mainTitleBarFormat;
108 }
109 
111 {
112  return m_maximumGridLines;
113 }
114 
116 {
117  return m_pdfResolution;
118 }
119 
120 void MainWindowModel::printStream(QString indentation,
121  QTextStream &str) const
122 {
123  str << indentation << "MainWindowModel\n";
124 
125  indentation += INDENTATION_DELTA;
126 
127  str << indentation << "locale=" << m_locale.name() << "\n";
128  str << indentation << "zoomControl=" << m_zoomControl << "\n";
129  str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
130  str << indentation << "mainWindowTitleBarFormat=" << (m_mainTitleBarFormat == MAIN_TITLE_BAR_FORMAT_NO_PATH ?
131  "NoPath" :
132  "Path") << "\n";
133  str << indentation << "pdfResolution=" << m_pdfResolution << "\n";
134  str << indentation << "importCropping=" << ImportCroppingUtilBase::importCroppingToString (m_importCropping).toLatin1().data() << "\n";
135  str << indentation << "maximumGridLines=" << m_maximumGridLines << "\n";
136  str << indentation << "highlightOpacity=" << m_highlightOpacity << "\n";
137  str << indentation << "smallDialogs=" << (m_smallDialogs ? "yes" : "no") << "\n";
138 }
139 
140 void MainWindowModel::saveXml(QXmlStreamWriter &writer) const
141 {
142  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
143 
144  writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
145  writer.writeEndElement();
146 }
147 
149 {
150  m_highlightOpacity = highlightOpacity;
151 }
152 
154 {
155  m_importCropping = importCropping;
156 }
157 
158 void MainWindowModel::setLocale (QLocale::Language language,
159  QLocale::Country country)
160 {
161  QLocale locale (language,
162  country);
163  locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
164 
165  m_locale = locale;
166 }
167 
168 void MainWindowModel::setLocale (const QLocale &locale)
169 {
170  m_locale = locale;
171  m_locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
172 }
173 
175 {
176  m_mainTitleBarFormat = mainTitleBarFormat;
177 }
178 
180 {
181  m_maximumGridLines = maximumGridLines;
182 }
183 
185 {
186  m_pdfResolution = resolution;
187 }
188 
190 {
191  m_smallDialogs = smallDialogs;
192 }
193 
195 {
196  m_zoomControl = zoomControl;
197 }
198 
200 {
201  m_zoomFactorInitial = zoomFactorInitial;
202 }
203 
205 {
206  return m_smallDialogs;
207 }
208 
209 ZoomControl MainWindowModel::zoomControl () const
210 {
211  return m_zoomControl;
212 }
213 
214 ZoomFactorInitial MainWindowModel::zoomFactorInitial() const
215 {
216  return m_zoomFactorInitial;
217 }
static QString importCroppingToString(ImportCropping importCropping)
Option as string for display to user.
MainWindowModel & operator=(const MainWindowModel &other)
Assignment constructor.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
double highlightOpacity() const
Get method for highlight opacity.
ZoomFactorInitial zoomFactorInitial() const
Get method for initial zoom factor.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
bool smallDialogs() const
Get method for small dialogs flag.
MainWindowModel()
Default constructor.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
ZoomControl zoomControl() const
Get method for zoom control.
ImportCropping importCropping() const
Get method for import cropping.
Model for DlgSettingsMainWindow.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
int maximumGridLines() const
Maximum number of grid lines.
int pdfResolution() const
Get method for resolution of imported PDF files, in dots per inch.
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
MainTitleBarFormat mainTitleBarFormat() const
Get method for MainWindow titlebar filename format.
QLocale locale() const
Get method for locale.
void setZoomControl(ZoomControl zoomControl)
Set method for zoom control.
void setMainTitleBarFormat(MainTitleBarFormat mainTitleBarFormat)
Set method for MainWindow titlebar filename format.
void setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
Set method for initial zoom factor.
void setSmallDialogs(bool smallDialogs)
Set method for small dialogs flag.
void setPdfResolution(int resolution)
Set method for resolution of imported PDF files, in dots per inch.
void setImportCropping(ImportCropping importCropping)
Set method for import cropping.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...