Skip to content

Commit

Permalink
fix Qt issue QVariant::value using enum (#8265)
Browse files Browse the repository at this point in the history
* 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 daf5394
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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>();
Expand Down Expand Up @@ -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>();
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsmaplayerstylecategoriesmodel.cpp
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -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" ),
Expand Down Expand Up @@ -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() );

Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsrelationadddlg.cpp
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsvectorlayerloadstyledialog.cpp
Expand Up @@ -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() );
Expand Down

0 comments on commit daf5394

Please sign in to comment.