QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 }
QgsEditorConfigWidget
Definition: qgseditorconfigwidget.h:38
QgsEditorWidgetFactory
Definition: qgseditorwidgetfactory.h:42
QgsDummyConfigDlg
Definition: qgsdummyconfigdlg.h:32
QgsEditorWidgetWrapper
Definition: qgseditorwidgetwrapper.h:47
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3280
qgsvectordataprovider.h
QgsMessageBar
Definition: qgsmessagebar.h:60
qgsbinarywidgetwrapper.h
QgsBinaryWidgetFactory::create
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
Definition: qgsbinarywidgetfactory.cpp:29
QgsFields::field
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:168
qgsvectorlayer.h
QgsBinaryWidgetFactory::QgsBinaryWidgetFactory
QgsBinaryWidgetFactory(const QString &name, QgsMessageBar *messageBar)
Constructor for QgsBinaryWidgetFactory, where name is a human-readable name for the factory.
Definition: qgsbinarywidgetfactory.cpp:23
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsdummyconfigdlg.h
QgsBinaryWidgetFactory::fieldScore
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
Definition: qgsbinarywidgetfactory.cpp:39
QgsBinaryWidgetWrapper
Definition: qgsbinarywidgetwrapper.h:35
QgsBinaryWidgetFactory::configWidget
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Definition: qgsbinarywidgetfactory.cpp:34
QgsField::type
QVariant::Type type
Definition: qgsfield.h:57
qgsbinarywidgetfactory.h
QgsField
Definition: qgsfield.h:49