QGIS API Documentation  3.6.0-Noosa (5873452)
qgsbinarywidgetfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbinarywidgetfactory.cpp
3  -------------------------
4  Date : November 2018
5  Copyright : (C) 2018 Nyall Dawson
6  Email : nyall dot dawson at gmail 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 #include "qgsbinarywidgetfactory.h"
17 
18 #include "qgsbinarywidgetwrapper.h"
19 #include "qgsdummyconfigdlg.h"
20 #include "qgsvectorlayer.h"
21 #include "qgsvectordataprovider.h"
22 
24  : QgsEditorWidgetFactory( name )
25  , mMessageBar( messageBar )
26 {
27 }
28 
29 QgsEditorWidgetWrapper *QgsBinaryWidgetFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
30 {
31  return new QgsBinaryWidgetWrapper( vl, fieldIdx, editor, parent, mMessageBar );
32 }
33 
35 {
36  return new QgsDummyConfigDlg( vl, fieldIdx, parent, QObject::tr( "A widget for interacting with binary (BLOB) fields." ) );
37 }
38 
39 unsigned int QgsBinaryWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
40 {
41  const QgsField field = vl->fields().field( fieldIdx );
42  const QVariant::Type type = field.type();
43  // ByteArray fields only
44  return type == QVariant::ByteArray ? 20 : 0;
45 }
This class should be subclassed for every configurable editor widget type.
Manages an editor widget Widget and wrapper share the same parent.
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Widget wrapper for binary (BLOB) fields.
Every attribute editor widget needs a factory, which inherits this class.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
QgsBinaryWidgetFactory(const QString &name, QgsMessageBar *messageBar)
Constructor for QgsBinaryWidgetFactory, where name is a human-readable name for the factory...
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Represents a vector layer which manages a vector based data sets.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:168
QVariant::Type type
Definition: qgsfield.h:56