Skip to content

Commit

Permalink
Merge pull request #1747 from NathanW2/measure_dialog
Browse files Browse the repository at this point in the history
Add units selector to measure dialog. Add info text to dialog
  • Loading branch information
NathanW2 committed Jan 10, 2015
2 parents d9042f5 + ee9c368 commit 6e60d67
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 17 deletions.
24 changes: 23 additions & 1 deletion src/app/qgsmeasuredialog.cpp
Expand Up @@ -43,7 +43,20 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WindowFlags f )
mMeasureArea = tool->measureArea();
mTotal = 0.;

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

QSettings settings;
QString units = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
mUnitsCombo->setCurrentIndex( mUnitsCombo->findText( units, Qt::MatchFixedString ) );

updateSettings();

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

groupBox->setCollapsed( true );
}

void QgsMeasureDialog::updateSettings()
Expand All @@ -52,8 +65,8 @@ 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() );
// Configure QgsDistanceArea
mDisplayUnits = QGis::fromLiteral( mUnitsCombo->currentText().toLower() );
mDa.setSourceCrs( mTool->canvas()->mapSettings().destinationCrs().srsid() );
mDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
// Only use ellipsoidal calculation when project wide transformation is enabled.
Expand All @@ -77,6 +90,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 @@ -269,6 +290,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
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
86 changes: 70 additions & 16 deletions src/ui/qgsmeasurebase.ui
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 @@ -88,19 +100,61 @@
<property name="text">
<string>Segments</string>
</property>
<property name="textAlignment">
<set>AlignRight|AlignVCenter</set>
</property>
</column>
</widget>
</item>
<item row="3" column="2">
<item row="6" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="QgsCollapsibleGroupBox" name="groupBox">
<property name="title">
<string>Info</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="mNotesLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mTable</tabstop>
<tabstop>editTotal</tabstop>
Expand Down

0 comments on commit 6e60d67

Please sign in to comment.