QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsconfigcache.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsconfigcache.h
3 ----------------
4 begin : July 24th, 2010
5 copyright : (C) 2010 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSCONFIGCACHE_H
19#define QGSCONFIGCACHE_H
20
21#include "qgsconfig.h"
22
23#include "qgis_server.h"
24#include "qgis_sip.h"
25#include "qgsproject.h"
26#include "qgsserversettings.h"
27
28#include <QCache>
29#include <QDomDocument>
30#include <QFileSystemWatcher>
31#include <QObject>
32#include <QString>
33#include <QTimer>
34
35using namespace Qt::StringLiterals;
36
37#ifndef SIP_RUN
38
39class QgsConfigCache;
40
48class SERVER_EXPORT QgsAbstractCacheStrategy
49{
50 public:
52 virtual QString name() const = 0;
53
58 virtual void entryRemoved( const QString &path ) = 0;
59
64 virtual void entryInserted( const QString &path ) = 0;
65
67 virtual void attach( QgsConfigCache *cache ) = 0;
68
69 virtual ~QgsAbstractCacheStrategy() = default;
70};
71
72#endif // SIP_RUN
73
78class SERVER_EXPORT QgsConfigCache : public QObject
79{
80 Q_OBJECT
81 public:
87 static void initialize( QgsServerSettings *settings );
88
92 static QgsConfigCache *instance();
93
98 void removeEntry( const QString &path );
99
111 const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );
112
117 QString strategyName() const { return mStrategy->name(); }
118
123 QList<QgsProject *> projects() const;
124
125 public:
128
131
132 signals:
133
138 void projectRemovedFromCache( const QString &path );
139
140 private:
141 // SIP require this
143
144 private:
146 QDomDocument *xmlDocument( const QString &filePath );
147
148 QCache<QString, QDomDocument> mXmlDocumentCache;
149 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject>>> mProjectCache;
150
151 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
152
153 private:
155 void cacheProject( const QString &path, QgsProject *project );
156
157 static QgsConfigCache *sInstance;
158
159 public slots:
161 void removeChangedEntry( const QString &path );
162
165};
166
167
168#ifndef SIP_RUN
169
176{
177 public:
180
182 QString name() const override { return u"filesystem"_s; };
183
185 void attach( QgsConfigCache *cache ) override;
186
191 void entryRemoved( const QString &path ) override;
192
197 void entryInserted( const QString &path ) override;
198
199 private:
201 QFileSystemWatcher mFileSystemWatcher;
202};
203
204
211{
212 public:
217 QgsPeriodicCacheStrategy( int interval = 3000 );
218
220 QString name() const override { return u"periodic"_s; };
221
228 void setCheckInterval( int msec );
229
231 int checkInterval() const { return mInterval; }
232
234 void attach( QgsConfigCache *owner ) override;
235
240 void entryRemoved( const QString &path ) override;
241
246 void entryInserted( const QString &path ) override;
247
248 private:
250 QTimer mTimer;
251
253 int mInterval;
254};
255
264{
265 public:
268
270 QString name() const override { return u"off"_s; };
271
273 void attach( QgsConfigCache *owner ) override;
274
279 void entryRemoved( const QString &path ) override;
280
285 void entryInserted( const QString &path ) override;
286};
287
288#endif // SIP_RUN
289
290#endif // QGSCONFIGCACHE_H
Abstract base class for implementing cache invalidation strategy.
virtual void attach(QgsConfigCache *cache)=0
Attache cache to this strategy.
virtual void entryInserted(const QString &path)=0
Called when an entry is removed from cache.
virtual ~QgsAbstractCacheStrategy()=default
virtual QString name() const =0
The name of the strategy.
virtual void entryRemoved(const QString &path)=0
Called when an entry is removed from cache.
Cache for server configuration.
QgsConfigCache(QgsServerSettings *settings)
Initialize from settings.
void removeChangedEntry(const QString &path)
Remove cache entry.
void removeEntry(const QString &path)
Removes an entry from cache.
QString strategyName() const
Returns the name of the current strategy.
void removeChangedEntries()
Remove all changed cache entries.
static QgsConfigCache * instance()
Returns the current instance.
static void initialize(QgsServerSettings *settings)
Initialize from settings.
void projectRemovedFromCache(const QString &path)
Emitted whenever a project is removed from the cache.
const QgsProject * project(const QString &path, const QgsServerSettings *settings=nullptr)
If the project is not cached yet, then the project is read from the path.
QgsFileSystemCacheStrategy()
Creates a new filesystem strategy.
QString name() const override
The name of the strategy.
QgsNullCacheStrategy()=default
Creates a new null strategy.
QString name() const override
The name of the strategy.
QgsPeriodicCacheStrategy(int interval=3000)
Creates a new periodic strategy.
int checkInterval() const
Returns the invalidation check interval.
QString name() const override
The name of the strategy.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:112
Provides a way to retrieve settings by prioritizing according to environment variables,...
#define SIP_FORCE
Definition qgis_sip.h:139
#define SIP_SKIP
Definition qgis_sip.h:134