thejester
5th May 2011, 07:34
Hi,
I'm trying to create a distance measure tool, that will display the delta X and delta Y values of 2 points within the plot, and draw a line between these two points.
I started out with some old code from (http://www.qtcentre.org/archive/index.php/t-10367.html). Some changes were needed to get it running in Qwt6.
class DistancePicker : public QwtPlotPicker
{
public:
DistancePicker( QwtPlotCanvas * canvas )
:QwtPlotPicker( canvas )
{
setStateMachine( new QwtPickerClickRectMachine );
setRubberBand( PolygonRubberBand );
setTrackerMode( QwtPicker::ActiveOnly );
}
protected:
virtual void drawRubberBand(QPainter* painter) const
{
painter->drawPolygon( selection() );
}
virtual QwtText trackerText (const QPoint& pos) const
{
const QPolygon& polygon = selection();
if ( polygon.size() != 2 )
{
return QwtText();
}
const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
QwtText text( QString::number(line.length()) );
QColor bg(Qt::white);
bg.setAlpha(180);
text.setBackgroundBrush(QBrush(bg));
return text;
}
};
While this seems to be working good, i do have a few problems with it.
1) Depending on where you move the second selection for the measurement, the measurement picker text runs through the default picker that that always displays the current x,y position. Is there something to do about that ?
2) When we zoom in to the plot, just after releasing the mouse for the zoom action, the plot zooms in to new selection, and then automagically a measurement is started.
Is it possible to do measurements only when user presses space bar for instance ?
Thanks for any help !
TJ
I'm trying to create a distance measure tool, that will display the delta X and delta Y values of 2 points within the plot, and draw a line between these two points.
I started out with some old code from (http://www.qtcentre.org/archive/index.php/t-10367.html). Some changes were needed to get it running in Qwt6.
class DistancePicker : public QwtPlotPicker
{
public:
DistancePicker( QwtPlotCanvas * canvas )
:QwtPlotPicker( canvas )
{
setStateMachine( new QwtPickerClickRectMachine );
setRubberBand( PolygonRubberBand );
setTrackerMode( QwtPicker::ActiveOnly );
}
protected:
virtual void drawRubberBand(QPainter* painter) const
{
painter->drawPolygon( selection() );
}
virtual QwtText trackerText (const QPoint& pos) const
{
const QPolygon& polygon = selection();
if ( polygon.size() != 2 )
{
return QwtText();
}
const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
QwtText text( QString::number(line.length()) );
QColor bg(Qt::white);
bg.setAlpha(180);
text.setBackgroundBrush(QBrush(bg));
return text;
}
};
While this seems to be working good, i do have a few problems with it.
1) Depending on where you move the second selection for the measurement, the measurement picker text runs through the default picker that that always displays the current x,y position. Is there something to do about that ?
2) When we zoom in to the plot, just after releasing the mouse for the zoom action, the plot zooms in to new selection, and then automagically a measurement is started.
Is it possible to do measurements only when user presses space bar for instance ?
Thanks for any help !
TJ