QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  {
32  rangeStackedWidget->setCurrentIndex( 0 );
33 
34  rangeWidget->clear();
35  rangeWidget->addItem( tr( "Editable" ), "SpinBox" );
36  rangeWidget->addItem( tr( "Slider" ), "Slider" );
37  rangeWidget->addItem( tr( "Dial" ), "Dial" );
38 
39  QVariant min = vl->minimumValue( fieldIdx );
40  QVariant max = vl->maximumValue( fieldIdx );
41 
42  text = tr( "Current minimum for this value is %1 and current maximum is %2." ).arg( min.toString() ).arg( max.toString() );
43  break;
44  }
45 
46  case QVariant::Double:
47  {
48  rangeStackedWidget->setCurrentIndex( 1 );
49 
50  rangeWidget->clear();
51  rangeWidget->addItem( tr( "Editable" ), "SpinBox" );
52  rangeWidget->addItem( tr( "Slider" ), "Slider" );
53 
54  QVariant min = vl->minimumValue( fieldIdx );
55  QVariant max = vl->maximumValue( fieldIdx );
56 
57  text = tr( "Current minimum for this value is %1 and current maximum is %2." ).arg( min.toString() ).arg( max.toString() );
58  break;
59  }
60 
61  default:
62  {
63  text = tr( "Attribute has no integer or real type, therefore range is not usable." );
64  break;
65  }
66  }
67 
68  valuesLabel->setText( text );
69 
70  connect( rangeWidget, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rangeWidgetChanged( int ) ) );
71 }
72 
74 {
76 
77  switch ( layer()->pendingFields()[field()].type() )
78  {
79  case QVariant::Int:
80  case QVariant::LongLong:
81  cfg.insert( "Min", minimumSpinBox->value() );
82  cfg.insert( "Max", maximumSpinBox->value() );
83  cfg.insert( "Step", stepSpinBox->value() );
84  break;
85 
86  case QVariant::Double:
87  cfg.insert( "Min", minimumDoubleSpinBox->value() );
88  cfg.insert( "Max", maximumDoubleSpinBox->value() );
89  cfg.insert( "Step", stepDoubleSpinBox->value() );
90  break;
91 
92  default:
93  break;
94  }
95 
96  cfg.insert( "Style", rangeWidget->itemData( rangeWidget->currentIndex() ).toString() );
97  cfg.insert( "AllowNull", allowNullCheckBox->isChecked() );
98 
99  if ( suffixLineEdit->text() != "" )
100  {
101  cfg.insert( "Suffix", suffixLineEdit->text() );
102  }
103 
104  return cfg;
105 }
106 
108 {
109  minimumDoubleSpinBox->setValue( config.value( "Min", 0.0 ).toDouble() );
110  maximumDoubleSpinBox->setValue( config.value( "Max", 5.0 ).toDouble() );
111  stepDoubleSpinBox->setValue( config.value( "Step", 1.0 ).toDouble() );
112 
113  minimumSpinBox->setValue( config.value( "Min", 0 ).toInt() );
114  maximumSpinBox->setValue( config.value( "Max", 5 ).toInt() );
115  stepSpinBox->setValue( config.value( "Step", 1 ).toInt() );
116 
117  rangeWidget->setCurrentIndex( rangeWidget->findData( config.value( "Style", "SpinBox" ) ) );
118 
119  suffixLineEdit->setText( config.value( "Suffix" ).toString() );
120 
121  allowNullCheckBox->setChecked( config.value( "AllowNull", true ).toBool() );
122 }
123 
125 {
126  QString style = rangeWidget->itemData( index ).toString();
127  allowNullCheckBox->setEnabled( style == "SpinBox" );
128 }