Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improvements to measure tool:
- display current distance/area while moving current point
- value shown in QLineEdit so it can be copied


git-svn-id: http://svn.osgeo.org/qgis/trunk@5003 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 11, 2006
1 parent 73fda62 commit 4b78432
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
40 changes: 25 additions & 15 deletions src/gui/qgsmeasure.cpp
Expand Up @@ -48,15 +48,6 @@ QgsMeasure::QgsMeasure(bool measureArea, QgsMapCanvas *mc, const char * name, Qt
//mTable->setColumnStretchable ( 1, true );
//mTable->setColumnStretchable ( 2, true );

// Widget font properties should normally be set in the ui file.
// This is here to work around the following bug in Qt 4.0.1:
// Setting another font attribute while using the default font size will
// cause uic3 to generate code setting the font size to 0.
// This causes text not to be drawn with Qt/X11 and a crash with Qt/Mac.
QFont font(lblTotal->font());
font.setBold(true);
lblTotal->setFont(font);

updateUi();

connect( mMapCanvas, SIGNAL(renderComplete(QPainter*)), this, SLOT(mapCanvasChanged()) );
Expand Down Expand Up @@ -120,7 +111,7 @@ void QgsMeasure::addPoint(QgsPoint &point)
if (mMeasureArea && mPoints.size() > 2)
{
double area = mCalc->measurePolygon(mPoints);
lblTotal->setText(formatArea(area));
editTotal->setText(formatArea(area));
}
else if (!mMeasureArea && mPoints.size() > 1)
{
Expand All @@ -131,7 +122,7 @@ void QgsMeasure::addPoint(QgsPoint &point)
double d = mCalc->measureLine(p1,p2);

mTotal += d;
lblTotal->setText(formatDistance(mTotal));
editTotal->setText(formatDistance(mTotal));

mTable->setNumRows ( mPoints.size()-1 );

Expand Down Expand Up @@ -163,6 +154,25 @@ void QgsMeasure::mouseMove(QgsPoint &point)
#endif

mRubberBand->movePoint(point);

// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
std::vector<QgsPoint> tmpPoints = mPoints;
tmpPoints.push_back(point);
if (mMeasureArea && tmpPoints.size() > 2)
{
double area = mCalc->measurePolygon(tmpPoints);
editTotal->setText(formatArea(area));
}
else if (!mMeasureArea && tmpPoints.size() > 1)
{
int last = tmpPoints.size()-2;
QgsPoint p1 = tmpPoints[last], p2 = tmpPoints[last+1];

double d = mCalc->measureLine(p1,p2);
editTotal->setText(formatDistance(mTotal + d));
}
}

void QgsMeasure::mapCanvasChanged()
Expand Down Expand Up @@ -243,12 +253,12 @@ QString QgsMeasure::formatArea(double area)
if (area < 1000)
{
txt = QString::number(area,'f',0);
txt += " m<sup>2</sup>";
txt += " m2";
}
else
{
txt = QString::number(area/1000000,'f',3);
txt += " km<sup>2</sup>";
txt += " km2";
}
return txt;
}
Expand All @@ -258,12 +268,12 @@ void QgsMeasure::updateUi()
if (mMeasureArea)
{
mTable->hide();
lblTotal->setText(formatArea(0));
editTotal->setText(formatArea(0));
}
else
{
mTable->show();
lblTotal->setText(formatDistance(0));
editTotal->setText(formatDistance(0));
}

}
Expand Down
44 changes: 31 additions & 13 deletions src/ui/qgsmeasurebase.ui
Expand Up @@ -26,12 +26,40 @@
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>4</number>
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="2" column="0" colspan="2" >
<item row="1" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" >
<widget class="QLineEdit" name="editTotal" >
<property name="font" >
<font>
<bold>true</bold>
</font>
</property>
<property name="alignment" >
<set>Qt::AlignRight</set>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3" >
<widget class="Q3Frame" name="frame4" >
<property name="minimumSize" >
<size>
Expand Down Expand Up @@ -95,7 +123,7 @@
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2" >
<item row="0" column="0" colspan="3" >
<widget class="Q3Table" name="mTable" >
<property name="resizePolicy" >
<enum>Q3ScrollView::Manual</enum>
Expand All @@ -121,16 +149,6 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLabel" name="lblTotal" >
<property name="text" >
<string/>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
Expand Down

0 comments on commit 4b78432

Please sign in to comment.