Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #44533 from troopa81/feat_dms_connexion_widget
[ExternalStorage] Add widget to configure/edit and visualize external storage
  • Loading branch information
3nids committed Aug 16, 2021
2 parents 7b7323c + 7d89628 commit a0507ee
Show file tree
Hide file tree
Showing 30 changed files with 2,978 additions and 131 deletions.
Expand Up @@ -29,6 +29,12 @@ and registered in :py:class:`QgsExternalStorageRegistry`.
virtual QString type() const = 0;
%Docstring
Unique identifier of the external storage type.
%End

virtual QString displayName() const = 0;
%Docstring
Returns the translated external storage name, which should be used for any
user-visible display of the external storage name.
%End

QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authCfg = QString(), Qgis::ActionStart storingMode = Qgis::ActionStart::Deferred ) const /Factory/;
Expand Down
Expand Up @@ -51,7 +51,8 @@ changed status of the widget will be saved.
enum Property
{
RootPath,
DocumentViewerContent
DocumentViewerContent,
StorageUrl
};

static const QgsPropertiesDefinition &propertyDefinitions();
Expand Down
55 changes: 53 additions & 2 deletions python/gui/auto_generated/qgsexternalresourcewidget.sip.in
Expand Up @@ -16,6 +16,8 @@
// doesn't add this include to the file where the code from
// ConvertToSubClassCode goes.
#include <qgsexternalresourcewidget.h>

#include <qgsexternalstoragefilewidget.h>
%End


Expand Down Expand Up @@ -59,9 +61,9 @@ documentPath returns the path of the current document in the widget
%End
void setDocumentPath( const QVariant &documentPath );

QgsFileWidget *fileWidget();
QgsExternalStorageFileWidget *fileWidget();
%Docstring
access the file widget to allow its configuration
Returns file widget to allow its configuration
%End

bool fileWidgetVisible() const;
Expand Down Expand Up @@ -133,6 +135,55 @@ is set to :py:class:`QgsFileWidget`.RelativeDefaultPath.
%Docstring
Configures the base path which should be used if the relativeStorage property
is set to :py:class:`QgsFileWidget`.RelativeDefaultPath.
%End

void setStorageType( const QString &storageType );
%Docstring
Set ``storageType`` storage type unique identifier as defined in :py:class:`QgsExternalStorageRegistry` or
null QString if there is no storage defined, only file selection.

.. seealso:: :py:func:`storageType`

.. versionadded:: 3.22
%End

QString storageType() const;
%Docstring
Returns storage type unique identifier as defined in :py:class:`QgsExternalStorageRegistry`.
Returns null QString if there is no storage defined, only file selection.

.. seealso:: :py:func:`setStorageType`

.. versionadded:: 3.22
%End

void setStorageAuthConfigId( const QString &authCfg );
%Docstring
Sets the authentication configuration ID to be used for the current external storage (if
defined)

.. versionadded:: 3.22
%End

QString storageAuthConfigId() const;
%Docstring
Returns the authentication configuration ID used for the current external storage (if defined)

.. versionadded:: 3.22
%End

void setMessageBar( QgsMessageBar *messageBar );
%Docstring
Set ``messageBar`` to report messages

.. versionadded:: 3.22
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns message bar used to report messages

.. versionadded:: 3.22
%End

signals:
Expand Down
179 changes: 179 additions & 0 deletions python/gui/auto_generated/qgsexternalstoragefilewidget.sip.in
@@ -0,0 +1,179 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsexternalstoragefilewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsExternalStorageFileWidget : QgsFileWidget
{
%Docstring(signature="appended")
The :py:class:`QgsExternalStorageFileWidget` class creates a widget for selecting a file or a folder
and stores it to a given external storage backend if defined

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsexternalstoragefilewidget.h"
%End
%ConvertToSubClassCode
if ( qobject_cast<QgsExternalStorageFileWidget *>( sipCpp ) )
sipType = sipType_QgsExternalStorageFileWidget;
else
sipType = NULL;
%End
public:

explicit QgsExternalStorageFileWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
QgsExternalStorageFileWidget creates a widget for selecting a file or a folder.
%End

void setStorageType( const QString &storageType );
%Docstring
Set ``storageType`` storage type unique identifier as defined in :py:class:`QgsExternalStorageRegistry` or
null QString if there is no storage defined.
If no external storage has been defined, QgsExternalStorageFileWidget will only update file path according to
selected files.

.. seealso:: :py:func:`storageType`

.. versionadded:: 3.22
%End

QString storageType() const;
%Docstring
Returns storage type unique identifier as defined in :py:class:`QgsExternalStorageRegistry`.
Returns null QString if there is no storage defined, only file selection.

.. seealso:: :py:func:`setStorageType`

.. versionadded:: 3.22
%End

QgsExternalStorage *externalStorage() const;
%Docstring
Returns external storage used to store selected file names, None if none have been defined.
If no external storage has been defined, QgsExternalStorageFileWidget will only update file path according to
selected files.

.. seealso:: :py:func:`setStorageType`

.. versionadded:: 3.22
%End

void setStorageAuthConfigId( const QString &authCfg );
%Docstring
Sets the authentication configuration ID to be used for the current external storage (if
defined)

.. versionadded:: 3.22
%End

const QString &storageAuthConfigId() const;
%Docstring
Returns the authentication configuration ID used for the current external storage (if defined)

.. versionadded:: 3.22
%End

void setStorageUrlExpression( const QString &urlExpression );
%Docstring
Set ``urlExpression`` expression, which once evaluated, provide the URL used to store selected
documents. This is used only if an external storage has been defined

.. seealso:: :py:func:`setStorageType`

.. versionadded:: 3.22
%End

QString storageUrlExpressionString() const;
%Docstring
Returns the original, unmodified expression string, which once evaluated, provide the
URL used to store selected documents. This is used only if an external storage has been defined.
Returns null if no expression has been set.

.. seealso:: :py:func:`setStorageUrlExpression`

.. versionadded:: 3.22
%End

QgsExpression *storageUrlExpression() const;
%Docstring
Returns expression, which once evaluated, provide the URL used to store selected
documents. This is used only if an external storage has been defined.
Returns null if no expression has been set.

.. seealso:: :py:func:`setStorageUrlExpression`

.. versionadded:: 3.22
%End

void setExpressionContext( const QgsExpressionContext &context );
%Docstring
Set expression context to be used when for storage URL expression evaluation

.. seealso:: :py:func:`setStorageUrlExpression`

.. versionadded:: 3.22
%End

const QgsExpressionContext &expressionContext() const;
%Docstring
Returns expression context used for storage url expression evaluation

.. seealso:: :py:func:`storageUrlExpression`

.. versionadded:: 3.22
%End

void setMessageBar( QgsMessageBar *messageBar );
%Docstring
Set ``messageBar`` to report messages

.. versionadded:: 3.22
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns message bar used to report messages

.. versionadded:: 3.22
%End

static QgsExpressionContextScope *createFileWidgetScope();
%Docstring
Creates and Returns an expression context scope specific to QgsExternalStorageFileWidget
It defines the variable containing the user selected file name

.. versionadded:: 3.22
%End

protected:

virtual void updateLayout();


virtual void setSelectedFileNames( QStringList fileNames );


void addFileWidgetScope();
%Docstring
Add file widget specific scope to expression context
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsexternalstoragefilewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
36 changes: 36 additions & 0 deletions python/gui/auto_generated/qgsfilewidget.sip.in
Expand Up @@ -9,6 +9,8 @@





class QgsFileWidget : QWidget
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -257,6 +259,40 @@ the appearance and behavior of the line edit portion of the widget.
void fileChanged( const QString &path );
%Docstring
Emitted whenever the current file or directory ``path`` is changed.
%End

protected:

virtual void updateLayout();
%Docstring
Update buttons visibility
%End

virtual void setSelectedFileNames( QStringList fileNames );
%Docstring
Called whenever user select ``fileNames`` from dialog
%End

static bool isMultiFiles( const QString &path );
%Docstring
Returns true if ``path`` is a multifiles
%End

void setFilePaths( const QStringList &filePaths );
%Docstring
Update filePath according to ``filePaths`` list
%End



QString toUrl( const QString &path ) const;
%Docstring
returns a HTML code with a link to the given file path
%End

QString relativePath( const QString &filePath, bool removeRelative ) const;
%Docstring
Returns a filePath with relative path options applied (or not) !
%End

};
Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -80,6 +80,7 @@
%Include auto_generated/qgsfilecontentsourcelineedit.sip
%Include auto_generated/qgsfiledownloaderdialog.sip
%Include auto_generated/qgsfilewidget.sip
%Include auto_generated/qgsexternalstoragefilewidget.sip
%Include auto_generated/qgsfilterlineedit.sip
%Include auto_generated/qgsfindfilesbypatternwidget.sip
%Include auto_generated/qgsfloatingwidget.sip
Expand Down
6 changes: 6 additions & 0 deletions src/core/externalstorage/qgsexternalstorage.h
Expand Up @@ -47,6 +47,12 @@ class CORE_EXPORT QgsExternalStorage
*/
virtual QString type() const = 0;

/**
* Returns the translated external storage name, which should be used for any
* user-visible display of the external storage name.
*/
virtual QString displayName() const = 0;

/**
* Stores file \a filePath to the \a url for this project external storage.
* Storing process is run in background.
Expand Down
5 changes: 5 additions & 0 deletions src/core/externalstorage/qgssimplecopyexternalstorage.cpp
Expand Up @@ -100,6 +100,11 @@ QString QgsSimpleCopyExternalStorage::type() const
return QStringLiteral( "SimpleCopy" );
};

QString QgsSimpleCopyExternalStorage::displayName() const
{
return QObject::tr( "Simple copy" );
};

QgsExternalStorageStoredContent *QgsSimpleCopyExternalStorage::doStore( const QString &filePath, const QString &url, const QString &authcfg ) const
{
return new QgsSimpleCopyExternalStorageStoredContent( filePath, url, authcfg );
Expand Down
2 changes: 2 additions & 0 deletions src/core/externalstorage/qgssimplecopyexternalstorage_p.h
Expand Up @@ -40,6 +40,8 @@ class CORE_EXPORT QgsSimpleCopyExternalStorage : public QgsExternalStorage

QString type() const override;

QString displayName() const override;

QgsExternalStorageStoredContent *doStore( const QString &filePath, const QString &url, const QString &authcfg = QString() ) const override;

QgsExternalStorageFetchedContent *doFetch( const QString &url, const QString &authConfig = QString() ) const override;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -465,6 +465,7 @@ set(QGIS_GUI_SRCS
qgsfieldvalueslineedit.cpp
qgsfilecontentsourcelineedit.cpp
qgsfilewidget.cpp
qgsexternalstoragefilewidget.cpp
qgsfilterlineedit.cpp
qgsfindfilesbypatternwidget.cpp
qgsfloatingwidget.cpp
Expand Down Expand Up @@ -715,6 +716,7 @@ set(QGIS_GUI_HDRS
qgsfilecontentsourcelineedit.h
qgsfiledownloaderdialog.h
qgsfilewidget.h
qgsexternalstoragefilewidget.h
qgsfilterlineedit.h
qgsfindfilesbypatternwidget.h
qgsfloatingwidget.h
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -63,7 +63,7 @@ void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBa
registerWidget( QStringLiteral( "Color" ), new QgsColorWidgetFactory( tr( "Color" ) ) );
registerWidget( QStringLiteral( "RelationReference" ), new QgsRelationReferenceFactory( tr( "Relation Reference" ), mapCanvas, messageBar ) );
registerWidget( QStringLiteral( "DateTime" ), new QgsDateTimeEditFactory( tr( "Date/Time" ) ) );
registerWidget( QStringLiteral( "ExternalResource" ), new QgsExternalResourceWidgetFactory( tr( "Attachment" ) ) );
registerWidget( QStringLiteral( "ExternalResource" ), new QgsExternalResourceWidgetFactory( tr( "Attachment" ), messageBar ) );
registerWidget( QStringLiteral( "KeyValue" ), new QgsKeyValueWidgetFactory( tr( "Key/Value" ) ) );
registerWidget( QStringLiteral( "List" ), new QgsListWidgetFactory( tr( "List" ) ) );
registerWidget( QStringLiteral( "Binary" ), new QgsBinaryWidgetFactory( tr( "Binary (BLOB)" ), messageBar ) );
Expand Down

0 comments on commit a0507ee

Please sign in to comment.