Skip to content
Permalink
Browse files
Add method to clear the history log
  • Loading branch information
nyalldawson committed Dec 21, 2021
1 parent 6783347 commit 09389ca7637da456886f5b95e7d9b10dd9aa97f5
@@ -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

};
@@ -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();
@@ -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:

/**
@@ -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,
@@ -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.