Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't write to PDF files with JKQTPlotter::saveImage() when passing a filename ending in ".pdf" #111

Closed
fpalazzolo opened this issue Dec 4, 2023 · 4 comments
Assignees
Labels

Comments

@fpalazzolo
Copy link
Contributor

The documentation indicates that saveImage() should be able to write to pdf files. But, at least in my case on Windows, if you pass a filename like "test.pdf", the file is not written. The issue is that the variable "selFormat" in JKQTBasePlotter::saveImage() is only set if it is parsed out of the filesave dialog, which is skipped if the filename is already set:

    QString selFormat="";
    if (fn.isEmpty()) {
        selFormat=currentFileFormat;
        fn = QFileDialog::getSaveFileName(nullptr, tr("Save Plot"),
                                    currentSaveDirectory,
                                          filt.join(";;"), &selFormat);

and then later:

    if (!fn.isEmpty()) {
        int filtID=filt.indexOf(selFormat);

After this, filtID is -1, and things are not right from that point on. At this point, an invalid reference gets passed to JKQTBasePlotter::savePixelImage(), which has similar logic, and also finds filtID = -1. Then, the only reason the other formats work at all is that QImage.save() knows how to save all the image formats based on the extension.

I suspect SVG file saving is similarly broken for this use case.

My quick workaround was to use saveAsPDF() directly.

In the end, JKQTBasePlotter::saveImage() (and maybe JKQTBasePlotter::savePixelImage()) should probably be reviewed to insure that they work properly for all file types they support, when the filename is set prior to calling. I don't have time to do this now, but maybe later.

@jkriege2 jkriege2 self-assigned this Dec 8, 2023
@jkriege2 jkriege2 added the bug label Dec 8, 2023
@jkriege2
Copy link
Owner

jkriege2 commented Dec 8, 2023

Hi!

thanks for reporting ... I will lokk into this... but give me some time!

Best,
JAN

jkriege2 added a commit that referenced this issue Dec 21, 2023
…::saveImage() when passing a filename ending in ".pdf" (thanks to https://github.com/fpalazzolo for reporting)

IMPROVED/REWORKED: The functions JKQTBasePlotter::saveImage(), JKQTBasePlotter::saveAsPixelImage(), JKQTBasePlotter::saveAsPDF(), JKQTBasePlotter::saveSVG(), ... gained a bool return value to indicate whether sacing was successful.
IMPROVED/REWORKED: More <code>save...()</code> functions will appear in the API of JKQTPlotter, so you don't have to go via JKQTPlotter::getPlotter(). These are merely forwarding the call to the internel JKQTBasePlotter instance.
@jkriege2
Copy link
Owner

Hi!

I reworked these methods, so the issue should be fixed via 995ca92 ...

Could you please verify?

Thanks,
JAN

@jkriege2
Copy link
Owner

@fpalazzolo: This should be resolved! Can I close the issue?

@jkriege2
Copy link
Owner

This should be fixed. Please reopen if the problem persists, or post a new issue!

THANKS!
JAN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants