Engauge Digitizer 2
Loading...
Searching...
No Matches
MainWindowModel.cpp
Go to the documentation of this file.
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"
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
24const QLocale::NumberOption HIDE_GROUP_SEPARATOR = QLocale::OmitGroupSeparator;
25
26bool DEFAULT_DRAG_DROP_EXPORT = false; // False value allows intuitive copy-and-drag to select a rectangular set of table cells
29bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT = true; // Pre-version 11.3 behavior
30
33 m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL),
34 m_mainTitleBarFormat (MAIN_TITLE_BAR_FORMAT_PATH),
35 m_pdfResolution (DEFAULT_IMPORT_PDF_RESOLUTION),
36 m_importCropping (DEFAULT_IMPORT_CROPPING),
37 m_maximumGridLines (DEFAULT_MAXIMUM_GRID_LINES),
38 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
39 m_smallDialogs (DEFAULT_SMALL_DIALOGS),
40 m_dragDropExport (DEFAULT_DRAG_DROP_EXPORT),
41 m_significantDigits (DEFAULT_SIGNIFICANT_DIGITS),
42 m_imageReplaceRenamesDocument (DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT)
43{
44 // Locale member variable m_locale is initialized to default locale when default constructor is called
45}
46
48 m_locale (other.locale()),
49 m_zoomControl (other.zoomControl()),
50 m_zoomFactorInitial (other.zoomFactorInitial()),
51 m_mainTitleBarFormat (other.mainTitleBarFormat()),
52 m_pdfResolution (other.pdfResolution()),
53 m_importCropping (other.importCropping()),
54 m_maximumGridLines (other.maximumGridLines()),
55 m_highlightOpacity (other.highlightOpacity()),
56 m_smallDialogs (other.smallDialogs()),
57 m_dragDropExport (other.dragDropExport()),
58 m_significantDigits (other.significantDigits()),
59 m_imageReplaceRenamesDocument (other.imageReplaceRenamesDocument())
60{
61}
62
64{
65 m_locale = other.locale();
66 m_zoomControl = other.zoomControl();
67 m_zoomFactorInitial = other.zoomFactorInitial();
68 m_mainTitleBarFormat = other.mainTitleBarFormat();
69 m_pdfResolution = other.pdfResolution();
70 m_importCropping = other.importCropping();
71 m_maximumGridLines = other.maximumGridLines();
72 m_highlightOpacity = other.highlightOpacity();
73 m_smallDialogs = other.smallDialogs();
74 m_dragDropExport = other.dragDropExport();
75 m_significantDigits = other.significantDigits();
76 m_imageReplaceRenamesDocument = other.imageReplaceRenamesDocument();
77
78 return *this;
79}
80
82{
83 return m_dragDropExport;
84}
85
87{
88 return m_highlightOpacity;
89}
90
92{
93 return m_imageReplaceRenamesDocument;
94}
95
97{
98 return m_importCropping;
99}
100
101void MainWindowModel::loadXml(QXmlStreamReader &reader)
102{
103 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
104
105 bool success = true;
106
107 // Read until end of this subtree
108 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
109 (reader.name() != DOCUMENT_SERIALIZE_MAIN_WINDOW)){
110 loadNextFromReader(reader);
111 if (reader.atEnd()) {
112 success = false;
113 break;
114 }
115 }
116
117 if (!success) {
118 reader.raiseError (QObject::tr ("Cannot read main window data"));
119 }
120}
121
123{
124 return m_locale;
125}
126
128{
129 return m_mainTitleBarFormat;
130}
131
133{
134 return m_maximumGridLines;
135}
136
138{
139 return m_pdfResolution;
140}
141
142void MainWindowModel::printStream(QString indentation,
143 QTextStream &str) const
144{
145 str << indentation << "MainWindowModel\n";
146
147 indentation += INDENTATION_DELTA;
148
149 str << indentation << "locale=" << m_locale.name() << "\n";
150 str << indentation << "zoomControl=" << m_zoomControl << "\n";
151 str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
152 str << indentation << "mainWindowTitleBarFormat=" << (m_mainTitleBarFormat == MAIN_TITLE_BAR_FORMAT_NO_PATH ?
153 "NoPath" :
154 "Path") << "\n";
155 str << indentation << "pdfResolution=" << m_pdfResolution << "\n";
156 str << indentation << "importCropping=" << ImportCroppingUtilBase::importCroppingToString (m_importCropping).toLatin1().data() << "\n";
157 str << indentation << "maximumGridLines=" << m_maximumGridLines << "\n";
158 str << indentation << "highlightOpacity=" << m_highlightOpacity << "\n";
159 str << indentation << "smallDialogs=" << (m_smallDialogs ? "yes" : "no") << "\n";
160 str << indentation << "dragDropExport=" << (m_dragDropExport ? "yes" : "no") << "\n";
161 str << indentation << "significantDigits=" << m_significantDigits << "\n";
162 str << indentation << "imageReplaceRenamesDocument=" << (m_imageReplaceRenamesDocument ? "yes" : "no") << "\n";
163}
164
165void MainWindowModel::saveXml(QXmlStreamWriter &writer) const
166{
167 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
168
169 writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
170 writer.writeEndElement();
171}
172
174{
175 m_dragDropExport = dragDropExport;
176}
177
179{
180 m_highlightOpacity = highlightOpacity;
181}
182
187
192
193void MainWindowModel::setLocale (QLocale::Language language,
194 QLocale::Country country)
195{
196 QLocale locale (language,
197 country);
198 locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
199
200 m_locale = locale;
201}
202
204{
205 m_locale = locale;
206 m_locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
207}
208
213
215{
216 m_maximumGridLines = maximumGridLines;
217}
218
220{
221 m_pdfResolution = resolution;
222}
223
225{
226 m_significantDigits = significantDigits;
227}
228
230{
231 m_smallDialogs = smallDialogs;
232}
233
238
243
245{
246 return m_significantDigits;
247}
248
250{
251 return m_smallDialogs;
252}
253
255{
256 return m_zoomControl;
257}
258
260{
261 return m_zoomFactorInitial;
262}
const QString DOCUMENT_SERIALIZE_MAIN_WINDOW
const double DEFAULT_HIGHLIGHT_OPACITY
const int DEFAULT_MAXIMUM_GRID_LINES
Default for maximum number of grid lines.
const ImportCropping DEFAULT_IMPORT_CROPPING
ImportCropping
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString INDENTATION_DELTA
MainTitleBarFormat
Format format in MainWindow title bar.
@ MAIN_TITLE_BAR_FORMAT_NO_PATH
@ MAIN_TITLE_BAR_FORMAT_PATH
Filename without path.
bool DEFAULT_DRAG_DROP_EXPORT
bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT
int DEFAULT_SIGNIFICANT_DIGITS
const QLocale::NumberOption HIDE_GROUP_SEPARATOR
bool DEFAULT_SMALL_DIALOGS
bool DEFAULT_DRAG_DROP_EXPORT
bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT
int DEFAULT_SIGNIFICANT_DIGITS
bool DEFAULT_SMALL_DIALOGS
int DEFAULT_IMPORT_PDF_RESOLUTION
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
ZoomControl
Definition ZoomControl.h:10
@ ZOOM_CONTROL_MENU_WHEEL_PLUSMINUS
Definition ZoomControl.h:14
const ZoomFactorInitial DEFAULT_ZOOM_FACTOR_INITIAL
ZoomFactorInitial
static QString importCroppingToString(ImportCropping importCropping)
Option as string for display to user.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setSmallDialogs(bool smallDialogs)
Set method for small dialogs flag.
QLocale locale() const
Get method for locale.
MainWindowModel()
Default constructor.
void setImageReplaceRenamesDocument(bool imageReplaceRenamesDocument)
Set method for image replace renames document.
MainWindowModel & operator=(const MainWindowModel &other)
Assignment constructor.
bool dragDropExport() const
Get method for drag and drop export.
bool imageReplaceRenamesDocument() const
Get method for image replaces renames document.
ZoomFactorInitial zoomFactorInitial() const
Get method for initial zoom factor.
void setImportCropping(ImportCropping importCropping)
Set method for import cropping.
ImportCropping importCropping() const
Get method for import cropping.
bool smallDialogs() const
Get method for small dialogs flag.
void setMainTitleBarFormat(MainTitleBarFormat mainTitleBarFormat)
Set method for MainWindow titlebar filename format.
void setDragDropExport(bool dragDropExport)
Set method for drag and drop export.
double highlightOpacity() const
Get method for highlight opacity.
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 setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
ZoomControl zoomControl() const
Get method for zoom control.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void setPdfResolution(int resolution)
Set method for resolution of imported PDF files, in dots per inch.
int maximumGridLines() const
Maximum number of grid lines.
int significantDigits() const
Get method for significant digits.
void setZoomFactorInitial(ZoomFactorInitial zoomFactorInitial)
Set method for initial zoom factor.
MainTitleBarFormat mainTitleBarFormat() const
Get method for MainWindow titlebar filename format.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
void setLocale(QLocale::Language language, QLocale::Country country)
Set method for locale given attributes.
int pdfResolution() const
Get method for resolution of imported PDF files, in dots per inch.
void setSignificantDigits(int significantDigits)
Set method for significant digits.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18