Skip to content

Commit 3651df0

Browse files
authored
add logMessage method to locator filter (#7222)
to discourage from using Python print()
1 parent 494f7bc commit 3651df0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

python/core/auto_generated/locator/qgslocatorfilter.sip.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ custom configuration widget.
241241
hasConfigWidget() must return true to indicate that the filter supports configuration.
242242
%End
243243

244+
void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
245+
%Docstring
246+
Logs a ``message`` to the log panel
247+
248+
.. warning::
249+
250+
in Python, do not use print() method as it might result in crashes
251+
since fetching results does not happen in the main thread.
252+
253+
.. versionadded:: 3.2
254+
%End
255+
256+
244257
signals:
245258

246259
void finished();

src/core/locator/qgslocatorfilter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgslocatorfilter.h"
2121
#include "qgsstringutils.h"
2222
#include "qgsfeedback.h"
23+
#include "qgsmessagelog.h"
2324

2425

2526
QgsLocatorFilter::QgsLocatorFilter( QObject *parent )
@@ -80,3 +81,8 @@ void QgsLocatorFilter::setActivePrefix( const QString &activePrefix )
8081
mActivePrefifx = activePrefix;
8182
}
8283

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+

src/core/locator/qgslocatorfilter.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
271271
*/
272272
virtual void openConfigWidget( QWidget *parent = nullptr );
273273

274+
/**
275+
* Logs a \a message to the log panel
276+
* \warning in Python, do not use print() method as it might result in crashes
277+
* since fetching results does not happen in the main thread.
278+
* \since QGIS 3.2
279+
*/
280+
void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
281+
282+
274283
signals:
275284

276285
/**

0 commit comments

Comments
 (0)