Skip to content

Commit

Permalink
Add method to clear the history log
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 21, 2021
1 parent 6783347 commit 09389ca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Expand Up @@ -150,6 +150,11 @@ The optional ``providerId`` and ``backends`` arguments can be used to filter ent
static QString userHistoryDbPath();
%Docstring
Returns the path to user's local history database.
%End

bool clearHistory( Qgis::HistoryProviderBackend backend );
%Docstring
Clears the history for the specified ``backend``.
%End

};
Expand Down
11 changes: 11 additions & 0 deletions src/gui/history/qgshistoryproviderregistry.cpp
Expand Up @@ -188,6 +188,17 @@ QString QgsHistoryProviderRegistry::userHistoryDbPath()
return QgsApplication::qgisSettingsDirPath() + QStringLiteral( "user-history.db" );
}

bool QgsHistoryProviderRegistry::clearHistory( Qgis::HistoryProviderBackend backend )
{
switch ( backend )
{
case Qgis::HistoryProviderBackend::LocalProfile:
runEmptyQuery( QStringLiteral( "DELETE from history;" ) );
break;
}
return true;
}

bool QgsHistoryProviderRegistry::createDatabase( const QString &filename, QString &error )
{
error.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/history/qgshistoryproviderregistry.h
Expand Up @@ -177,6 +177,11 @@ class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
*/
static QString userHistoryDbPath();

/**
* Clears the history for the specified \a backend.
*/
bool clearHistory( Qgis::HistoryProviderBackend backend );

private:

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgshistoryproviderregistry.py
Expand Up @@ -11,12 +11,14 @@
__copyright__ = 'Copyright 2016, The QGIS Project'

import qgis # NOQA switch sip api
import qgis.core

from qgis.PyQt import sip
from qgis.PyQt.QtCore import (
QDateTime,
QDate
)
from qgis.core import Qgis
from qgis.gui import (
QgsHistoryEntry,
QgsHistoryProviderRegistry,
Expand Down Expand Up @@ -143,6 +145,9 @@ def test_registry_entries(self):
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].providerId, 'my provider 3')

self.assertTrue(reg.clearHistory(Qgis.HistoryProviderBackend.LocalProfile))
self.assertFalse(reg.queryEntries())


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

0 comments on commit 09389ca

Please sign in to comment.