35 QgsConfigCache::QgsConfigCache()
37 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsConfigCache::removeChangedEntry );
42 if ( ! mProjectCache[ path ] )
44 std::unique_ptr<QgsProject> prj(
new QgsProject() );
46 prj->setBadLayerHandler( badLayerHandler );
47 if ( prj->read( path ) )
49 if ( !badLayerHandler->
badLayers().isEmpty() )
51 QString errorMsg = QStringLiteral(
"Layer(s) %1 not valid" ).arg( badLayerHandler->
badLayers().join(
',' ) );
55 mProjectCache.insert( path, prj.release() );
56 mFileSystemWatcher.addPath( path );
61 tr(
"Error when loading project file '%1': %2 " ).arg( path, prj->error() ),
65 QgsProject::setInstance( mProjectCache[ path ] );
66 return mProjectCache[ path ];
69 QDomDocument *QgsConfigCache::xmlDocument(
const QString &filePath )
72 QFile configFile( filePath );
73 if ( !configFile.exists() )
79 if ( !configFile.open( QIODevice::ReadOnly ) )
86 QDomDocument *xmlDoc = mXmlDocumentCache.object( filePath );
90 xmlDoc =
new QDomDocument();
93 if ( !xmlDoc->setContent( &configFile,
true, &errorMsg, &line, &column ) )
96 QStringLiteral(
"': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), QStringLiteral(
"Server" ),
Qgis::Critical );
100 mXmlDocumentCache.insert( filePath, xmlDoc );
101 mFileSystemWatcher.addPath( filePath );
102 xmlDoc = mXmlDocumentCache.object( filePath );
108 void QgsConfigCache::removeChangedEntry(
const QString &path )
110 mProjectCache.remove( path );
113 mXmlDocumentCache.remove( path );
115 mFileSystemWatcher.removePath( path );
121 removeChangedEntry( path );
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).
Reads and writes project states.
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.
QStringList badLayers() const
badLayers
static QgsConfigCache * instance()
Returns the current instance.