Skip to content

Commit

Permalink
Merge pull request #18 from OpenDigitalWorks/integrate_into_sst
Browse files Browse the repository at this point in the history
Bug fixes and modular structure for integrating into SST
  • Loading branch information
jorgegil committed Jun 29, 2017
2 parents 056a839 + 7d4e3c3 commit 57add7c
Show file tree
Hide file tree
Showing 13 changed files with 1,385 additions and 646 deletions.
20 changes: 19 additions & 1 deletion CreateNew_Entrance_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

import os

from PyQt4 import QtGui, uic
from PyQt4 import QtCore, QtGui, uic

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'CreateNew_Entrance_dialog_base.ui'))


class CreateNew_EntranceDialog(QtGui.QDialog, FORM_CLASS):
create_new_layer = QtCore.pyqtSignal()

def __init__(self, parent=None):
"""Constructor."""
super(CreateNew_EntranceDialog, self).__init__(parent)
Expand All @@ -39,3 +41,19 @@ def __init__(self, parent=None):
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)

# setup signals
self.pushButtonSelectLocationEntrance.clicked.connect(self.selectSaveLocationEntrance)
self.pushButtonEntrancesNewFileDLG.clicked.connect(self.newEntranceLayer)
self.closePopUpEntrancesButton.clicked.connect(self.closePopUpEntrances)

def closePopUpEntrances(self):
self.close()

# Open Save file dialogue and set location in text edit
def selectSaveLocationEntrance(self):
filename = QtGui.QFileDialog.getSaveFileName(None, "Select Save Location ", "", '*.shp')
self.lineEditEntrances.setText(filename)

def newEntranceLayer(self):
self.create_new_layer.emit()
23 changes: 22 additions & 1 deletion CreateNew_LU_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

import os

from PyQt4 import QtGui, uic
from PyQt4 import QtCore, QtGui, uic

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'CreateNew_LU_dialog_base.ui'))


class CreateNew_LUDialog(QtGui.QDialog, FORM_CLASS):
create_new_layer = QtCore.pyqtSignal()

def __init__(self, parent=None):
"""Constructor."""
super(CreateNew_LUDialog, self).__init__(parent)
Expand All @@ -39,3 +41,22 @@ def __init__(self, parent=None):
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)

# setup signals
self.pushButtonSelectLocationLU.clicked.connect(self.selectSaveLocationLU)
self.pushButtonLUNewFileDLG.clicked.connect(self.newLULayer)
self.closePopUpLUButton.clicked.connect(self.closePopUpLU)

def closePopUpLU(self):
self.close()

# Open Save file dialogue and set location in text edit
def selectSaveLocationLU(self):
filename = QtGui.QFileDialog.getSaveFileName(None, "Select Save Location ", "", '*.shp')
self.lineEditLU.setText(filename)

def newLULayer(self):
self.create_new_layer.emit()

def getSelectedLULayerID(self):
return self.selectIDbuildingCombo.currentText()
18 changes: 16 additions & 2 deletions CreateNew_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

import os

from PyQt4 import QtGui, uic
from . import utility_functions as uf
from PyQt4 import QtCore, QtGui, uic


FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'CreateNew_dialog_base.ui'))


class CreatenewDialog(QtGui.QDialog, FORM_CLASS):
create_new_layer = QtCore.pyqtSignal()

def __init__(self, parent=None):
"""Constructor."""
Expand All @@ -43,7 +43,21 @@ def __init__(self, parent=None):
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)

# setup signals
self.closePopUpButton.clicked.connect(self.closePopUp)
self.pushButtonSelectLocation.clicked.connect(self.selectSaveLocation)
self.pushButtonNewFileDLG.clicked.connect(self.createLayer)


# Close create new file pop up dialogue when cancel button is pressed
def closePopUp(self):
self.close()

# Open Save file dialogue and set location in text edit
def selectSaveLocation(self):
filename = QtGui.QFileDialog.getSaveFileName(None, "Select Save Location ", "", '*.shp')
self.lineEditFrontages.setText(filename)

def createLayer(self):
self.create_new_layer.emit()

93 changes: 49 additions & 44 deletions entrances.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,44 @@
"""

# Import the PyQt and QGIS libraries
import os
from PyQt4.QtCore import *
from PyQt4 import QtGui

from qgis.core import *
from qgis.gui import *

from . import utility_functions as uf

import os


class EntranceTool(QObject):

def __init__(self, iface, dockwidget, entrancedlg):
def __init__(self, iface, dockwidget):
QObject.__init__(self)
self.iface = iface
self.legend = self.iface.legendInterface()
self.entrancedlg = entrancedlg
self.canvas = self.iface.mapCanvas()

self.dockwidget = dockwidget
self.entrancedlg = self.dockwidget.entrancedlg

self.plugin_path = os.path.dirname(__file__)

self.entrance_layer = None

# signals from dockwidget
self.dockwidget.updateEntranceButton.clicked.connect(self.updateSelectedEntranceAttribute)
self.dockwidget.updateEntranceIDButton.clicked.connect(self.updateIDEntrances)
self.dockwidget.useExistingEntrancescomboBox.currentIndexChanged.connect(self.loadEntranceLayer)

# signals from new entrance dialog
self.entrancedlg.create_new_layer.connect(self.newEntranceLayer)

#######
# Data functions
#######

# Close create new file pop up dialogue when cancel button is pressed
def closePopUpEntrances(self):
self.entrancedlg.close()

# Update the F_ID column of the Frontage layer
def updateIDEntrances(self):
layer = self.dockwidget.setEntranceLayer()
Expand All @@ -63,13 +74,10 @@ def updateIDEntrances(self):
layer.commitChanges()
layer.startEditing()

# Open Save file dialogue and set location in text edit
def selectSaveLocationEntrance(self):
filename = QtGui.QFileDialog.getSaveFileName(None, "Select Save Location ", "", '*.shp')
self.entrancedlg.lineEditEntrances.setText(filename)

# Add Frontage layer to combobox if conditions are satisfied
def updateEntranceLayer(self):
# disconnect any current entrance layer
self.disconnectEntranceLayer()
self.dockwidget.useExistingEntrancescomboBox.clear()
self.dockwidget.useExistingEntrancescomboBox.setEnabled(False)
layers = self.legend.layers()
Expand All @@ -80,8 +88,8 @@ def updateEntranceLayer(self):

if self.dockwidget.useExistingEntrancescomboBox.count() > 0:
self.dockwidget.useExistingEntrancescomboBox.setEnabled(True)
self.dockwidget.setEntranceLayer()

self.entrance_layer = self.dockwidget.setEntranceLayer()
self.connectEntranceLayer()

# Create New Layer
def newEntranceLayer(self):
Expand Down Expand Up @@ -119,14 +127,7 @@ def newEntranceLayer(self):
msgBar = self.iface.messageBar()
msg = msgBar.createMessage(u'New Frontages Layer Created:' + location)
msgBar.pushWidget(msg, QgsMessageBar.INFO, 10)

input2.startEditing()


input2.commitChanges()
self.updateEntranceLayer()
self.closePopUpEntrances()

else:
# Save to memory, no base land use layer
destCRS = self.canvas.mapRenderer().destinationCrs()
Expand All @@ -144,33 +145,42 @@ def newEntranceLayer(self):
msgBar.pushWidget(msg, QgsMessageBar.INFO, 10)

vl.startEditing()

edit1 = vl.dataProvider()
edit1.addAttributes([QgsField("E_ID", QVariant.Int),
QgsField("E_Category", QVariant.String),
QgsField("E_SubCat", QVariant.String),
QgsField("E_Level", QVariant.Double)])

vl.commitChanges()
self.updateEntranceLayer()
self.closePopUpEntrances()
vl.startEditing()

self.updateEntranceLayer()
self.entrancedlg.closePopUpEntrances()

# Set layer as frontage layer and apply thematic style
# Set layer as entrance layer and apply thematic style
def loadEntranceLayer(self):
# disconnect any current entrance layer
self.disconnectEntranceLayer()
if self.dockwidget.useExistingEntrancescomboBox.count() > 0:
input = self.dockwidget.setEntranceLayer()

self.entrance_layer = self.dockwidget.setEntranceLayer()
qml_path = self.plugin_path + "/styles/entrancesThematic.qml"
input.loadNamedStyle(qml_path)

input.startEditing()

input.featureAdded.connect(self.logEntranceFeatureAdded)
input.selectionChanged.connect(self.dockwidget.addEntranceDataFields)
input.featureDeleted.connect(self.dockwidget.clearEntranceDataFields)

# Draw New Feature
self.entrance_layer.loadNamedStyle(qml_path)
self.entrance_layer.startEditing()
self.connectEntranceLayer()

def connectEntranceLayer(self):
if self.entrance_layer:
self.entrance_layer.featureAdded.connect(self.logEntranceFeatureAdded)
self.entrance_layer.selectionChanged.connect(self.dockwidget.addEntranceDataFields)
self.entrance_layer.featureDeleted.connect(self.dockwidget.clearEntranceDataFields)

def disconnectEntranceLayer(self):
if self.entrance_layer:
self.entrance_layer.selectionChanged.disconnect(self.dockwidget.addEntranceDataFields)
self.entrance_layer.featureAdded.disconnect(self.logEntranceFeatureAdded)
self.entrance_layer.featureDeleted.disconnect(self.dockwidget.clearEntranceDataFields)
self.entrance_layer = None

# Draw New Feature
def logEntranceFeatureAdded(self, fid):

QgsMessageLog.logMessage("feature added, id = " + str(fid))
Expand Down Expand Up @@ -201,13 +211,11 @@ def logEntranceFeatureAdded(self, fid):
v_layer.changeAttributeValue(fid, update2, subcategorytext, True)
v_layer.changeAttributeValue(fid, update3, inputid, True)
v_layer.changeAttributeValue(fid, update4, accessleveltext, True)
v_layer.featureDeleted.connect(self.dockwidget.clearEntranceDataFields)
v_layer.updateFields()


# Update Feature
def updateSelectedEntranceAttribute(self):
QtGui.QApplication.beep()
#QtGui.QApplication.beep()
mc = self.canvas
layer = self.dockwidget.setEntranceLayer()
features = layer.selectedFeatures()
Expand All @@ -221,7 +229,4 @@ def updateSelectedEntranceAttribute(self):
feat['E_SubCat'] = subcategorytext
feat['E_Level'] = accessleveltext
layer.updateFeature(feat)
self.dockwidget.addEntranceDataFields()

layer.featureDeleted.connect(self.dockwidget.clearEntranceDataFields)

self.dockwidget.addEntranceDataFields()

0 comments on commit 57add7c

Please sign in to comment.