mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
allow to use remote content for init code file path in attribute form
This commit is contained in:
parent
e47d55f6e3
commit
493d9c68a2
@ -242,6 +242,13 @@ void QgsEditFormConfig::setInitFilePath( const QString &filePath )
|
||||
{
|
||||
d.detach();
|
||||
d->mInitFilePath = filePath;
|
||||
|
||||
// if this is an URL, download file as there is a good chance it will be used later
|
||||
if ( !filePath.isEmpty() && !QUrl::fromUserInput( filePath ).isLocalFile() )
|
||||
{
|
||||
// any existing download will not be restarted!
|
||||
QgsApplication::instance()->networkContentFetcherRegistry()->fetch( filePath, QgsNetworkContentFetcherRegistry::DownloadImmediately );
|
||||
}
|
||||
}
|
||||
|
||||
QgsEditFormConfig::PythonInitCodeSource QgsEditFormConfig::initCodeSource() const
|
||||
|
@ -1712,16 +1712,16 @@ void QgsAttributeForm::initPython()
|
||||
switch ( mLayer->editFormConfig().initCodeSource() )
|
||||
{
|
||||
case QgsEditFormConfig::CodeSourceFile:
|
||||
if ( ! initFilePath.isEmpty() )
|
||||
if ( !initFilePath.isEmpty() )
|
||||
{
|
||||
QFile inputFile( initFilePath );
|
||||
QFile *inputFile = QgsApplication::instance()->networkContentFetcherRegistry()->localFile( initFilePath );
|
||||
|
||||
if ( inputFile.open( QFile::ReadOnly ) )
|
||||
if ( inputFile && inputFile->open( QFile::ReadOnly ) )
|
||||
{
|
||||
// Read it into a string
|
||||
QTextStream inf( &inputFile );
|
||||
QTextStream inf( inputFile );
|
||||
initCode = inf.readAll();
|
||||
inputFile.close();
|
||||
inputFile->close();
|
||||
}
|
||||
else // The file couldn't be opened
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user