QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslocatorfilter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocatorfilter.cpp
3  --------------------
4  begin : May 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <QThread>
19 
20 #include "qgslocatorfilter.h"
21 #include "qgsstringutils.h"
22 #include "qgsfeedback.h"
23 #include "qgsmessagelog.h"
24 
25 
27  : QObject( parent )
28 {
29 }
30 
31 QgsLocatorFilter::Flags QgsLocatorFilter::flags() const
32 {
33  return nullptr;
34 }
35 
36 void QgsLocatorFilter::triggerResultFromAction( const QgsLocatorResult &result, const int actionId )
37 {
38  Q_UNUSED( result )
39  Q_UNUSED( actionId )
40 }
41 
42 bool QgsLocatorFilter::stringMatches( const QString &candidate, const QString &search )
43 {
44  return !search.isEmpty() && candidate.contains( search, Qt::CaseInsensitive );
45 }
46 
47 double QgsLocatorFilter::fuzzyScore( const QString &candidate, const QString &search )
48 {
49  return QgsStringUtils::fuzzyScore( candidate, search );
50 }
51 
53 {
54  return mEnabled;
55 }
56 
57 void QgsLocatorFilter::setEnabled( bool enabled )
58 {
59  mEnabled = enabled;
60 }
61 
63 {
64  return false;
65 }
66 
67 void QgsLocatorFilter::openConfigWidget( QWidget *parent )
68 {
69  Q_UNUSED( parent )
70 }
71 
73 {
74  return mUseWithoutPrefix;
75 }
76 
77 void QgsLocatorFilter::setUseWithoutPrefix( bool useWithoutPrefix )
78 {
79  mUseWithoutPrefix = useWithoutPrefix;
80 }
81 
83 {
84  // do not change this to isEmpty!
85  // if any issue with an in-built locator filter
86  // do not forget to add it in QgsLocator::CORE_FILTERS
87  if ( mActivePrefifx.isNull() )
88  return prefix();
89  else
90  return mActivePrefifx;
91 }
92 
93 void QgsLocatorFilter::setActivePrefix( const QString &activePrefix )
94 {
95  mActivePrefifx = activePrefix;
96 }
97 
98 void QgsLocatorFilter::logMessage( const QString &message, Qgis::MessageLevel level )
99 {
100  QgsMessageLog::logMessage( QString( "%1: %2" ).arg( name(), message ), QStringLiteral( "Locator bar" ), level );
101 }
102 
QgsLocatorFilter::logMessage
void logMessage(const QString &message, Qgis::MessageLevel level=Qgis::Info)
Logs a message to the log panel.
Definition: qgslocatorfilter.cpp:98
QgsLocatorFilter::prefix
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
Definition: qgslocatorfilter.h:215
qgsstringutils.h
QgsLocatorFilter::name
virtual QString name() const =0
Returns the unique name for the filter.
QgsLocatorFilter::openConfigWidget
virtual void openConfigWidget(QWidget *parent=nullptr)
Opens the configuration widget for the filter (if it has one), with the specified parent widget.
Definition: qgslocatorfilter.cpp:67
QgsLocatorFilter::hasConfigWidget
virtual bool hasConfigWidget() const
Should return true if the filter has a configuration widget.
Definition: qgslocatorfilter.cpp:62
QgsLocatorResult
Definition: qgslocatorfilter.h:39
QgsLocatorFilter::enabled
bool enabled() const
Returns true if the filter is enabled.
Definition: qgslocatorfilter.cpp:52
QgsStringUtils::fuzzyScore
static double fuzzyScore(const QString &candidate, const QString &search)
Tests a candidate string to see how likely it is a match for a specified search string.
Definition: qgsstringutils.cpp:412
QgsLocatorFilter::fuzzyScore
static double fuzzyScore(const QString &candidate, const QString &search)
Tests a candidate string to see how likely it is a match for a specified search string.
Definition: qgslocatorfilter.cpp:47
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:101
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsLocatorFilter::setEnabled
void setEnabled(bool enabled)
Sets whether the filter is enabled.
Definition: qgslocatorfilter.cpp:57
QgsLocatorFilter::useWithoutPrefix
bool useWithoutPrefix() const
Returns true if the filter should be used when no prefix is entered.
Definition: qgslocatorfilter.cpp:72
QgsLocatorFilter::setActivePrefix
void setActivePrefix(const QString &activePrefix)
Sets the prefix as being used by the locator.
Definition: qgslocatorfilter.cpp:93
QgsLocatorFilter::activePrefix
QString activePrefix() const
Returns the prefix in use in the locator is entered.
Definition: qgslocatorfilter.cpp:82
qgsfeedback.h
QgsLocatorFilter::triggerResultFromAction
virtual void triggerResultFromAction(const QgsLocatorResult &result, const int actionId)
Triggers a filter result from this filter for an entry in the context menu.
Definition: qgslocatorfilter.cpp:36
qgslocatorfilter.h
QgsLocatorFilter::stringMatches
static bool stringMatches(const QString &candidate, const QString &search)
Tests a candidate string to see if it should be considered a match for a specified search string.
Definition: qgslocatorfilter.cpp:42
QgsLocatorFilter::QgsLocatorFilter
QgsLocatorFilter(QObject *parent=nullptr)
Constructor for QgsLocatorFilter.
Definition: qgslocatorfilter.cpp:26
QgsLocatorFilter::setUseWithoutPrefix
void setUseWithoutPrefix(bool useWithoutPrefix)
Sets whether the filter should be used when no prefix is entered.
Definition: qgslocatorfilter.cpp:77
qgsmessagelog.h
QgsLocatorFilter::flags
virtual QgsLocatorFilter::Flags flags() const
Returns flags which specify the filter's behavior.
Definition: qgslocatorfilter.cpp:31