Skip to content
Permalink
Browse files

Use messagebar for binary extraction feedback

  • Loading branch information
nyalldawson committed Nov 11, 2018
1 parent 2819a07 commit 9f1d00d92ebe108938d877d8c9ff4af92fa26728
@@ -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()
@@ -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
@@ -19,6 +19,8 @@
#include "qgseditorwidgetfactory.h"
#include "qgis_gui.h"

class QgsMessageBar;

SIP_NO_FILE

/**
@@ -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
@@ -18,6 +18,7 @@
#include "qgsvectordataprovider.h"
#include "qgsfileutils.h"
#include "qgssettings.h"
#include "qgsmessagebar.h"
#include <QHBoxLayout>
#include <QFileDialog>
#include <QLabel>
@@ -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 )
{
}

@@ -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()
@@ -21,6 +21,7 @@

class QLabel;
class QToolButton;
class QgsMessageBar;

SIP_NO_FILE

@@ -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:
@@ -73,6 +74,8 @@ class GUI_EXPORT QgsBinaryWidgetWrapper : public QgsEditorWidgetWrapper

QByteArray mValue;

QgsMessageBar *mMessageBar = nullptr;

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

0 comments on commit 9f1d00d

Please sign in to comment.
You can’t perform that action at this time.