File indexing completed on 2024-12-08 09:34:11
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2010 Torsten Rahn <rahn@kde.org> 0004 // SPDX-FileCopyrightText: 2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0005 // 0006 0007 #include "LocalDatabaseRunner.h" 0008 0009 #include "MarbleModel.h" 0010 #include "MarblePlacemarkModel.h" 0011 #include "GeoDataPlacemark.h" 0012 #include "GeoDataCoordinates.h" 0013 #include "GeoDataLatLonAltBox.h" 0014 0015 #include "MarbleDebug.h" 0016 #include <QString> 0017 #include <QVector> 0018 0019 #include <QtDebug> 0020 0021 namespace Marble 0022 { 0023 0024 LocalDatabaseRunner::LocalDatabaseRunner(QObject *parent) : 0025 SearchRunner(parent) 0026 { 0027 } 0028 0029 LocalDatabaseRunner::~LocalDatabaseRunner() 0030 { 0031 0032 } 0033 0034 void LocalDatabaseRunner::search( const QString &searchTerm, const GeoDataLatLonBox &preferred ) 0035 { 0036 QVector<GeoDataPlacemark*> vector; 0037 0038 if (model()) { 0039 const QAbstractItemModel * placemarkModel = model()->placemarkModel(); 0040 0041 if (placemarkModel) { 0042 QModelIndexList resultList; 0043 QModelIndex firstIndex = placemarkModel->index( 0, 0 ); 0044 resultList = placemarkModel->match( firstIndex, 0045 Qt::DisplayRole, searchTerm, -1, 0046 Qt::MatchStartsWith ); 0047 0048 bool const searchEverywhere = preferred.isEmpty(); 0049 for ( const QModelIndex& index: resultList ) { 0050 if( !index.isValid() ) { 0051 mDebug() << "invalid index!!!"; 0052 continue; 0053 } 0054 GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>( index.data( MarblePlacemarkModel::ObjectPointerRole ))); 0055 if ( placemark && 0056 ( searchEverywhere || preferred.contains( placemark->coordinate() ) ) ) { 0057 vector.append( new GeoDataPlacemark( *placemark )); 0058 } 0059 } 0060 } 0061 } 0062 0063 emit searchFinished( vector ); 0064 } 0065 0066 } 0067 0068 #include "moc_LocalDatabaseRunner.cpp"