QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsexternalstoragefilewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexternalstoragefilewidget.h
3  --------------------------------------
4  Date : August 2021
5  Copyright : (C) 2021 by Julien Cabieces
6  Email : julien dot cabieces at oslandia dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSEXTERNALSTORAGEFILEWIDGET_H
17 #define QGSEXTERNALSTORAGEFILEWIDGET_H
18 
19 class QLabel;
20 class QToolButton;
21 class QVariant;
22 class QHBoxLayout;
23 class QProgressBar;
24 class QgsExternalStorage;
25 class QgsMessageBar;
26 
27 #include <QWidget>
28 #include <QFileDialog>
29 
30 #include "qgsfilewidget.h"
31 #include "qgsexpressioncontext.h"
32 
40 {
41 
42 #ifdef SIP_RUN
44  if ( qobject_cast<QgsExternalStorageFileWidget *>( sipCpp ) )
45  sipType = sipType_QgsExternalStorageFileWidget;
46  else
47  sipType = NULL;
48  SIP_END
49 #endif
50 
51  Q_OBJECT
52  Q_PROPERTY( QString storageType READ storageType WRITE setStorageType )
53  Q_PROPERTY( QString auth READ storageAuthConfigId WRITE setStorageAuthConfigId )
54  Q_PROPERTY( QString storageUrlExpression READ storageUrlExpressionString WRITE setStorageUrlExpression )
55 
56  public:
57 
61  explicit QgsExternalStorageFileWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
62 
71  void setStorageType( const QString &storageType );
72 
79  QString storageType() const;
80 
88  QgsExternalStorage *externalStorage() const;
89 
95  void setStorageAuthConfigId( const QString &authCfg );
96 
101  const QString &storageAuthConfigId() const;
102 
109  void setStorageUrlExpression( const QString &urlExpression );
110 
118  QString storageUrlExpressionString() const;
119 
127  QgsExpression *storageUrlExpression() const;
128 
134  void setExpressionContext( const QgsExpressionContext &context );
135 
141  const QgsExpressionContext &expressionContext() const;
142 
147  void setMessageBar( QgsMessageBar *messageBar );
148 
153  QgsMessageBar *messageBar() const;
154 
160  static QgsExpressionContextScope *createFileWidgetScope();
161 
162  void setReadOnly( bool readOnly ) override;
163 
164  protected:
165 
166  void updateLayout() override;
167 
168  void setSelectedFileNames( QStringList fileNames ) override;
169 
173  void addFileWidgetScope();
174 
175  void dragEnterEvent( QDragEnterEvent *event ) override;
176 
177  void dropEvent( QDropEvent *event ) override;
178 
179  private:
180 
181  // stores \a fileNames files using current external storage.
182  // This is a recursive method, \a storedUrls contains urls for previously stored
183  // fileNames. When all files have been successfully stored, current mFilePath
184  // is updated
185  void storeExternalFiles( QStringList fileNames, QStringList storedUrls = QStringList() );
186 
188  void updateAcceptDrops();
189 
190  bool mStoreInProgress = false;
191 
192  QgsExternalStorage *mExternalStorage = nullptr;
193  QString mAuthCfg;
194  std::unique_ptr< QgsExpression > mStorageUrlExpression;
195  QgsExpressionContext mExpressionContext;
196  QgsExpressionContextScope *mScope = nullptr;
197 
198  QLabel *mProgressLabel = nullptr;
199  QProgressBar *mProgressBar = nullptr;
200  QToolButton *mCancelButton = nullptr;
201  QgsMessageBar *mMessageBar = nullptr;
202 
203  friend class TestQgsExternalResourceWidgetWrapper;
204  friend class TestQgsExternalStorageFileWidget;
205 };
206 
207 #endif // QGSEXTERNALSTORAGEFILEWIDGET_H
Single scope for storing variables and functions for use within a QgsExpressionContext.
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").
The QgsExternalStorageFileWidget class creates a widget for selecting a file or a folder and stores i...
Abstract interface for external storage - to be implemented by various backends and registered in Qgs...
The QgsFileWidget class creates a widget for selecting a file or a folder.
Definition: qgsfilewidget.h:39
virtual void setSelectedFileNames(QStringList fileNames)
Called whenever user select fileNames from dialog.
virtual void setReadOnly(bool readOnly)
Sets whether the widget should be read only.
virtual void updateLayout()
Update buttons visibility.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:194