16
16
#include " qgisapp.h"
17
17
#include " qgslocatorfilter.h"
18
18
#include " qgslocator.h"
19
+ #include " qgsprintlayout.h"
20
+ #include " qgslayoutmanager.h"
19
21
#include " locator/qgsinbuiltlocatorfilters.h"
20
22
#include < QSignalSpy>
21
23
#include < QClipboard>
@@ -32,6 +34,8 @@ class TestQgsAppLocatorFilters : public QObject
32
34
void initTestCase ();// will be called before the first testfunction is executed.
33
35
void cleanupTestCase ();// will be called after the last testfunction was executed.
34
36
void testCalculator ();
37
+ void testLayers ();
38
+ void testLayouts ();
35
39
36
40
private:
37
41
QgisApp *mQgisApp = nullptr ;
@@ -70,6 +74,77 @@ void TestQgsAppLocatorFilters::testCalculator()
70
74
// invalid expression
71
75
results = gatherResults ( &filter, QStringLiteral ( " 1+" ), QgsLocatorContext () );
72
76
QVERIFY ( results.empty () );
77
+ }
78
+
79
+ void TestQgsAppLocatorFilters::testLayers ()
80
+ {
81
+ QgsVectorLayer *l1 = new QgsVectorLayer ( QStringLiteral ( " Point" ), QStringLiteral ( " aaaaa" ), QStringLiteral ( " memory" ) );
82
+ QgsVectorLayer *l2 = new QgsVectorLayer ( QStringLiteral ( " Point" ), QStringLiteral ( " abc" ), QStringLiteral ( " memory" ) );
83
+ QgsVectorLayer *l3 = new QgsVectorLayer ( QStringLiteral ( " Point" ), QStringLiteral ( " ccccc" ), QStringLiteral ( " memory" ) );
84
+ QgsProject::instance ()->addMapLayers ( QList< QgsMapLayer *>() << l1 << l2 << l3 );
85
+
86
+ QgsLayerTreeLocatorFilter filter;
87
+
88
+ QList< QgsLocatorResult > results = gatherResults ( &filter, QStringLiteral ( " xxxxx" ), QgsLocatorContext () );
89
+ QCOMPARE ( results.count (), 0 );
90
+
91
+ results = gatherResults ( &filter, QStringLiteral ( " aa" ), QgsLocatorContext () );
92
+ QCOMPARE ( results.count (), 1 );
93
+ QCOMPARE ( results.at ( 0 ).userData .toString (), l1->id () );
94
+
95
+ results = gatherResults ( &filter, QStringLiteral ( " A" ), QgsLocatorContext () );
96
+ QCOMPARE ( results.count (), 2 );
97
+ QCOMPARE ( results.at ( 0 ).userData .toString (), l1->id () );
98
+ QCOMPARE ( results.at ( 1 ).userData .toString (), l2->id () );
99
+
100
+ results = gatherResults ( &filter, QString (), QgsLocatorContext () );
101
+ QCOMPARE ( results.count (), 0 );
102
+
103
+ QgsLocatorContext context;
104
+ context.usingPrefix = true ;
105
+ results = gatherResults ( &filter, QString (), context );
106
+ QCOMPARE ( results.count (), 3 );
107
+ QCOMPARE ( results.at ( 0 ).userData .toString (), l1->id () );
108
+ QCOMPARE ( results.at ( 1 ).userData .toString (), l2->id () );
109
+ QCOMPARE ( results.at ( 2 ).userData .toString (), l3->id () );
110
+ }
111
+
112
+ void TestQgsAppLocatorFilters::testLayouts ()
113
+ {
114
+ QgsPrintLayout *pl1 = new QgsPrintLayout ( QgsProject::instance () );
115
+ pl1->setName ( QStringLiteral ( " aaaaaa" ) );
116
+ QgsProject::instance ()->layoutManager ()->addLayout ( pl1 );
117
+ QgsPrintLayout *pl2 = new QgsPrintLayout ( QgsProject::instance () );
118
+ pl2->setName ( QStringLiteral ( " abc" ) );
119
+ QgsProject::instance ()->layoutManager ()->addLayout ( pl2 );
120
+ QgsPrintLayout *pl3 = new QgsPrintLayout ( QgsProject::instance () );
121
+ pl3->setName ( QStringLiteral ( " ccccc" ) );
122
+ QgsProject::instance ()->layoutManager ()->addLayout ( pl3 );
123
+
124
+ QgsLayoutLocatorFilter filter;
125
+
126
+ QList< QgsLocatorResult > results = gatherResults ( &filter, QStringLiteral ( " xxxxx" ), QgsLocatorContext () );
127
+ QCOMPARE ( results.count (), 0 );
128
+
129
+ results = gatherResults ( &filter, QStringLiteral ( " aa" ), QgsLocatorContext () );
130
+ QCOMPARE ( results.count (), 1 );
131
+ QCOMPARE ( results.at ( 0 ).userData .toString (), pl1->name () );
132
+
133
+ results = gatherResults ( &filter, QStringLiteral ( " A" ), QgsLocatorContext () );
134
+ QCOMPARE ( results.count (), 2 );
135
+ QCOMPARE ( results.at ( 0 ).userData .toString (), pl1->name () );
136
+ QCOMPARE ( results.at ( 1 ).userData .toString (), pl2->name () );
137
+
138
+ results = gatherResults ( &filter, QString (), QgsLocatorContext () );
139
+ QCOMPARE ( results.count (), 0 );
140
+
141
+ QgsLocatorContext context;
142
+ context.usingPrefix = true ;
143
+ results = gatherResults ( &filter, QString (), context );
144
+ QCOMPARE ( results.count (), 3 );
145
+ QCOMPARE ( results.at ( 0 ).userData .toString (), pl1->name () );
146
+ QCOMPARE ( results.at ( 1 ).userData .toString (), pl2->name () );
147
+ QCOMPARE ( results.at ( 2 ).userData .toString (), pl3->name () );
73
148
74
149
}
75
150
@@ -82,7 +157,7 @@ QList<QgsLocatorResult> TestQgsAppLocatorFilters::gatherResults( QgsLocatorFilte
82
157
QList< QgsLocatorResult > results;
83
158
for ( int i = 0 ; i < spy.count (); ++ i )
84
159
{
85
- QVariant v = spy.at ( i ).at ( i );
160
+ QVariant v = spy.at ( i ).at ( 0 );
86
161
QgsLocatorResult result = v.value <QgsLocatorResult>();
87
162
results.append ( result );
88
163
}
0 commit comments