QGIS API Documentation  2.8.6-Wien
qgsrangeconfigdlg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrangeconfigdlgbase.cpp
3  --------------------------------------
4  Date : 5.1.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias dot kuhn at gmx 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 "qgsrangeconfigdlg.h"
17 
18 #include "qgsvectorlayer.h"
19 
20 QgsRangeConfigDlg::QgsRangeConfigDlg( QgsVectorLayer* vl, int fieldIdx, QWidget *parent )
21  : QgsEditorConfigWidget( vl, fieldIdx, parent )
22 {
23  setupUi( this );
24 
25  QString text;
26 
27  switch ( vl->pendingFields()[fieldIdx].type() )
28  {
29  case QVariant::Int:
30  case QVariant::LongLong:
31  case QVariant::Double:
32  {
33  rangeStackedWidget->setCurrentIndex( vl->pendingFields()[fieldIdx].type() == QVariant::Double ? 1 : 0 );
34 
35  rangeWidget->clear();
36  rangeWidget->addItem( tr( "Editable" ), "SpinBox" );
37  rangeWidget->addItem( tr( "Slider" ), "Slider" );
38  rangeWidget->addItem( tr( "Dial" ), "Dial" );
39 
40  QVariant min = vl->minimumValue( fieldIdx );
41  QVariant max = vl->maximumValue( fieldIdx );
42 
43  text = tr( "Current minimum for this value is %1 and current maximum is %2." ).arg( min.toString() ).arg( max.toString() );
44  break;
45  }
46 
47  default:
48  text = tr( "Attribute has no integer or real type, therefore range is not usable." );
49  break;
50  }
51 
52  valuesLabel->setText( text );
53 
54  connect( rangeWidget, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rangeWidgetChanged( int ) ) );
55 }
56 
58 {
60 
61  switch ( layer()->pendingFields()[field()].type() )
62  {
63  case QVariant::Int:
64  case QVariant::LongLong:
65  cfg.insert( "Min", minimumSpinBox->value() );
66  cfg.insert( "Max", maximumSpinBox->value() );
67  cfg.insert( "Step", stepSpinBox->value() );
68  break;
69 
70  case QVariant::Double:
71  cfg.insert( "Min", minimumDoubleSpinBox->value() );
72  cfg.insert( "Max", maximumDoubleSpinBox->value() );
73  cfg.insert( "Step", stepDoubleSpinBox->value() );
74  break;
75 
76  default:
77  break;
78  }
79 
80  cfg.insert( "Style", rangeWidget->itemData( rangeWidget->currentIndex() ).toString() );
81  cfg.insert( "AllowNull", allowNullCheckBox->isChecked() );
82 
83  if ( suffixLineEdit->text() != "" )
84  {
85  cfg.insert( "Suffix", suffixLineEdit->text() );
86  }
87 
88  return cfg;
89 }
90 
92 {
93  minimumDoubleSpinBox->setValue( config.value( "Min", 0.0 ).toDouble() );
94  maximumDoubleSpinBox->setValue( config.value( "Max", 5.0 ).toDouble() );
95  stepDoubleSpinBox->setValue( config.value( "Step", 1.0 ).toDouble() );
96 
97  minimumSpinBox->setValue( config.value( "Min", 0 ).toInt() );
98  maximumSpinBox->setValue( config.value( "Max", 5 ).toInt() );
99  stepSpinBox->setValue( config.value( "Step", 1 ).toInt() );
100 
101  rangeWidget->setCurrentIndex( rangeWidget->findData( config.value( "Style", "SpinBox" ) ) );
102 
103  suffixLineEdit->setText( config.value( "Suffix" ).toString() );
104 
105  allowNullCheckBox->setChecked( config.value( "AllowNull", true ).toBool() );
106 }
107 
109 {
110  QString style = rangeWidget->itemData( index ).toString();
111  allowNullCheckBox->setEnabled( style == "SpinBox" );
112 }
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
int field()
Returns the field for which this configuration widget applies.
static unsigned index
void rangeWidgetChanged(int index)
This class should be subclassed for every configurable editor widget type.
QVariant maximumValue(int index)
Returns maximum value for an attribute column or invalid variant in case of error.
QVariant minimumValue(int index)
Returns minimum value for an attribute column or invalid variant in case of error.
virtual void setConfig(const QgsEditorWidgetConfig &config) override
Update the configuration widget to represent the given configuration.
int min(int a, int b)
Definition: util.h:93
QgsRangeConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
QMap< QString, QVariant > QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
Represents a vector layer which manages a vector based data sets.
int max(int a, int b)
Definition: util.h:87
virtual QgsEditorWidgetConfig config() override
Create a configuration from the current GUI state.
#define tr(sourceText)