Skip to content
Permalink
Browse files

Correctly sort items in QgsLayoutItemComboBOx

  • Loading branch information
nyalldawson committed Mar 11, 2019
1 parent 9191841 commit 422d0f7a2e08dc2ad7a2d59e496dd58023308443
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/gui/layout/qgslayoutitemcombobox.cpp
  2. +9 −0 tests/src/gui/testqgslayoutgui.cpp
@@ -33,7 +33,7 @@ void QgsLayoutItemComboBox::setCurrentLayout( QgsLayout *layout )
connect( mProxyModel.get(), &QAbstractItemModel::rowsRemoved, this, &QgsLayoutItemComboBox::rowsChanged );
setModel( mProxyModel.get() );
setModelColumn( QgsLayoutModel::ItemId );
mProxyModel->sort( 0, Qt::AscendingOrder );
mProxyModel->sort( QgsLayoutModel::ItemId, Qt::AscendingOrder );
mProxyModel->setAllowEmptyItem( prevAllowEmpty );
}

@@ -133,6 +133,15 @@ void TestQgsLayoutGui::itemTypeComboBox()
QCOMPARE( spy1.count(), expectedSpy1Count ); // must be unchanged from earlier
QCOMPARE( spy2.count(), expectedSpy2Count );

item3->setId( "a" );
QCOMPARE( cb->itemText( 0 ), QStringLiteral( "a" ) );
QCOMPARE( cb->itemText( 1 ), QStringLiteral( "item 1" ) );
QCOMPARE( cb->itemText( 2 ), QStringLiteral( "item 2" ) );
item3->setId( "item 3" );
QCOMPARE( cb->itemText( 0 ), QStringLiteral( "item 1" ) );
QCOMPARE( cb->itemText( 1 ), QStringLiteral( "item 2" ) );
QCOMPARE( cb->itemText( 2 ), QStringLiteral( "item 3" ) );

//manually change item
cb->setItem( item3 );
expectedSpy1Count++;

0 comments on commit 422d0f7

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