36 QgsConfigCache::QgsConfigCache()
38 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsConfigCache::removeChangedEntry );
44 if ( ! mProjectCache[ path ] )
46 std::unique_ptr<QgsProject> prj(
new QgsProject() );
48 prj->setBadLayerHandler( badLayerHandler );
49 if ( prj->read( path ) )
51 if ( !badLayerHandler->
badLayers().isEmpty() )
54 QStringList unrestrictedBadLayers;
56 const QStringList badLayerIds = badLayerHandler->
badLayers();
57 const QMap<QString, QString> badLayerNames = badLayerHandler->
badLayerNames();
59 for (
const QString &badLayerId : badLayerIds )
63 if ( badLayerNames.contains( badLayerId ) &&
64 resctrictedLayers.contains( badLayerNames.value( badLayerId ) ) )
68 unrestrictedBadLayers.append( badLayerId );
70 if ( !unrestrictedBadLayers.isEmpty() )
76 QStringLiteral(
"Error, Layer(s) %1 not valid in project %2" ).arg( unrestrictedBadLayers.join( QStringLiteral(
", " ) ), path ),
83 QStringLiteral(
"Warning, Layer(s) %1 not valid in project %2" ).arg( unrestrictedBadLayers.join( QStringLiteral(
", " ) ), path ),
88 mProjectCache.insert( path, prj.release() );
89 mFileSystemWatcher.addPath( path );
94 QStringLiteral(
"Error when loading project file '%1': %2 " ).arg( path, prj->error() ),
98 QgsProject::setInstance( mProjectCache[ path ] );
99 return mProjectCache[ path ];
103 QDomDocument *QgsConfigCache::xmlDocument(
const QString &filePath )
106 QFile configFile( filePath );
107 if ( !configFile.exists() )
113 if ( !configFile.open( QIODevice::ReadOnly ) )
120 QDomDocument *xmlDoc = mXmlDocumentCache.object( filePath );
124 xmlDoc =
new QDomDocument();
127 if ( !xmlDoc->setContent( &configFile,
true, &errorMsg, &line, &column ) )
130 QStringLiteral(
"': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), QStringLiteral(
"Server" ),
Qgis::Critical );
134 mXmlDocumentCache.insert( filePath, xmlDoc );
135 mFileSystemWatcher.addPath( filePath );
136 xmlDoc = mXmlDocumentCache.object( filePath );
142 void QgsConfigCache::removeChangedEntry(
const QString &path )
144 mProjectCache.remove( path );
147 mXmlDocumentCache.remove( path );
149 mFileSystemWatcher.removePath( path );
155 removeChangedEntry( path );