Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions libimageviewer/widgets/printhelper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020 - 2024 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -69,7 +69,9 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
m_re->appendImage(img);
}
}
tempExsitPaths << paths;
if (!path.isEmpty()) {
tempExsitPaths << path;
Comment on lines +72 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Align tempExsitPaths with successfully loaded images rather than non-empty paths.

Currently any non-empty path is added to tempExsitPaths, even when image loading/appendImage fails. This can produce doc names based on files that were never printed. Please only append to tempExsitPaths after the image has been successfully loaded/handled so the doc name matches the actual printed content.

Suggested implementation:

                m_re->appendImage(img);
                if (!path.isEmpty()) {
                    tempExsitPaths << path;
                }
            }
        }

    }

Depending on the surrounding code, you may also want to ensure this block is only reached when the image has been successfully loaded (e.g. !img.isNull() or a successful return value from a loader). In that case, make sure the if (!path.isEmpty()) { tempExsitPaths << path; } remains inside that success-checking if so tempExsitPaths reflects only successfully loaded/printed images.

}
}

// 看图采用同步,因为只有一张图片,传入父指针
Expand All @@ -78,10 +80,13 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
(DTK_VERSION_MAJOR >= 5 && DTK_VERSION_MINOR >= 4 && DTK_VERSION_PATCH >= 10)) // 5.4.4暂时没有合入
// 增加运行时版本判断
if (DApplication::runtimeDtkVersion() >= DTK_VERSION_CHECK(5, 4, 10, 0)) {
if (!tempExsitPaths.isEmpty()) {
// 直接传递为路径,不会有问题
printDialog2.setDocName(QFileInfo(tempExsitPaths.at(0)).absoluteFilePath());
QString documentName = tempExsitPaths.isEmpty()
? QStringLiteral("print")
: QFileInfo(tempExsitPaths.first()).fileName();
if (documentName.isEmpty()) {
documentName = QStringLiteral("print");
}
printDialog2.setDocName(documentName);
}
#endif

Expand Down
Loading