QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 "moc_qgslocatorfilter.cpp"
22#include "qgsstringutils.h"
23#include "qgsfeedback.h"
24#include "qgsmessagelog.h"
25
26
28 : QObject( parent )
29{
30}
31
36
37void QgsLocatorFilter::triggerResultFromAction( const QgsLocatorResult &result, const int actionId )
38{
39 Q_UNUSED( result )
40 Q_UNUSED( actionId )
41}
42
43bool QgsLocatorFilter::stringMatches( const QString &candidate, const QString &search )
44{
45 return !search.isEmpty() && candidate.contains( search, Qt::CaseInsensitive );
46}
47
48double QgsLocatorFilter::fuzzyScore( const QString &candidate, const QString &search )
49{
50 return QgsStringUtils::fuzzyScore( candidate, search );
51}
52
54{
55 return mEnabled;
56}
57
58void QgsLocatorFilter::setEnabled( bool enabled )
59{
60 mEnabled = enabled;
61}
62
64{
65 return false;
66}
67
69{
70 Q_UNUSED( parent )
71}
72
74{
75 return mUseWithoutPrefix;
76}
77
78void QgsLocatorFilter::setUseWithoutPrefix( bool useWithoutPrefix )
79{
80 mUseWithoutPrefix = useWithoutPrefix;
81}
82
84{
85 // do not change this to isEmpty!
86 // if any issue with an in-built locator filter
87 // do not forget to add it in QgsLocator::CORE_FILTERS
88 if ( mActivePrefifx.isNull() )
89 return prefix();
90 else
91 return mActivePrefifx;
92}
93
94void QgsLocatorFilter::setActivePrefix( const QString &activePrefix )
95{
96 mActivePrefifx = activePrefix;
97}
98
99void QgsLocatorFilter::logMessage( const QString &message, Qgis::MessageLevel level )
100{
101 QgsMessageLog::logMessage( QString( "%1: %2" ).arg( name(), message ), QStringLiteral( "Locator bar" ), level );
102}
103
104
106{
107 return mUserData;
108}
109
110void QgsLocatorResult::setUserData( const QVariant &userData )
111{
112 mUserData = userData;
113}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
void setEnabled(bool enabled)
Sets whether the filter is enabled.
QFlags< Flag > Flags
void setActivePrefix(const QString &activePrefix)
Sets the prefix as being used by the locator.
virtual QgsLocatorFilter::Flags flags() const
Returns flags which specify the filter's behavior.
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
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.
bool useWithoutPrefix() const
Returns true if the filter should be used when no prefix is entered.
virtual void triggerResultFromAction(const QgsLocatorResult &result, const int actionId)
Triggers a filter result from this filter for an entry in the context menu.
void setUseWithoutPrefix(bool useWithoutPrefix)
Sets whether the filter should be used when no prefix is entered.
void logMessage(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Logs a message to the log panel.
bool enabled() const
Returns true if the filter is enabled.
virtual void openConfigWidget(QWidget *parent=nullptr)
Opens the configuration widget for the filter (if it has one), with the specified parent widget.
QString activePrefix() const
Returns the prefix in use in the locator is entered.
virtual QString name() const =0
Returns the unique name for the filter.
QgsLocatorFilter(QObject *parent=nullptr)
Constructor for QgsLocatorFilter.
virtual bool hasConfigWidget() const
Should return true if the filter has a configuration widget.
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.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
void setUserData(const QVariant &userData)
Set userData for the locator result.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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.