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
26const bool DEFAULT_DRAG_DROP_EXPORT = false; // False value allows intuitive copy-and-drag to select a rectangular set of table cells
28const bool DEFAULT_SMALL_DIALOGS = false;
29const bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT = true; // Pre-version 11.3 behavior
30const int DEFAULT_MAXIMUM_EXPORTED_POINTS_PER_CURVE = 5000; // Moved 1/2020 from Export classes
31const ColorPalette DEFAULT_GUIDELINE_COLOR = COLOR_PALETTE_GREEN; // Bright so it gets noticed
32
35 m_zoomFactorInitial (DEFAULT_ZOOM_FACTOR_INITIAL),
36 m_mainTitleBarFormat (MAIN_TITLE_BAR_FORMAT_PATH),
37 m_pdfResolution (DEFAULT_IMPORT_PDF_RESOLUTION),
38 m_importCropping (DEFAULT_IMPORT_CROPPING),
39 m_maximumGridLines (DEFAULT_MAXIMUM_GRID_LINES),
40 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
41 m_smallDialogs (DEFAULT_SMALL_DIALOGS),
42 m_dragDropExport (DEFAULT_DRAG_DROP_EXPORT),
43 m_significantDigits (DEFAULT_SIGNIFICANT_DIGITS),
44 m_imageReplaceRenamesDocument (DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT),
45 m_maximumExportedPointsPerCurve (DEFAULT_MAXIMUM_EXPORTED_POINTS_PER_CURVE),
46 m_guidelineColor (DEFAULT_GUIDELINE_COLOR)
47{
48 // Locale member variable m_locale is initialized to default locale when default constructor is called
49}
50
52 m_locale (other.locale()),
53 m_zoomControl (other.zoomControl()),
54 m_zoomFactorInitial (other.zoomFactorInitial()),
55 m_mainTitleBarFormat (other.mainTitleBarFormat()),
56 m_pdfResolution (other.pdfResolution()),
57 m_importCropping (other.importCropping()),
58 m_maximumGridLines (other.maximumGridLines()),
59 m_highlightOpacity (other.highlightOpacity()),
60 m_smallDialogs (other.smallDialogs()),
61 m_dragDropExport (other.dragDropExport()),
62 m_significantDigits (other.significantDigits()),
63 m_imageReplaceRenamesDocument (other.imageReplaceRenamesDocument()),
64 m_maximumExportedPointsPerCurve (other.maximumExportedPointsPerCurve ()),
65 m_guidelineColor (other.guidelineColor ())
66{
67}
68
70{
71 m_locale = other.locale();
72 m_zoomControl = other.zoomControl();
73 m_zoomFactorInitial = other.zoomFactorInitial();
74 m_mainTitleBarFormat = other.mainTitleBarFormat();
75 m_pdfResolution = other.pdfResolution();
76 m_importCropping = other.importCropping();
77 m_maximumGridLines = other.maximumGridLines();
78 m_highlightOpacity = other.highlightOpacity();
79 m_smallDialogs = other.smallDialogs();
80 m_dragDropExport = other.dragDropExport();
81 m_significantDigits = other.significantDigits();
82 m_imageReplaceRenamesDocument = other.imageReplaceRenamesDocument();
83 m_maximumExportedPointsPerCurve = other.maximumExportedPointsPerCurve();
84 m_guidelineColor = other.guidelineColor ();
85
86 return *this;
87}
88
90{
91 return m_dragDropExport;
92}
93
95{
96 return m_guidelineColor;
97}
98
100{
101 return m_highlightOpacity;
102}
103
105{
106 return m_imageReplaceRenamesDocument;
107}
108
110{
111 return m_importCropping;
112}
113
115{
116 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::loadXml";
117
118 bool success = true;
119
120 // Read until end of this subtree
121 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
124 if (reader.atEnd()) {
125 success = false;
126 break;
127 }
128 }
129
130 if (!success) {
131 reader.raiseError (QObject::tr ("Cannot read main window data"));
132 }
133}
134
136{
137 return m_locale;
138}
139
141{
142 return m_mainTitleBarFormat;
143}
144
146{
147 return m_maximumExportedPointsPerCurve;
148}
149
151{
152 return m_maximumGridLines;
153}
154
156{
157 return m_pdfResolution;
158}
159
161 QTextStream &str) const
162{
163 str << indentation << "MainWindowModel\n";
164
166
167 str << indentation << "locale=" << m_locale.name() << "\n";
168 str << indentation << "zoomControl=" << m_zoomControl << "\n";
169 str << indentation << "zoomFactorInitial=" << m_zoomFactorInitial << "\n";
170 str << indentation << "mainWindowTitleBarFormat=" << (m_mainTitleBarFormat == MAIN_TITLE_BAR_FORMAT_NO_PATH ?
171 "NoPath" :
172 "Path") << "\n";
173 str << indentation << "pdfResolution=" << m_pdfResolution << "\n";
174 str << indentation << "importCropping=" << ImportCroppingUtilBase::importCroppingToString (m_importCropping).toLatin1().data() << "\n";
175 str << indentation << "maximumGridLines=" << m_maximumGridLines << "\n";
176 str << indentation << "highlightOpacity=" << m_highlightOpacity << "\n";
177 str << indentation << "smallDialogs=" << (m_smallDialogs ? "yes" : "no") << "\n";
178 str << indentation << "dragDropExport=" << (m_dragDropExport ? "yes" : "no") << "\n";
179 str << indentation << "significantDigits=" << m_significantDigits << "\n";
180 str << indentation << "imageReplaceRenamesDocument=" << (m_imageReplaceRenamesDocument ? "yes" : "no") << "\n";
181 str << indentation << "maximumExportedPointsPerCurve=" << m_maximumExportedPointsPerCurve << "\n";
182 str << indentation << "guidelineColor=" << colorPaletteToString (m_guidelineColor).toLatin1().data() << "\n";
183}
184
186{
187 LOG4CPP_INFO_S ((*mainCat)) << "MainWindowModel::saveXml";
188
189 writer.writeStartElement(DOCUMENT_SERIALIZE_MAIN_WINDOW);
190 writer.writeEndElement();
191}
192
193void MainWindowModel::setDragDropExport(bool dragDropExport)
194{
195 m_dragDropExport = dragDropExport;
196}
197
199{
200 m_guidelineColor = guidelineColor;
201}
202
203void MainWindowModel::setHighlightOpacity(double highlightOpacity)
204{
205 m_highlightOpacity = highlightOpacity;
206}
207
208void MainWindowModel::setImageReplaceRenamesDocument(bool imageReplaceRenamesDocument)
209{
210 m_imageReplaceRenamesDocument = imageReplaceRenamesDocument;
211}
212
214{
215 m_importCropping = importCropping;
216}
217
218void MainWindowModel::setLocale (QLocale::Language language,
219 QLocale::Country country)
220{
222 country);
223 locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
224
225 m_locale = locale;
226}
227
229{
230 m_locale = locale;
231 m_locale.setNumberOptions(HIDE_GROUP_SEPARATOR);
232}
233
235{
236 m_mainTitleBarFormat = mainTitleBarFormat;
237}
238
239void MainWindowModel::setMaximumExportedPointsPerCurve(int maximumExportedPointsPerCurve)
240{
241 m_maximumExportedPointsPerCurve = maximumExportedPointsPerCurve;
242}
243
244void MainWindowModel::setMaximumGridLines(int maximumGridLines)
245{
246 m_maximumGridLines = maximumGridLines;
247}
248
250{
251 m_pdfResolution = resolution;
252}
253
254void MainWindowModel::setSignificantDigits (int significantDigits)
255{
256 m_significantDigits = significantDigits;
257}
258
259void MainWindowModel::setSmallDialogs(bool smallDialogs)
260{
261 m_smallDialogs = smallDialogs;
262}
263
265{
266 m_zoomControl = zoomControl;
267}
268
270{
271 m_zoomFactorInitial = zoomFactorInitial;
272}
273
275{
276 return m_significantDigits;
277}
278
280{
281 return m_smallDialogs;
282}
283
285{
286 return m_zoomControl;
287}
288
290{
291 return m_zoomFactorInitial;
292}
QString colorPaletteToString(ColorPalette colorPalette)
ColorPalette
@ COLOR_PALETTE_GREEN
const int INNER_RADIUS_MIN
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.
const bool DEFAULT_SMALL_DIALOGS
const ColorPalette DEFAULT_GUIDELINE_COLOR
const int DEFAULT_MAXIMUM_EXPORTED_POINTS_PER_CURVE
const QLocale::NumberOption HIDE_GROUP_SEPARATOR
const bool DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT
const int DEFAULT_SIGNIFICANT_DIGITS
const bool DEFAULT_DRAG_DROP_EXPORT
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.
Model for DlgSettingsMainWindow.
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 setGuidelineColor(ColorPalette guidelineColor)
Set method for guideline color.
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.
void setMaximumExportedPointsPerCurve(int maximumExportedPointsPerCurve)
Set method for maximum number of exported points per curve.
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
Get method for maximum number of grid lines.
int significantDigits() const
Get method for significant digits.
ColorPalette guidelineColor() const
Get method for guideline color.
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.
int maximumExportedPointsPerCurve() const
Get method for maximum number of exported points per curve.
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