Skip to content
Permalink
Browse files

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
wonder committed Mar 11, 2006
1 parent 73fda62 commit 4b7843289fb92799dc754b5dd45d7327819d1a0b
Showing with 56 additions and 28 deletions.
  1. +25 −15 src/gui/qgsmeasure.cpp
  2. +31 −13 src/ui/qgsmeasurebase.ui
@@ -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()) );
@@ -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)
{
@@ -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 );

@@ -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()
@@ -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;
}
@@ -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));
}

}
@@ -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>
@@ -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>
@@ -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" />

0 comments on commit 4b78432

Please sign in to comment.
You can’t perform that action at this time.