QGIS API Documentation  3.6.0-Noosa (5873452)
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 QVariantMap config = field.editorWidgetSetup().config();
56  if ( field.isDateOrTime() || config.contains( QStringLiteral( "field_format" ) ) )
57  {
58  return 20;
59  }
60  else
61  {
62  return 5;
63  }
64 }
Shows a search widget on a filter form.
QVariantMap config() const
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)
Constructor for QgsDateTimeEditFactory, where name is a human-readable name for the factory...
Manages an editor widget Widget and wrapper share the same parent.
Wraps a date time widget.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:410
Wraps a date/time edit widget for searching.
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
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
bool isDateOrTime
Definition: qgsfield.h:53
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.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:168