Skip to content
Permalink
Browse files

Unit tests for editing row height/column width

  • Loading branch information
nyalldawson committed Jan 13, 2020
1 parent 20b7a52 commit 0aef9a178b31cb3bdd5efe374b7a85f4de2a253b
Showing with 86 additions and 0 deletions.
  1. +86 −0 tests/src/gui/testqgstableeditor.cpp
@@ -41,6 +41,8 @@ class TestQgsTableEditor: public QObject
void foregroundColor();
void backgroundColor();
void numericFormat();
void rowHeight();
void columnWidth();

private:

@@ -904,6 +906,90 @@ void TestQgsTableEditor::numericFormat()
QVERIFY( w.hasMixedSelectionNumericFormat() );
}

void TestQgsTableEditor::rowHeight()
{
QgsTableEditorWidget w;
QVERIFY( w.tableContents().isEmpty() );

QSignalSpy spy( &w, &QgsTableEditorWidget::tableChanged );
w.setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() ) );
QCOMPARE( spy.count(), 1 );
w.setTableRowHeight( 1, 14.0 );

QCOMPARE( w.selectionRowHeight(), 0.0 );
QCOMPARE( w.tableRowHeight( 0 ), 0.0 );
QCOMPARE( w.tableRowHeight( 1 ), 14.0 );
QCOMPARE( w.tableRowHeight( 2 ), 0.0 );
w.selectionModel()->clearSelection();
w.setSelectionRowHeight( 15.0 );
QCOMPARE( spy.count(), 2 );
QCOMPARE( w.selectionRowHeight(), 0.0 );
QCOMPARE( w.tableRowHeight( 0 ), 0.0 );
QCOMPARE( w.tableRowHeight( 1 ), 14.0 );
QCOMPARE( w.tableRowHeight( 2 ), 0.0 );

w.selectionModel()->select( w.model()->index( 0, 0 ), QItemSelectionModel::ClearAndSelect );
QCOMPARE( w.selectionRowHeight(), 0.0 );
w.selectionModel()->select( w.model()->index( 1, 0 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionRowHeight(), -1.0 );
w.selectionModel()->select( w.model()->index( 1, 0 ), QItemSelectionModel::ClearAndSelect );
QCOMPARE( w.selectionRowHeight(), 14.0 );
w.selectionModel()->select( w.model()->index( 0, 1 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionRowHeight(), -1.0 );
w.setSelectionRowHeight( 15.0 );
QCOMPARE( spy.count(), 3 );
QCOMPARE( w.selectionRowHeight(), 15.0 );
QCOMPARE( w.tableRowHeight( 0 ), 15.0 );
QCOMPARE( w.tableRowHeight( 1 ), 15.0 );
QCOMPARE( w.tableRowHeight( 2 ), 0.0 );
w.selectionModel()->select( w.model()->index( 2, 2 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionRowHeight(), -1.0 );
}

void TestQgsTableEditor::columnWidth()
{
QgsTableEditorWidget w;
QVERIFY( w.tableContents().isEmpty() );

QSignalSpy spy( &w, &QgsTableEditorWidget::tableChanged );
w.setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() ) );
QCOMPARE( spy.count(), 1 );
w.setTableColumnWidth( 1, 14.0 );

QCOMPARE( w.selectionColumnWidth(), 0.0 );
QCOMPARE( w.tableColumnWidth( 0 ), 0.0 );
QCOMPARE( w.tableColumnWidth( 1 ), 14.0 );
QCOMPARE( w.tableColumnWidth( 2 ), 0.0 );
w.selectionModel()->clearSelection();
w.setSelectionColumnWidth( 15.0 );
QCOMPARE( spy.count(), 2 );
QCOMPARE( w.selectionColumnWidth(), 0.0 );
QCOMPARE( w.tableColumnWidth( 0 ), 0.0 );
QCOMPARE( w.tableColumnWidth( 1 ), 14.0 );
QCOMPARE( w.tableColumnWidth( 2 ), 0.0 );

w.selectionModel()->select( w.model()->index( 0, 0 ), QItemSelectionModel::ClearAndSelect );
QCOMPARE( w.selectionColumnWidth(), 0.0 );
w.selectionModel()->select( w.model()->index( 0, 1 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionColumnWidth(), -1.0 );
w.selectionModel()->select( w.model()->index( 0, 1 ), QItemSelectionModel::ClearAndSelect );
QCOMPARE( w.selectionColumnWidth(), 14.0 );
w.selectionModel()->select( w.model()->index( 1, 0 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionColumnWidth(), -1.0 );
w.setSelectionColumnWidth( 15.0 );
QCOMPARE( spy.count(), 3 );
QCOMPARE( w.selectionColumnWidth(), 15.0 );
QCOMPARE( w.tableColumnWidth( 0 ), 15.0 );
QCOMPARE( w.tableColumnWidth( 1 ), 15.0 );
QCOMPARE( w.tableColumnWidth( 2 ), 0.0 );
w.selectionModel()->select( w.model()->index( 2, 2 ), QItemSelectionModel::Select );
QCOMPARE( w.selectionColumnWidth(), -1.0 );
}


QGSTEST_MAIN( TestQgsTableEditor )
#include "testqgstableeditor.moc"

0 comments on commit 0aef9a1

Please sign in to comment.
You can’t perform that action at this time.