QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsrangewidgetfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrangewidgetfactory.cpp
3  --------------------------------------
4  Date : 5.1.2014
5  Copyright : (C) 2014 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 "qgsrangewidgetfactory.h"
17 #include "qgsrangeconfigdlg.h"
18 #include "qgsrangewidgetwrapper.h"
19 #include "qgsvectorlayer.h"
20 #include <QDial>
21 
23  : QgsEditorWidgetFactory( name )
24 {
25 }
26 
27 QgsEditorWidgetWrapper *QgsRangeWidgetFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
28 {
29  return new QgsRangeWidgetWrapper( vl, fieldIdx, editor, parent );
30 }
31 
32 QgsEditorConfigWidget *QgsRangeWidgetFactory::configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const
33 {
34  return new QgsRangeConfigDlg( vl, fieldIdx, parent );
35 }
36 
37 unsigned int QgsRangeWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
38 {
39  const QgsField field = vl->fields().at( fieldIdx );
40  if ( field.type() == QVariant::Int ) return 20;
41  if ( field.type() == QVariant::Double ) return 5; // low priority because the fixed number of decimal places may alter the original data
42  if ( field.isNumeric() ) return 5; // widgets used support only signed 32bits (int) and double
43  return 0;
44 }
45 
47 {
48  QHash<const char *, int> map = QHash<const char *, int>();
49  map.insert( QSlider::staticMetaObject.className(), 10 );
50  map.insert( QDial::staticMetaObject.className(), 10 );
51  map.insert( QSpinBox::staticMetaObject.className(), 10 );
52  map.insert( QDoubleSpinBox::staticMetaObject.className(), 10 );
53  return map;
54 }
QgsRangeConfigDlg
Definition: qgsrangeconfigdlg.h:31
QgsEditorConfigWidget
This class should be subclassed for every configurable editor widget type.
Definition: qgseditorconfigwidget.h:38
QgsField::isNumeric
bool isNumeric
Definition: qgsfield.h:54
QgsEditorWidgetFactory
Every attribute editor widget needs a factory, which inherits this class.
Definition: qgseditorwidgetfactory.h:42
qgsrangewidgetwrapper.h
QgsRangeWidgetFactory::create
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
Definition: qgsrangewidgetfactory.cpp:27
QgsRangeWidgetFactory::supportedWidgetTypes
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
Definition: qgsrangewidgetfactory.cpp:46
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
QgsRangeWidgetWrapper
Wraps a range widget.
Definition: qgsrangewidgetwrapper.h:48
QgsRangeWidgetFactory::QgsRangeWidgetFactory
QgsRangeWidgetFactory(const QString &name)
Constructor for QgsRangeWidgetFactory, where name is a human-readable name for the factory.
Definition: qgsrangewidgetfactory.cpp:22
qgsrangeconfigdlg.h
qgsvectorlayer.h
QgsRangeWidgetFactory::configWidget
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Definition: qgsrangewidgetfactory.cpp:32
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFields::at
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:163
QgsField::type
QVariant::Type type
Definition: qgsfield.h:58
qgsrangewidgetfactory.h
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50