Skip to content

Commit

Permalink
Merge pull request #33 from erpas/migration_to_QGIS3
Browse files Browse the repository at this point in the history
porting to QGIS 3
  • Loading branch information
erpas authored May 3, 2018
2 parents 2079d3f + c5092b2 commit 4b0f3d3
Show file tree
Hide file tree
Showing 34 changed files with 657 additions and 107,392 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
out
gen

rivergis/help/_build/
rivergis/settings.json

### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
13 changes: 13 additions & 0 deletions install_plugin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SET DIR=%cd%

SET PLUGIN=rivergis
SET SRC=%DIR%\%PLUGIN%

SET DEST=%UserProfile%\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins
SET DEST_PLUGIN=%DEST%\%PLUGIN%

rd %DEST_PLUGIN% /s /q

xcopy %SRC% %DEST_PLUGIN% /s/i/h/e/k/f/c

32 changes: 32 additions & 0 deletions install_plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

########################################################################################################################
# Link QGIS fibre network design plugin to .qgis2/python/plugin directory (with all python deps linked)
########################################################################################################################

set -u # Exit if we try to use an uninitialised variable
set -e # Return early if any command returns a non-0 exit status

echo "ADD PLUGIN TO QGIS (dev version -- link)"

PWD=`pwd`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

PLUGIN=rivergis
SRC=$DIR/$PLUGIN

DEST=~/.local/share/QGIS/QGIS3/profiles/default/python/plugins
DEST_PLUGIN=$DEST/$PLUGIN

if [ ! -d "$SRC" ]; then
echo "Missing directory $SRC"
exit 1
fi

rm -rf $DEST_PLUGIN

ln -s $SRC $DEST_PLUGIN

echo "$DEST_PLUGIN created"

cd $PWD
6 changes: 0 additions & 6 deletions rivergis/.gitignore

This file was deleted.

17 changes: 10 additions & 7 deletions rivergis/dlg_rasCreateRasLayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
* *
***************************************************************************/
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import hecobjects as heco
from ui.ui_rasCreateRASLayers import *
from __future__ import absolute_import
import os
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QApplication
from . import hecobjects as heco
# from .ui.ui_rasCreateRASLayers import *
from qgis.PyQt import uic


class DlgCreateRasLayers(QDialog):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.ui = Ui_CreateRasLayers()
self.ui.setupUi(self)
tdir = os.path.dirname(os.path.realpath(__file__))
uif = os.path.join(tdir, "ui", "ui_rasCreateRasLayers.ui")
self.ui = uic.loadUi(uif, self)
self.rgis = parent
self.rdb = parent.rdb

Expand Down
46 changes: 23 additions & 23 deletions rivergis/dlg_rasImportDataIntoRasTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
* *
***************************************************************************/
"""

import hecobjects as heco
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from ui.ui_importDataIntoRasTables import *
from __future__ import absolute_import
import os
from . import hecobjects as heco
from qgis.core import QgsProject
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QApplication


class DlgImportDataIntoRasTables(QDialog):
def __init__(self, rgis):
QDialog.__init__(self)
self.ui = Ui_importDataIntoRasTables()
self.ui.setupUi(self)
tdir = os.path.dirname(os.path.realpath(__file__))
uif = os.path.join(tdir, "ui", "ui_importDataIntoRasTables.ui")
self.ui = uic.loadUi(uif, self)
self.rgis = rgis
self.ui.buttonBox.accepted.connect(self.acceptDialog)
self.ui.buttonBox.rejected.connect(self.rejectDlg)
Expand Down Expand Up @@ -262,16 +262,16 @@ def __init__(self, rgis):
}

self.populateCbos()
for layer, data in self.layers.iteritems():
for layer, data in self.layers.items():
if data['attrs']:
data['cbo'].currentIndexChanged.connect(self.layerCboChanged)

def processLayers(self, name, data):
curInd = data['cbo'].currentIndex()
lid = data['cbo'].itemData(curInd)
layer = self.rgis.mapRegistry.mapLayer(lid)
layer = QgsProject.instance().mapLayer(lid)
attrMap = {}
for attr, attrData in data['attrs'].iteritems():
for attr, attrData in data['attrs'].items():
curText = attrData['cbo'].currentText()
if curText:
attrMap[attr] = curText
Expand All @@ -281,14 +281,14 @@ def processLayers(self, name, data):
attr_map=attrMap,
selected=self.onlySel)
self.importInfo.append(name)
if self.rgis.iface.mapCanvas().isCachingEnabled():
layer.setCacheImage(None)
# if self.rgis.iface.mapCanvas().isCachingEnabled():
# layer.setCacheImage(None)

def acceptDialog(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
self.onlySel = self.ui.chkOnlySelected.isChecked()
tabs = self.rgis.rdb.list_tables()
for key, data in self.layers.iteritems():
for key, data in self.layers.items():
if not data['cbo'].currentText() == '':
if data['className'] not in tabs:
hecobject = getattr(heco, data['className'])
Expand All @@ -305,14 +305,14 @@ def acceptDialog(self):

def populateCbos(self):
allCbosByGeomType = {0: [], 1: [], 2: []}
for impLayer, data in self.layers.iteritems():
for impLayer, data in self.layers.items():
data['cbo'].clear()
data['cbo'].addItem('')
allCbosByGeomType[data['geomType']].append(data['cbo'])
for attr, attrData in data['attrs'].iteritems():
for attr, attrData in data['attrs'].items():
attrData['cbo'].clear()
attrData['cbo'].addItem('')
for layerId, layer in sorted(self.rgis.mapRegistry.mapLayers().iteritems()):
for layerId, layer in sorted(QgsProject.instance().mapLayers().items()):
if layer.type() == 0 and layer.geometryType() == 0: # vector and points
for cbo in allCbosByGeomType[0]:
cbo.addItem(layer.name(), layerId)
Expand All @@ -329,16 +329,16 @@ def layerCboChanged(self):
layerCbo = self.sender()
curInd = layerCbo.currentIndex()
lid = layerCbo.itemData(curInd)
cboLayer = self.rgis.mapRegistry.mapLayer(lid)
cboLayer = QgsProject.instance().mapLayer(lid)
if cboLayer:
if cboLayer.featureCount():
impLayerAttrs = cboLayer.pendingFields()
impLayerAttrs = cboLayer.fields()
# find data of the current combo
for layer, data in self.layers.iteritems():
for layer, data in self.layers.items():
# if the combos match
if data['cbo'] == layerCbo:
# for all attributes combos
for attr, attrData in data['attrs'].iteritems():
for attr, attrData in data['attrs'].items():
# clear it
attrData['cbo'].clear()
attrData['cbo'].addItem('')
Expand Down
36 changes: 17 additions & 19 deletions rivergis/dlg_rasXSUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import
import os

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from ui.ui_rasXSUpdate import *
import hecobjects as heco
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QApplication
from qgis.PyQt import uic
from . import hecobjects as heco
from qgis.core import QgsProject


class DlgXSUpdateInsertMeasuredPts(QDialog):
def __init__(self, rgis):
QDialog.__init__(self)
self.ui = Ui_rasXSUpdate()
self.ui.setupUi(self)
tdir = os.path.dirname(os.path.realpath(__file__))
uif = os.path.join(tdir, "ui", "ui_rasXSUpdate.ui")
self.ui = uic.loadUi(uif, self)
self.rgis = rgis
self.ui.buttonBox.accepted.connect(self.acceptDialog)
self.ui.buttonBox.rejected.connect(self.rejectDialog)
Expand Down Expand Up @@ -72,9 +73,9 @@ def acceptDialog(self):
if not data['cbo'].currentText() == '':
curInd = data['cbo'].currentIndex()
lid = data['cbo'].itemData(curInd)
layer = self.rgis.mapRegistry.mapLayer(lid)
layer = QgsProject.instance().mapLayer(lid)
attrMap = {}
for attr, attrData in data['attrs'].iteritems():
for attr, attrData in data['attrs'].items():
curText = attrData['cbo'].currentText()
if curText:
attrMap[attr] = curText
Expand Down Expand Up @@ -109,7 +110,6 @@ def acceptDialog(self):
upArea = self.ui.cboInterpArea.currentText()
self.rgis.rdb.process_hecobject(heco.XSCutLines, 'pg_update_banks', area=upArea, xs_tol=tol)


# Update area defined by bathymetry extents polygons

else:
Expand All @@ -131,9 +131,9 @@ def acceptDialog(self):
if not data['cbo'].currentText() == '':
curInd = data['cbo'].currentIndex()
lid = data['cbo'].itemData(curInd)
layer = self.rgis.mapRegistry.mapLayer(lid)
layer = QgsProject.instance().mapLayer(lid)
attrMap = {}
for attr, attrData in data['attrs'].iteritems():
for attr, attrData in data['attrs'].items():
curText = attrData['cbo'].currentText()
if curText:
attrMap[attr] = curText
Expand All @@ -149,13 +149,12 @@ def acceptDialog(self):
QApplication.restoreOverrideCursor()
QDialog.accept(self)


def populateCbos(self):
self.ui.cboMeasuredLayer.clear()
self.ui.cboMeasuredLayer.addItem('')
self.ui.cboBathyExtLayer.clear()
self.ui.cboBathyExtLayer.addItem('')
for layerId, layer in sorted(self.rgis.mapRegistry.mapLayers().iteritems()):
for layerId, layer in sorted(QgsProject.instance().mapLayers().items()):
if layer.type() == 0 and layer.geometryType() == 0: # vector and points
self.ui.cboMeasuredLayer.addItem(layer.name(), layerId)
if layer.type() == 0 and layer.geometryType() == 1: # vector and polylines
Expand All @@ -169,16 +168,15 @@ def populateCbos(self):
self.ui.cboInterpArea.addItem(area)
self.ui.cboInterpArea.setCurrentIndex(0)


def cboMeasuredLayerChanged(self):
curInd = self.ui.cboMeasuredLayer.currentIndex()
lid = self.ui.cboMeasuredLayer.itemData(curInd)
cboLayer = self.rgis.mapRegistry.mapLayer(lid)
cboLayer = QgsProject.instance().mapLayer(lid)
if cboLayer:
if cboLayer.featureCount():
self.ui.cboMeasuredElevation.clear()
self.ui.cboMeasuredElevation.addItem('')
for a in cboLayer.pendingFields():
for a in cboLayer.fields():
self.ui.cboMeasuredElevation.addItem(a.name())
attrIndex = self.ui.cboMeasuredElevation.findText('elevation', flags=Qt.MatchFixedString)
if attrIndex > 0:
Expand Down
23 changes: 12 additions & 11 deletions rivergis/dlg_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
* *
***************************************************************************/
"""
from builtins import range

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from ui._ui_settings import *
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QApplication
from qgis.PyQt.QtGui import QStandardItem, QStandardItemModel
from qgis.core import QgsProject
import os


class DlgSettings(QDialog):

def __init__(self, parent=None, widget=0):
QDialog.__init__(self, parent)
self.ui = Ui_Settings()
self.ui.setupUi(self)
tdir = os.path.dirname(os.path.realpath(__file__))
uif = os.path.join(tdir, "ui", "ui_settings.ui")
self.ui = uic.loadUi(uif, self)
self.ui.optionsList.setCurrentRow(widget)
self.rgis = parent
self.rdb = parent.rdb
Expand All @@ -50,12 +52,12 @@ def __init__(self, parent=None, widget=0):
for row in range(self.rgis.dtmModel.rowCount()):
modelDtmLids.append(self.rgis.dtmModel.item(row).data()[1])

for layerId, layer in sorted(self.rgis.mapRegistry.mapLayers().iteritems()):
for layerId, layer in sorted(QgsProject.instance().mapLayers().items()):
if layer.type() == 1: # it's a raster
# skip the raster if already in the model
if layerId in modelDtmLids:
continue
item = QStandardItem('{0}'.format(layer.name())) #layerId
item = QStandardItem('{0}'.format(layer.name())) #layerId
check = Qt.Unchecked
item.setCheckState(check)
item.setCheckable(True)
Expand Down Expand Up @@ -97,7 +99,6 @@ def acceptDialog(self):

# write settings to json
self.rgis.writeSettings()
# print self.rgis.opts

QApplication.restoreOverrideCursor()
QDialog.accept(self)
Expand Down
Loading

0 comments on commit 4b0f3d3

Please sign in to comment.