19 #include <QToolButton> 
   21 #include <QGridLayout> 
   24 #include <QRegularExpression> 
   25 #include <QProgressBar> 
   39 #define FILEPATH_VARIABLE "selected_file_path" 
   44   mProgressLabel = 
new QLabel( 
this );
 
   45   mLayout->addWidget( mProgressLabel );
 
   46   mProgressLabel->hide();
 
   48   mProgressBar = 
new QProgressBar( 
this );
 
   49   mLayout->addWidget( mProgressBar );
 
   52   mCancelButton = 
new QToolButton( 
this );
 
   53   mLayout->addWidget( mCancelButton );
 
   55   mCancelButton->hide();
 
   63     mExternalStorage = 
nullptr;
 
   68     if ( !mExternalStorage )
 
   87 void QgsExternalStorageFileWidget::updateAcceptDrops()
 
   89   setAcceptDrops( !
mReadOnly &&  mExternalStorage );
 
   94   return mExternalStorage ? mExternalStorage->
type() : QString();
 
   99   return mExternalStorage;
 
  114   mStorageUrlExpression.reset( 
new QgsExpression( urlExpression ) );
 
  119   return mStorageUrlExpression.get();
 
  124   return mStorageUrlExpression ? mStorageUrlExpression->expression() : QString();
 
  131   mExpressionContext = context;
 
  137   if ( !mExternalStorage || mScope )
 
  141   mExpressionContext << mScope;
 
  149                         QString(), 
true, 
false, tr( 
"User selected absolute filepath" ) ) );
 
  155   return mExpressionContext;
 
  171   mProgressLabel->setVisible( mStoreInProgress );
 
  172   mProgressBar->setVisible( mStoreInProgress );
 
  173   mCancelButton->setVisible( mStoreInProgress );
 
  177   mLineEdit->setVisible( !mStoreInProgress && !linkVisible );
 
  178   mLinkLabel->setVisible( !mStoreInProgress && linkVisible );
 
  192   Q_ASSERT( fileNames.count() );
 
  195   if ( mExternalStorage )
 
  197     if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
 
  202                                    tr( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  205       QgsDebugMsg( tr( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  209     storeExternalFiles( fileNames );
 
  217 void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QStringList storedUrls )
 
  219   if ( fileNames.isEmpty() )
 
  222   const QString 
filePath = fileNames.takeFirst();
 
  224   mProgressLabel->setText( tr( 
"Storing file %1 ..." ).arg( QFileInfo( 
filePath ).fileName() ) );
 
  225   mStoreInProgress = 
true;
 
  226   mProgressBar->setValue( 0 );
 
  232   QVariant url = mStorageUrlExpression->evaluate( &mExpressionContext );
 
  233   if ( !url.isValid() )
 
  238                                  tr( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  241     mStoreInProgress = 
false;
 
  252   auto onStoreFinished = [ = ]
 
  254     mStoreInProgress = 
false;
 
  256     storedContent->deleteLater();
 
  261                                  tr( 
"Storing file '%1' to url '%2' has failed : %3" ).arg( 
filePath, url.toString(), storedContent->
errorString() ) );
 
  267     QStringList newStoredUrls = storedUrls;
 
  268     newStoredUrls << storedContent->
url();
 
  271     if ( fileNames.isEmpty() )
 
  276       storeExternalFiles( fileNames, newStoredUrls );
 
  283   storedContent->
store();
 
  288   const QStringList filePaths = 
mLineEdit->acceptableFilePaths( event );
 
  289   if ( !filePaths.isEmpty() )
 
  291     event->acceptProposedAction();
 
  301   storeExternalFiles( 
mLineEdit->acceptableFilePaths( event ) );
 
  302   event->acceptProposedAction();
 
@ Finished
Content fetching/storing is finished and successful.
@ Failed
Content fetching/storing has failed.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsExternalStorageRegistry * externalStorageRegistry()
Returns registry of available external storage implementations.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
void canceled()
The signal is emitted when content fetching/storing has been canceled.
void progressChanged(double progress)
The signal is emitted whenever content fetching/storing estimated progression value progress has chan...
void errorOccurred(const QString &errorString)
The signal is emitted when an error occurred.
Qgis::ContentStatus status() const
Returns content status.
virtual void cancel()
Cancels content fetching/storing.
const QString & errorString() const
Returns error textual description if an error occurred and status() returns Failed.
QgsExternalStorage * externalStorageFromType(const QString &type) const
Returns external storage implementation if the storage type matches one.
Class for QgsExternalStorage stored content.
void stored()
The signal is emitted when the resource has successfully been stored.
virtual QString url() const =0
Returns stored resource URL.
virtual void store()=0
Starts storing.
Abstract interface for external storage - to be implemented by various backends and registered in Qgs...
virtual QString type() const =0
Unique identifier of the external storage type.
QgsExternalStorageStoredContent * store(const QString &filePath, const QString &url, const QString &authCfg=QString(), Qgis::ActionStart storingMode=Qgis::ActionStart::Deferred) const
Stores file filePath to the url for this project external storage.
A bar for displaying non-blocking messages to the user.
void pushWarning(const QString &title, const QString &message)
Pushes a warning message that must be manually dismissed by the user.
Single variable definition for use within a QgsExpressionContextScope.