Skip to content

Commit 422d0f7

Browse files
committed
Correctly sort items in QgsLayoutItemComboBOx
1 parent 9191841 commit 422d0f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/gui/layout/qgslayoutitemcombobox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void QgsLayoutItemComboBox::setCurrentLayout( QgsLayout *layout )
3333
connect( mProxyModel.get(), &QAbstractItemModel::rowsRemoved, this, &QgsLayoutItemComboBox::rowsChanged );
3434
setModel( mProxyModel.get() );
3535
setModelColumn( QgsLayoutModel::ItemId );
36-
mProxyModel->sort( 0, Qt::AscendingOrder );
36+
mProxyModel->sort( QgsLayoutModel::ItemId, Qt::AscendingOrder );
3737
mProxyModel->setAllowEmptyItem( prevAllowEmpty );
3838
}
3939

tests/src/gui/testqgslayoutgui.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ void TestQgsLayoutGui::itemTypeComboBox()
133133
QCOMPARE( spy1.count(), expectedSpy1Count ); // must be unchanged from earlier
134134
QCOMPARE( spy2.count(), expectedSpy2Count );
135135

136+
item3->setId( "a" );
137+
QCOMPARE( cb->itemText( 0 ), QStringLiteral( "a" ) );
138+
QCOMPARE( cb->itemText( 1 ), QStringLiteral( "item 1" ) );
139+
QCOMPARE( cb->itemText( 2 ), QStringLiteral( "item 2" ) );
140+
item3->setId( "item 3" );
141+
QCOMPARE( cb->itemText( 0 ), QStringLiteral( "item 1" ) );
142+
QCOMPARE( cb->itemText( 1 ), QStringLiteral( "item 2" ) );
143+
QCOMPARE( cb->itemText( 2 ), QStringLiteral( "item 3" ) );
144+
136145
//manually change item
137146
cb->setItem( item3 );
138147
expectedSpy1Count++;

0 commit comments

Comments
 (0)