PDA

View Full Version : Multiple, always visible QwtPickers



gibi70
26th January 2013, 21:58
I need to put a number of always-visible pickers on a canvas. This is the code I have devised so far:


class QwtPickerStayMachine : public QwtPickerMachine
{
public:
QwtPickerStayMachine():
QwtPickerMachine( PointSelection )
{
// 0 = button not pressed
// 1 = button pressed
setState(0);
}

QList<QwtPickerMachine::Command> transition(
const QwtEventPattern &eventPattern, const QEvent *e )
{
QList<QwtPickerMachine::Command> cmdList;

switch ( e->type() )
{
case QEvent::MouseButtonPress:
{
if ( eventPattern.mouseMatch(
QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
{
if ( state() == 0 )
{
cmdList += End;
cmdList += Begin;
cmdList += Append;
setState(1);
}
else
{
//cmdList += Move;
}
//qDebug() << "machine mousebuttonpress state" << state() ;
}
break;
}
case QEvent::MouseMove:
case QEvent::Wheel:
{
if ( state() == 0 )
{

}
else
{
cmdList += Move;
}
//qDebug() << "machine mousemove state" << state();
break;
}
case QEvent::MouseButtonRelease:
{
//setState(0);
if ( state() == 0 )
{

}
else
{
//cmdList += End;
setState(0);
}
//qDebug() << "machine mousebuttonrelease state" << state();
break;
}
case QEvent::Leave:
{
//setState(0);
//qDebug() << "machine leave state" << state();
}
case QEvent::KeyPress:
{
if ( eventPattern.keyMatch(
QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
setState( 1 );
}
else
{
//cmdList += End;
//setState( 0 );
}
}
break;
}
default:
break;
}

return cmdList;
}
};

It seems to work and the rubberband stays visible. I instantiate the picker in its constructor like in the following code


Picker(QwtPlotCanvas *canvas, QColor col)
: QwtPicker(canvas)
{
//setStateMachine( new QwtPickerDragPointMachine() );
setStateMachine( new QwtPickerStayMachine() );
setRubberBandPen(QPen(QBrush(col), 3));
//setRubberBand( QwtPicker::NoRubberBand );
setRubberBand( QwtPicker::VLineRubberBand );
setTrackerMode(QwtPicker::AlwaysOn);
setTrackerPen( QColor( Qt::blue ) );

connect(this, SIGNAL(moved(QPoint)), this, SLOT(onPickerDragged(QPoint)));
}


The first type of problem I am facing is that the signal moved() does not seem to be emitted, as the code on the connected slot is never called.
The second problem is that when I associate two pickers to the canvas, they move synchronously one over another, when actually I would like to move just one of them (the one nearest to the point where I click).
Thanks for any advice.

Uwe
27th January 2013, 06:16
Use markers ( QwtPlotMarker::VLine ) and one picker only !

Connect a slot to the selected() signal of the picker, where you identify the corresponding marker ( closest line ), hide it and let the rubber band ( same pen as the marker ) of the picker take its place. When the picker selection is done, move the marker to the new position and make it visible again.

Have look at the itemeditor example of Qwt 6.1. Your situation is easier as the rubber band of a picker already has the option to look exactly like a line marker, but it might be interesting to get the idea:

1) select an item
2) hide the item, let the widget overlay ( the rubberband of a picker is one ) take its place
3) move the item to its new position and show it again

This is the way I am implementing drag and drop of plot items myself.

Uwe