11/*
22 * Copyright 2016 Mitchell Krome
3- * Copyright 2017-2022, 2025 Kai Pastor
3+ * Copyright 2017-2022 Kai Pastor
44 *
55 * This file is part of OpenOrienteering.
66 *
2020
2121#include " object_query_t.h"
2222
23- #include < algorithm>
2423#include < memory>
24+ #include < algorithm>
2525
2626#include < QtGlobal>
2727#include < QtTest>
2828#include < QByteArray>
2929#include < QLatin1String>
3030#include < QString>
3131
32- #include " global.h"
3332#include " core/map.h"
34- #include " core/map_part.h"
3533#include " core/objects/object.h"
36- #include " core/objects/object_query.h"
3734#include " core/objects/text_object.h"
35+ #include " core/objects/object_query.h"
3836#include " core/symbols/point_symbol.h"
39- #include " gui/main_window.h"
40- #include " gui/map/map_editor.h"
41- #include " gui/map/map_find_feature.h"
4237
4338using namespace OpenOrienteering ;
4439
@@ -58,7 +53,6 @@ ObjectQueryTest::ObjectQueryTest(QObject* parent)
5853 // nothing
5954}
6055
61-
6256const Object* ObjectQueryTest::testObject ()
6357{
6458 static TextObject obj;
@@ -515,88 +509,11 @@ void ObjectQueryTest::testParser()
515509}
516510
517511
518- void ObjectQueryTest::testFindObjects ()
519- {
520- Q_INIT_RESOURCE (resources);
521- doStaticInitializations ();
522-
523- Map map;
524- auto * window = new MainWindow ();
525- auto * editor = new MapEditorController (MapEditorController::MapEditor, &map);
526- window->setController (editor);
527- const auto * part = map.getCurrentPart ();
528-
529- auto * point_symbol_1 = new PointSymbol ();
530- point_symbol_1->setNumberComponent (0 , 123 );
531- map.addSymbol (point_symbol_1, 0 );
532- auto * point_object_1 = new PointObject (point_symbol_1);
533- point_object_1->setTag (QLatin1String (" match" ), QLatin1String (" yes" ));
534- QVERIFY (map.addObject (point_object_1) == 0 ); // object pos 0
535-
536- auto * point_object_2 = new PointObject (point_symbol_1);
537- point_object_2->setTag (QLatin1String (" match" ), QLatin1String (" no" ));
538- QVERIFY (map.addObject (point_object_2) == 1 ); // object pos 1
539-
540- point_object_2 = new PointObject (point_symbol_1);
541- point_object_2->setTag (QLatin1String (" match" ), QLatin1String (" yes" ));
542- QVERIFY (map.addObject (point_object_2) == 2 ); // object pos 2
543-
544- auto * point_symbol_2 = new PointSymbol ();
545- point_symbol_2->setNumberComponent (0 , 124 );
546- point_symbol_2->setHidden (true );
547- map.addSymbol (point_symbol_2, 1 );
548- point_object_2 = new PointObject (point_symbol_2);
549- point_object_2->setTag (QLatin1String (" match" ), QLatin1String (" yes" ));
550- QVERIFY (map.addObject (point_object_2) == 3 ); // object pos 3
551-
552- point_object_2 = new PointObject (point_symbol_1);
553- point_object_2->setTag (QLatin1String (" match" ), QLatin1String (" yes" ));
554- QVERIFY (map.addObject (point_object_2) == 4 ); // object pos 4
555-
556- auto * point_symbol_3 = new PointSymbol ();
557- point_symbol_3->setNumberComponent (0 , 125 );
558- point_symbol_3->setProtected (true );
559- map.addSymbol (point_symbol_3, 2 );
560- point_object_2 = new PointObject (point_symbol_3);
561- point_object_2->setTag (QLatin1String (" match" ), QLatin1String (" yes" ));
562- QVERIFY (map.addObject (point_object_2) == 5 ); // object pos 5
563-
564- std::unique_ptr<MapFindFeature> find_feature = std::make_unique<MapFindFeature>(*editor);
565- ObjectQuery single_query_is_true{QLatin1String (" match" ), ObjectQuery::OperatorIs, QLatin1String (" yes" )};
566-
567- map.clearObjectSelection (false );
568- auto symbol_query = ObjectQuery (single_query_is_true);
569- find_feature->findAllMatchingObjects (symbol_query);
570- QVERIFY (map.getNumSelectedObjects () == 3 ); // matching objects at pos 0, 2, 4 while ignoring objects at pos 1, 3, 5
571-
572- map.clearObjectSelection (false );
573- find_feature->findNextMatchingObject (symbol_query);
574- QVERIFY (map.getNumSelectedObjects () == 1 );
575- auto * selected_object = map.getFirstSelectedObject ();
576- QCOMPARE (part->findObjectIndex (selected_object), 4 ); // search first returns the last matching object
577-
578- find_feature->findNextMatchingObject (symbol_query);
579- QVERIFY (map.getNumSelectedObjects () == 1 );
580- selected_object = map.getFirstSelectedObject ();
581- QCOMPARE (part->findObjectIndex (selected_object), 2 );
582-
583- find_feature->findNextMatchingObject (symbol_query);
584- QVERIFY (map.getNumSelectedObjects () == 1 );
585- selected_object = map.getFirstSelectedObject ();
586- QCOMPARE (part->findObjectIndex (selected_object), 0 );
587-
588- find_feature->findNextMatchingObject (symbol_query);
589- QVERIFY (map.getNumSelectedObjects () == 1 );
590- selected_object = map.getFirstSelectedObject ();
591- QCOMPARE (part->findObjectIndex (selected_object), 4 );
592- }
593-
594-
595512/*
596513 * We don't need a real GUI window.
597514 */
598515namespace {
599- auto const Q_DECL_UNUSED qpa_selected = qputenv(" QT_QPA_PLATFORM" , " minimal" ); // clazy:exclude=non-pod-global-static
516+ auto Q_DECL_UNUSED qpa_selected = qputenv(" QT_QPA_PLATFORM" , " minimal" ); // clazy:exclude=non-pod-global-static
600517}
601518
602519
0 commit comments