QGIS API Documentation  3.6.0-Noosa (5873452)
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 }
This class should be subclassed for every configurable editor widget type.
Manages an editor widget Widget and wrapper share the same parent.
QgsRangeWidgetFactory(const QString &name)
Constructor for QgsRangeWidgetFactory, where name is a human-readable name for the factory...
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:163
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Wraps a range widget.
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.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
bool isNumeric
Definition: qgsfield.h:52
Represents a vector layer which manages a vector based data sets.
QVariant::Type type
Definition: qgsfield.h:56