Allow history to be cleared for one provider only

This commit is contained in:
Nyall Dawson 2023-04-23 21:15:28 +10:00
parent 5f83b84c4e
commit ea58fd747f
5 changed files with 24 additions and 9 deletions

View File

@ -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``.
@ -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

View File

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

View File

@ -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:

View File

@ -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;
}

View File

@ -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:
@ -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: