QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgshistoryproviderregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgshistoryproviderregistry.h
3 --------------------------
4 begin : April 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSHISTORYPROVIDERREGISTRY_H
17#define QGSHISTORYPROVIDERREGISTRY_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgis.h"
22
23#include <QObject>
24#include <QMap>
25#include <QString>
26#include <QDateTime>
27#include <QVariant>
28#include <QVector>
29
30#include "qgssqliteutils.h"
31
33
40class GUI_EXPORT QgsHistoryEntry
41{
42 public:
43
47 QgsHistoryEntry( const QString &providerId, const QDateTime &timestamp, const QVariantMap &entry );
48
54 QgsHistoryEntry( const QVariantMap &entry );
55
57 QDateTime timestamp;
58
60 QString providerId;
61
68 QVariantMap entry;
69
70#ifdef SIP_RUN
71 SIP_PYOBJECT __repr__();
72 % MethodCode
73 const QString str = QStringLiteral( "<QgsHistoryEntry: %1 %2>" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) );
74 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
75 % End
76#endif
77
78};
79
89class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
90{
91 Q_OBJECT
92
93 public:
94
101 QgsHistoryProviderRegistry( QObject *parent = nullptr, bool useMemoryDatabase = false );
102
104
109 void addDefaultProviders() SIP_SKIP;
110
117 bool addProvider( QgsAbstractHistoryProvider *provider SIP_TRANSFER );
118
123 QgsAbstractHistoryProvider *providerById( const QString &id );
124
132 bool removeProvider( const QString &id );
133
137 QStringList providerIds() const;
138
146 {
147 public:
148
153
155 Qgis::HistoryProviderBackends storageBackends = Qgis::HistoryProviderBackend::LocalProfile;
156 };
157
173 long long addEntry( const QString &providerId, const QVariantMap &entry, bool &ok SIP_OUT, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
174
185
189 bool addEntries( const QList< QgsHistoryEntry > &entries, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
190
200 QgsHistoryEntry entry( long long id, bool &ok, Qgis::HistoryProviderBackend backend = Qgis::HistoryProviderBackend::LocalProfile ) const;
201
208 bool updateEntry( long long id, const QVariantMap &entry, Qgis::HistoryProviderBackend backend = Qgis::HistoryProviderBackend::LocalProfile );
209
215 QList< QgsHistoryEntry > queryEntries( const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
216 const QString &providerId = QString(), Qgis::HistoryProviderBackends backends = Qgis::HistoryProviderBackend::LocalProfile ) const;
217
221 static QString userHistoryDbPath();
222
226 bool clearHistory( Qgis::HistoryProviderBackend backend );
227
228 private:
229
233 bool createDatabase( const QString &filename, QString &error );
234
236 bool openDatabase( const QString &filename, QString &error );
237
241 void createTables();
242
249 bool runEmptyQuery( const QString &query );
250
251 QMap< QString, QgsAbstractHistoryProvider * > mProviders;
252
254
255};
256
257#endif //QGSHISTORYPROVIDERREGISTRY_H
HistoryProviderBackend
History provider backends.
Definition: qgis.h:1843
@ LocalProfile
Local profile.
Abstract base class for objects which track user history (i.e.
Encapsulates a history entry.
QDateTime timestamp
Entry timestamp.
QString providerId
Associated history provider ID.
QVariantMap entry
Entry details.
Contains options for storing history entries.
HistoryEntryOptions()
Constructor for HistoryEntryOptions.
The QgsHistoryProviderRegistry is a registry for objects which track user history (i....
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58