24#include <QRegularExpression>
25#include <QProgressBar>
34#define FILEPATH_VARIABLE "selected_file_path"
39 mProgressLabel =
new QLabel(
this );
40 mLayout->addWidget( mProgressLabel );
41 mProgressLabel->hide();
43 mProgressBar =
new QProgressBar(
this );
44 mLayout->addWidget( mProgressBar );
47 mCancelButton =
new QToolButton(
this );
48 mLayout->addWidget( mCancelButton );
50 mCancelButton->hide();
58 mExternalStorage =
nullptr;
63 if ( !mExternalStorage )
82void QgsExternalStorageFileWidget::updateAcceptDrops()
84 setAcceptDrops( !
mReadOnly && mExternalStorage );
89 return mExternalStorage ? mExternalStorage->
type() : QString();
94 return mExternalStorage;
109 mStorageUrlExpression.reset(
new QgsExpression( urlExpression ) );
114 return mStorageUrlExpression.get();
119 return mStorageUrlExpression ? mStorageUrlExpression->expression() : QString();
126 mExpressionContext = context;
132 if ( !mExternalStorage || mScope )
136 mExpressionContext << mScope;
144 QString(),
true,
false, tr(
"User selected absolute filepath" ) ) );
150 return mExpressionContext;
166 mProgressLabel->setVisible( mStoreInProgress );
167 mProgressBar->setVisible( mStoreInProgress );
168 mCancelButton->setVisible( mStoreInProgress );
172 mLineEdit->setVisible( !mStoreInProgress && !linkVisible );
173 mLinkLabel->setVisible( !mStoreInProgress && linkVisible );
187 Q_ASSERT( fileNames.count() );
190 if ( mExternalStorage )
192 if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
197 tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
200 QgsDebugError( QStringLiteral(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
204 storeExternalFiles( fileNames );
212void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QStringList storedUrls )
214 if ( fileNames.isEmpty() )
217 const QString
filePath = fileNames.takeFirst();
219 mProgressLabel->setText( tr(
"Storing file %1 ..." ).arg( QFileInfo(
filePath ).fileName() ) );
220 mStoreInProgress =
true;
221 mProgressBar->setValue( 0 );
227 QVariant url = mStorageUrlExpression->evaluate( &mExpressionContext );
228 if ( !url.isValid() )
233 tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
236 mStoreInProgress =
false;
247 auto onStoreFinished = [ = ]
249 mStoreInProgress =
false;
251 storedContent->deleteLater();
256 tr(
"Storing file '%1' to url '%2' has failed : %3" ).arg(
filePath, url.toString(), storedContent->
errorString() ) );
262 QStringList newStoredUrls = storedUrls;
263 newStoredUrls << storedContent->
url();
266 if ( fileNames.isEmpty() )
271 storeExternalFiles( fileNames, newStoredUrls );
278 storedContent->
store();
283 const QStringList filePaths =
mLineEdit->acceptableFilePaths( event );
284 if ( !filePaths.isEmpty() )
286 event->acceptProposedAction();
296 storeExternalFiles(
mLineEdit->acceptableFilePaths( event ) );
297 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.