Skip to content
Permalink
Browse files

Qt 5.2 has QComboBox::currentData

  • Loading branch information
jef-n committed Jan 25, 2017
1 parent 43faf33 commit a61b9222ded60ffe04ec32867c4d5ed6d40dbf8c
@@ -73,7 +73,7 @@ def chooseOutputFile(self):
lastUsedDir = settings.value(self.lastUsedVectorDirSettingsKey, ".")

# get selected filter
selectedFilter = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
selectedFilter = self.cboFileFormat.currentData()

# ask for a filename
filename, filter = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
@@ -152,7 +152,7 @@ def accept(self):
options = {}

# set the OGR driver will be used
driverName = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
driverName = self.cboFileFormat.currentData()
options['driverName'] = driverName

# set the output file encoding
@@ -31,7 +31,7 @@
from collections import OrderedDict

from qgis.PyQt import uic
from qgis.PyQt.QtGui import QBrush, QIcon
from qgis.PyQt.QtGui import QBrush
from qgis.PyQt.QtWidgets import QComboBox, QHeaderView, QLineEdit, QSpacerItem, QMessageBox, QSpinBox, QStyledItemDelegate
from qgis.PyQt.QtCore import QItemSelectionModel, QAbstractTableModel, QModelIndex, QVariant, Qt, pyqtSlot

@@ -297,7 +297,7 @@ def setModelData(self, editor, model, index):

fieldType = FieldsMappingModel.columns[column]['type']
if fieldType == QVariant.Type:
value = editor.itemData(editor.currentIndex())
value = editor.currentData()
if value is None:
value = QVariant.Invalid
model.setData(index, value)
@@ -480,7 +480,7 @@ def updateLayerCombo(self):

@pyqtSlot(bool, name='on_loadLayerFieldsButton_clicked')
def on_loadLayerFieldsButton_clicked(self, checked=False):
layer = self.layerCombo.itemData(self.layerCombo.currentIndex())
layer = self.layerCombo.currentData()
if layer is None:
return
self.model.loadLayerFields(layer)
@@ -34,7 +34,7 @@
import os
from functools import cmp_to_key

from qgis.core import QgsCoordinateReferenceSystem, QgsVectorLayer, QgsApplication, QgsWkbTypes, QgsMapLayerProxyModel
from qgis.core import QgsCoordinateReferenceSystem, QgsApplication, QgsWkbTypes, QgsMapLayerProxyModel
from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit, QWidget, QHBoxLayout, QToolButton, QFileDialog
from qgis.gui import (QgsFieldExpressionWidget,
QgsExpressionLineEdit,
@@ -121,7 +121,7 @@ def comboValue(self, validator=None, combobox=None):
if validator is not None and not validator(v):
raise InvalidParameterValue()
return v
return combobox.itemData(combobox.currentIndex())
return combobox.currentData()

def createWidget(self):
pass
@@ -352,7 +352,7 @@ def value(self):
raise InvalidParameterValue()
return s
else:
return self.widget.itemData(self.widget.currentIndex())
return self.widget.currentData()


class PointWidgetWrapper(WidgetWrapper):
@@ -397,7 +397,7 @@ def value(self):
raise InvalidParameterValue()
return s
else:
return self.widget.itemData(self.widget.currentIndex())
return self.widget.currentData()


class FileWidgetWrapper(WidgetWrapper):
@@ -33,7 +33,6 @@
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
@@ -265,8 +264,8 @@ def setupUi(self):

self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
| QDialogButtonBox.Ok)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel |
QDialogButtonBox.Ok)
self.buttonBox.setObjectName('buttonBox')
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)
@@ -292,17 +291,17 @@ def okPressed(self):
name = safeName.lower() + str(i)
else:
name = self.param.name
if (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN
or isinstance(self.param, ParameterBoolean)):
if (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN or
isinstance(self.param, ParameterBoolean)):
self.param = ParameterBoolean(name, description, self.state.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD
or isinstance(self.param, ParameterTableField)):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or
isinstance(self.param, ParameterTableField)):
if self.parentCombo.currentIndex() < 0:
QMessageBox.warning(self, self.tr('Unable to define parameter'),
self.tr('Wrong or missing parameter values'))
return
parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
datatype = self.datatypeCombo.itemData(self.datatypeCombo.currentIndex())
parent = self.parentCombo.currentData()
datatype = self.datatypeCombo.currentData()
self.param = ParameterTableField(name, description, parent, datatype, multiple=self.multipleCheck.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or
isinstance(self.param, ParameterRaster)):
@@ -343,7 +342,7 @@ def okPressed(self):
return
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXPRESSION or
isinstance(self.param, ParameterExpression)):
parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
parent = self.parentCombo.currentData()
self.param = ParameterExpression(name, description,
default=str(self.defaultEdit.expression()),
parent_layer=parent)
@@ -61,7 +61,7 @@ def getValue(self):
if self.combo.currentIndex() == 0:
return str(self.textBox.toPlainText())
else:
return self.combo.itemData(self.combo.currentIndex())
return self.combo.currentData()

def setValue(self, value):
items = [self.combo.itemData(i) for i in range(1, self.combo.count())]
@@ -65,12 +65,12 @@ class APP_EXPORT QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalcula
inline QgsField fieldDefinition()
{
return QgsField( mOutputFieldNameLineEdit->text(),
static_cast< QVariant::Type >( mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole ).toInt() ),
mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole + 1 ).toString(),
static_cast< QVariant::Type >( mOutputFieldTypeComboBox->currentData( Qt::UserRole ).toInt() ),
mOutputFieldTypeComboBox->currentData( Qt::UserRole + 1 ).toString(),
mOutputFieldWidthSpinBox->value(),
mOutputFieldPrecisionSpinBox->value(),
QString(),
static_cast< QVariant::Type >( mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole + 6 ).toInt() )
static_cast< QVariant::Type >( mOutputFieldTypeComboBox->currentData( Qt::UserRole + 6 ).toInt() )
);
}

@@ -60,7 +60,7 @@ QgsAuthCertTrustPolicyComboBox::QgsAuthCertTrustPolicyComboBox( QWidget *parent,

QgsAuthCertUtils::CertTrustPolicy QgsAuthCertTrustPolicyComboBox::trustPolicy()
{
return ( QgsAuthCertUtils::CertTrustPolicy )itemData( currentIndex() ).toInt();
return ( QgsAuthCertUtils::CertTrustPolicy )currentData().toInt();
}

QgsAuthCertUtils::CertTrustPolicy QgsAuthCertTrustPolicyComboBox::trustPolicyForIndex( int indx )
@@ -37,7 +37,7 @@ QgsEffectDrawModeComboBox::QgsEffectDrawModeComboBox( QWidget* parent )

QgsPaintEffect::DrawMode QgsEffectDrawModeComboBox::drawMode() const
{
return ( QgsPaintEffect::DrawMode ) itemData( currentIndex() ).toInt();
return ( QgsPaintEffect::DrawMode ) currentData().toInt();
}

void QgsEffectDrawModeComboBox::setDrawMode( QgsPaintEffect::DrawMode drawMode )
@@ -58,7 +58,7 @@ QgsBrushStyleComboBox::QgsBrushStyleComboBox( QWidget* parent )

Qt::BrushStyle QgsBrushStyleComboBox::brushStyle() const
{
return ( Qt::BrushStyle ) itemData( currentIndex() ).toInt();
return ( Qt::BrushStyle ) currentData().toInt();
}

void QgsBrushStyleComboBox::setBrushStyle( Qt::BrushStyle style )
@@ -46,7 +46,7 @@ QgsPenStyleComboBox::QgsPenStyleComboBox( QWidget* parent )

Qt::PenStyle QgsPenStyleComboBox::penStyle() const
{
return ( Qt::PenStyle ) itemData( currentIndex() ).toInt();
return ( Qt::PenStyle ) currentData().toInt();
}

void QgsPenStyleComboBox::setPenStyle( Qt::PenStyle style )
@@ -87,7 +87,7 @@ QgsPenJoinStyleComboBox::QgsPenJoinStyleComboBox( QWidget* parent )

Qt::PenJoinStyle QgsPenJoinStyleComboBox::penJoinStyle() const
{
return ( Qt::PenJoinStyle ) itemData( currentIndex() ).toInt();
return ( Qt::PenJoinStyle ) currentData().toInt();
}

void QgsPenJoinStyleComboBox::setPenJoinStyle( Qt::PenJoinStyle style )
@@ -111,7 +111,7 @@ QgsPenCapStyleComboBox::QgsPenCapStyleComboBox( QWidget* parent )

Qt::PenCapStyle QgsPenCapStyleComboBox::penCapStyle() const
{
return ( Qt::PenCapStyle ) itemData( currentIndex() ).toInt();
return ( Qt::PenCapStyle ) currentData().toInt();
}

void QgsPenCapStyleComboBox::setPenCapStyle( Qt::PenCapStyle style )

0 comments on commit a61b922

Please sign in to comment.
You can’t perform that action at this time.