@@ -75,6 +75,7 @@ void TestQgsBrowserModel::testModel()
75
75
76
76
// add a root child
77
77
QgsDataCollectionItem *rootItem1 = new QgsDataCollectionItem ( nullptr , QStringLiteral ( " Test" ), QStringLiteral ( " root1" ) );
78
+ QVERIFY ( !model.findItem ( rootItem1 ).isValid () );
78
79
model.connectItem ( rootItem1 );
79
80
model.mRootItems .append ( rootItem1 );
80
81
@@ -94,6 +95,7 @@ void TestQgsBrowserModel::testModel()
94
95
QCOMPARE ( model.data ( root1Index ).toString (), QStringLiteral ( " Test" ) );
95
96
QCOMPARE ( model.data ( root1Index, QgsBrowserModel::PathRole ).toString (), QStringLiteral ( " root1" ) );
96
97
QCOMPARE ( model.dataItem ( root1Index ), rootItem1 );
98
+ QCOMPARE ( model.findItem ( rootItem1 ), root1Index );
97
99
98
100
// second root item
99
101
QgsDataCollectionItem *rootItem2 = new QgsDataCollectionItem ( nullptr , QStringLiteral ( " Test2" ), QStringLiteral ( " root2" ) );
@@ -109,6 +111,7 @@ void TestQgsBrowserModel::testModel()
109
111
QCOMPARE ( model.data ( root2Index ).toString (), QStringLiteral ( " Test2" ) );
110
112
QCOMPARE ( model.data ( root2Index, QgsBrowserModel::PathRole ).toString (), QStringLiteral ( " root2" ) );
111
113
QCOMPARE ( model.dataItem ( root2Index ), rootItem2 );
114
+ QCOMPARE ( model.findItem ( rootItem2 ), root2Index );
112
115
113
116
// child item
114
117
QgsDataCollectionItem *childItem1 = new QgsDataCollectionItem ( nullptr , QStringLiteral ( " Child1" ), QStringLiteral ( " child1" ) );
@@ -124,6 +127,11 @@ void TestQgsBrowserModel::testModel()
124
127
QCOMPARE ( model.data ( child1Index ).toString (), QStringLiteral ( " Child1" ) );
125
128
QCOMPARE ( model.data ( child1Index, QgsBrowserModel::PathRole ).toString (), QStringLiteral ( " child1" ) );
126
129
QCOMPARE ( model.dataItem ( child1Index ), childItem1 );
130
+ QCOMPARE ( model.findItem ( childItem1 ), child1Index );
131
+ QCOMPARE ( model.findItem ( childItem1, rootItem1 ), child1Index );
132
+ // search for child in wrong parent
133
+ QVERIFY ( !model.findItem ( childItem1, rootItem2 ).isValid () );
134
+
127
135
128
136
}
129
137
0 commit comments