|
1 | 1 | /*************************************************************************** |
2 | | - qgsinbuiltlocatorfilters.cpp |
3 | | - ---------------------------- |
4 | | - begin : May 2017 |
5 | | - copyright : (C) 2017 by Nyall Dawson |
6 | | - email : nyall dot dawson at gmail dot com |
7 | | - ***************************************************************************/ |
| 2 | + qgsinbuiltlocatorfilters.cpp |
| 3 | + ---------------------------- |
| 4 | + begin : May 2017 |
| 5 | + copyright : (C) 2017 by Nyall Dawson |
| 6 | + email : nyall dot dawson at gmail dot com |
| 7 | +***************************************************************************/ |
8 | 8 |
|
9 | 9 | /*************************************************************************** |
10 | 10 | * * |
@@ -320,3 +320,50 @@ void QgsExpressionCalculatorLocatorFilter::triggerResult( const QgsLocatorResult |
320 | 320 | { |
321 | 321 | QApplication::clipboard()->setText( result.userData.toString() ); |
322 | 322 | } |
| 323 | +// QgBookmarkLocatorFilter |
| 324 | +// |
| 325 | + |
| 326 | +QgsBookmarkLocatorFilter::QgsBookmarkLocatorFilter( QObject *parent ) |
| 327 | + : QgsLocatorFilter( parent ) |
| 328 | +{} |
| 329 | + |
| 330 | +QgsBookmarkLocatorFilter *QgsBookmarkLocatorFilter::clone() const |
| 331 | +{ |
| 332 | + return new QgsBookmarkLocatorFilter(); |
| 333 | +} |
| 334 | + |
| 335 | +void QgsBookmarkLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &, QgsFeedback *feedback ) |
| 336 | +{ |
| 337 | + QMap<QString, QModelIndex> bookmarkMap = QgisApp::instance()->getBookmarkIndexMap(); |
| 338 | + |
| 339 | + QMapIterator<QString, QModelIndex> i( bookmarkMap ); |
| 340 | + |
| 341 | + while ( i.hasNext() ) |
| 342 | + { |
| 343 | + i.next(); |
| 344 | + if ( feedback->isCanceled() ) |
| 345 | + return; |
| 346 | + |
| 347 | + QString name = i.key(); |
| 348 | + |
| 349 | + if ( stringMatches( name, string ) ) |
| 350 | + { |
| 351 | + QModelIndex index = i.value(); |
| 352 | + QgsLocatorResult result; |
| 353 | + result.filter = this; |
| 354 | + result.displayString = name; |
| 355 | + result.userData = index; |
| 356 | + //TODO Create svg for "Bookmark"? |
| 357 | + //result.icon = TBD |
| 358 | + result.score = static_cast< double >( string.length() ) / name.length(); |
| 359 | + emit resultFetched( result ); |
| 360 | + } |
| 361 | + } |
| 362 | + |
| 363 | +} |
| 364 | + |
| 365 | +void QgsBookmarkLocatorFilter::triggerResult( const QgsLocatorResult &result ) |
| 366 | +{ |
| 367 | + QModelIndex index = qvariant_cast<QModelIndex>( result.userData ); |
| 368 | + QgisApp::instance()->zoomToBookmarkIndex( index ); |
| 369 | +} |
0 commit comments