-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgLayerProperties.py
123 lines (106 loc) · 5.15 KB
/
dlgLayerProperties.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
119
120
121
122
# -*- coding:utf-8 -*-
#---------------------------------------------------------------------
#
# Visor Geográfico
#
# Original sources Copyright (C) 2004 by Gary E. Sherman sherman at mrcc.com
# Ported to Python by Germán Carrillo 2009 (http://geotux.tuxfamily.org)
#
#---------------------------------------------------------------------
#
# licensed under the terms of GNU GPL 2
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
#
#---------------------------------------------------------------------
from PyQt4.QtCore import Qt, SIGNAL, QVariant
from PyQt4.QtGui import QDialog
from dlgLayerProperties_ui import Ui_LayerProperties
class LayerProperties( QDialog, Ui_LayerProperties ):
""" Open a dialog to manage the layer properties """
def __init__( self, parent, layer ):
self.parent = parent
QDialog.__init__( self, self.parent )
self.setupUi( self )
self.layer = layer
self.updateControls()
self.connect( self.chkScale, SIGNAL( "stateChanged(int)" ), self.chkScaleChanged )
self.connect( self, SIGNAL( "accepted()" ), self.apply )
self.connect( self, SIGNAL( "rejected()" ), self.close )
def updateControls( self ):
""" Set the appropriate value/state for controls """
self.txtLayerName.setText( self.layer.name() )
if self.layer.type() == 0: # Vector Layer
self.lblDisplayField.setVisible( True )
self.cboDisplayFieldName.setVisible( True )
self.cboDisplayFieldName.setEnabled( True )
self.fields = self.layer.pendingFields()
for ( key, field ) in self.fields.iteritems():
#if not field.type() == QVariant.Double:
# self.displayName = self.vectorLayer.attributeDisplayName( key )
self.cboDisplayFieldName.addItem( field.name(), QVariant( key ) )
idx = self.cboDisplayFieldName.findText( self.layer.displayField() )
self.cboDisplayFieldName.setCurrentIndex( idx )
else:
self.lblDisplayField.setVisible( False )
self.cboDisplayFieldName.setVisible( False )
self.cboDisplayFieldName.setEnabled( False )
if self.layer.hasScaleBasedVisibility():
self.chkScale.setCheckState( Qt.Checked )
self.chkScaleChanged( 1 )
self.initialScaleDependency = True
else:
self.chkScale.setCheckState( Qt.Unchecked )
self.chkScaleChanged( 0 )
self.initialScaleDependency = False
self.initialMaxScale = self.layer.minimumScale() # To know if refresh the canvas
self.initialMinScale = self.layer.maximumScale()
self.maxScaleSpinBox.setValue( self.layer.minimumScale() )
self.minScaleSpinBox.setValue( self.layer.maximumScale() )
def chkScaleChanged( self, state ):
""" Slot. """
if state:
self.lblMaxScale.setEnabled( True )
self.lblMinScale.setEnabled( True )
self.maxScaleSpinBox.setEnabled( True )
self.minScaleSpinBox.setEnabled( True )
else:
self.lblMaxScale.setEnabled( False )
self.lblMinScale.setEnabled( False )
self.maxScaleSpinBox.setEnabled( False )
self.minScaleSpinBox.setEnabled( False )
def apply( self ):
""" Apply the new symbology to the vector layer """
newLayerName = self.txtLayerName.text()
if newLayerName:
if not newLayerName == self.layer.name():
self.layer.setLayerName( newLayerName )
self.emit( SIGNAL( "layerNameChanged(PyQt_PyObject)" ), self.layer )
if self.cboDisplayFieldName.isEnabled():
self.layer.setDisplayField( self.cboDisplayFieldName.currentText() )
if self.chkScale.checkState() == Qt.Checked:
self.layer.toggleScaleBasedVisibility( True )
self.layer.setMaximumScale( self.minScaleSpinBox.value() )
self.layer.setMinimumScale( self.maxScaleSpinBox.value() )
finalScaleDependency = True
else:
self.layer.toggleScaleBasedVisibility( False )
finalScaleDependency = False
if ( not self.initialScaleDependency == finalScaleDependency ) or \
( finalScaleDependency and ( ( not self.initialMaxScale == self.maxScaleSpinBox.value() ) or \
( not self.initialMinScale == self.minScaleSpinBox.value() ) ) ):
self.parent.canvas.refresh() # Scale dependency changed, so refresh
def mostrar( self ):
""" Show the modal dialog """
self.exec_()