Skip to content
Permalink
Browse files
Don't always show first column in attribute table
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 ffcf655b850224c1299b8217acd9b1e30825ba73
Showing with 35 additions and 2 deletions.
  1. +1 −2 src/gui/attributetable/qgsattributetablefiltermodel.cpp
  2. +34 −0 tests/src/gui/testqgsdualview.cpp
@@ -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 );
@@ -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 );
}
}
@@ -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();
@@ -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 );

0 comments on commit ffcf655

Please sign in to comment.