QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 }
QgsBinaryWidgetFactory(const QString &name, QgsMessageBar *messageBar)
Constructor for QgsBinaryWidgetFactory, where name is a human-readable name for the factory.
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
Widget wrapper for binary (BLOB) fields.
This class should be subclassed for every configurable editor widget type.
Every attribute editor widget needs a factory, which inherits this class.
Manages an editor widget Widget and wrapper share the same parent.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
QVariant::Type type
Definition: qgsfield.h:58
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:168
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
const QgsField & field
Definition: qgsfield.h:463