Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use messagebar for binary extraction feedback
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent 2819a07 commit 9f1d00d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -64,7 +64,7 @@ void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBa
registerWidget( QStringLiteral( "ExternalResource" ), new QgsExternalResourceWidgetFactory( tr( "Attachment" ) ) );
registerWidget( QStringLiteral( "KeyValue" ), new QgsKeyValueWidgetFactory( tr( "Key/Value" ) ) );
registerWidget( QStringLiteral( "List" ), new QgsListWidgetFactory( tr( "List" ) ) );
registerWidget( QStringLiteral( "Binary" ), new QgsBinaryWidgetFactory( tr( "Binary (BLOB)" ) ) );
registerWidget( QStringLiteral( "Binary" ), new QgsBinaryWidgetFactory( tr( "Binary (BLOB)" ), messageBar ) );
}

QgsEditorWidgetRegistry::~QgsEditorWidgetRegistry()
Expand Down
5 changes: 3 additions & 2 deletions src/gui/editorwidgets/qgsbinarywidgetfactory.cpp
Expand Up @@ -20,14 +20,15 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

QgsBinaryWidgetFactory::QgsBinaryWidgetFactory( const QString &name )
QgsBinaryWidgetFactory::QgsBinaryWidgetFactory( const QString &name, QgsMessageBar *messageBar )
: QgsEditorWidgetFactory( name )
, mMessageBar( messageBar )
{
}

QgsEditorWidgetWrapper *QgsBinaryWidgetFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
{
return new QgsBinaryWidgetWrapper( vl, fieldIdx, editor, parent );
return new QgsBinaryWidgetWrapper( vl, fieldIdx, editor, parent, mMessageBar );
}

QgsEditorConfigWidget *QgsBinaryWidgetFactory::configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const
Expand Down
11 changes: 10 additions & 1 deletion src/gui/editorwidgets/qgsbinarywidgetfactory.h
Expand Up @@ -19,6 +19,8 @@
#include "qgseditorwidgetfactory.h"
#include "qgis_gui.h"

class QgsMessageBar;

SIP_NO_FILE

/**
Expand All @@ -36,15 +38,22 @@ class GUI_EXPORT QgsBinaryWidgetFactory : public QgsEditorWidgetFactory
/**
* Constructor for QgsBinaryWidgetFactory, where \a name is a human-readable
* name for the factory.
*
* The \a messageBar argument can be used to link the widget to a QgsMessageBar
* for providing user feedback.
*/
explicit QgsBinaryWidgetFactory( const QString &name );
explicit QgsBinaryWidgetFactory( const QString &name, QgsMessageBar *messageBar );

// QgsEditorWidgetFactory interface
public:
QgsEditorWidgetWrapper *create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const override;
QgsEditorConfigWidget *configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const override;

unsigned int fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const override;

private:

QgsMessageBar *mMessageBar = nullptr;
};

#endif // QGSBINARYWIDGETFACTORY_H
9 changes: 7 additions & 2 deletions src/gui/editorwidgets/qgsbinarywidgetwrapper.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsvectordataprovider.h"
#include "qgsfileutils.h"
#include "qgssettings.h"
#include "qgsmessagebar.h"
#include <QHBoxLayout>
#include <QFileDialog>
#include <QLabel>
Expand All @@ -26,9 +27,9 @@
#include <QMenu>
#include <QMessageBox>

QgsBinaryWidgetWrapper::QgsBinaryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent )
QgsBinaryWidgetWrapper::QgsBinaryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent, QgsMessageBar *messageBar )
: QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )

, mMessageBar( messageBar )
{
}

Expand Down Expand Up @@ -149,6 +150,10 @@ void QgsBinaryWidgetWrapper::saveContent()
fileOut.open( QIODevice::WriteOnly );
fileOut.write( mValue );
fileOut.close();

if ( mMessageBar )
mMessageBar->pushSuccess( QString(), tr( "Saved content to <a href=\"%1\">%2</a>" ).arg(
QUrl::fromLocalFile( file ).toString(), QDir::toNativeSeparators( file ) ) );
}

void QgsBinaryWidgetWrapper::setContent()
Expand Down
5 changes: 4 additions & 1 deletion src/gui/editorwidgets/qgsbinarywidgetwrapper.h
Expand Up @@ -21,6 +21,7 @@

class QLabel;
class QToolButton;
class QgsMessageBar;

SIP_NO_FILE

Expand All @@ -46,7 +47,7 @@ class GUI_EXPORT QgsBinaryWidgetWrapper : public QgsEditorWidgetWrapper
*
* A \a parent widget for this widget wrapper and the created widget can also be specified.
*/
explicit QgsBinaryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor = nullptr, QWidget *parent = nullptr );
explicit QgsBinaryWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor = nullptr, QWidget *parent = nullptr, QgsMessageBar *messageBar = nullptr );

// QgsEditorWidgetWrapper interface
public:
Expand All @@ -73,6 +74,8 @@ class GUI_EXPORT QgsBinaryWidgetWrapper : public QgsEditorWidgetWrapper

QByteArray mValue;

QgsMessageBar *mMessageBar = nullptr;

QLabel *mLabel = nullptr;
QToolButton *mButton = nullptr;
QAction *mSetAction = nullptr;
Expand Down

0 comments on commit 9f1d00d

Please sign in to comment.