PDA

View Full Version : QwtPlotPicker questions



ttvo
24th February 2009, 15:30
Hi all,

I'd like to plot an image to QwtPlot and currently subclassing QwtPlotRasterItem by overriding renderImage method. Once the image is plotted:
1) I added a QwtPlotPicker, and it seems to work fine. But how can I get the picker selection (i.e. a rectangle or ellipsoid) to stay on the plot?
2) how can I iterate through the points on my image to highlight those that are inside the picker selection?

Thanks.

Uwe
24th February 2009, 18:46
1) I added a QwtPlotPicker, and it seems to work fine. But how can I get the picker selection (i.e. a rectangle or ellipsoid) to stay on the plot?

You have to implement a new type of QwtPlotItem, that displays your rectangle/ellipsoid. In YourPlotItem::draw use QwtPainter::drawRect/drawEllipse instead of QPainter::drawRect/Ellipse if you want to use QwtPlot::print.


2) how can I iterate through the points on my image to highlight those that are inside the picker selection?



QRect QwtPlotItem::transform(const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QwtDoubleRect& rect) const


Uwe

ttvo
24th February 2009, 20:04
You have to implement a new type of QwtPlotItem, that displays your rectangle/ellipsoid. In YourPlotItem::draw use QwtPainter::drawRect/drawEllipse instead of QPainter::drawRect/Ellipse if you want to use QwtPlot::print.

I tried the following



class SelectionPlotItem : public QwtPlotItem
{
public:
SelectionPlotItem(const QwtText &title=QwtText());
virtual void draw (QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const;


private:
};

and override the draw() method


void SelectionPlotItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const
{
painter->save();
QwtPolygon poly = QwtPolygon(canvasRect);
painter->setPen(QPen(QColor(Qt::blue)));

QwtPainter::drawPolygon(painter, poly);
painter->restore();
}

but it doesn't seem to do anything



QRect QwtPlotItem::transform(const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QwtDoubleRect& rect) const


Uwe
Re/ my 2nd question - but how am I going to iterate through the points on my image to select those point inside the polygon selection?

Perhaps my renderImage is defined incorrectly?



QImage OverlayImagePlot::renderImage(const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QwtDoubleRect &area) const
{


return QImage(_filename);
}

my custom class was defined as:


class OverlayImagePlot : public QwtPlotRasterItem
{
public:
OverlayImagePlot();
OverlayImagePlot(const QwtText &title);
OverlayImagePlot(const QString &title);

virtual ~OverlayImagePlot();
void setArea(QRect area) {_area = area;}
void setFilename(QString filename);
void setPlot(QwtPlot *plot);

protected:
virtual QImage renderImage(const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QwtDoubleRect &area) const;

private:
QwtPlot *_plot;
QRect _area;
QString _filename;
};

Uwe
26th February 2009, 06:52
I tried the following
A selection item without a selection ???



class SelectionPlotItem : public QwtPlotItem
{
public:
SelectionPlotItem(const QwtText &title=QwtText());

void setSelection(const QwtDoubleRect &);
virtual void draw (QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const;


private:
QwtDoubleRect m_selection;
};

void SelectionPlotItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const
{
if ( !m_selection.isEmpty() )
{
const QRect r = transform(xMap, yMap, m_selection);
painter->setPen(...);
painter->setBrush(...);
QwtPainter::drawRect(painter, r);
}


Instead of the rectangle you could paint all without the rectangle with a semi-transparent ( small alpha value ) white brush. "Lowlighting" the non-selected parts has a similar effect as highlighting the selected area.


Re/ my 2nd question - but how am I going to iterate through the points on my image to select those point inside the polygon selection?

Look at the implementation of QwtPlotSpectrogram::renderImage.

Uwe

ttvo
26th February 2009, 14:22
Thx. I got the selection drawn. Though it didn't seem to rescale when the canvas' size changes. Also, I'll split the renderImage into a separate thread.

ttvo
26th February 2009, 16:58
Resize works now, :). Thanks.

Sachtech
28th February 2009, 03:01
Hi,
When I draw the selection rectangle, the grid and the plot comes over the rectangle. How do I set the z-order so that the selection rectangle comes over other things.

---------------

I found it "SetZ" .

Uwe
28th February 2009, 09:44
How do I set the z-order so that the selection rectangle comes over other things.

QwtPlotItem::setZ(...)
You noticed, that there are docs ?

Uwe