Skip to content

Commit 09389ca

Browse files
committedDec 21, 2021
Add method to clear the history log
1 parent 6783347 commit 09389ca

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
 

‎python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ The optional ``providerId`` and ``backends`` arguments can be used to filter ent
150150
static QString userHistoryDbPath();
151151
%Docstring
152152
Returns the path to user's local history database.
153+
%End
154+
155+
bool clearHistory( Qgis::HistoryProviderBackend backend );
156+
%Docstring
157+
Clears the history for the specified ``backend``.
153158
%End
154159

155160
};

‎src/gui/history/qgshistoryproviderregistry.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ QString QgsHistoryProviderRegistry::userHistoryDbPath()
188188
return QgsApplication::qgisSettingsDirPath() + QStringLiteral( "user-history.db" );
189189
}
190190

191+
bool QgsHistoryProviderRegistry::clearHistory( Qgis::HistoryProviderBackend backend )
192+
{
193+
switch ( backend )
194+
{
195+
case Qgis::HistoryProviderBackend::LocalProfile:
196+
runEmptyQuery( QStringLiteral( "DELETE from history;" ) );
197+
break;
198+
}
199+
return true;
200+
}
201+
191202
bool QgsHistoryProviderRegistry::createDatabase( const QString &filename, QString &error )
192203
{
193204
error.clear();

‎src/gui/history/qgshistoryproviderregistry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
177177
*/
178178
static QString userHistoryDbPath();
179179

180+
/**
181+
* Clears the history for the specified \a backend.
182+
*/
183+
bool clearHistory( Qgis::HistoryProviderBackend backend );
184+
180185
private:
181186

182187
/**

‎tests/src/python/test_qgshistoryproviderregistry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
__copyright__ = 'Copyright 2016, The QGIS Project'
1212

1313
import qgis # NOQA switch sip api
14+
import qgis.core
1415

1516
from qgis.PyQt import sip
1617
from qgis.PyQt.QtCore import (
1718
QDateTime,
1819
QDate
1920
)
21+
from qgis.core import Qgis
2022
from qgis.gui import (
2123
QgsHistoryEntry,
2224
QgsHistoryProviderRegistry,
@@ -143,6 +145,9 @@ def test_registry_entries(self):
143145
self.assertEqual(len(entries), 1)
144146
self.assertEqual(entries[0].providerId, 'my provider 3')
145147

148+
self.assertTrue(reg.clearHistory(Qgis.HistoryProviderBackend.LocalProfile))
149+
self.assertFalse(reg.queryEntries())
150+
146151

147152
if __name__ == '__main__':
148153
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.