Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow history to be cleared for one provider only
  • Loading branch information
nyalldawson committed Apr 24, 2023
1 parent 5f83b84 commit ea58fd7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Expand Up @@ -158,7 +158,7 @@ The optional ``providerId`` and ``backends`` arguments can be used to filter ent
Returns the path to user's local history database.
%End

bool clearHistory( Qgis::HistoryProviderBackend backend );
bool clearHistory( Qgis::HistoryProviderBackend backend, const QString &providerId = QString() );
%Docstring
Clears the history for the specified ``backend``.

Expand All @@ -181,10 +181,13 @@ Emitted when an ``entry`` is updated.
.. versionadded:: 3.32
%End

void historyCleared( Qgis::HistoryProviderBackend backend );
void historyCleared( Qgis::HistoryProviderBackend backend, const QString &providerId );
%Docstring
Emitted when the history is cleared for a ``backend``.

If ``providerId`` is non-empty then the history has only been cleared for the
specified provider.

.. versionadded:: 3.32
%End

Expand Down
5 changes: 4 additions & 1 deletion src/gui/history/qgshistoryentrymodel.cpp
Expand Up @@ -250,12 +250,15 @@ void QgsHistoryEntryModel::entryUpdated( long long id, const QVariantMap &entry,
}
}

void QgsHistoryEntryModel::historyCleared( Qgis::HistoryProviderBackend backend )
void QgsHistoryEntryModel::historyCleared( Qgis::HistoryProviderBackend backend, const QString &providerId )
{
// ignore entries we don't care about
if ( !( mBackends & backend ) )
return;

if ( !mProviderId.isEmpty() && !providerId.isEmpty() && providerId != mProviderId )
return;

beginResetModel();
mRootNode->clear();
mIdToNodeHash.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/history/qgshistoryentrymodel.h
Expand Up @@ -80,7 +80,7 @@ class GUI_EXPORT QgsHistoryEntryModel : public QAbstractItemModel

void entryAdded( long long id, const QgsHistoryEntry &entry, Qgis::HistoryProviderBackend backend );
void entryUpdated( long long id, const QVariantMap &entry, Qgis::HistoryProviderBackend backend );
void historyCleared( Qgis::HistoryProviderBackend backend );
void historyCleared( Qgis::HistoryProviderBackend backend, const QString &providerId );

private:

Expand Down
12 changes: 9 additions & 3 deletions src/gui/history/qgshistoryproviderregistry.cpp
Expand Up @@ -267,15 +267,21 @@ QString QgsHistoryProviderRegistry::userHistoryDbPath()
return QgsApplication::qgisSettingsDirPath() + QStringLiteral( "user-history.db" );
}

bool QgsHistoryProviderRegistry::clearHistory( Qgis::HistoryProviderBackend backend )
bool QgsHistoryProviderRegistry::clearHistory( Qgis::HistoryProviderBackend backend, const QString &providerId )
{
switch ( backend )
{
case Qgis::HistoryProviderBackend::LocalProfile:
runEmptyQuery( QStringLiteral( "DELETE from history;" ) );
{
if ( providerId.isEmpty() )
runEmptyQuery( QStringLiteral( "DELETE from history;" ) );
else
runEmptyQuery( QStringLiteral( "DELETE from history WHERE provider_id='%1'" )
.arg( providerId ) );
break;
}
}
emit historyCleared( backend );
emit historyCleared( backend, providerId );
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/gui/history/qgshistoryproviderregistry.h
Expand Up @@ -185,7 +185,7 @@ class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
*
* \see historyCleared()
*/
bool clearHistory( Qgis::HistoryProviderBackend backend );
bool clearHistory( Qgis::HistoryProviderBackend backend, const QString &providerId = QString() );

signals:

Expand All @@ -206,9 +206,12 @@ class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
/**
* Emitted when the history is cleared for a \a backend.
*
* If \a providerId is non-empty then the history has only been cleared for the
* specified provider.
*
* \since QGIS 3.32
*/
void historyCleared( Qgis::HistoryProviderBackend backend );
void historyCleared( Qgis::HistoryProviderBackend backend, const QString &providerId );

private:

Expand Down

0 comments on commit ea58fd7

Please sign in to comment.