Skip to content

Commit

Permalink
fix(Qt6): fix crash when built with Qt6 debug
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Jul 16, 2024
1 parent 37deed0 commit 7e4b30e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/gui/proj/qgsprojectionselectionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,11 @@ QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent,

QgsCoordinateReferenceSystem QgsProjectionSelectionWidget::crs() const
{
return mModel->data( mModel->index( mCrsComboBox->currentIndex(), 0 ), StandardCoordinateReferenceSystemsModel::RoleCrs ).value< QgsCoordinateReferenceSystem >();
const int idx = mCrsComboBox->currentIndex();
if ( idx >= 0 && idx < mModel->rowCount() )
return mModel->data( mModel->index( idx, 0 ), StandardCoordinateReferenceSystemsModel::RoleCrs ).value< QgsCoordinateReferenceSystem >();
else
return QgsCoordinateReferenceSystem();
}

void QgsProjectionSelectionWidget::setOptionVisible( const QgsProjectionSelectionWidget::CrsOption option, const bool visible )
Expand Down Expand Up @@ -720,19 +724,23 @@ void QgsProjectionSelectionWidget::setShowAccuracyWarnings( bool show )

void QgsProjectionSelectionWidget::comboIndexChanged( int idx )
{
const QgsCoordinateReferenceSystem crs = mModel->data( mModel->index( idx, 0 ), StandardCoordinateReferenceSystemsModel::RoleCrs ).value< QgsCoordinateReferenceSystem >();
const QVariant optionData = mModel->data( mModel->index( idx, 0 ), StandardCoordinateReferenceSystemsModel::RoleOption );
if ( !optionData.isValid() || static_cast< CrsOption >( optionData.toInt() ) != QgsProjectionSelectionWidget::CrsNotSet )
if ( idx >= 0 && idx < mModel->rowCount() )
{
// RoleOption is only available for items from the standard coordinate reference system model, but we
// are using a combined model which also has items from QgsRecentCoordinateReferenceSystemsModel
emit crsChanged( crs );
}
else
{
emit cleared();
emit crsChanged( QgsCoordinateReferenceSystem() );
const QgsCoordinateReferenceSystem crs = mModel->data( mModel->index( idx, 0 ), StandardCoordinateReferenceSystemsModel::RoleCrs ).value< QgsCoordinateReferenceSystem >();
const QVariant optionData = mModel->data( mModel->index( idx, 0 ), StandardCoordinateReferenceSystemsModel::RoleOption );
if ( !optionData.isValid() || static_cast< CrsOption >( optionData.toInt() ) != QgsProjectionSelectionWidget::CrsNotSet )
{
// RoleOption is only available for items from the standard coordinate reference system model, but we
// are using a combined model which also has items from QgsRecentCoordinateReferenceSystemsModel
emit crsChanged( crs );
}
else
{
emit cleared();
emit crsChanged( QgsCoordinateReferenceSystem() );
}
}

updateTooltip();
}

Expand Down Expand Up @@ -873,4 +881,3 @@ QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData( const QMimeData
}
return nullptr;
}

0 comments on commit 7e4b30e

Please sign in to comment.