allow to use remote content for init code file path in attribute form

This commit is contained in:
Denis Rouzaud 2019-09-26 07:53:13 +02:00
parent e47d55f6e3
commit 493d9c68a2
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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
{