dtToolsDialog.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. """
  3. /***************************************************************************
  4. DigitizingTools
  5. A QGIS plugin
  6. Subsumes different tools useful during digitizing sessions
  7. -------------------
  8. begin : 2017-12-12
  9. copyright : (C) 2017 by Bernhard Ströbl
  10. email : bernhard.stroebl@jena.de
  11. ***************************************************************************/
  12. /***************************************************************************
  13. * *
  14. * This program is free software; you can redistribute it and/or modify *
  15. * it under the terms of the GNU General Public License as published by *
  16. * the Free Software Foundation; either version 2 of the License, or *
  17. * (at your option) any later version. *
  18. * *
  19. ***************************************************************************/
  20. """
  21. from qgis.PyQt import QtWidgets, QtCore, uic
  22. from dtutils import dtGetHighlightSettings
  23. from qgis.core import *
  24. from qgis.gui import QgsHighlight
  25. import os
  26. FORM_CLASS, _ = uic.loadUiType(os.path.join(
  27. os.path.dirname(__file__), 'ui_dtchooseremaining.ui'))
  28. class DigitizingToolsChooseRemaining(QtWidgets.QDialog, FORM_CLASS):
  29. def __init__(self, iface, editLayer, pkValues, featDict, title):
  30. QtWidgets.QDialog.__init__(self)
  31. self.setupUi(self)
  32. self.iface = iface
  33. self.editLayer = editLayer
  34. self.pkValues = pkValues
  35. self.featDict = featDict
  36. self.chooseId.addItems(list(self.pkValues.keys()))
  37. self.setWindowTitle(title)
  38. self.label.setText(QtWidgets.QApplication.translate(
  39. "digitizingtools", "Choose which already existing feature should remain"))
  40. self.buttonBox.rejected.connect(self.reject)
  41. self.buttonBox.accepted.connect(self.accept)
  42. def clearHighlight(self):
  43. try:
  44. self.hl.hide()
  45. except:
  46. pass
  47. @QtCore.pyqtSlot(int)
  48. def on_chooseId_currentIndexChanged(self, thisIndex):
  49. self.clearHighlight()
  50. aPkValue = self.chooseId.currentText()
  51. aGeom = self.featDict[self.pkValues[aPkValue]].geometry()
  52. hlColor, hlFillColor, hlBuffer, hlMinWidth = dtGetHighlightSettings()
  53. self.hl = QgsHighlight(self.iface.mapCanvas(), aGeom, self.editLayer)
  54. self.hl.setColor(hlColor)
  55. self.hl.setFillColor(hlFillColor)
  56. self.hl.setBuffer(hlBuffer)
  57. self.hl.setWidth(hlMinWidth)
  58. self.hl.show()
  59. @QtCore.pyqtSlot()
  60. def reject(self):
  61. self.clearHighlight()
  62. self.done(0)
  63. @QtCore.pyqtSlot()
  64. def accept(self):
  65. self.clearHighlight()
  66. self.pkValueToKeep = self.chooseId.currentText()
  67. self.done(1)