Skip to content

Commit

Permalink
Qt 5.2 has QComboBox::currentData
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 25, 2017
1 parent 43faf33 commit a61b922
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_export_vector.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Expand Up @@ -33,7 +33,6 @@
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
Expand Down Expand Up @@ -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)
Expand All @@ -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)):
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/modeler/MultilineTextPanel.py
Expand Up @@ -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())]
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsfieldcalculator.h
Expand Up @@ -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() )
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/auth/qgsauthcerttrustpolicycombobox.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/effects/qgseffectdrawmodecombobox.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsbrushstylecombobox.cpp
Expand Up @@ -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 )
Expand Down
6 changes: 3 additions & 3 deletions src/gui/symbology-ng/qgspenstylecombobox.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down

0 comments on commit a61b922

Please sign in to comment.