Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
8098679b
Commit
8098679b
authored
Mar 21, 2016
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up exporter classes (to remove excessive code duplication)
parent
fea02af4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
89 deletions
+69
-89
UBExportAdaptor.cpp
src/adaptors/UBExportAdaptor.cpp
+50
-0
UBExportAdaptor.h
src/adaptors/UBExportAdaptor.h
+4
-1
UBExportDocument.cpp
src/adaptors/UBExportDocument.cpp
+2
-36
UBExportDocument.h
src/adaptors/UBExportDocument.h
+1
-1
UBExportFullPDF.cpp
src/adaptors/UBExportFullPDF.cpp
+4
-34
UBExportFullPDF.h
src/adaptors/UBExportFullPDF.h
+3
-0
UBExportPDF.cpp
src/adaptors/UBExportPDF.cpp
+4
-16
UBExportPDF.h
src/adaptors/UBExportPDF.h
+1
-1
No files found.
src/adaptors/UBExportAdaptor.cpp
View file @
8098679b
...
...
@@ -117,6 +117,56 @@ QString UBExportAdaptor::askForDirName(UBDocumentProxy* pDocument, const QString
return
dirname
;
}
void
UBExportAdaptor
::
persistLocally
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
pDialogTitle
)
{
if
(
!
pDocumentProxy
)
return
;
QString
filename
=
askForFileName
(
pDocumentProxy
,
pDialogTitle
);
if
(
filename
.
length
()
>
0
)
{
QApplication
::
setOverrideCursor
(
QCursor
(
Qt
::
WaitCursor
));
if
(
mIsVerbose
)
UBApplication
::
showMessage
(
tr
(
"Exporting document..."
));
// Check that the location is writeable
QFileInfo
info
(
filename
);
info
.
setFile
(
info
.
absolutePath
());
if
(
!
info
.
isWritable
())
{
QMessageBox
errorBox
;
errorBox
.
setWindowTitle
(
tr
(
"Export failed"
));
errorBox
.
setText
(
tr
(
"Unable to export to the selected location. You do not have the permissions necessary to save the file."
));
errorBox
.
setIcon
(
QMessageBox
::
Critical
);
errorBox
.
exec
();
if
(
mIsVerbose
)
UBApplication
::
showMessage
(
tr
(
"Export failed: location not writable"
));
QApplication
::
restoreOverrideCursor
();
return
;
}
bool
persisted
=
this
->
persistsDocument
(
pDocumentProxy
,
filename
);
if
(
mIsVerbose
&&
persisted
)
UBApplication
::
showMessage
(
tr
(
"Export successful."
));
QApplication
::
restoreOverrideCursor
();
}
}
bool
UBExportAdaptor
::
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
)
{
// Implemented in child classes
Q_UNUSED
(
pDocument
);
Q_UNUSED
(
filename
);
return
false
;
}
void
UBExportAdaptor
::
showErrorsList
(
QList
<
QString
>
errorsList
)
{
if
(
errorsList
.
count
())
...
...
src/adaptors/UBExportAdaptor.h
View file @
8098679b
...
...
@@ -43,8 +43,9 @@ class UBExportAdaptor : public QObject
virtual
QString
exportName
()
=
0
;
virtual
QString
exportExtention
()
{
return
""
;}
virtual
void
persist
(
UBDocumentProxy
*
pDocument
)
=
0
;
virtual
bool
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
);
virtual
void
setVerbo
d
e
(
bool
verbose
)
virtual
void
setVerbo
s
e
(
bool
verbose
)
{
mIsVerbose
=
verbose
;
}
...
...
@@ -58,6 +59,8 @@ class UBExportAdaptor : public QObject
QString
askForFileName
(
UBDocumentProxy
*
pDocument
,
const
QString
&
pDialogTitle
);
QString
askForDirName
(
UBDocumentProxy
*
pDocument
,
const
QString
&
pDialogTitle
);
virtual
void
persistLocally
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
pDialogTitle
);
void
showErrorsList
(
QList
<
QString
>
errorsList
);
bool
mIsVerbose
;
...
...
src/adaptors/UBExportDocument.cpp
View file @
8098679b
...
...
@@ -56,46 +56,12 @@ UBExportDocument::~UBExportDocument()
void
UBExportDocument
::
persist
(
UBDocumentProxy
*
pDocumentProxy
)
{
if
(
!
pDocumentProxy
)
return
;
QString
filename
=
askForFileName
(
pDocumentProxy
,
tr
(
"Export as UBZ File"
));
if
(
filename
.
length
()
>
0
)
{
QApplication
::
setOverrideCursor
(
QCursor
(
Qt
::
WaitCursor
));
if
(
mIsVerbose
)
UBApplication
::
showMessage
(
tr
(
"Exporting document..."
));
bool
success
=
persistsDocument
(
pDocumentProxy
,
filename
);
if
(
mIsVerbose
&&
success
)
UBApplication
::
showMessage
(
tr
(
"Export successful."
));
QApplication
::
restoreOverrideCursor
();
}
persistLocally
(
pDocumentProxy
,
tr
(
"Export as UBZ File"
));
}
bool
UBExportDocument
::
persistsDocument
(
UBDocumentProxy
*
pDocumentProxy
,
QString
filename
)
bool
UBExportDocument
::
persistsDocument
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
filename
)
{
QFileInfo
info
(
filename
);
info
.
setFile
(
info
.
absolutePath
());
if
(
!
info
.
isWritable
())
{
UBApplication
::
showMessage
(
tr
(
"Export failed: location not writable"
));
// The message is a bit discreet: also show a pop-up
QMessageBox
errorBox
;
errorBox
.
setWindowTitle
(
tr
(
"Export failed"
));
errorBox
.
setText
(
tr
(
"Unable to export to the selected location. You do not have the permissions necessary to save the file."
));
errorBox
.
setIcon
(
QMessageBox
::
Critical
);
errorBox
.
exec
();
return
false
;
}
QuaZip
zip
(
filename
);
zip
.
setFileNameCodec
(
"UTF-8"
);
if
(
!
zip
.
open
(
QuaZip
::
mdCreate
))
...
...
src/adaptors/UBExportDocument.h
View file @
8098679b
...
...
@@ -49,7 +49,7 @@ class UBExportDocument : public UBExportAdaptor, public UBProcessingProgressList
virtual
QString
exportExtention
();
virtual
void
persist
(
UBDocumentProxy
*
pDocument
);
virtual
bool
persistsDocument
(
UBDocumentProxy
*
pDocument
,
QString
filename
);
virtual
bool
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
);
virtual
void
processing
(
const
QString
&
pObjectName
,
int
pCurrent
,
int
pTotal
);
};
...
...
src/adaptors/UBExportFullPDF.cpp
View file @
8098679b
...
...
@@ -63,6 +63,8 @@ UBExportFullPDF::UBExportFullPDF(QObject *parent)
QDesktopWidget
*
desktop
=
UBApplication
::
desktop
();
int
dpiCommon
=
(
desktop
->
physicalDpiX
()
+
desktop
->
physicalDpiY
())
/
2
;
mScaleFactor
=
72.0
f
/
dpiCommon
;
mSimpleExporter
=
new
UBExportPDF
();
}
...
...
@@ -131,44 +133,12 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr
void
UBExportFullPDF
::
persist
(
UBDocumentProxy
*
pDocumentProxy
)
{
if
(
!
pDocumentProxy
)
return
;
QString
filename
=
askForFileName
(
pDocumentProxy
,
tr
(
"Export as PDF File"
));
if
(
filename
.
length
()
>
0
)
{
QApplication
::
setOverrideCursor
(
QCursor
(
Qt
::
WaitCursor
));
if
(
mIsVerbose
)
UBApplication
::
showMessage
(
tr
(
"Exporting document..."
));
bool
success
=
persistsDocument
(
pDocumentProxy
,
filename
);
if
(
mIsVerbose
&&
success
)
UBApplication
::
showMessage
(
tr
(
"Export successful."
));
QApplication
::
restoreOverrideCursor
();
}
persistLocally
(
pDocumentProxy
,
tr
(
"Export as PDF File"
));
}
bool
UBExportFullPDF
::
persistsDocument
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
filename
)
{
QFileInfo
info
(
filename
);
info
.
setFile
(
info
.
absolutePath
());
if
(
!
info
.
isWritable
())
{
UBApplication
::
showMessage
(
tr
(
"Export failed: location not writable"
));
// The message is a bit discreet: also show a pop-up
QMessageBox
errorBox
;
errorBox
.
setWindowTitle
(
tr
(
"Export failed"
));
errorBox
.
setText
(
tr
(
"Unable to export to the selected location. You do not have the permissions necessary to save the file."
));
errorBox
.
setIcon
(
QMessageBox
::
Critical
);
errorBox
.
exec
();
return
false
;
}
QFile
file
(
filename
);
if
(
file
.
exists
())
file
.
remove
();
...
...
@@ -277,7 +247,7 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS
qDebug
()
<<
"PdfMerger failed to merge documents to "
<<
filename
<<
" - Exception : "
<<
e
.
what
();
// default to raster export
UBExportPDF
::
persistsDocument
(
pDocumentProxy
,
filename
);
mSimpleExporter
->
persistsDocument
(
pDocumentProxy
,
filename
);
}
if
(
!
UBApplication
::
app
()
->
isVerbose
())
...
...
src/adaptors/UBExportFullPDF.h
View file @
8098679b
...
...
@@ -30,6 +30,7 @@
#include <QtCore>
#include "UBExportAdaptor.h"
#include "UBExportPDF.h"
class
UBDocumentProxy
;
...
...
@@ -53,6 +54,8 @@ class UBExportFullPDF : public UBExportAdaptor
private
:
float
mScaleFactor
;
bool
mHasPDFBackgrounds
;
UBExportPDF
*
mSimpleExporter
;
};
#endif
/* UBExportFullPDF_H_ */
src/adaptors/UBExportPDF.cpp
View file @
8098679b
...
...
@@ -58,25 +58,11 @@ UBExportPDF::~UBExportPDF()
void
UBExportPDF
::
persist
(
UBDocumentProxy
*
pDocumentProxy
)
{
if
(
!
pDocumentProxy
)
return
;
QString
filename
=
askForFileName
(
pDocumentProxy
,
tr
(
"Export as PDF File"
));
if
(
filename
.
length
()
>
0
)
{
QApplication
::
setOverrideCursor
(
QCursor
(
Qt
::
WaitCursor
));
UBApplication
::
showMessage
(
tr
(
"Exporting document..."
));
persistsDocument
(
pDocumentProxy
,
filename
);
UBApplication
::
showMessage
(
tr
(
"Export successful."
));
QApplication
::
restoreOverrideCursor
();
}
persistLocally
(
pDocumentProxy
,
tr
(
"Export as PDF File"
));
}
void
UBExportPDF
::
persistsDocument
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
filename
)
bool
UBExportPDF
::
persistsDocument
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
filename
)
{
QPrinter
pdfPrinter
;
...
...
@@ -128,6 +114,8 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin
scene
->
setBackground
(
isDark
,
isCrossed
);
}
if
(
!
painterNeedsBegin
)
pdfPainter
.
end
();
return
true
;
}
QString
UBExportPDF
::
exportExtention
()
...
...
src/adaptors/UBExportPDF.h
View file @
8098679b
...
...
@@ -45,7 +45,7 @@ class UBExportPDF : public UBExportAdaptor
virtual
QString
exportExtention
();
virtual
void
persist
(
UBDocumentProxy
*
pDocument
);
static
void
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
);
virtual
bool
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
);
};
#endif
/* UBEXPORTPDF_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment