31#include <QProgressBar>
32#include <QRegularExpression>
36#include "moc_qgsexternalstoragefilewidget.cpp"
38#define FILEPATH_VARIABLE "selected_file_path"
43 mProgressLabel =
new QLabel(
this );
44 mLayout->addWidget( mProgressLabel );
45 mProgressLabel->hide();
47 mProgressBar =
new QProgressBar(
this );
48 mLayout->addWidget( mProgressBar );
51 mCancelButton =
new QToolButton(
this );
52 mLayout->addWidget( mCancelButton );
54 mCancelButton->hide();
62 mExternalStorage =
nullptr;
67 if ( !mExternalStorage )
86void QgsExternalStorageFileWidget::updateAcceptDrops()
88 setAcceptDrops( !
mReadOnly && mExternalStorage );
93 return mExternalStorage ? mExternalStorage->type() : QString();
98 return mExternalStorage;
113 mStorageUrlExpression = std::make_unique<QgsExpression>( urlExpression );
118 return mStorageUrlExpression.get();
123 return mStorageUrlExpression ? mStorageUrlExpression->
expression() : QString();
130 mExpressionContext = context;
136 if ( !mExternalStorage || mScope )
140 mExpressionContext << mScope;
148 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 );
190 Q_ASSERT( fileNames.count() );
193 if ( mExternalStorage )
195 if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
199 messageBar()->
pushWarning( tr(
"Storing External resource" ), tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
202 QgsDebugError( QStringLiteral(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
206 storeExternalFiles( fileNames );
214void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QStringList storedUrls )
216 if ( fileNames.isEmpty() )
219 const QString
filePath = fileNames.takeFirst();
221 mProgressLabel->setText( tr(
"Storing file %1 ..." ).arg( QFileInfo(
filePath ).fileName() ) );
222 mStoreInProgress =
true;
223 mProgressBar->setValue( 0 );
229 QVariant url = mStorageUrlExpression->evaluate( &mExpressionContext );
230 if ( !url.isValid() )
234 messageBar()->
pushWarning( tr(
"Storing External resource" ), tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
237 mStoreInProgress =
false;
243 QgsExternalStorageStoredContent *storedContent = mExternalStorage->store(
filePath, url.toString(), mAuthCfg );
248 auto onStoreFinished = [
this, storedContent, fileNames, storedUrls,
filePath, url] {
249 mStoreInProgress =
false;
251 storedContent->deleteLater();
261 QStringList newStoredUrls = storedUrls;
262 newStoredUrls << storedContent->
url();
265 if ( fileNames.isEmpty() )
270 storeExternalFiles( fileNames, newStoredUrls );
277 storedContent->
store();
282 const QStringList filePaths =
mLineEdit->acceptableFilePaths( event );
283 if ( !filePaths.isEmpty() )
285 event->acceptProposedAction();
295 storeExternalFiles(
mLineEdit->acceptableFilePaths( event ) );
296 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...
Handles parsing and evaluation of expressions (formerly called "search strings").
QString expression() const
Returns the original, unmodified expression string.
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.
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...
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.