36 QgsConfigCache::QgsConfigCache()
38 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsConfigCache::removeChangedEntry );
44 if ( ! mProjectCache[ path ] )
47 std::unique_ptr<QgsProject> prj(
new QgsProject() );
53 prj->setBadLayerHandler( badLayerHandler );
71 if ( prj->read( path, readFlags ) )
73 if ( !badLayerHandler->
badLayers().isEmpty() )
76 QStringList unrestrictedBadLayers;
78 const QStringList badLayerIds = badLayerHandler->
badLayers();
79 const QMap<QString, QString> badLayerNames = badLayerHandler->
badLayerNames();
81 for (
const QString &badLayerId : badLayerIds )
85 if ( badLayerNames.contains( badLayerId ) &&
86 resctrictedLayers.contains( badLayerNames.value( badLayerId ) ) )
90 unrestrictedBadLayers.append( badLayerId );
92 if ( !unrestrictedBadLayers.isEmpty() )
98 QStringLiteral(
"Error, Layer(s) %1 not valid in project %2" ).arg( unrestrictedBadLayers.join( QLatin1String(
", " ) ), path ),
99 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
105 QStringLiteral(
"Warning, Layer(s) %1 not valid in project %2" ).arg( unrestrictedBadLayers.join( QLatin1String(
", " ) ), path ),
106 QStringLiteral(
"Server" ), Qgis::MessageLevel::Warning );
110 mProjectCache.insert( path, prj.release() );
111 mFileSystemWatcher.addPath( path );
116 QStringLiteral(
"Error when loading project file '%1': %2 " ).arg( path, prj->error() ),
117 QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
120 return mProjectCache[ path ];
123 QDomDocument *QgsConfigCache::xmlDocument(
const QString &filePath )
126 QFile configFile( filePath );
127 if ( !configFile.exists() )
129 QgsMessageLog::logMessage(
"Error, configuration file '" + filePath +
"' does not exist", QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
133 if ( !configFile.open( QIODevice::ReadOnly ) )
135 QgsMessageLog::logMessage(
"Error, cannot open configuration file '" + filePath +
"'", QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
140 QDomDocument *xmlDoc = mXmlDocumentCache.object( filePath );
144 xmlDoc =
new QDomDocument();
147 if ( !xmlDoc->setContent( &configFile,
true, &errorMsg, &line, &column ) )
150 QStringLiteral(
"': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), QStringLiteral(
"Server" ), Qgis::MessageLevel::Critical );
154 mXmlDocumentCache.insert( filePath, xmlDoc );
155 mFileSystemWatcher.addPath( filePath );
156 xmlDoc = mXmlDocumentCache.object( filePath );
162 void QgsConfigCache::removeChangedEntry(
const QString &path )
164 mProjectCache.remove( path );
167 mXmlDocumentCache.remove( path );
169 mFileSystemWatcher.removePath( path );
175 removeChangedEntry( path );
Cache for server configuration.
void removeEntry(const QString &path)
Removes an entry from cache.
static QgsConfigCache * instance()
Returns the current instance.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static void setInstance(QgsProject *project)
Set the current project singleton instance to project.
ReadFlag
Flags which control project read behavior.
@ FlagTrustLayerMetadata
Trust layer metadata. Improves project read time. Do not use it if layers' extent is not fixed during...
@ FlagDontStoreOriginalStyles
Skip the initial XML style storage for layers. Useful for minimising project load times in non-intera...
@ FlagDontLoadLayouts
Don't load print layouts. Improves project read time if layouts are not required, and allows projects...
Exception base class for server exceptions.
Provides a way to retrieve settings by prioritizing according to environment variables,...
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
bool ignoreBadLayers() const
Returns true if the bad layers are ignored and false when the presence of a bad layers invalidates th...
bool trustLayerMetadata() const
Returns true if the reading flag trust layer metadata is activated.
Stores layer ids of bad layers.
QMap< QString, QString > badLayerNames() const
Returns names of bad layers with ids.
QStringList badLayers() const
badLayers
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.