QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsdatetimeeditfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatetimeeditfactory.cpp
3  --------------------------------------
4  Date : 03.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
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 "qgsdatetimeeditfactory.h"
17 #include "qgsdatetimeeditconfig.h"
18 #include "qgsdatetimeeditwrapper.h"
20 #include "qgsdatetimeedit.h"
21 
22 #include <QSettings>
23 
25  : QgsEditorWidgetFactory( name )
26 {
27 }
28 
29 QgsEditorWidgetWrapper *QgsDateTimeEditFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
30 {
31  return new QgsDateTimeEditWrapper( vl, fieldIdx, editor, parent );
32 }
33 
35 {
36  return new QgsDateTimeSearchWidgetWrapper( vl, fieldIdx, parent );
37 }
38 
40 {
41  return new QgsDateTimeEditConfig( vl, fieldIdx, parent );
42 }
43 
45 {
46  QHash<const char *, int> map = QHash<const char *, int>();
47  map.insert( QDateTimeEdit::staticMetaObject.className(), 10 );
48  map.insert( QgsDateTimeEdit::staticMetaObject.className(), 10 );
49  return map;
50 }
51 
52 unsigned int QgsDateTimeEditFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
53 {
54  const QgsField field = vl->fields().field( fieldIdx );
55  const QVariant::Type type = field.type();
56  const QVariantMap config = field.editorWidgetSetup().config();
57  if ( type == QVariant::DateTime || type == QVariant::Date || type == QVariant::Time || config.contains( QStringLiteral( "field_format" ) ) )
58  {
59  return 20;
60  }
61  else
62  {
63  return 5;
64  }
65 }
Shows a search widget on a filter form.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
This class should be subclassed for every configurable editor widget type.
QgsDateTimeEditFactory(const QString &name)
Manages an editor widget Widget and wrapper share the same parent.
Wraps a date time widget.
Wraps a date/time edit widget for searching.
QVariantMap config() const
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
Every attribute editor widget needs a factory, which inherits this class.
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:168
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.
Represents a vector layer which manages a vector based data sets.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:429
QVariant::Type type
Definition: qgsfield.h:55