Skip to content

Commit

Permalink
Unit tests for selection modes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent f82fea5 commit e3507ff
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion python/gui/gui_auto.sip
Expand Up @@ -358,7 +358,6 @@
%Include auto_generated/symbology/qgssymbolwidgetcontext.sip
%Include auto_generated/symbology/qgsvectorfieldsymbollayerwidget.sip
%Include auto_generated/tableeditor/qgstableeditordialog.sip
%Include auto_generated/tableeditor/qgstableeditorformattingwidget.sip
%Include auto_generated/tableeditor/qgstableeditorwidget.sip
%Include auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip
%Include auto_generated/qgsadvanceddigitizingcanvasitem.sip
4 changes: 4 additions & 0 deletions src/gui/tableeditor/qgstableeditorformattingwidget.h
Expand Up @@ -20,6 +20,8 @@
#include "qgspanelwidget.h"
#include <memory>

#define SIP_NO_FILE

class QgsNumericFormat;

/**
Expand All @@ -30,6 +32,8 @@ class QgsNumericFormat;
*
* The editor has support for table foreground and background colors, and numeric formats.
*
* \note Not available in Python bindings
*
* \since QGIS 3.12
*/
class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private Ui::QgsTableEditorFormattingWidgetBase
Expand Down
66 changes: 66 additions & 0 deletions tests/src/gui/testqgstableeditor.cpp
Expand Up @@ -34,6 +34,8 @@ class TestQgsTableEditor: public QObject
void insertColumnsAfter();
void deleteRows();
void deleteColumns();
void selectRows();
void selectColumns();

private:

Expand Down Expand Up @@ -597,6 +599,70 @@ void TestQgsTableEditor::deleteColumns()

}

void TestQgsTableEditor::selectRows()
{
QgsTableEditorWidget w;
w.setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() ) );

w.selectionModel()->select( w.model()->index( 0, 0 ), QItemSelectionModel::ClearAndSelect );
w.expandRowSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 3 );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 0 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 2 ) ) );


w.selectionModel()->select( w.model()->index( 1, 1 ), QItemSelectionModel::ClearAndSelect );
w.selectionModel()->select( w.model()->index( 1, 2 ), QItemSelectionModel::Select );
w.selectionModel()->select( w.model()->index( 2, 0 ), QItemSelectionModel::Select );
w.expandRowSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 6 );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 0 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 2 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 0 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 2 ) ) );

w.selectionModel()->clearSelection();
w.expandRowSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 0 );
}

void TestQgsTableEditor::selectColumns()
{
QgsTableEditorWidget w;
w.setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() )
<< ( QgsTableRow() << QgsTableCell() << QgsTableCell() << QgsTableCell() ) );

w.selectionModel()->select( w.model()->index( 0, 0 ), QItemSelectionModel::ClearAndSelect );
w.expandColumnSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 3 );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 0 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 0 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 0 ) ) );

w.selectionModel()->select( w.model()->index( 1, 1 ), QItemSelectionModel::ClearAndSelect );
w.selectionModel()->select( w.model()->index( 2, 1 ), QItemSelectionModel::Select );
w.selectionModel()->select( w.model()->index( 0, 2 ), QItemSelectionModel::Select );
w.expandColumnSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 6 );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 1 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 0, 2 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 1, 2 ) ) );
QVERIFY( w.selectionModel()->isSelected( w.model()->index( 2, 2 ) ) );

w.selectionModel()->clearSelection();
w.expandColumnSelection();
QCOMPARE( w.selectionModel()->selectedIndexes().size(), 0 );
}


QGSTEST_MAIN( TestQgsTableEditor )
#include "testqgstableeditor.moc"

0 comments on commit e3507ff

Please sign in to comment.