-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsnappingdialog.py
118 lines (105 loc) · 4.65 KB
/
snappingdialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
"""
/***************************************************************************
pickLayerSnappingDialog
A QGIS plugin
pick layer
-------------------
begin : 2014-06-16
git sha : $Format:%H$
copyright : (C) 2014 by Enrico Ferreguti
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt4 import QtCore, QtGui, uic
from qgis.core import *
from ui_picksnapdialog import Ui_pickSnapDialog
class trace:
def __init__(self):
self.trace = None
def ce(self,string):
if self.trace:
print string
class snappingDialog(QtGui.QDialog, Ui_pickSnapDialog):
def __init__(self, iface):
QtGui.QDialog.__init__(self)
self.mapCanvas = iface.mapCanvas()
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
self.tra = trace()
self.buttonOkNo.accepted.connect(self.saveSnappingOptions)
self.buttonOkNo.rejected.connect(self.cancelSnappingOptions)
def cancelSnappingOptions(self):
self.hide()
def saveSnappingOptions(self):
# hide the dialog
self.hide()
if self.snapStateCombo.currentIndex() == 0:
enabled = True
else:
enabled = False
snappingType = self.snapModeCombo.currentIndex()
if self.snapModeCombo.currentIndex() == 1:
unitType = 1
else:
unitType = 0
tolerance = float(self.toleranceCombo.currentText())
avoidInterceptions = self.avoidIntersections.isChecked()
'''
utils = self.mapCanvas.snappingUtils()
if utils.SnapToMapMode() != QgsSnappingUtils.SnapAdvanced:
root = QgsProject.instance().layerTreeRoot()
layer_list = []
for layer in root.findLayers():
# LayerConfig(layer, snapping type, tolerance, units)
if layer.layer().type() == QgsMapLayer.VectorLayer:
layer_list.append(utils.LayerConfig(layer.layer(), QgsPointLocator.Vertex, 5.0, 2))
utils.setLayers(layer_list)
utils.setSnapToMapMode(QgsSnappingUtils.SnapAdvanced)
self.mapCanvas.setSnappingUtils(utils)
'''
proj = QgsProject.instance()
print self.selectedLayer.id(),enabled,snappingType,unitType,tolerance,avoidInterceptions
proj.setSnapSettingsForLayer(self.selectedLayer.id(),enabled,snappingType,unitType,tolerance,avoidInterceptions)
def getSnappingOptionsDialog(self,layer):
self.selectedLayer = layer
proj = QgsProject.instance()
res = proj.snapSettingsForLayer(layer.id())
self.compileSnapForm(res)
self.label.setText(self.selectedLayer.name())
self.show()
def compileSnapForm(self,snappingOptions):
print snappingOptions
enabled = snappingOptions[1]
snappingType = snappingOptions[2]
unitType = snappingOptions[3]
tolerance = snappingOptions[4]
avoidInterceptions = snappingOptions[5]
if enabled:
self.snapStateCombo.setCurrentIndex(0)
else:
self.snapStateCombo.setCurrentIndex(1)
self.snapModeCombo.setCurrentIndex(snappingType)
if unitType == 1:
self.snapModeCombo.setCurrentIndex(1)
else:
self.snapModeCombo.setCurrentIndex(0)
self.toleranceCombo.insertItem(0,str(tolerance))
self.toleranceCombo.setCurrentIndex(0)
if avoidInterceptions:
self.avoidIntersections.setCheckState(True)
else:
self.avoidIntersections.setChecked(False)
self.avoidIntersections.setChecked(avoidInterceptions)