Skip to content

Commit

Permalink
Add units selector to measure dialog. Add info text to dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jan 1, 2015
1 parent 246de9f commit 53c4c8f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
20 changes: 19 additions & 1 deletion src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WindowFlags f )
mMeasureArea = tool->measureArea();
mTotal = 0.;

mUnitsCombo->addItem( "Meters");
mUnitsCombo->addItem( "Feet");
mUnitsCombo->addItem( "Degrees");
mUnitsCombo->addItem( "Nautical Miles");
mUnitsCombo->setCurrentIndex( 0 );

updateSettings();

connect( mUnitsCombo, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( unitsChanged( const QString & ) ) );
}

void QgsMeasureDialog::updateSettings()
Expand All @@ -52,7 +60,7 @@ void QgsMeasureDialog::updateSettings()

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

void QgsMeasureDialog::unitsChanged(const QString &units)
{
mDisplayUnits = QGis::fromLiteral( units.toLower() );
mTable->clear();
mTotal = 0.;
updateUi();
}

void QgsMeasureDialog::restart()
{
mTool->restart();
Expand Down Expand Up @@ -221,6 +237,7 @@ QString QgsMeasureDialog::formatDistance( double distance )
QSettings settings;
bool baseUnit = settings.value( "/qgis/measure/keepbaseunit", false ).toBool();

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

editTotal->setToolTip( toolTip );
mTable->setToolTip( toolTip );
mNotesLabel->setText( toolTip );

QGis::UnitType newDisplayUnits;
double dummy = 1.0;
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
//! When any external settings change
void updateSettings();

private slots:
void unitsChanged( const QString &units );

private:

//! formats distance to most appropriate units
Expand Down
54 changes: 38 additions & 16 deletions src/ui/qgsmeasurebase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>272</height>
<width>359</width>
<height>301</height>
</rect>
</property>
<property name="baseSize">
Expand All @@ -25,13 +25,32 @@
</iconset>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="2" column="2">
<item row="4" column="0">
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Total</string>
</property>
<property name="buddy">
<cstring>editTotal</cstring>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="editTotal">
<property name="font">
<font>
Expand All @@ -47,7 +66,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -63,17 +82,10 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Total</string>
</property>
<property name="buddy">
<cstring>editTotal</cstring>
</property>
</widget>
<item row="4" column="3">
<widget class="QComboBox" name="mUnitsCombo"/>
</item>
<item row="1" column="0" colspan="3">
<item row="2" column="0" colspan="4">
<widget class="QTreeWidget" name="mTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
Expand All @@ -91,7 +103,17 @@
</column>
</widget>
</item>
<item row="3" column="2">
<item row="5" column="0" colspan="4">
<widget class="QLabel" name="mNotesLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
Expand Down

0 comments on commit 53c4c8f

Please sign in to comment.