@@ -115,7 +115,7 @@ def __init__(self, param, dialog, row=0, col=0):
115
115
self .setValue (param .default )
116
116
117
117
def comboValue (self , validator = None , combobox = None ):
118
- if not combobox :
118
+ if combobox is None :
119
119
combobox = self .widget
120
120
idx = combobox .findText (combobox .currentText ())
121
121
if idx < 0 :
@@ -132,7 +132,7 @@ def setValue(self, value):
132
132
pass
133
133
134
134
def setComboValue (self , value , combobox = None ):
135
- if not combobox :
135
+ if combobox is None :
136
136
combobox = self .widget
137
137
if isinstance (value , list ):
138
138
value = value [0 ]
@@ -265,7 +265,6 @@ def createWidget(self):
265
265
self .combo .setEditText (self .param .default )
266
266
return widget
267
267
else :
268
-
269
268
widget = QgsProjectionSelectionWidget ()
270
269
if self .param .optional :
271
270
widget .setOptionVisible (QgsProjectionSelectionWidget .CrsNotSet , True )
@@ -584,31 +583,47 @@ def createWidget(self):
584
583
elif self .dialogType == DIALOG_BATCH :
585
584
return BatchInputSelectionPanel (self .param , self .row , self .col , self .dialog )
586
585
else :
587
- widget = QComboBox ()
588
- widget . setEditable ( True )
589
- files = self .dialog . getAvailableValuesOfType ( ParameterRaster , OutputRaster )
590
- for f in files :
591
- widget . addItem (self .dialog .resolveValueDescription (f ), f )
586
+ self . combo = QComboBox ()
587
+ layers = self . dialog . getAvailableValuesOfType ( ParameterRaster , OutputRaster )
588
+ self .combo . setEditable ( True )
589
+ for layer in layers :
590
+ self . combo . addItem (self .dialog .resolveValueDescription (layer ), layer )
592
591
if self .param .optional :
593
- widget .setEditText ("" )
592
+ self .combo .setEditText ("" )
593
+
594
+ widget = QWidget ()
595
+ layout = QHBoxLayout ()
596
+ layout .setMargin (0 )
597
+ layout .setContentsMargins (0 , 0 , 0 , 0 )
598
+ layout .setSpacing (2 )
599
+ layout .addWidget (self .combo )
600
+ btn = QToolButton ()
601
+ btn .setText ('...' )
602
+ btn .setToolTip (self .tr ("Select file" ))
603
+ btn .clicked .connect (self .selectFile )
604
+ layout .addWidget (btn )
605
+ widget .setLayout (layout )
594
606
return widget
595
607
596
608
def selectFile (self ):
597
609
filename , selected_filter = self .getFileName (self .combo .currentText ())
598
610
if filename :
599
611
filename = dataobjects .getRasterSublayer (filename , self .param )
600
- items = self .combo .additionalItems ()
601
- items .append (filename )
602
- self .combo .setAdditionalItems (items )
603
- self .combo .setCurrentIndex (self .combo .findText (filename ))
612
+ if isinstance (self .combo , QgsMapLayerComboBox ):
613
+ items = self .combo .additionalItems ()
614
+ items .append (filename )
615
+ self .combo .setAdditionalItems (items )
616
+ self .combo .setCurrentIndex (self .combo .findText (filename ))
617
+ else :
618
+ self .combo .setEditText (filename )
604
619
605
620
def setValue (self , value ):
606
621
if self .dialogType == DIALOG_STANDARD :
607
622
pass # TODO
608
623
elif self .dialogType == DIALOG_BATCH :
609
624
self .widget .setText (value )
610
625
else :
611
- self .setComboValue (value )
626
+ self .setComboValue (value , combobox = self . combo )
612
627
613
628
def value (self ):
614
629
if self .dialogType == DIALOG_STANDARD :
@@ -628,7 +643,7 @@ def validator(v):
628
643
return self .param .optional
629
644
else :
630
645
return os .path .exists (v )
631
- return self .comboValue (validator )
646
+ return self .comboValue (validator , combobox = self . combo )
632
647
633
648
634
649
class SelectionWidgetWrapper (WidgetWrapper ):
@@ -704,31 +719,47 @@ def createWidget(self):
704
719
widget .valueChanged .connect (lambda : self .widgetValueHasChanged .emit (self ))
705
720
return widget
706
721
else :
707
- widget = QComboBox ()
722
+ self . combo = QComboBox ()
708
723
layers = self .dialog .getAvailableValuesOfType (ParameterVector , OutputVector )
709
- widget .setEditable (True )
724
+ self . combo .setEditable (True )
710
725
for layer in layers :
711
- widget .addItem (self .dialog .resolveValueDescription (layer ), layer )
726
+ self . combo .addItem (self .dialog .resolveValueDescription (layer ), layer )
712
727
if self .param .optional :
713
- widget .setEditText ("" )
728
+ self .combo .setEditText ("" )
729
+
730
+ widget = QWidget ()
731
+ layout = QHBoxLayout ()
732
+ layout .setMargin (0 )
733
+ layout .setContentsMargins (0 , 0 , 0 , 0 )
734
+ layout .setSpacing (2 )
735
+ layout .addWidget (self .combo )
736
+ btn = QToolButton ()
737
+ btn .setText ('...' )
738
+ btn .setToolTip (self .tr ("Select file" ))
739
+ btn .clicked .connect (self .selectFile )
740
+ layout .addWidget (btn )
741
+ widget .setLayout (layout )
714
742
return widget
715
743
716
744
def selectFile (self ):
717
745
filename , selected_filter = self .getFileName (self .combo .currentText ())
718
746
if filename :
719
747
filename = dataobjects .getRasterSublayer (filename , self .param )
720
- items = self .combo .additionalItems ()
721
- items .append (filename )
722
- self .combo .setAdditionalItems (items )
723
- self .combo .setCurrentIndex (self .combo .findText (filename ))
748
+ if isinstance (self .combo , QgsMapLayerComboBox ):
749
+ items = self .combo .additionalItems ()
750
+ items .append (filename )
751
+ self .combo .setAdditionalItems (items )
752
+ self .combo .setCurrentIndex (self .combo .findText (filename ))
753
+ else :
754
+ self .combo .setEditText (filename )
724
755
725
756
def setValue (self , value ):
726
757
if self .dialogType == DIALOG_STANDARD :
727
758
pass # TODO
728
759
elif self .dialogType == DIALOG_BATCH :
729
760
self .widget .setValue (value )
730
761
else :
731
- self .setComboValue (value )
762
+ self .setComboValue (value , combobox = self . combo )
732
763
733
764
def value (self ):
734
765
if self .dialogType == DIALOG_STANDARD :
@@ -748,7 +779,7 @@ def validator(v):
748
779
return self .param .optional
749
780
else :
750
781
return os .path .exists (v )
751
- return self .comboValue (validator )
782
+ return self .comboValue (validator , combobox = self . combo )
752
783
753
784
754
785
class StringWidgetWrapper (WidgetWrapper ):
@@ -911,33 +942,51 @@ def createWidget(self):
911
942
elif self .dialogType == DIALOG_BATCH :
912
943
return BatchInputSelectionPanel (self .param , self .row , self .col , self .dialog )
913
944
else :
914
- widget = QComboBox ()
945
+ self .combo = QComboBox ()
946
+ layers = self .dialog .getAvailableValuesOfType (ParameterRaster , OutputRaster )
947
+ self .combo .setEditable (True )
915
948
tables = self .dialog .getAvailableValuesOfType (ParameterTable , OutputTable )
916
949
layers = self .dialog .getAvailableValuesOfType (ParameterVector , OutputVector )
917
950
if self .param .optional :
918
- widget .addItem (self .NOT_SELECTED , None )
951
+ self . combo .addItem (self .NOT_SELECTED , None )
919
952
for table in tables :
920
- widget .addItem (self .dialog .resolveValueDescription (table ), table )
953
+ self . combo .addItem (self .dialog .resolveValueDescription (table ), table )
921
954
for layer in layers :
922
- widget .addItem (self .dialog .resolveValueDescription (layer ), layer )
955
+ self .combo .addItem (self .dialog .resolveValueDescription (layer ), layer )
956
+
957
+ widget = QWidget ()
958
+ layout = QHBoxLayout ()
959
+ layout .setMargin (0 )
960
+ layout .setContentsMargins (0 , 0 , 0 , 0 )
961
+ layout .setSpacing (2 )
962
+ layout .addWidget (self .combo )
963
+ btn = QToolButton ()
964
+ btn .setText ('...' )
965
+ btn .setToolTip (self .tr ("Select file" ))
966
+ btn .clicked .connect (self .selectFile )
967
+ layout .addWidget (btn )
968
+ widget .setLayout (layout )
923
969
return widget
924
970
925
971
def selectFile (self ):
926
972
filename , selected_filter = self .getFileName (self .combo .currentText ())
927
973
if filename :
928
974
filename = dataobjects .getRasterSublayer (filename , self .param )
929
- items = self .combo .additionalItems ()
930
- items .append (filename )
931
- self .combo .setAdditionalItems (items )
932
- self .combo .setCurrentIndex (self .combo .findText (filename ))
975
+ if isinstance (self .combo , QgsMapLayerComboBox ):
976
+ items = self .combo .additionalItems ()
977
+ items .append (filename )
978
+ self .combo .setAdditionalItems (items )
979
+ self .combo .setCurrentIndex (self .combo .findText (filename ))
980
+ else :
981
+ self .combo .setEditText (filename )
933
982
934
983
def setValue (self , value ):
935
984
if self .dialogType == DIALOG_STANDARD :
936
985
pass # TODO
937
986
elif self .dialogType == DIALOG_BATCH :
938
987
return self .widget .setText (value )
939
988
else :
940
- self .setComboValue (value )
989
+ self .setComboValue (value , combobox = self . combo )
941
990
942
991
def value (self ):
943
992
if self .dialogType == DIALOG_STANDARD :
@@ -954,7 +1003,7 @@ def value(self):
954
1003
else :
955
1004
def validator (v ):
956
1005
return bool (v ) or self .param .optional
957
- return self .comboValue (validator )
1006
+ return self .comboValue (validator , combobox = self . combo )
958
1007
959
1008
960
1009
class TableFieldWidgetWrapper (WidgetWrapper ):
0 commit comments