36 QgsConfigCache::QgsConfigCache()
38 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsConfigCache::removeChangedEntry );
43 if ( ! mProjectCache[ path ] )
45 std::unique_ptr<QgsProject> prj(
new QgsProject() );
47 prj->setBadLayerHandler( badLayerHandler );
48 if ( prj->read( path ) )
50 if ( !badLayerHandler->
badLayers().isEmpty() )
53 QStringList unrestrictedBadLayers;
55 const QStringList badLayerIds = badLayerHandler->
badLayers();
56 const QMap<QString, QString> badLayerNames = badLayerHandler->
badLayerNames();
58 for (
const QString &badLayerId : badLayerIds )
62 if ( badLayerNames.contains( badLayerId ) &&
63 resctrictedLayers.contains( badLayerNames.value( badLayerId ) ) )
67 unrestrictedBadLayers.append( badLayerId );
69 if ( !unrestrictedBadLayers.isEmpty() )
72 QStringLiteral(
"Error, Layer(s) %1 not valid in project %2" ).arg( unrestrictedBadLayers.join( QStringLiteral(
", " ) ), path ),
77 mProjectCache.insert( path, prj.release() );
78 mFileSystemWatcher.addPath( path );
83 QStringLiteral(
"Error when loading project file '%1': %2 " ).arg( path, prj->error() ),
87 QgsProject::setInstance( mProjectCache[ path ] );
88 return mProjectCache[ path ];
91 QDomDocument *QgsConfigCache::xmlDocument(
const QString &filePath )
94 QFile configFile( filePath );
95 if ( !configFile.exists() )
101 if ( !configFile.open( QIODevice::ReadOnly ) )
108 QDomDocument *xmlDoc = mXmlDocumentCache.object( filePath );
112 xmlDoc =
new QDomDocument();
115 if ( !xmlDoc->setContent( &configFile,
true, &errorMsg, &line, &column ) )
118 QStringLiteral(
"': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), QStringLiteral(
"Server" ),
Qgis::Critical );
122 mXmlDocumentCache.insert( filePath, xmlDoc );
123 mFileSystemWatcher.addPath( filePath );
124 xmlDoc = mXmlDocumentCache.object( filePath );
130 void QgsConfigCache::removeChangedEntry(
const QString &path )
132 mProjectCache.remove( path );
135 mXmlDocumentCache.remove( path );
137 mFileSystemWatcher.removePath( path );
143 removeChangedEntry( path );
QMap< QString, QString > badLayerNames() const
Returns names of bad layers with ids.
QStringList badLayers() const
badLayers
void removeEntry(const QString &path)
Removes an entry from cache.
Stores layer ids of bad layers.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::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, annotations, canvases, etc.
const QgsProject * project(const QString &path)
If the project is not cached yet, then the project is read thanks to the path.
Exception base class for server exceptions.
Cache for server configuration.
static QgsConfigCache * instance()
Returns the current instance.
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.