Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve layout resolution customization #34

Merged
merged 4 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions processing_provider/export_layouts_from_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ def processAlgorithm(self, parameters, context, feedback):
"ExportLayoutsFromFolder", "\n--> Layout found: '{}'!").format(composer.name())
)

# Save the layout dialog's dpi and override it with the user selection
oldResolution = composer.renderContext().dpi()
if resolution:
composer.renderContext().setDpi(resolution)
# Retrieve the resolution to apply to the export
self.processor.getResolution(composer, resolution)

title = composer.name()
title = project.baseName() + '_' + title
Expand All @@ -179,9 +177,6 @@ def processAlgorithm(self, parameters, context, feedback):
)
)

# Set back the original dpi in the layout dialog
composer.renderContext().setDpi(oldResolution)

if exported_count:
feedback.pushInfo(
QCoreApplication.translate(
Expand Down
20 changes: 9 additions & 11 deletions processing_provider/export_layouts_from_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ def processAlgorithm(self, parameters, context, feedback):
title = self.layoutList[layout]
cView = QgsProject.instance().layoutManager().layoutByName(title)

# Save the layout dialog's dpi and override it with the user selection
oldResolution = cView.renderContext().dpi()
if resolution:
cView.renderContext().setDpi(resolution)

#feedback.pushInfo('cView= {}, Title= {}, extension= {}, outputFolder= {}'.format(cView, title, extension, outputFolder))

# Retrieve the resolution to apply to the export
self.processor.getResolution(cView, resolution)

#feedback.pushInfo('cView= {}, Title= {}, extension= {},
# resolution= {}, outputFolder= {}'.format(
# cView, title, extension,
# self.processor.getResolution(cView, resolution),
# outputFolder)
# )
#feedback.pushInfo(self.tr("total layoutIds '{}'").format( len(layoutIds) ) )
feedback.pushInfo(self.tr("Exporting layout '{}'").format( title ) )
result = self.processor.exportCompo(cView, outputFolder, title, extension)
Expand All @@ -163,11 +165,7 @@ def processAlgorithm(self, parameters, context, feedback):

current += 1
feedback.setProgress(current * 100 / len(layoutIds))

# Set back the original dpi in the layout dialog
cView.renderContext().setDpi(oldResolution)

EXPORTEDLAYOUTS = exportedCount
feedback.pushInfo( self.tr('End of export!'))

if exportedCount:
Expand Down
22 changes: 19 additions & 3 deletions processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ def exportCompo(self, cView, folder, title, extension):

return result == QgsLayoutExporter.Success

def getResolution(self, layout, resolution):
"""Define the resolution to use during export (custom or layout)
Returns an integer representing the resolution
:param layout: The print layout to export
:param resolution: The custom value set by user
"""

global layoutDpi
if resolution:
layoutDpi = resolution
else:
# rely on value set in the layout properties dialog
layoutDpi = layout.renderContext().dpi()

return layoutDpi

def overrideExportSettings(self, layout, extension):
"""Because GUI settings are not exposed in Python,
we need to find and catch user selection and override
Expand All @@ -158,7 +174,7 @@ def overrideExportSettings(self, layout, extension):
# let's follow non-default values if set
exportSettings = QgsLayoutExporter.PdfExportSettings()
exportSettings.flags = layout.renderContext().flags()
#exportSettings.dpi = layout.renderContext().dpi() # default value of exportSettings is to use the layout dpi
exportSettings.dpi = layoutDpi
if layout.customProperty('rasterize') in ['true', True]:
exportSettings.rasterizeWholeImage = True

Expand Down Expand Up @@ -194,7 +210,7 @@ def overrideExportSettings(self, layout, extension):
# See QgsLayoutDesignerDialog::getSvgExportSettings
exportSettings = QgsLayoutExporter.SvgExportSettings()
exportSettings.flags = layout.renderContext().flags()
#exportSettings.dpi = layout.renderContext().dpi() # default value of exportSettings is to use the layout dpi
exportSettings.dpi = layoutDpi
if layout.customProperty('forceVector') == 1:
exportSettings.forceVectorOutput = True

Expand All @@ -220,7 +236,7 @@ def overrideExportSettings(self, layout, extension):
# see QgsLayoutDesignerDialog::getRasterExportSettings for settings
exportSettings = QgsLayoutExporter.ImageExportSettings()
exportSettings.flags = layout.renderContext().flags()
#exportSettings.dpi = layout.renderContext().dpi() # default value of exportSettings is to use the layout dpi
exportSettings.dpi = layoutDpi
if layout.customProperty('exportWorldFile') in ['true', True]:
exportSettings.generateWorldFile = True

Expand Down