Skip to content

Commit

Permalink
Fix for issue #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldebek committed Jan 10, 2018
1 parent 453a79a commit 0f2b4ed
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 326 deletions.
6 changes: 4 additions & 2 deletions QGIS Plugin/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name=Project Selector
qgisMinimumVersion=2.0
qgisMaximumVersion=2.99
description=Tool for selecting pre-defined QGIS projects.
version=1.2.0
version=1.2.1
author=Dartmoor National Park Authority
[email protected]
about=Tools for simplifying and automating common tasks for national parks and other protected areas. Catchy name courtesy of Dartmoor National Park, UK.
Expand All @@ -24,7 +24,9 @@ about=Tools for simplifying and automating common tasks for national parks and o

# Uncomment the following line and add your changelog entries:

changelog=1.2.0 - New features:
changelog=1.2.1 - New features:
- Added checkbox for using only identifiable layers in legend compositions
<p>1.2.0 - New features:
- Added ability to enable / disable project selector through settings
<p>1.1.4 - New features:
- Added option for setting custom dpi values for printing
Expand Down
16 changes: 7 additions & 9 deletions QGIS Plugin/projectselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
***************************************************************************/
"""
# Import the PyQt and QGIS libraries
import os.path
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
Expand All @@ -29,10 +30,9 @@
from projectselectordialog import *
from templateselectordialog import *
from settingsdialog import *
import os.path


class ProjectSelector:
class ProjectSelector(object):

def __init__(self, iface):
# Save reference to the QGIS interface
Expand All @@ -54,12 +54,10 @@ def __init__(self, iface):

def initGui(self):
# Create action that will start plugin configuration
self.projectSelectorAction = QAction(
QIcon(":/plugins/projectselector/icon.png"),
u"Project Selector", self.iface.mainWindow())
self.templateSelectorAction = QAction(
QIcon(":/plugins/projectselector/template_selector_icon.png"),
u"Template Selector", self.iface.mainWindow())
self.projectSelectorAction = QAction(QIcon(":/plugins/projectselector/icon.png"),
u"Project Selector", self.iface.mainWindow())
self.templateSelectorAction = QAction(QIcon(":/plugins/projectselector/template_selector_icon.png"),
u"Template Selector", self.iface.mainWindow())
self.configureAction = QAction(u"Configure Moor Tools", self.iface.mainWindow())
# connect the action to the run method
self.projectSelectorAction.triggered.connect(self.selectProject)
Expand All @@ -74,7 +72,7 @@ def initGui(self):
self.iface.addPluginToMenu(u"&Moor Tools", self.configureAction)

# Connect the dialog to QGIS' initializationCompleted() signal
QObject.connect( self.iface, SIGNAL("initializationCompleted()"), self.onInitializationCompleted )
QObject.connect(self.iface, SIGNAL("initializationCompleted()"), self.onInitializationCompleted )

def unload(self):
# Disconnect the dialog to QGIS' initializationCompleted() signal
Expand Down
10 changes: 5 additions & 5 deletions QGIS Plugin/projectselectordialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
***************************************************************************/
"""
import os

from PyQt4 import QtCore, QtGui
from ui_projectselector import Ui_ProjectSelector
from PyQt4 import QtCore, QtGui, uic
# create the dialog for zoom to point

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui_projectselector.ui')


class ProjectSelectorException(Exception):
pass
Expand All @@ -35,10 +35,10 @@ class ProjectSelectorDialog(QtGui.QDialog):
def __init__(self, iface):

self.iface = iface

QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_ProjectSelector()
self.ui.setupUi(self)
self.ui = uic.loadUi(ui_file, self)
self.plugin_dir = os.path.dirname(__file__)

# import pydevd; pydevd.settrace()
Expand Down
15 changes: 9 additions & 6 deletions QGIS Plugin/settingsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
***************************************************************************/
"""

from PyQt4 import QtCore, QtGui
from ui_settings import Ui_Dialog
# create the dialog for zoom to point

import os
from PyQt4 import QtCore, QtGui, uic
# create the dialog for zoom to point

PARENT_DIR = os.path.dirname(os.path.abspath(__file__))
DEFAULTS = os.path.join(PARENT_DIR, 'defaults.txt')

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui_settings.ui')


class SettingsDialog(QtGui.QDialog):

def __init__(self):

QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.ui = uic.loadUi(ui_file, self)

self.settings = QtCore.QSettings()

Expand All @@ -48,7 +47,9 @@ def __init__(self):
self.ui.projectsFolderLineEdit.setText(projects)
self.ui.templateRootLineEdit.setText(templates)
project_selector_enabled = self.settings.value("MoorTools/ProjectSelector/isEnabled", True, type=bool)
identifiable_only = self.settings.value("MoorTools/ProjectSelector/identifiableOnly", True, type=bool)
self.ui.projectSelectorEnabledCheckBox.setChecked(project_selector_enabled)
self.ui.identifiableOnly.setChecked(identifiable_only)

def browseForProjectRoot(self):
startingDir = str(self.settings.value("MoorTools/ProjectSelector/projectRoot", os.path.expanduser("~"), type=str))
Expand All @@ -72,4 +73,6 @@ def accept(self):
paths.write('templates:{}\n'.format(templates))
project_selector_enabled = self.ui.projectSelectorEnabledCheckBox.isChecked()
self.settings.setValue("MoorTools/ProjectSelector/isEnabled", project_selector_enabled)
identifiable_only = self.ui.identifiableOnly.isChecked()
self.settings.setValue("MoorTools/ProjectSelector/identifiableOnly", identifiable_only)
QtGui.QDialog.accept(self)
30 changes: 25 additions & 5 deletions QGIS Plugin/templateselectordialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
***************************************************************************/
"""

from PyQt4 import QtCore, QtGui, QtXml
from PyQt4 import QtCore, QtGui, QtXml, uic
from qgis.core import *
from qgis.gui import *
from ui_templateselector import Ui_TemplateSelector
from math import ceil
# create the dialog for zoom to point

Expand All @@ -33,6 +32,8 @@
from xml.etree import ElementTree as ET
from xy_to_osgb import xy_to_osgb

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui_templateselector.ui')


class TemplateSelectorException(Exception):
pass
Expand All @@ -49,11 +50,11 @@ def __init__(self, iface):
self.iface = iface
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_TemplateSelector()
self.ui.setupUi(self)
self.ui = uic.loadUi(ui_file, self)

# Set up the list of templates
s = QtCore.QSettings()
self.identifiable_only = s.value("MoorTools/ProjectSelector/identifiableOnly", True, type=bool)
self.templateFileRoot = s.value("MoorTools/TemplateSelector/templateRoot", '', type=str)
if len(self.templateFileRoot) == 0 or not os.path.isdir(self.templateFileRoot):
raise TemplateSelectorException('\'%s\' is not a valid template file root folder.' % self.templateFileRoot)
Expand Down Expand Up @@ -259,6 +260,24 @@ def fetchComposerMapNames(self):
i += 1
return composerNames

def set_legend_compositions(self, composerView):
non_ident = QgsProject.instance().nonIdentifiableLayers()
self.legend_tree_root = QgsLayerTreeGroup()
layer_nodes = []

for lyr in self.iface.mapCanvas().layers():
if lyr.id() not in non_ident:
layer_nodes.append(QgsLayerTreeLayer(lyr))

self.legend_tree_root.insertChildNodes(-1, layer_nodes)
# update the model
for item in composerView.composition().items():
if not isinstance(item, QgsComposerLegend):
continue
legend_model = item.modelV2()
legend_model.setRootGroup(self.legend_tree_root)
item.synchronizeWithModel()

def getQptFilePath(self):
try:
qptFilePath = os.path.join(self.templateFileRoot,
Expand Down Expand Up @@ -378,7 +397,8 @@ def openTemplate(self):
return

# Update the ComposerMap cached images of all ComposerMaps

if self.identifiable_only:
self.set_legend_compositions(composerView)
for i in range(len(self.maps_properties)):
compMap = composerView.composition().getComposerMapById(i)
values = self.maps_properties[compMap.displayName()]
Expand Down
72 changes: 0 additions & 72 deletions QGIS Plugin/ui_projectselector.py

This file was deleted.

80 changes: 0 additions & 80 deletions QGIS Plugin/ui_settings.py

This file was deleted.

Loading

0 comments on commit 0f2b4ed

Please sign in to comment.