QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsunitselectionwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsunitselectionwidget.h
3  -------------------
4  begin : Mar 24, 2014
5  copyright : (C) 2014 Sandro Mani
6  email : [email protected]
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "qgsunitselectionwidget.h"
20 
22  : QDialog( parent )
23 {
24  setupUi( this );
25  mComboBoxMinScale->setScale( 0.0000001 );
26  mComboBoxMaxScale->setScale( 1 );
27  connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMinComboBox() ) );
28  connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMaxComboBox() ) );
29  connect( mComboBoxMinScale, SIGNAL( scaleChanged() ), this, SLOT( configureMaxComboBox() ) );
30  connect( mComboBoxMaxScale, SIGNAL( scaleChanged() ), this, SLOT( configureMinComboBox() ) );
31 }
32 
34 {
35  mComboBoxMinScale->setScale( scale.minScale > 0.0 ? scale.minScale : 0.0000001 );
36  mCheckBoxMinScale->setChecked( scale.minScale > 0.0 );
37  mComboBoxMinScale->setEnabled( scale.minScale > 0.0 );
38  mComboBoxMaxScale->setScale( scale.maxScale > 0.0 ? scale.maxScale : 1.0 );
39  mCheckBoxMaxScale->setChecked( scale.maxScale > 0.0 );
40  mComboBoxMaxScale->setEnabled( scale.maxScale > 0.0 );
41 }
42 
44 {
45  mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
46  if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() > mComboBoxMaxScale->scale() )
47  {
48  mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
49  }
50 }
51 
53 {
54  mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
55  if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() < mComboBoxMinScale->scale() )
56  {
57  mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
58  }
59 }
60 
62 {
63  QgsMapUnitScale scale;
64  scale.minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
65  scale.maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
66  return scale;
67 }
68 
69 
71  : QWidget( parent )
72 {
73  mMapUnitIdx = -1;
75 
76  setupUi( this );
77  mMapScaleButton->setVisible( false );
78  mMapScaleButton->setToolTip( tr( "Adjust scaling range" ) );
79 
80  connect( mUnitCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( toggleUnitRangeButton() ) );
81  connect( mMapScaleButton, SIGNAL( clicked() ), this, SLOT( showDialog() ) );
82  connect( mUnitCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( changed() ) );
83 }
84 
85 void QgsUnitSelectionWidget::setUnits( const QStringList &units, int mapUnitIdx )
86 {
87  blockSignals( true );
88  mUnitCombo->addItems( units );
89  mMapUnitIdx = mapUnitIdx;
90  blockSignals( false );
91 }
92 
93 void QgsUnitSelectionWidget::setUnit( int unitIndex )
94 {
95  blockSignals( true );
96  mUnitCombo->setCurrentIndex( unitIndex );
97  blockSignals( false );
98 }
99 
101 {
103  if ( mUnitScaleDialog->exec() != QDialog::Accepted )
104  {
106  }
107  else
108  {
110  if ( scale.minScale != newScale.minScale || scale.maxScale != newScale.maxScale )
111  {
112  emit changed();
113  }
114  }
115 }
116 
118 {
119  mMapScaleButton->setVisible( mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
120 }
121 
122 
123 
QgsMapUnitScaleDialog * mUnitScaleDialog
QgsMapUnitScale getMapUnitScale() const
Returns the map unit scale.
void setUnit(int unitIndex)
Sets the selected unit index.
void setUnits(const QStringList &units, int mapUnitIdx)
Sets the units which the user can choose from in the combobox.
QgsMapUnitScaleDialog(QWidget *parent)
double maxScale
The maximum scale, or 0.0 if unset.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale.
Dialog allowing the user to choose the minimum and maximum scale of an object in map units...
double minScale
The minimum scale, or 0.0 if unset.
QgsUnitSelectionWidget(QWidget *parent=0)
#define tr(sourceText)