PDA

View Full Version : QwtPlotItem copy, or better solution



Asting
8th June 2014, 18:26
Hello all,
my question: is it possible to copy QwtPlotItem(curve, or shape for example), for used it later after it was used once? Easier explain: I want to initialize
QwtPlotShapeItem *shape1;
shape1 = new QwtPlotShape;
shape1.setRect(...); then attach this item to plot:
shape1->attach(ui->qwtPlot);
ui->qwtPlot->replot();. Then clear this plot, use some other items, and then again attach this shape1:

ui->qwtPlot->detachItems();
shape1->attach(ui->qwtPlot);
ui->qwtPlot->replot;
But now, I think item after "attach" metod going out and losing a date. I tried to copy:
QwtPlotShapeItem shape2;
shape2 = shape1; but it seems to copy only poiter to first data. And after applying shape2, item shape1 also clearing. Ofc I tried copy *shape2 = *shape1; But compiler says so QwtPlotShapeItem::d_data* is private.
So Im looking a way to keep QwtPlotItem in memory for multi-using it. Way with saving date for this items and generete new items every time from date I now, but I have a lot of date and I need perfomance, so that is a question.

Let me try describe my task in general, mb someone can suggest better solution:
I getting a text file with date - spectrogram. Date its multiplicity of rectangles and temperatures for them. For example one file can contains 100 different plot-s with 6000 rectangles for each plot. For draw it in QwtPlot I just drawing rectangles with color witch obtained through QwtLinearColorMap from temperature value. General task is to try make animation from this plots in qwtPlot - so replot this date in QwtPlot as fast as possible (not faster then 24 fps:)) Ofcourse Im going to keep all this date in prog memory, but now I can work succesfull only like keep this date like multiplicity of QRectF-s and QColor-s and for every plot going to create new QwtPlotItemShape -> setRect/setBrush... Perfomance witch I got: 2-2.2 plot/second (ofc depens from computer, but it for work pc). In case if I will keep in memory ready QwtPlotItemShapes, I will have around 8-9 plot/sec...better, but I cannot use twice items wich was attached already(first question of topic.). Actually best solution can be store ready content of QwtPlot as a whole (mb plotLayout, but Idc what is it and how it work...).
So I would be very gratefull if someone can give me some recommendation about copy of QwtItes or in gereral about solution for my task. Feel free to clarify, if my describtion is unclear.

Cah
9th June 2014, 17:13
The copy constructor is declared private... i.e. disabled.


ui->qwtPlot->detachItems();
Calling detachItems() without arguments causes all QwtPlotItem::Rtti_PlotItem to be detached and deleted.

You need to call detachItems() with arguments. In particular the second argument must be false to prevent the item from being deleted.

If I follow you correctly, QwtPlotItem::setVisible() might be an option

Asting
14th June 2014, 23:25
tnx for answer Cah,
detachItems() with Rtti argumet very useful, Im going to this way.
Also I found, that in this command can be specified argument for auto-deliting detached items, and by default it delet, but this way is not realy usefull for me.