Skip to content

Commit

Permalink
Don't always show first column in attribute table
Browse files Browse the repository at this point in the history
Add tests for some basic attribute table functionality

Fix #14774
Fix #14765
Fix #14766
  • Loading branch information
m-kuhn committed May 9, 2016
1 parent 59db4d0 commit ffcf655
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Expand Up @@ -214,7 +214,6 @@ void QgsAttributeTableFilterModel::setSourceModel( QgsAttributeTableModel* sourc
{
mTableModel = sourceModel;

mColumnMapping.append( -1 ); // -1 for actions column
for ( int i = 0; i < mTableModel->columnCount(); ++i )
{
mColumnMapping.append( i );
Expand Down Expand Up @@ -488,6 +487,6 @@ QModelIndex QgsAttributeTableFilterModel::index( int row, int column, const QMod
}
else
{
return QSortFilterProxyModel::index( row, 0, parent );
return QSortFilterProxyModel::index( row, column, parent );
}
}
34 changes: 34 additions & 0 deletions tests/src/gui/testqgsdualview.cpp
Expand Up @@ -42,6 +42,12 @@ class TestQgsDualView : public QObject
void init(); // will be called before each testfunction is executed.
void cleanup(); // will be called after every testfunction.

void testColumnCount();

void testColumnHeaders();

void testData();

void testSelectAll();

void testAttributeFormSharedValueScanning();
Expand Down Expand Up @@ -93,6 +99,34 @@ void TestQgsDualView::cleanup()
delete mDualView;
}

void TestQgsDualView::testColumnCount()
{
QCOMPARE( mDualView->tableView()->model()->columnCount(), mPointsLayer->fields().count() );
}

void TestQgsDualView::testColumnHeaders()
{
for ( int i = 0; i < mPointsLayer->fields().count(); ++i )
{
const QgsField& fld = mPointsLayer->fields().at( i );
QCOMPARE( mDualView->tableView()->model()->headerData( i, Qt::Horizontal ).toString(), fld.name() );
}
}

void TestQgsDualView::testData()
{
QgsFeature feature;
mPointsLayer->getFeatures( QgsFeatureRequest().setFilterFid( 0 ) ).nextFeature( feature );

for ( int i = 0; i < mPointsLayer->fields().count(); ++i )
{
const QgsField& fld = mPointsLayer->fields().at( i );

QModelIndex index = mDualView->tableView()->model()->index( 0, i );
QCOMPARE( mDualView->tableView()->model()->data( index ).toString(), fld.displayString( feature.attribute( i ) ) );
}
}

void TestQgsDualView::testSelectAll()
{
mDualView->setFilterMode( QgsAttributeTableFilterModel::ShowVisible );
Expand Down

0 comments on commit ffcf655

Please sign in to comment.