@@ -69,7 +69,7 @@ void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
69
69
70
70
QVariant QgsAttributeTableFilterModel::data ( const QModelIndex& index, int role ) const
71
71
{
72
- if ( mColumnMapping . at ( index .column () ) == -1 ) // actions
72
+ if ( mapColumnToSource ( index .column () ) == -1 ) // actions
73
73
{
74
74
if ( role == TypeRole )
75
75
return ColumnTypeActionButton;
@@ -355,6 +355,14 @@ void QgsAttributeTableFilterModel::onColumnsChanged()
355
355
setAttributeTableConfig ( mConfig );
356
356
}
357
357
358
+ int QgsAttributeTableFilterModel::mapColumnToSource ( int column ) const
359
+ {
360
+ if ( mColumnMapping .isEmpty () )
361
+ return 0 ;
362
+ else
363
+ return mColumnMapping .at ( column );
364
+ }
365
+
358
366
void QgsAttributeTableFilterModel::generateListOfVisibleFeatures ()
359
367
{
360
368
if ( !layer () )
@@ -466,26 +474,29 @@ QModelIndex QgsAttributeTableFilterModel::mapToSource( const QModelIndex& proxyI
466
474
if ( !proxyIndex.isValid () )
467
475
return QModelIndex ();
468
476
469
- int sourceColumn = mColumnMapping . at ( proxyIndex.column () );
477
+ int sourceColumn = mapColumnToSource ( proxyIndex.column () );
470
478
471
479
// For the action column there is no matching column in the source model: invalid
472
480
if ( sourceColumn == -1 )
473
481
return QModelIndex ();
474
482
475
- return QSortFilterProxyModel::mapToSource ( index ( proxyIndex.row (), mColumnMapping . at ( proxyIndex. column () ) , proxyIndex.parent () ) );
483
+ return QSortFilterProxyModel::mapToSource ( index ( proxyIndex.row (), sourceColumn , proxyIndex.parent () ) );
476
484
}
477
485
478
486
QModelIndex QgsAttributeTableFilterModel::mapFromSource ( const QModelIndex& sourceIndex ) const
479
487
{
480
488
QModelIndex proxyIndex = QSortFilterProxyModel::mapFromSource ( sourceIndex );
481
489
482
- return index ( proxyIndex.row (), mColumnMapping .indexOf ( proxyIndex.column () ), proxyIndex.parent () );
490
+ if ( proxyIndex.column () < 0 )
491
+ return QModelIndex ();
492
+
493
+ return index ( proxyIndex.row (), mapColumnToSource ( proxyIndex.column () ), proxyIndex.parent () );
483
494
}
484
495
485
496
Qt::ItemFlags QgsAttributeTableFilterModel::flags ( const QModelIndex& index ) const
486
497
{
487
498
// Handle the action column flags here, the master model doesn't know it
488
- if ( mColumnMapping . at ( index .column () ) == -1 )
499
+ if ( mapColumnToSource ( index .column () ) == -1 )
489
500
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
490
501
491
502
QModelIndex source_index = mapToSource ( index );
0 commit comments