Skip to content
Permalink
Browse files

Unit tests for selection modes

  • Loading branch information
nyalldawson committed Jan 13, 2020
1 parent f82fea5 commit e3507ff24cbc2c63866718b8fbfc8e53714b36ec
@@ -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
@@ -20,6 +20,8 @@
#include "qgspanelwidget.h"
#include <memory>

#define SIP_NO_FILE

class QgsNumericFormat;

/**
@@ -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
@@ -34,6 +34,8 @@ class TestQgsTableEditor: public QObject
void insertColumnsAfter();
void deleteRows();
void deleteColumns();
void selectRows();
void selectColumns();

private:

@@ -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.
You can’t perform that action at this time.