Skip to content
Permalink
Browse files

fix Qt issue QVariant::value using enum (#8265)

* fix Qt issue QVariant::value using enum

see https://bugreports.qt.io/browse/QTBUG-53384
fix #19868
  • Loading branch information
3nids committed Oct 23, 2018
1 parent 17f30f5 commit daf53940421de07a5daf7e419cfbf06826ad2469
@@ -330,7 +330,13 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
for ( int row = 0; row < model->rowCount(); ++row )
{
QModelIndex index = model->index( row, 0 );
#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
QgsMapLayer::StyleCategory category = static_cast<QgsMapLayer::StyleCategory>( model->data( index, Qt::UserRole ).toInt() );
#else
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
#endif
QString name = model->data( index, Qt::DisplayRole ).toString();
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
@@ -369,7 +375,13 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
for ( int row = 0; row < model->rowCount(); ++row )
{
QModelIndex index = model->index( row, 0 );
#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
QgsMapLayer::StyleCategory category = static_cast<QgsMapLayer::StyleCategory>( model->data( index, Qt::UserRole ).toInt() );
#else
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
#endif
QString name = model->data( index, Qt::DisplayRole ).toString();
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
@@ -242,7 +242,13 @@ bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const Q

if ( role == Qt::CheckStateRole )
{
#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
QgsMapLayer::StyleCategory category = static_cast<QgsMapLayer::StyleCategory>( data( index, Qt::UserRole ).toInt() );
#else
QgsMapLayer::StyleCategory category = data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
#endif
if ( value.value<Qt::CheckState>() == Qt::Checked )
{
mCategories |= category;
@@ -1564,7 +1564,7 @@ void QgsOptions::saveOptions()

//default snap mode
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), ( QgsSnappingConfig::SnappingType )mDefaultSnapModeComboBox->currentData().toInt() );
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), static_cast<QgsSnappingConfig::SnappingType>( mDefaultSnapModeComboBox->currentData().toInt() ) );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), mDefaultSnappingToleranceSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), mSearchRadiusVertexEditSpinBox->value() );
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ),
@@ -1597,7 +1597,13 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/digitizing/disable_enter_attribute_values_dialog" ), chkDisableAttributeValuesDlg->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/validate_geometries" ), mValidateGeometries->currentIndex() );

#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/offset_join_style" ), static_cast<QgsGeometry::JoinStyle>( mOffsetJoinStyleComboBox->currentData().toInt() ) );
#else
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/offset_join_style" ), mOffsetJoinStyleComboBox->currentData().value<QgsGeometry::JoinStyle>() );
#endif
mSettings->setValue( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), mOffsetQuadSegSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), mCurveOffsetMiterLimitComboBox->value() );

@@ -80,7 +80,13 @@ QString QgsRelationAddDlg::relationName()

QgsRelation::RelationStrength QgsRelationAddDlg::relationStrength()
{
#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
return static_cast<QgsRelation::RelationStrength>( mCbxRelationStrength->currentData().toInt() );
#else
return mCbxRelationStrength->currentData().value<QgsRelation::RelationStrength>();
#endif
}

void QgsRelationAddDlg::checkDefinitionValid()
@@ -111,7 +111,13 @@ QgsMapLayer::StyleCategories QgsVectorLayerLoadStyleDialog::styleCategories() co

QgsVectorLayerProperties::StyleType QgsVectorLayerLoadStyleDialog::currentStyleType() const
{
#if QT_VERSION <= 0x050601
// in Qt 5.6.1 and former, QVariant does not correctly convert enum using value
// see https://bugreports.qt.io/browse/QTBUG-53384
QgsVectorLayerProperties::StyleType type = static_cast<QgsVectorLayerProperties::StyleType>( mStyleTypeComboBox->currentData().toInt() );
#else
QgsVectorLayerProperties::StyleType type = mStyleTypeComboBox->currentData().value<QgsVectorLayerProperties::StyleType>();
#endif
if ( type == QgsVectorLayerProperties::QML )
{
QFileInfo fi( mFileWidget->filePath() );

0 comments on commit daf5394

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