17#include "moc_qgsexternalstoragefilewidget.cpp" 
   25#include <QRegularExpression> 
   26#include <QProgressBar> 
   35#define FILEPATH_VARIABLE "selected_file_path" 
   40  mProgressLabel = 
new QLabel( 
this );
 
   41  mLayout->addWidget( mProgressLabel );
 
   42  mProgressLabel->hide();
 
   44  mProgressBar = 
new QProgressBar( 
this );
 
   45  mLayout->addWidget( mProgressBar );
 
   48  mCancelButton = 
new QToolButton( 
this );
 
   49  mLayout->addWidget( mCancelButton );
 
   51  mCancelButton->hide();
 
 
   59    mExternalStorage = 
nullptr;
 
   64    if ( !mExternalStorage )
 
 
   83void QgsExternalStorageFileWidget::updateAcceptDrops()
 
   85  setAcceptDrops( !
mReadOnly && mExternalStorage );
 
   90  return mExternalStorage ? mExternalStorage->
type() : QString();
 
 
   95  return mExternalStorage;
 
 
  110  mStorageUrlExpression.reset( 
new QgsExpression( urlExpression ) );
 
 
  115  return mStorageUrlExpression.get();
 
 
  120  return mStorageUrlExpression ? mStorageUrlExpression->expression() : QString();
 
 
  127  mExpressionContext = context;
 
 
  133  if ( !mExternalStorage || mScope )
 
  137  mExpressionContext << mScope;
 
 
  145    QString(), 
true, 
false, tr( 
"User selected absolute filepath" )
 
 
  152  return mExpressionContext;
 
 
  168  mProgressLabel->setVisible( mStoreInProgress );
 
  169  mProgressBar->setVisible( mStoreInProgress );
 
  170  mCancelButton->setVisible( mStoreInProgress );
 
  174  mLineEdit->setVisible( !mStoreInProgress && !linkVisible );
 
  175  mLinkLabel->setVisible( !mStoreInProgress && linkVisible );
 
 
  187  Q_ASSERT( fileNames.count() );
 
  190  if ( mExternalStorage )
 
  192    if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
 
  196        messageBar()->
pushWarning( tr( 
"Storing External resource" ), tr( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  199      QgsDebugError( QStringLiteral( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  203    storeExternalFiles( fileNames );
 
 
  211void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QStringList storedUrls )
 
  213  if ( fileNames.isEmpty() )
 
  216  const QString 
filePath = fileNames.takeFirst();
 
  218  mProgressLabel->setText( tr( 
"Storing file %1 ..." ).arg( QFileInfo( 
filePath ).fileName() ) );
 
  219  mStoreInProgress = 
true;
 
  220  mProgressBar->setValue( 0 );
 
  226  QVariant url = mStorageUrlExpression->evaluate( &mExpressionContext );
 
  227  if ( !url.isValid() )
 
  231      messageBar()->
pushWarning( tr( 
"Storing External resource" ), tr( 
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
 
  234    mStoreInProgress = 
false;
 
  245  auto onStoreFinished = [
this, storedContent, fileNames, storedUrls, 
filePath, url] {
 
  246    mStoreInProgress = 
false;
 
  248    storedContent->deleteLater();
 
  258    QStringList newStoredUrls = storedUrls;
 
  259    newStoredUrls << storedContent->
url();
 
  262    if ( fileNames.isEmpty() )
 
  267      storeExternalFiles( fileNames, newStoredUrls );
 
  274  storedContent->
store();
 
  279  const QStringList filePaths = 
mLineEdit->acceptableFilePaths( event );
 
  280  if ( !filePaths.isEmpty() )
 
  282    event->acceptProposedAction();
 
 
  292  storeExternalFiles( 
mLineEdit->acceptableFilePaths( event ) );
 
  293  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.
 
#define QgsDebugError(str)
 
Single variable definition for use within a QgsExpressionContextScope.