Skip to content

Commit

Permalink
Fix for #758 - use user defined north arrow for composer layouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Feb 15, 2014
1 parent f8db72d commit 7ee5ff2
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 233 deletions.
17 changes: 17 additions & 0 deletions safe_qgis/report/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, iface):
self.composition = None
self.extent = iface.mapCanvas().extent()
self.safe_logo = ':/plugins/inasafe/inasafe-logo-url.svg'
self.north_arrow = ':/plugins/inasafe/simple_north_arrow.png'
self.org_logo = ':/plugins/inasafe/supporters.png'
self.template = ':/plugins/inasafe/inasafe-portrait-a4.qpt'
self.disclaimer = disclaimer()
Expand Down Expand Up @@ -82,6 +83,14 @@ def set_impact_layer(self, layer):
"""
self.layer = layer

def set_north_arrow_image(self, logo_path):
"""Set image that will be used as organisation logo in reports.
:param logo_path: Path to image file
:type logo_path: str
"""
self.north_arrow = logo_path

def set_organisation_logo(self, logo):
"""Set image that will be used as organisation logo in reports.
Expand Down Expand Up @@ -244,6 +253,14 @@ def load_template(self):
raise ReportCreationError(self.tr(
'Image "safe-logo" could not be found'))

# set north arrow
image = self.composition.getComposerItemById('north-arrow')
if image is not None:
image.setPictureFile(self.north_arrow)
else:
raise ReportCreationError(self.tr(
'Image "north arrow" could not be found'))

# set organisation logo
image = self.composition.getComposerItemById('organisation-logo')
if image is not None:
Expand Down
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Composer title="Composer 1" visible="1">
<Composition printResolution="300" paperWidth="210" snapGridOffsetX="0" snapGridResolution="5" snapGridOffsetY="0" alignmentSnap="0" snapping="0" numPages="1" paperHeight="297" alignmentSnapTolerance="0" printAsRaster="0">
<ComposerPicture pictureWidth="11.5387" file="/usr/local/qgis-2.0/share/qgis/svg/arrows/Arrow_05.svg" pictureHeight="11.8732" mapId="-1">
<ComposerItem width="11.5387" x="187.797" transparency="40" y="26.9237" rotation="0" height="11.8732" positionMode="0" frame="false" outlineWidth="0.3" zValue="9" lastValidViewScaleFactor="5.97987" uuid="{2c35d3f6-2709-4b47-94a9-ec183f96dfc3}" id="" background="true" blendMode="0" positionLock="false">
<ComposerPicture pictureWidth="11.5387" file="." pictureHeight="11.8732" mapId="-1">
<ComposerItem width="11.5387" x="187.797" transparency="40" y="26.9237" rotation="0" height="11.8732" positionMode="0" frame="false" outlineWidth="0.3" zValue="9" lastValidViewScaleFactor="5.97987" uuid="{2c35d3f6-2709-4b47-94a9-ec183f96dfc3}" id="" background="true" blendMode="0" positionLock="false" id="north-arrow">
<FrameColor alpha="255" red="0" blue="0" green="0"/>
<BackgroundColor alpha="170" red="255" blue="255" green="255"/>
</ComposerItem>
Expand Down
2 changes: 2 additions & 0 deletions safe_qgis/resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<file alias="save-as-scenario.svg">img/icons/save-as-scenario.svg</file>
<file alias="show-converter-tool.svg">img/icons/show-converter-tool.svg</file>
<file alias="show-impact-merge.svg">img/icons/show-impact-merge.svg</file>
<!-- North arrows -->
<file alias="simple_north_arrow.png">img/logos/simple_north_arrow.png</file>
<!-- logos -->
<file alias="inasafe-logo.svg">img/logos/inasafe-logo.svg</file>
<file alias="inasafe-logo-url.svg">img/logos/inasafe-logo-url.svg</file>
Expand Down
18 changes: 18 additions & 0 deletions safe_qgis/tools/options_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def restore_state(self):
self.keyword_io.default_keyword_db_path(), type=str)
self.leKeywordCachePath.setText(path)

path = settings.value('inasafe/northArrowPath', '', type=str)
self.leNorthArrowPath.setText(path)

path = settings.value('inasafe/orgLogoPath', '', type=str)
self.leOrgLogoPath.setText(path)

Expand Down Expand Up @@ -168,6 +171,9 @@ def save_state(self):
settings.setValue(
'inasafe/keywordCachePath',
self.leKeywordCachePath.text())
settings.setValue(
'inasafe/northArrowPath',
self.northArrowPath.text())
settings.setValue(
'inasafe/orgLogoPath',
self.leOrgLogoPath.text())
Expand Down Expand Up @@ -206,6 +212,18 @@ def on_toolKeywordCachePath_clicked(self):
self.tr('Sqlite DB File (*.db)'))
self.leKeywordCachePath.setText(file_name)

@pyqtSignature('') # prevents actions being handled twice
def on_toolNorhtArrowPath_clicked(self):
"""Auto-connect slot activated when north arrow tool button is clicked.
"""
# noinspection PyCallByClass,PyTypeChecker
file_name = QtGui.QFileDialog.getOpenFileName(
self,
self.tr('Set north arrow image file'),
'',
self.tr('Portable Network Graphics files (*.png *.PNG)'))
self.leNorthArrowPath.setText(file_name)

@pyqtSignature('') # prevents actions being handled twice
def on_toolOrgLogoPath_clicked(self):
"""Auto-connect slot activated when logo file tool button is clicked.
Expand Down
59 changes: 38 additions & 21 deletions safe_qgis/ui/options_dialog_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'options_dialog_base.ui'
#
# Created: Wed Feb 12 18:14:30 2014
# Created: Sat Feb 15 21:31:38 2014
# by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -32,6 +32,11 @@ def setupUi(self, OptionsDialogBase):
OptionsDialogBase.setWindowIcon(icon)
self.gridLayout_2 = QtGui.QGridLayout(OptionsDialogBase)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.buttonBox = QtGui.QDialogButtonBox(OptionsDialogBase)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Help|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout_2.addWidget(self.buttonBox, 1, 0, 1, 1)
self.tabWidget = QtGui.QTabWidget(OptionsDialogBase)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.tab_basic = QtGui.QWidget()
Expand Down Expand Up @@ -165,27 +170,42 @@ def setupUi(self, OptionsDialogBase):
self.toolOrgLogoPath.setObjectName(_fromUtf8("toolOrgLogoPath"))
self.horizontalLayout_9.addWidget(self.toolOrgLogoPath)
self.gridLayout_5.addLayout(self.horizontalLayout_9, 1, 0, 1, 1)
self.lblNorthArrowPath = QtGui.QLabel(self.tab_templates)
self.lblNorthArrowPath.setEnabled(True)
self.lblNorthArrowPath.setObjectName(_fromUtf8("lblNorthArrowPath"))
self.gridLayout_5.addWidget(self.lblNorthArrowPath, 2, 0, 1, 1)
self.horizontalLayout_8 = QtGui.QHBoxLayout()
self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8"))
self.leNorthArrowPath = QtGui.QLineEdit(self.tab_templates)
self.leNorthArrowPath.setEnabled(True)
self.leNorthArrowPath.setObjectName(_fromUtf8("leNorthArrowPath"))
self.horizontalLayout_8.addWidget(self.leNorthArrowPath)
self.toolNorthArrowPath = QtGui.QToolButton(self.tab_templates)
self.toolNorthArrowPath.setEnabled(True)
self.toolNorthArrowPath.setObjectName(_fromUtf8("toolNorthArrowPath"))
self.horizontalLayout_8.addWidget(self.toolNorthArrowPath)
self.gridLayout_5.addLayout(self.horizontalLayout_8, 3, 0, 1, 1)
self.lblReportTemplate = QtGui.QLabel(self.tab_templates)
self.lblReportTemplate.setEnabled(True)
self.lblReportTemplate.setObjectName(_fromUtf8("lblReportTemplate"))
self.gridLayout_5.addWidget(self.lblReportTemplate, 2, 0, 1, 1)
self.horizontalLayout_8 = QtGui.QHBoxLayout()
self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8"))
self.gridLayout_5.addWidget(self.lblReportTemplate, 4, 0, 1, 1)
self.horizontalLayout_10 = QtGui.QHBoxLayout()
self.horizontalLayout_10.setObjectName(_fromUtf8("horizontalLayout_10"))
self.leReportTemplatePath = QtGui.QLineEdit(self.tab_templates)
self.leReportTemplatePath.setEnabled(True)
self.leReportTemplatePath.setObjectName(_fromUtf8("leReportTemplatePath"))
self.horizontalLayout_8.addWidget(self.leReportTemplatePath)
self.toolReportTemplatePath = QtGui.QToolButton(self.tab_templates)
self.toolReportTemplatePath.setEnabled(True)
self.toolReportTemplatePath.setObjectName(_fromUtf8("toolReportTemplatePath"))
self.horizontalLayout_8.addWidget(self.toolReportTemplatePath)
self.gridLayout_5.addLayout(self.horizontalLayout_8, 3, 0, 1, 1)
self.horizontalLayout_10.addWidget(self.leReportTemplatePath)
self.toolReportTemplatePath_2 = QtGui.QToolButton(self.tab_templates)
self.toolReportTemplatePath_2.setEnabled(True)
self.toolReportTemplatePath_2.setObjectName(_fromUtf8("toolReportTemplatePath_2"))
self.horizontalLayout_10.addWidget(self.toolReportTemplatePath_2)
self.gridLayout_5.addLayout(self.horizontalLayout_10, 5, 0, 1, 1)
self.label_2 = QtGui.QLabel(self.tab_templates)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.gridLayout_5.addWidget(self.label_2, 4, 0, 1, 1)
self.gridLayout_5.addWidget(self.label_2, 6, 0, 1, 1)
self.txtDisclaimer = QtGui.QPlainTextEdit(self.tab_templates)
self.txtDisclaimer.setObjectName(_fromUtf8("txtDisclaimer"))
self.gridLayout_5.addWidget(self.txtDisclaimer, 5, 0, 1, 1)
self.gridLayout_5.addWidget(self.txtDisclaimer, 7, 0, 1, 1)
self.tabWidget.addTab(self.tab_templates, _fromUtf8(""))
self.tab_advanced = QtGui.QWidget()
self.tab_advanced.setObjectName(_fromUtf8("tab_advanced"))
Expand Down Expand Up @@ -227,11 +247,6 @@ def setupUi(self, OptionsDialogBase):
self.gridLayout_6.addItem(spacerItem2, 6, 0, 1, 1)
self.tabWidget.addTab(self.tab_advanced, _fromUtf8(""))
self.gridLayout_2.addWidget(self.tabWidget, 0, 0, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(OptionsDialogBase)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Help|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout_2.addWidget(self.buttonBox, 1, 0, 1, 1)

self.retranslateUi(OptionsDialogBase)
self.tabWidget.setCurrentIndex(0)
Expand All @@ -256,9 +271,9 @@ def setupUi(self, OptionsDialogBase):
OptionsDialogBase.setTabOrder(self.dsbFemaleRatioDefault, self.cbxClipHard)
OptionsDialogBase.setTabOrder(self.cbxClipHard, self.scrollArea)
OptionsDialogBase.setTabOrder(self.scrollArea, self.txtDisclaimer)
OptionsDialogBase.setTabOrder(self.txtDisclaimer, self.leReportTemplatePath)
OptionsDialogBase.setTabOrder(self.leReportTemplatePath, self.toolReportTemplatePath)
OptionsDialogBase.setTabOrder(self.toolReportTemplatePath, self.leOrgLogoPath)
OptionsDialogBase.setTabOrder(self.txtDisclaimer, self.leNorthArrowPath)
OptionsDialogBase.setTabOrder(self.leNorthArrowPath, self.toolNorthArrowPath)
OptionsDialogBase.setTabOrder(self.toolNorthArrowPath, self.leOrgLogoPath)
OptionsDialogBase.setTabOrder(self.leOrgLogoPath, self.toolOrgLogoPath)
OptionsDialogBase.setTabOrder(self.toolOrgLogoPath, self.cbxDevMode)
OptionsDialogBase.setTabOrder(self.cbxDevMode, self.textBrowser)
Expand Down Expand Up @@ -289,8 +304,10 @@ def retranslateUi(self, OptionsDialogBase):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_basic), _translate("OptionsDialogBase", "Basic Options", None))
self.lblOrganisationLogo.setText(_translate("OptionsDialogBase", "Organisation logo", None))
self.toolOrgLogoPath.setText(_translate("OptionsDialogBase", "...", None))
self.lblNorthArrowPath.setText(_translate("OptionsDialogBase", "North arrow image", None))
self.toolNorthArrowPath.setText(_translate("OptionsDialogBase", "...", None))
self.lblReportTemplate.setText(_translate("OptionsDialogBase", "Report templates directory", None))
self.toolReportTemplatePath.setText(_translate("OptionsDialogBase", "...", None))
self.toolReportTemplatePath_2.setText(_translate("OptionsDialogBase", "...", None))
self.label_2.setText(_translate("OptionsDialogBase", "Organisation disclaimer text", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_templates), _translate("OptionsDialogBase", "Template Options", None))
self.lblKeywordCache.setText(_translate("OptionsDialogBase", "Keyword cache for remote datasources", None))
Expand Down
67 changes: 50 additions & 17 deletions safe_qgis/ui/options_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
<normaloff>:/plugins/inasafe/icon.png</normaloff>:/plugins/inasafe/icon.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
Expand Down Expand Up @@ -321,26 +331,26 @@
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblReportTemplate">
<widget class="QLabel" name="lblNorthArrowPath">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Report templates directory</string>
<string>North arrow image</string>
</property>
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLineEdit" name="leReportTemplatePath">
<widget class="QLineEdit" name="leNorthArrowPath">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolReportTemplatePath">
<widget class="QToolButton" name="toolNorthArrowPath">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -352,19 +362,52 @@
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblReportTemplate">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Report templates directory</string>
</property>
</widget>
</item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLineEdit" name="leReportTemplatePath">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolReportTemplatePath_2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Organisation disclaimer text</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="7" column="0">
<widget class="QPlainTextEdit" name="txtDisclaimer"/>
</item>
</layout>
<zorder>label_2</zorder>
<zorder>txtDisclaimer</zorder>
<zorder>lblOrganisationLogo</zorder>
<zorder>lblNorthArrowPath</zorder>
<zorder>layoutWidget</zorder>
<zorder>lblReportTemplate</zorder>
</widget>
<widget class="QWidget" name="tab_advanced">
Expand Down Expand Up @@ -458,16 +501,6 @@ p, li { white-space: pre-wrap; }
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
Expand All @@ -490,8 +523,8 @@ p, li { white-space: pre-wrap; }
<tabstop>cbxClipHard</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>txtDisclaimer</tabstop>
<tabstop>leReportTemplatePath</tabstop>
<tabstop>toolReportTemplatePath</tabstop>
<tabstop>leNorthArrowPath</tabstop>
<tabstop>toolNorthArrowPath</tabstop>
<tabstop>leOrgLogoPath</tabstop>
<tabstop>toolOrgLogoPath</tabstop>
<tabstop>cbxDevMode</tabstop>
Expand Down

0 comments on commit 7ee5ff2

Please sign in to comment.