Skip to content

Commit 53c4c8f

Browse files
committed
Add units selector to measure dialog. Add info text to dialog
1 parent 246de9f commit 53c4c8f

3 files changed

Lines changed: 60 additions & 17 deletions

File tree

src/app/qgsmeasuredialog.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WindowFlags f )
4343
mMeasureArea = tool->measureArea();
4444
mTotal = 0.;
4545

46+
mUnitsCombo->addItem( "Meters");
47+
mUnitsCombo->addItem( "Feet");
48+
mUnitsCombo->addItem( "Degrees");
49+
mUnitsCombo->addItem( "Nautical Miles");
50+
mUnitsCombo->setCurrentIndex( 0 );
51+
4652
updateSettings();
53+
54+
connect( mUnitsCombo, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( unitsChanged( const QString & ) ) );
4755
}
4856

4957
void QgsMeasureDialog::updateSettings()
@@ -52,7 +60,7 @@ void QgsMeasureDialog::updateSettings()
5260

5361
mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
5462
mCanvasUnits = mTool->canvas()->mapUnits();
55-
mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
63+
mDisplayUnits = QGis::fromLiteral( mUnitsCombo->currentText().toLower() );
5664
// Configure QgsDistanceArea
5765
mDa.setSourceCrs( mTool->canvas()->mapSettings().destinationCrs().srsid() );
5866
mDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
@@ -77,6 +85,14 @@ void QgsMeasureDialog::updateSettings()
7785
updateUi();
7886
}
7987

88+
void QgsMeasureDialog::unitsChanged(const QString &units)
89+
{
90+
mDisplayUnits = QGis::fromLiteral( units.toLower() );
91+
mTable->clear();
92+
mTotal = 0.;
93+
updateUi();
94+
}
95+
8096
void QgsMeasureDialog::restart()
8197
{
8298
mTool->restart();
@@ -221,6 +237,7 @@ QString QgsMeasureDialog::formatDistance( double distance )
221237
QSettings settings;
222238
bool baseUnit = settings.value( "/qgis/measure/keepbaseunit", false ).toBool();
223239

240+
QgsDebugMsg( mUnitsCombo->currentText().toLower() );
224241
QGis::UnitType newDisplayUnits;
225242
convertMeasurement( distance, newDisplayUnits, false );
226243
return QgsDistanceArea::textUnit( distance, mDecimalPlaces, newDisplayUnits, false, baseUnit );
@@ -269,6 +286,7 @@ void QgsMeasureDialog::updateUi()
269286

270287
editTotal->setToolTip( toolTip );
271288
mTable->setToolTip( toolTip );
289+
mNotesLabel->setText( toolTip );
272290

273291
QGis::UnitType newDisplayUnits;
274292
double dummy = 1.0;

src/app/qgsmeasuredialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
6666
//! When any external settings change
6767
void updateSettings();
6868

69+
private slots:
70+
void unitsChanged( const QString &units );
71+
6972
private:
7073

7174
//! formats distance to most appropriate units

src/ui/qgsmeasurebase.ui

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>281</width>
10-
<height>272</height>
9+
<width>359</width>
10+
<height>301</height>
1111
</rect>
1212
</property>
1313
<property name="baseSize">
@@ -25,13 +25,32 @@
2525
</iconset>
2626
</property>
2727
<layout class="QGridLayout">
28-
<property name="margin">
28+
<property name="leftMargin">
29+
<number>9</number>
30+
</property>
31+
<property name="topMargin">
32+
<number>9</number>
33+
</property>
34+
<property name="rightMargin">
35+
<number>9</number>
36+
</property>
37+
<property name="bottomMargin">
2938
<number>9</number>
3039
</property>
3140
<property name="spacing">
3241
<number>6</number>
3342
</property>
34-
<item row="2" column="2">
43+
<item row="4" column="0">
44+
<widget class="QLabel" name="textLabel2">
45+
<property name="text">
46+
<string>Total</string>
47+
</property>
48+
<property name="buddy">
49+
<cstring>editTotal</cstring>
50+
</property>
51+
</widget>
52+
</item>
53+
<item row="4" column="2">
3554
<widget class="QLineEdit" name="editTotal">
3655
<property name="font">
3756
<font>
@@ -47,7 +66,7 @@
4766
</property>
4867
</widget>
4968
</item>
50-
<item row="2" column="1">
69+
<item row="4" column="1">
5170
<spacer>
5271
<property name="orientation">
5372
<enum>Qt::Horizontal</enum>
@@ -63,17 +82,10 @@
6382
</property>
6483
</spacer>
6584
</item>
66-
<item row="2" column="0">
67-
<widget class="QLabel" name="textLabel2">
68-
<property name="text">
69-
<string>Total</string>
70-
</property>
71-
<property name="buddy">
72-
<cstring>editTotal</cstring>
73-
</property>
74-
</widget>
85+
<item row="4" column="3">
86+
<widget class="QComboBox" name="mUnitsCombo"/>
7587
</item>
76-
<item row="1" column="0" colspan="3">
88+
<item row="2" column="0" colspan="4">
7789
<widget class="QTreeWidget" name="mTable">
7890
<property name="editTriggers">
7991
<set>QAbstractItemView::NoEditTriggers</set>
@@ -91,7 +103,17 @@
91103
</column>
92104
</widget>
93105
</item>
94-
<item row="3" column="2">
106+
<item row="5" column="0" colspan="4">
107+
<widget class="QLabel" name="mNotesLabel">
108+
<property name="text">
109+
<string/>
110+
</property>
111+
<property name="wordWrap">
112+
<bool>true</bool>
113+
</property>
114+
</widget>
115+
</item>
116+
<item row="6" column="0" colspan="4">
95117
<widget class="QDialogButtonBox" name="buttonBox">
96118
<property name="standardButtons">
97119
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>

0 commit comments

Comments
 (0)