diff --git a/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in b/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in index 078897bb834..ad41d5cb34e 100644 --- a/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in +++ b/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in @@ -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 diff --git a/src/gui/history/qgshistoryentrymodel.cpp b/src/gui/history/qgshistoryentrymodel.cpp index 8dce3d5a6c7..c2f77e561d0 100644 --- a/src/gui/history/qgshistoryentrymodel.cpp +++ b/src/gui/history/qgshistoryentrymodel.cpp @@ -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(); diff --git a/src/gui/history/qgshistoryentrymodel.h b/src/gui/history/qgshistoryentrymodel.h index 3d2202def72..3c36cb2246e 100644 --- a/src/gui/history/qgshistoryentrymodel.h +++ b/src/gui/history/qgshistoryentrymodel.h @@ -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: diff --git a/src/gui/history/qgshistoryproviderregistry.cpp b/src/gui/history/qgshistoryproviderregistry.cpp index 981be5bc167..7911e53d072 100644 --- a/src/gui/history/qgshistoryproviderregistry.cpp +++ b/src/gui/history/qgshistoryproviderregistry.cpp @@ -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; } diff --git a/src/gui/history/qgshistoryproviderregistry.h b/src/gui/history/qgshistoryproviderregistry.h index b18ac5dd786..145840bf91b 100644 --- a/src/gui/history/qgshistoryproviderregistry.h +++ b/src/gui/history/qgshistoryproviderregistry.h @@ -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: