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_DRAG_DROP_EXPORT = false; // False value allows intuitive copy-and-drag to select a rectangular set of table cells
27 bool DEFAULT_SMALL_DIALOGS = false;
28 
30  m_zoomControl (ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS),
31  m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL),
32  m_mainTitleBarFormat (MAIN_TITLE_BAR_FORMAT_PATH),
33  m_pdfResolution (DEFAULT_IMPORT_PDF_RESOLUTION),
34  m_importCropping (DEFAULT_IMPORT_CROPPING),
35  m_maximumGridLines (DEFAULT_MAXIMUM_GRID_LINES),
36  m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
37  m_smallDialogs (DEFAULT_SMALL_DIALOGS),
38  m_dragDropExport (DEFAULT_DRAG_DROP_EXPORT)
39 {
40  // Locale member variable m_locale is initialized to default locale when default constructor is called
41 }
42 
44  m_locale (other.locale()),
45  m_zoomControl (other.zoomControl()),
46  m_zoomFactorInitial (other.zoomFactorInitial()),
47  m_mainTitleBarFormat (other.mainTitleBarFormat()),
48  m_pdfResolution (other.pdfResolution()),
49  m_importCropping (other.importCropping()),
50  m_maximumGridLines (other.maximumGridLines()),
51  m_highlightOpacity (other.highlightOpacity()),
52  m_smallDialogs (other.smallDialogs()),
53  m_dragDropExport (other.dragDropExport())
54 {
55 }
56 
58 {
59  m_locale = other.locale();
60  m_zoomControl = other.zoomControl();
61  m_zoomFactorInitial = other.zoomFactorInitial();
62  m_mainTitleBarFormat = other.mainTitleBarFormat();
63  m_pdfResolution = other.pdfResolution();
64  m_importCropping = other.importCropping();
65  m_maximumGridLines = other.maximumGridLines();
66  m_highlightOpacity = other.highlightOpacity();
67  m_smallDialogs = other.smallDialogs();
68  m_dragDropExport = other.dragDropExport();
69 
70  return *this;
71 }
72 
74 {
75  return m_dragDropExport;
76 }
77 
79 {
80  return m_highlightOpacity;
81 }
82 
83 ImportCropping MainWindowModel::importCropping() const
84 {
85  return m_importCropping;
86 }
87 
88 void MainWindowModel::loadXml(QXmlStreamReader &reader)
89 {
90  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
91 
92  bool success = true;
93 
94  // Read until end of this subtree
95  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
96  (reader.name() != DOCUMENT_SERIALIZE_MAIN_WINDOW)){
97  loadNextFromReader(reader);
98  if (reader.atEnd()) {
99  success = false;
100  break;
101  }
102  }
103 
104  if (!success) {
105  reader.raiseError (QObject::tr ("Cannot read main window data"));
106  }
107 }
108 
109 QLocale MainWindowModel::locale () const
110 {
111  return m_locale;
112 }
113 
114 MainTitleBarFormat MainWindowModel::mainTitleBarFormat() const
115 {
116  return m_mainTitleBarFormat;
117 }
118 
120 {
121  return m_maximumGridLines;
122 }
123 
125 {
126  return m_pdfResolution;
127 }
128 
129 void MainWindowModel::printStream(QString indentation,
130  QTextStream &str) const
131 {
132  str << indentation << "MainWindowModel\n";
133 
134  indentation += INDENTATION_DELTA;
135 
136  str << indentation << "locale=" << m_locale.name() << "\n";
137  str << indentation << "zoomControl=" << m_zoomControl << "\n";
138  str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
139  str << indentation << "mainWindowTitleBarFormat=" << (m_mainTitleBarFormat == MAIN_TITLE_BAR_FORMAT_NO_PATH ?
140  "NoPath" :
141  "Path") << "\n";
142  str << indentation << "pdfResolution=" << m_pdfResolution << "\n";
143  str << indentation << "importCropping=" << ImportCroppingUtilBase::importCroppingToString (m_importCropping).toLatin1().data() << "\n";
144  str << indentation << "maximumGridLines=" << m_maximumGridLines << "\n";
145  str << indentation << "highlightOpacity=" << m_highlightOpacity << "\n";
146  str << indentation << "smallDialogs=" << (m_smallDialogs ? "yes" : "no") << "\n";
147  str << indentation << "dragDropExport=" << (m_dragDropExport ? "yes" : "no") << "\n";
148 }
149 
150 void MainWindowModel::saveXml(QXmlStreamWriter &writer) const
151 {
152  LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
153 
154  writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
155  writer.writeEndElement();
156 }
157 
159 {
160  m_dragDropExport = dragDropExport;
161 }
162 
164 {
165  m_highlightOpacity = highlightOpacity;
166 }
167 
169 {
170  m_importCropping = importCropping;
171 }
172 
173 void MainWindowModel::setLocale (QLocale::Language language,
174  QLocale::Country country)
175 {
176  QLocale locale (language,
177  country);
178  locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
179 
180  m_locale = locale;
181 }
182 
183 void MainWindowModel::setLocale (const QLocale &locale)
184 {
185  m_locale = locale;
186  m_locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
187 }
188 
190 {
191  m_mainTitleBarFormat = mainTitleBarFormat;
192 }
193 
195 {
196  m_maximumGridLines = maximumGridLines;
197 }
198 
200 {
201  m_pdfResolution = resolution;
202 }
203 
205 {
206  m_smallDialogs = smallDialogs;
207 }
208 
210 {
211  m_zoomControl = zoomControl;
212 }
213 
215 {
216  m_zoomFactorInitial = zoomFactorInitial;
217 }
218 
220 {
221  return m_smallDialogs;
222 }
223 
224 ZoomControl MainWindowModel::zoomControl () const
225 {
226  return m_zoomControl;
227 }
228 
229 ZoomFactorInitial MainWindowModel::zoomFactorInitial() const
230 {
231  return m_zoomFactorInitial;
232 }
static QString importCroppingToString(ImportCropping importCropping)
Option as string for display to user.
MainWindowModel & operator=(const MainWindowModel &other)
Assignment constructor.
void setDragDropExport(bool dragDropExport)
Set method for drag and drop export.
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.
bool dragDropExport() const
Get method for drag and drop export.
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(...