QGIS API Documentation  2.15.0-Master (02a0ebe)
qgseditorwidgetfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditorwidgetfactory.cpp
3  --------------------------------------
4  Date : 21.4.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
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 "qgseditorwidgetfactory.h"
18 #include "qgssearchwidgetwrapper.h"
19 #include "qgsfield.h"
20 
21 #include <QSettings>
22 
24 
26  : mName( name )
27 {
28 }
29 
31 {
32 }
33 
39 {
40  return new QgsDefaultSearchWidgetWrapper( vl, fieldIdx, parent );
41 }
42 
44 {
45  return mName;
46 }
47 
49 {
50  return readConfig( configElement, layer, fieldIdx );
51 }
52 
54 {
55  Q_UNUSED( config );
56  Q_UNUSED( configElement );
57  Q_UNUSED( doc );
58  Q_UNUSED( layer );
59  Q_UNUSED( fieldIdx );
60 }
61 
62 QString QgsEditorWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
63 {
64  Q_UNUSED( vl )
65  Q_UNUSED( fieldIdx )
66  Q_UNUSED( config )
67  Q_UNUSED( cache )
68  Q_UNUSED( value )
69 
70  return vl->fields().at( fieldIdx ).displayString( value );
71 }
72 
73 Qt::AlignmentFlag QgsEditorWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const
74 {
75  Q_UNUSED( config );
76 
77  QVariant::Type fldType = vl->fields().at( fieldIdx ).type();
78  bool alignRight = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong
79  || fldType == QVariant::DateTime || fldType == QVariant::Date || fldType == QVariant::Time );
80 
81  if ( alignRight )
82  return Qt::AlignRight;
83  else
84  return Qt::AlignLeft;
85 }
86 
88 {
89  Q_UNUSED( vl )
90  Q_UNUSED( fieldIdx )
91  Q_UNUSED( config )
92 
93  return QVariant();
94 }
95 
97 {
98  Q_UNUSED( configElement );
99  Q_UNUSED( layer );
100  Q_UNUSED( fieldIdx );
101 
102  return QgsEditorWidgetConfig();
103 }
104 
105 bool QgsEditorWidgetFactory::isFieldSupported( QgsVectorLayer* vl, int fieldIdx )
106 {
107  Q_UNUSED( vl )
108  Q_UNUSED( fieldIdx )
109  return true;
110 }
111 
Manages an editor widget Widget and wrapper share the same parent.
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:155
QgsFields fields() const
Returns the list of fields of this layer.
QgsEditorWidgetFactory(const QString &name)
Constructor.
virtual QVariant createCache(QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config)
Create a cache for a given field.
const char * name() const
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:385
virtual Qt::AlignmentFlag alignmentFlag(QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config) const
Return the alignment for a particular field.
QString name()
Return The human readable identifier name of this widget type.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
virtual QgsEditorWidgetConfig readConfig(const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx)
Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.
QgsVectorLayer * layer() const
Access the QgsVectorLayer, you are working on.
QgsDefaultSearchWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
QgsEditorWidgetConfig readEditorConfig(const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx)
Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.
virtual void writeConfig(const QgsEditorWidgetConfig &config, QDomElement &configElement, QDomDocument &doc, const QgsVectorLayer *layer, int fieldIdx)
Serialize your configuration and save it in a xml doc.
virtual QString representValue(QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value) const
Create a pretty String representation of the value.
QgsEditorWidgetConfig config() const
Returns the whole config.
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
virtual QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const
By default a simple QgsFilterLineEdit is returned as search widget.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:89