31#include <QProgressBar>
32#include <QRegularExpression>
37#include "moc_qgsexternalstoragefilewidget.cpp"
39using namespace Qt::StringLiterals;
41#define FILEPATH_VARIABLE "selected_file_path"
46 mProgressLabel =
new QLabel(
this );
47 mLayout->addWidget( mProgressLabel );
48 mProgressLabel->hide();
50 mProgressBar =
new QProgressBar(
this );
51 mLayout->addWidget( mProgressBar );
54 mCancelButton =
new QToolButton(
this );
55 mLayout->addWidget( mCancelButton );
57 mCancelButton->hide();
65 mExternalStorage =
nullptr;
70 if ( !mExternalStorage )
89void QgsExternalStorageFileWidget::updateAcceptDrops()
91 setAcceptDrops( !
mReadOnly && mExternalStorage );
96 return mExternalStorage ? mExternalStorage->type() : QString();
101 return mExternalStorage;
116 mStorageUrlExpression = std::make_unique<QgsExpression>( urlExpression );
121 return mStorageUrlExpression.get();
126 return mStorageUrlExpression ? mStorageUrlExpression->
expression() : QString();
133 mExpressionContext = context;
139 if ( !mExternalStorage || mScope )
143 mExpressionContext << mScope;
151 QString(),
true,
false, tr(
"User selected absolute filepath" )
158 return mExpressionContext;
174 mProgressLabel->setVisible( mStoreInProgress );
175 mProgressBar->setVisible( mStoreInProgress );
176 mCancelButton->setVisible( mStoreInProgress );
180 mLineEdit->setVisible( !mStoreInProgress && !linkVisible );
181 mLinkLabel->setVisible( !mStoreInProgress && linkVisible );
193 Q_ASSERT( fileNames.count() );
196 if ( mExternalStorage )
198 if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
202 messageBar()->
pushWarning( tr(
"Storing External resource" ), tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
205 QgsDebugError( u
"Storage URL expression is invalid : %1"_s.arg( mStorageUrlExpression->evalErrorString() ) );
209 storeExternalFiles( fileNames );
217void 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() )
237 messageBar()->
pushWarning( tr(
"Storing External resource" ), tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
240 mStoreInProgress =
false;
246 QgsExternalStorageStoredContent *storedContent = mExternalStorage->store(
filePath, url.toString(), mAuthCfg );
251 auto onStoreFinished = [
this, storedContent, fileNames, storedUrls,
filePath, url] {
252 mStoreInProgress =
false;
254 storedContent->deleteLater();
264 QStringList newStoredUrls = storedUrls;
265 newStoredUrls << storedContent->
url();
268 if ( fileNames.isEmpty() )
273 storeExternalFiles( fileNames, newStoredUrls );
280 storedContent->
store();
285 const QStringList filePaths =
mLineEdit->acceptableFilePaths( event );
286 if ( !filePaths.isEmpty() )
288 event->acceptProposedAction();
298 storeExternalFiles(
mLineEdit->acceptableFilePaths( event ) );
299 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.