/
qgshistoryproviderregistry.h
219 lines (181 loc) · 6.74 KB
/
qgshistoryproviderregistry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/***************************************************************************
qgshistoryproviderregistry.h
--------------------------
begin : April 2019
copyright : (C) 2019 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSHISTORYPROVIDERREGISTRY_H
#define QGSHISTORYPROVIDERREGISTRY_H
#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgis.h"
#include <QObject>
#include <QMap>
#include <QString>
#include <QDateTime>
#include <QVariant>
#include <QVector>
#include "qgssqliteutils.h"
class QgsAbstractHistoryProvider;
/**
* Encapsulates a history entry.
*
* \ingroup gui
* \since QGIS 3.24
*/
class GUI_EXPORT QgsHistoryEntry
{
public:
/**
* Constructor for QgsHistoryEntry \a entry, with the specified \a providerId and \a timestamp.
*/
QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, const QVariantMap &entry );
/**
* Constructor for QgsHistoryEntry \a entry.
*
* The entry timestamp will be automatically set to the current date/time.
*/
QgsHistoryEntry( const QVariantMap &entry );
//! Entry timestamp
QDateTime timestamp;
//! Associated history provider ID
QString providerId;
/**
* Entry details.
*
* Entries details are stored as a free-form map. Interpretation of this map is the responsiblity of the
* associated history provider.
*/
QVariantMap entry;
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
const QString str = QStringLiteral( "<QgsHistoryEntry: %1 %2>" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
};
/**
* The QgsHistoryProviderRegistry is a registry for objects which track user history (i.e. operations performed through the GUI).
*
* QgsHistoryProviderRegistry is not usually directly created, but rather accessed through
* QgsGui::historyProviderRegistry().
*
* \ingroup gui
* \since QGIS 3.24
*/
class GUI_EXPORT QgsHistoryProviderRegistry : public QObject
{
Q_OBJECT
public:
/**
* Creates a new empty history provider registry.
*
* QgsHistoryProviderRegistry is not usually directly created, but rather accessed through
* QgsGui::historyProviderRegistry().
*/
QgsHistoryProviderRegistry( QObject *parent = nullptr, bool useMemoryDatabase = false );
~QgsHistoryProviderRegistry() override;
/**
* Adds a \a provider to the registry. Ownership of the provider is
* transferred to the registry.
*
* Returns TRUE if the provider was successfully added.
*/
bool addProvider( QgsAbstractHistoryProvider *provider SIP_TRANSFER );
/**
* Returns the provider with matching \a id, or NULLPTR if no matching
* provider is registered.
*/
QgsAbstractHistoryProvider *providerById( const QString &id );
/**
* Removes the provider with matching \a id.
*
* The provider will be deleted.
*
* Returns TRUE if the provider was successfully removed.
*/
bool removeProvider( const QString &id );
/**
* Returns a list of the registered provider IDs.
*/
QStringList providerIds() const;
/**
* Contains options for storing history entries.
*
* \ingroup gui
* \since QGIS 3.24
*/
class HistoryEntryOptions
{
public:
/**
* Constructor for HistoryEntryOptions.
*/
HistoryEntryOptions() {}
//! Target storage backends
Qgis::HistoryProviderBackends storageBackends = Qgis::HistoryProviderBackend::LocalProfile;
};
/**
* Adds an \a entry to the history logs.
*
* The entry will be tagged with the current date/time as the timestamp.
*
* The \a providerId specifies the history provider responsible for this entry.
* Entry options are specified via the \a options argument.
*/
bool addEntry( const QString &providerId, const QVariantMap &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
/**
* Adds an \a entry to the history logs.
*/
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.
*
* The optional \a providerId and \a backends arguments can be used to filter entries.
*/
QList< QgsHistoryEntry > queryEntries( const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
const QString &providerId = QString(), Qgis::HistoryProviderBackends backends = Qgis::HistoryProviderBackend::LocalProfile ) const;
/**
* Returns the path to user's local history database.
*/
static QString userHistoryDbPath();
/**
* Clears the history for the specified \a backend.
*/
bool clearHistory( Qgis::HistoryProviderBackend backend );
private:
/**
* Creates an on-disk history database.
*/
bool createDatabase( const QString &filename, QString &error );
//! Convenience function to open the DB
bool openDatabase( const QString &filename, QString &error );
/**
* Creates tables structure for history database.
*/
void createTables();
/**
* Convenience function that would run queries which don't generate return values
*
* \param query query to run
* \returns success TRUE on success
*/
bool runEmptyQuery( const QString &query );
QMap< QString, QgsAbstractHistoryProvider * > mProviders;
sqlite3_database_unique_ptr mLocalDB;
};
#endif //QGSHISTORYPROVIDERREGISTRY_H