Reimplement Chart::paint() to fix printing issues
ClosedPublic

Authored by habacker on Mar 5 2019, 1:57 PM.

Details

Summary

The previous implementation did not take the headers and footers
into account when resizing the diagram.

The implementation has been taken from AbstractArea::paintIntoRectArea().

This patch adds the method PrintingParameters::scaleFactor(), because
in branch 2.6 the class member PrintingParameters::scaleFactor was made
private.

BUG:405075
FIXED-IN:2.6.2

Test Plan

tested on linux

Diff Detail

Repository
R478 KDiagram: Libraries for diagrams
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
habacker requested review of this revision.Mar 5 2019, 1:57 PM
habacker created this revision.

You may check this with the extended test case from D19516

habacker updated this revision to Diff 53254.Mar 6 2019, 8:12 AM
  • reset scale factor after painting

A few points:

  • KChartPrintingParameters::setScaleFactor( ) is needed?
  • Line 1357: Use nullptr
  • Patch dosen't apply for me, git gives no reason so don't know why.

Need to test this with calligra as it uses the paint method to paint charts.

A few points:

  • KChartPrintingParameters::setScaleFactor( ) is needed?

It was used before, so I added it to. With this call visual inspection shows that the graph looks nicer in my opinion

  • Line 1357: Use nullptr

I will fix this

  • Patch dosen't apply for me, git gives no reason so don't know why.

Sorry, my local 2.6. branch seemed to be outdated - patch applies to git master, i will update it

Need to test this with calligra as it uses the paint method to paint charts.

habacker updated this revision to Diff 53639.Mar 11 2019, 10:17 AM
habacker edited the summary of this revision. (Show Details)
  • rebased patch to 2.6 head

Naah, doesn't work with calligra. I think you need scaling also for the widget case.

Naah, doesn't work with calligra.

I verified that this patch works with the extended test case added by D19516. Does it work for you ?

Sorry, my local 2.6. branch seemed to be outdated - patch applies to git master, i will update it

git master seemed also to be moved, original patch does not apply also. rebase 2.6 patch should apply on master also.

Naah, doesn't work with calligra. I think you need scaling also for the widget case.

You are refering to add the call to PrintingParameters::setScaleFactor unconditionally ?

Hmmm, my system seems very broken atm, so cannot test anything with confidence.
I'll get back to you when I get it sorted.

danders accepted this revision.Mar 12 2019, 11:46 AM

Yup, it was my system acting up, so please commit.

This revision is now accepted and ready to land.Mar 12 2019, 11:46 AM

Accepting was a bit premature.
I found the problem with my system (qt 5.12 has some changes in drag/drop).
Anyway this does not work in calligra, give me a little time to figure it out.

Ok, it works in calligra if stuff is invalidated like in the original:

d->isPlanesLayoutDirty = true;
d->isFloatingLegendsLayoutDirty = true;
invalidateLayoutTree( d->dataAndLegendLayout );
d->dataAndLegendLayout->setGeometry( QRect( QPoint(), rect.size() ) );

I don't know if you need it both before and after painting.

habacker added a comment.EditedMar 13 2019, 10:21 AM

Just to be sure, you checked printing, generating png and pdf from the DrawInPainter example with D19680 and D19685 applied and didn't noticed any unusual ?

Ok, it works in calligra if stuff is invalidated like in the original:

d->isPlanesLayoutDirty = true;
d->isFloatingLegendsLayoutDirty = true;
invalidateLayoutTree( d->dataAndLegendLayout );
d->dataAndLegendLayout->setGeometry( QRect( QPoint(), rect.size() ) );

I don't know if you need it both before and after painting.

This code was the reason for the initial bug report, because it does not care about header/footer positions (see recent HeaderFooterAdvanced example).

In the opposite calling KChart::setGeometry() covers all geometry, which can be verified with recent HeaderFooterAdvanced example and this patch applied.

With this patch, the DrawInPainter example shows a slightly different behavior with respect to the extension of the diagram. Previously the diagram was adapted to the size of the drawing area by changing the aspect ratio. This patch preserves the original aspect ratio, which can be desired. Maybe you can make this switchable.

Just to be sure, you checked printing, generating png and pdf from the DrawInPainter example with D19680 and D19685 applied and didn't noticed any unusual ?

Ok, it works in calligra if stuff is invalidated like in the original:

d->isPlanesLayoutDirty = true;
d->isFloatingLegendsLayoutDirty = true;
invalidateLayoutTree( d->dataAndLegendLayout );
d->dataAndLegendLayout->setGeometry( QRect( QPoint(), rect.size() ) );

I don't know if you need it both before and after painting.

This code was the reason for the initial bug report, because it does not care about header/footer positions (see recent HeaderFooterAdvanced example).

In the opposite calling KChart::setGeometry() covers all geometry, which can be verified with recent HeaderFooterAdvanced example and this patch applied.

With this patch, the DrawInPainter example shows a slightly different behavior with respect to the extension of the diagram. Previously the diagram was adapted to the size of the drawing area by changing the aspect ratio. This patch preserves the original aspect ratio, which can be desired. Maybe you can make this switchable.

Sorry, only checked HeadersFooters which seems to work fine also with invalidating.

Original DrawIntoPainter:
Even the original doen't work well. Save as png works "ok", but does not include the small charts on top.
Save as PDF only include part of the basic chart -> useless.

DrawIntoPainter with your patches:
Chart has a fixed size so does not resize.
Png saves the same even after resize.
Pdf a total mess.

So, I'm usure of what to expect and assume you get better results?
(This is without any invalidating, just you patches).

I have applied this patch (it does not apply, so did it manually) along with D19680 and D19685.

I have applied this patch (it does not apply, so did it manually) along with D19680 and D19685.

I do not see the patches from D19680 and D19685 in kdiagram master branch

I have applied this patch (it does not apply, so did it manually) along with D19680 and D19685.

I do not see the patches from  D19680 and D19685 in kdiagram master branch

No, no, I just downloded them and git apply.

I created a task T10614 to be able to upload some screenshots and files, so you can see how this works for me.

This revision was automatically updated to reflect the committed changes.