Qt 5.2 has QComboBox::currentData

This commit is contained in:
Juergen E. Fischer 2017-01-25 03:28:53 +01:00
parent 43faf338f3
commit a61b9222de
10 changed files with 28 additions and 29 deletions

View File

@ -73,7 +73,7 @@ class DlgExportVector(QDialog, Ui_Dialog):
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 @@ class DlgExportVector(QDialog, Ui_Dialog):
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

View File

@ -31,7 +31,7 @@ import os
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 @@ class FieldDelegate(QStyledItemDelegate):
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 @@ class FieldsMappingPanel(BASE, WIDGET):
@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)

View File

@ -34,7 +34,7 @@ import locale
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 @@ class WidgetWrapper(QObject):
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 @@ class ExtentWidgetWrapper(WidgetWrapper):
raise InvalidParameterValue()
return s
else:
return self.widget.itemData(self.widget.currentIndex())
return self.widget.currentData()
class PointWidgetWrapper(WidgetWrapper):
@ -397,7 +397,7 @@ class PointWidgetWrapper(WidgetWrapper):
raise InvalidParameterValue()
return s
else:
return self.widget.itemData(self.widget.currentIndex())
return self.widget.currentData()
class FileWidgetWrapper(WidgetWrapper):

View File

@ -33,7 +33,6 @@ from qgis.core import QgsCoordinateReferenceSystem
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
@ -265,8 +264,8 @@ class ModelerParameterDefinitionDialog(QDialog):
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 @@ class ModelerParameterDefinitionDialog(QDialog):
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 @@ class ModelerParameterDefinitionDialog(QDialog):
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)

View File

@ -61,7 +61,7 @@ class MultilineTextPanel(QWidget):
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())]

View File

@ -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() )
);
}

View File

@ -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 )

View File

@ -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 )

View File

@ -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 )

View File

@ -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 )