mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Add bulk addEntries method for efficiently adding many entries at once to history
This commit is contained in:
parent
09389ca763
commit
dd5cbb746e
@ -137,6 +137,11 @@ Entry options are specified via the ``options`` argument.
|
|||||||
bool addEntry( const QgsHistoryEntry &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
bool addEntry( const QgsHistoryEntry &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
||||||
%Docstring
|
%Docstring
|
||||||
Adds an ``entry`` to the history logs.
|
Adds an ``entry`` to the history logs.
|
||||||
|
%End
|
||||||
|
|
||||||
|
bool addEntries( const QList< QgsHistoryEntry > &entries, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
||||||
|
%Docstring
|
||||||
|
Adds a list of ``entries`` to the history logs.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QList< QgsHistoryEntry > queryEntries( const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
|
QList< QgsHistoryEntry > queryEntries( const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
|
||||||
|
|||||||
@ -131,6 +131,19 @@ bool QgsHistoryProviderRegistry::addEntry( const QgsHistoryEntry &entry, History
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsHistoryProviderRegistry::addEntries( const QList<QgsHistoryEntry> &entries, HistoryEntryOptions options )
|
||||||
|
{
|
||||||
|
if ( options.storageBackends & Qgis::HistoryProviderBackend::LocalProfile )
|
||||||
|
{
|
||||||
|
runEmptyQuery( QStringLiteral( "BEGIN TRANSACTION;" ) );
|
||||||
|
for ( const QgsHistoryEntry &entry : entries )
|
||||||
|
addEntry( entry, options );
|
||||||
|
runEmptyQuery( QStringLiteral( "COMMIT TRANSACTION;" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QgsHistoryEntry> QgsHistoryProviderRegistry::queryEntries( const QDateTime &start, const QDateTime &end, const QString &providerId, Qgis::HistoryProviderBackends backends ) const
|
QList<QgsHistoryEntry> QgsHistoryProviderRegistry::queryEntries( const QDateTime &start, const QDateTime &end, const QString &providerId, Qgis::HistoryProviderBackends backends ) const
|
||||||
{
|
{
|
||||||
QList<QgsHistoryEntry> entries;
|
QList<QgsHistoryEntry> entries;
|
||||||
|
|||||||
@ -164,6 +164,11 @@ class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
|
|||||||
*/
|
*/
|
||||||
bool addEntry( const QgsHistoryEntry &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
bool addEntry( const QgsHistoryEntry &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a list of \a entries to the history logs.
|
||||||
|
*/
|
||||||
|
bool addEntries( const QList< QgsHistoryEntry > &entries, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries history entries which occurred between the specified \a start and \a end times.
|
* Queries history entries which occurred between the specified \a start and \a end times.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -148,6 +148,18 @@ class TestQgsHistoryProviderRegistry(unittest.TestCase):
|
|||||||
self.assertTrue(reg.clearHistory(Qgis.HistoryProviderBackend.LocalProfile))
|
self.assertTrue(reg.clearHistory(Qgis.HistoryProviderBackend.LocalProfile))
|
||||||
self.assertFalse(reg.queryEntries())
|
self.assertFalse(reg.queryEntries())
|
||||||
|
|
||||||
|
# bulk add entries
|
||||||
|
self.assertTrue(reg.addEntries([
|
||||||
|
QgsHistoryEntry('my provider 4', QDateTime(2021, 1, 2, 3, 4, 5), {'var': 7}),
|
||||||
|
QgsHistoryEntry('my provider 5', QDateTime(2021, 1, 2, 3, 4, 5), {'var': 8})
|
||||||
|
]))
|
||||||
|
self.assertEqual(len(reg.queryEntries()), 2)
|
||||||
|
self.assertEqual(reg.queryEntries()[0].providerId, 'my provider 4')
|
||||||
|
self.assertEqual(reg.queryEntries()[0].entry, {'var': 7})
|
||||||
|
|
||||||
|
self.assertEqual(reg.queryEntries()[1].providerId, 'my provider 5')
|
||||||
|
self.assertEqual(reg.queryEntries()[1].entry, {'var': 8})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user