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" ) ) );
151 return mExpressionContext;
167 mProgressLabel->setVisible( mStoreInProgress );
168 mProgressBar->setVisible( mStoreInProgress );
169 mCancelButton->setVisible( mStoreInProgress );
173 mLineEdit->setVisible( !mStoreInProgress && !linkVisible );
174 mLinkLabel->setVisible( !mStoreInProgress && linkVisible );
188 Q_ASSERT( fileNames.count() );
191 if ( mExternalStorage )
193 if ( !mStorageUrlExpression->prepare( &mExpressionContext ) )
198 tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
201 QgsDebugError( QStringLiteral(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
205 storeExternalFiles( fileNames );
213void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QStringList storedUrls )
215 if ( fileNames.isEmpty() )
218 const QString
filePath = fileNames.takeFirst();
220 mProgressLabel->setText( tr(
"Storing file %1 ..." ).arg( QFileInfo(
filePath ).fileName() ) );
221 mStoreInProgress =
true;
222 mProgressBar->setValue( 0 );
228 QVariant url = mStorageUrlExpression->evaluate( &mExpressionContext );
229 if ( !url.isValid() )
234 tr(
"Storage URL expression is invalid : %1" ).arg( mStorageUrlExpression->evalErrorString() ) );
237 mStoreInProgress =
false;
248 auto onStoreFinished = [ = ]
250 mStoreInProgress =
false;
252 storedContent->deleteLater();
257 tr(
"Storing file '%1' to url '%2' has failed : %3" ).arg(
filePath, url.toString(), storedContent->
errorString() ) );
263 QStringList newStoredUrls = storedUrls;
264 newStoredUrls << storedContent->
url();
267 if ( fileNames.isEmpty() )
272 storeExternalFiles( fileNames, newStoredUrls );
279 storedContent->
store();
284 const QStringList filePaths =
mLineEdit->acceptableFilePaths( event );
285 if ( !filePaths.isEmpty() )
287 event->acceptProposedAction();
297 storeExternalFiles(
mLineEdit->acceptableFilePaths( event ) );
298 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.