1 // SPDX-License-Identifier: LGPL-2.1-or-later 2 // 3 // SPDX-FileCopyrightText: 2010 Torsten Rahn <rahn@kde.org> 4 // SPDX-FileCopyrightText: 2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 5 // 6 7 #include "LocalDatabaseRunner.h" 8 9 #include "MarbleModel.h" 10 #include "MarblePlacemarkModel.h" 11 #include "GeoDataPlacemark.h" 12 #include "GeoDataCoordinates.h" 13 #include "GeoDataLatLonAltBox.h" 14 15 #include "MarbleDebug.h" 16 #include <QString> 17 #include <QVector> 18 19 #include <QtDebug> 20 21 namespace Marble 22 { 23 LocalDatabaseRunner(QObject * parent)24LocalDatabaseRunner::LocalDatabaseRunner(QObject *parent) : 25 SearchRunner(parent) 26 { 27 } 28 ~LocalDatabaseRunner()29LocalDatabaseRunner::~LocalDatabaseRunner() 30 { 31 32 } 33 search(const QString & searchTerm,const GeoDataLatLonBox & preferred)34void LocalDatabaseRunner::search( const QString &searchTerm, const GeoDataLatLonBox &preferred ) 35 { 36 QVector<GeoDataPlacemark*> vector; 37 38 if (model()) { 39 const QAbstractItemModel * placemarkModel = model()->placemarkModel(); 40 41 if (placemarkModel) { 42 QModelIndexList resultList; 43 QModelIndex firstIndex = placemarkModel->index( 0, 0 ); 44 resultList = placemarkModel->match( firstIndex, 45 Qt::DisplayRole, searchTerm, -1, 46 Qt::MatchStartsWith ); 47 48 bool const searchEverywhere = preferred.isEmpty(); 49 for ( const QModelIndex& index: resultList ) { 50 if( !index.isValid() ) { 51 mDebug() << "invalid index!!!"; 52 continue; 53 } 54 GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>( index.data( MarblePlacemarkModel::ObjectPointerRole ))); 55 if ( placemark && 56 ( searchEverywhere || preferred.contains( placemark->coordinate() ) ) ) { 57 vector.append( new GeoDataPlacemark( *placemark )); 58 } 59 } 60 } 61 } 62 63 emit searchFinished( vector ); 64 } 65 66 } 67 68 #include "moc_LocalDatabaseRunner.cpp" 69