QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsEditorConfigWidget
This class should be subclassed for every configurable editor widget type.
Definition: qgseditorconfigwidget.h:38
QgsEditorWidgetFactory
Every attribute editor widget needs a factory, which inherits this class.
Definition: qgseditorwidgetfactory.h:42
QgsDateTimeSearchWidgetWrapper
Wraps a date/time edit widget for searching.
Definition: qgsdatetimesearchwidgetwrapper.h:37
QgsField::isDateOrTime
bool isDateOrTime
Definition: qgsfield.h:55
QgsEditorWidgetSetup::config
QVariantMap config() const
Definition: qgseditorwidgetsetup.h:64
QgsSearchWidgetWrapper
Shows a search widget on a filter form.
Definition: qgssearchwidgetwrapper.h:85
qgsdatetimesearchwidgetwrapper.h
QgsDateTimeEditFactory::fieldScore
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
Definition: qgsdatetimeeditfactory.cpp:52
field
const QgsField & field
Definition: qgsfield.h:463
QgsEditorWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgseditorwidgetwrapper.h:47
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3436
QgsDateTimeEditFactory::configWidget
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Definition: qgsdatetimeeditfactory.cpp:39
qgsdatetimeedit.h
QgsDateTimeEditFactory::create
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
Definition: qgsdatetimeeditfactory.cpp:29
qgsdatetimeeditfactory.h
qgsdatetimeeditwrapper.h
QgsFields::field
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:168
QgsDateTimeEditWrapper
Wraps a date time widget. Users will be able to choose date and time from an appropriate dialog.
Definition: qgsdatetimeeditwrapper.h:43
QgsDateTimeEditFactory::QgsDateTimeEditFactory
QgsDateTimeEditFactory(const QString &name)
Constructor for QgsDateTimeEditFactory, where name is a human-readable name for the factory.
Definition: qgsdatetimeeditfactory.cpp:24
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsDateTimeEditFactory::supportedWidgetTypes
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
Definition: qgsdatetimeeditfactory.cpp:44
QgsField::editorWidgetSetup
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:602
QgsDateTimeEditFactory::createSearchWidget
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
Definition: qgsdatetimeeditfactory.cpp:34
qgsdatetimeeditconfig.h
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50