QwtPlot - Copying before using with QwtPlotRenderer
I have a custom QwtPlot that I want to render inside a pdf document. (see use-case image)
QwtPlotRenderer looks to be perfect for doing this, the only thing is that I need to edit a few thing on the Plot before rendering it.
Right now I just modify the original plot directly before rendering it, which cause the interface to also be modified.
Here is an example :
Code:
void WorkoutCreator::exportWorkoutToPdf() {
/// TODO: Add Title, remove background image, increase margins
ui->widget_plot->setContentsMargins(20,20,20,20);
QwtPlotRenderer renderer;
renderer.exportTo( ui->widget_plot, "shapes.pdf" );
/// Revert plot back to normal (best would be to copy to a new QwtPlot and trash it after this function is done..)
ui->widget_plot->setContentsMargins(0,0,0,0);
}
I would like to copy the QwtPlot with all it's objects (it's just a normal QwtPlot with a few QwtPlotShapeItem)
I have tried to code a copy Constructor, but I'm having problem copying the QwtPlotShapeItem.
Is there an easier solution that I'm missing?
Thanks a lot!
Re: QwtPlot - Copying before using with QwtPlotRenderer
You can't copy widgets ( or QwtPlotItems ). Your only option - beside modify + export + revert of the original one - is to create a second ( invisible ) one.
The plot items could be temporarily attached to the second one and reattached to the first one again, when the export is done.
Uwe
Re: QwtPlot - Copying before using with QwtPlotRenderer
Oh nice idea to have a second invisible one!
Thanks Uwe and many thanks for Qwt hopefully I can repay you sometime soon!
This did the trick:
Code:
void WorkoutCreator::exportWorkoutToPdf() {
/// ui->widget_plot_report is a copy of ui->widget_plot formatted for reports - widget is setVisible(false)
ui->widget_plot_report->setTitle(workout.getName());
ui->widget_plot_report->setContentsMargins(20,20,20,20);
QwtPlotRenderer renderer;
renderer.exportTo( ui->widget_plot_report, "shapes.pdf" );
}