QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
40 class 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 
89 class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
90 {
91  Q_OBJECT
92 
93  public:
94 
101  QgsHistoryProviderRegistry( QObject *parent = nullptr, bool useMemoryDatabase = false );
102 
103  ~QgsHistoryProviderRegistry() override;
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
Qgis::HistoryProviderBackend
HistoryProviderBackend
History provider backends.
Definition: qgis.h:1673
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsHistoryEntry::timestamp
QDateTime timestamp
Entry timestamp.
Definition: qgshistoryproviderregistry.h:57
qgis.h
QgsHistoryEntry
Encapsulates a history entry.
Definition: qgshistoryproviderregistry.h:40
QgsHistoryEntry::providerId
QString providerId
Associated history provider ID.
Definition: qgshistoryproviderregistry.h:60
QgsHistoryProviderRegistry::HistoryEntryOptions
Contains options for storing history entries.
Definition: qgshistoryproviderregistry.h:145
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgis::HistoryProviderBackend::LocalProfile
@ LocalProfile
Local profile.
QgsHistoryProviderRegistry
The QgsHistoryProviderRegistry is a registry for objects which track user history (i....
Definition: qgshistoryproviderregistry.h:89
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsHistoryProviderRegistry::HistoryEntryOptions::HistoryEntryOptions
HistoryEntryOptions()
Constructor for HistoryEntryOptions.
Definition: qgshistoryproviderregistry.h:152
QgsHistoryEntry::entry
QVariantMap entry
Entry details.
Definition: qgshistoryproviderregistry.h:68
str
#define str(x)
Definition: qgis.cpp:37
QgsAbstractHistoryProvider
Abstract base class for objects which track user history (i.e.
Definition: qgshistoryprovider.h:35
qgssqliteutils.h
sqlite3_database_unique_ptr
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Definition: qgssqliteutils.h:118