QGIS API Documentation  3.2.0-Bonn (bc43194)
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 bool QgsLocatorFilter::stringMatches( const QString &candidate, const QString &search )
37 {
38  return !search.isEmpty() && candidate.contains( search, Qt::CaseInsensitive );
39 }
40 
42 {
43  return mEnabled;
44 }
45 
47 {
48  mEnabled = enabled;
49 }
50 
52 {
53  return false;
54 }
55 
56 void QgsLocatorFilter::openConfigWidget( QWidget *parent )
57 {
58  Q_UNUSED( parent );
59 }
60 
62 {
63  return mUseWithoutPrefix;
64 }
65 
67 {
68  mUseWithoutPrefix = useWithoutPrefix;
69 }
70 
72 {
73  if ( mActivePrefifx.isNull() )
74  return prefix();
75  else
76  return mActivePrefifx;
77 }
78 
80 {
81  mActivePrefifx = activePrefix;
82 }
83 
84 void QgsLocatorFilter::logMessage( const QString &message, Qgis::MessageLevel level )
85 {
86  QgsMessageLog::logMessage( QString( "%1: %2" ).arg( name(), message ), QStringLiteral( "Locator bar" ), level );
87 }
88 
void setEnabled(bool enabled)
Sets whether the filter is enabled.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78
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...
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::Info)
Logs a message to the log panel.
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).
bool useWithoutPrefix() const
Returns true if the filter should be used when no prefix is entered.
QgsLocatorFilter(QObject *parent=nullptr)
Constructor for QgsLocatorFilter.
void setActivePrefix(const QString &activePrefix)
Sets the prefix as being used by the locator.
QString activePrefix() const
Returns the prefix in use in the locator is entered.
virtual QgsLocatorFilter::Flags flags() const
Returns flags which specify the filter&#39;s behavior.
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
virtual QString name() const =0
Returns the unique name for the filter.
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...
virtual bool hasConfigWidget() const
Should return true if the filter has a configuration widget.