Repository navigation
Conversation
1. Root cause: DPrintPreviewDialog (DTK6) only exposes paintRequested signal, no error/failure/saved signal. DocSheet::onPopPrintDialog() connects only paintRequested, has no way to detect save failures. When user saves PDF to a no-permission directory, DTK internal save fails silently, dialog closes, no error shown to user. 2. Fix: save the DPrinter pointer in onPrintRequested callback, then connect QDialog::accepted signal in onPopPrintDialog to check if the output file was actually created via QFile::exists(). If the save path is non-empty (meaning save-to-file mode) but the file does not exist, show a DMessageBox warning prompting possible permission failure. 3. Impact: only affects print preview save-to-file flow; physical printer and normal save paths are unaffected; no API or behavior change for existing callers. Log: Fix print preview not showing error when saving to no-permission directory Influence: 1. Test print preview save to a writable directory (normal path) 2. Test print preview save to a read-only directory (error prompt shown) 3. Test print preview cancel operation (no false error prompt) 4. Test physical printer printing (no file existence check triggered) fix: 修复打印预览保存到无权限目录时无失败提示 1. 根因:DPrintPreviewDialog(DTK6)仅暴露 paintRequested 信号,无错误/ 失败/保存成功信号。DocSheet::onPopPrintDialog() 仅连接 paintRequested, 无法检测保存失败。用户保存 PDF 到无权限目录时,DTK 内部保存静默失败, 对话框关闭,用户无任何错误提示。 2. 方案:在 onPrintRequested 回调中保存 DPrinter 指针,在 onPopPrintDialog 中连接 QDialog::accepted 信号,检查输出文件是否实际创建(QFile::exists)。 若保存路径非空(即保存到文件模式)但文件不存在,弹出 DMessageBox 提示 可能是权限不足导致保存失败。 3. 影响:仅影响打印预览保存到文件的流程;物理打印和正常保存路径不受影响; 对现有调用者无 API 或行为变化。 Log: 修复打印预览保存到无权限目录时无失败提示的问题 Influence: 1. 测试打印预览保存到有写权限的目录(正常路径) 2. 测试打印预览保存到只读目录(弹出错误提示) 3. 测试打印预览取消操作(无误报提示) 4. 测试物理打印机打印(不触发文件存在性检查) PMS: BUG-380955
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideUITrack the active print request and warn after the preview is accepted when a save-to-file path was not created.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="reader/uiframe/DocSheet.cpp" line_range="2093" />
<code_context>
+ connect(preview, &QDialog::accepted, this, [this]() {
+ if (m_printPrinter && !m_printPrinter->outputFileName().isEmpty()) {
+ QString savePath = m_printPrinter->outputFileName();
+ if (!QFile::exists(savePath)) {
+ DMessageBox::warning(this, tr("打印"), tr("保存失败,目标目录可能没有写入权限。"));
+ }
</code_context>
<issue_to_address>
**Save feedback misreports outcomes**
When the destination exists, a failed write leaves a partial file, a non-permission failure leaves no file, or a volume disconnects after writing, `QFile::exists(savePath)` suppresses warnings for failed overwrites or partial writes, but warns after a successful write followed by disconnection and labels other missing-output failures as permission problems; users get incorrect save feedback.
Use the print/write result to decide whether to warn, not file existence.
Also at `reader/uiframe/DocSheet.cpp:2095`.
</issue_to_address>
### Comment 2
<location path="reader/uiframe/DocSheet.cpp" line_range="2089" />
<code_context>
#include <DPrintPreviewDialog>
#include <DWidgetUtil>
+#include <DMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
</code_context>
<issue_to_address>
**Earlier preview can crash**
When two preview dialogs for the same `DocSheet` remain active and the later one closes first, `m_printPrinter` is shared and reset or overwritten by the later request, so the earlier dialog's accepted handler reads its printer, possibly after deletion, missing its save result or dereferencing a stale pointer and crashing.
Capture and use each preview's own printer in its accepted handler instead of reading `m_printPrinter`.
Also at `reader/uiframe/DocSheet.cpp:1035`, `reader/uiframe/DocSheet.cpp:2091`.
</issue_to_address>
### Comment 3
<location path="reader/uiframe/DocSheet.cpp" line_range="1035" />
<code_context>
void DocSheet::onPrintRequested(DPrinter *printer, const QVector<int> &pageRange)
{
+ m_printPrinter = printer;
qCDebug(appLog) << "Print requested for pages:" << pageRange;
if (pageRange.isEmpty()) {
</code_context>
<issue_to_address>
**Direct-path saves skip detection**
When DTK handles a `setPrintFromPath()` print without emitting `paintRequested`, `m_printPrinter` stays null because its only assignment is in `onPrintRequested`; the accepted handler then skips the warning, leaving failed saves on this route silent.
Capture the printer independently of `paintRequested`, or connect failure detection to the direct-path save operation.
Also at `reader/uiframe/DocSheet.cpp:2091`.
</issue_to_address>| connect(preview, &QDialog::accepted, this, [this]() { | ||
| if (m_printPrinter && !m_printPrinter->outputFileName().isEmpty()) { | ||
| QString savePath = m_printPrinter->outputFileName(); | ||
| if (!QFile::exists(savePath)) { |
There was a problem hiding this comment.
🟡 Medium · Save feedback misreports outcomes
When the destination exists, a failed write leaves a partial file, a non-permission failure leaves no file, or a volume disconnects after writing, QFile::exists(savePath) suppresses warnings for failed overwrites or partial writes, but warns after a successful write followed by disconnection and labels other missing-output failures as permission problems; users get incorrect save feedback.
Use the print/write result to decide whether to warn, not file existence.
Also at reader/uiframe/DocSheet.cpp:2095.
Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 2093:
**Save feedback misreports outcomes**
When the destination exists, a failed write leaves a partial file, a non-permission failure leaves no file, or a volume disconnects after writing, `QFile::exists(savePath)` suppresses warnings for failed overwrites or partial writes, but warns after a successful write followed by disconnection and labels other missing-output failures as permission problems; users get incorrect save feedback.
Use the print/write result to decide whether to warn, not file existence.
Also at `reader/uiframe/DocSheet.cpp:2095`.| connect(preview, QOverload<DPrinter *>::of(&DPrintPreviewDialog::paintRequested), this, QOverload<DPrinter *>::of(&DocSheet::onPrintRequested)); | ||
| #endif | ||
| m_printPrinter = nullptr; | ||
|
|
There was a problem hiding this comment.
🟡 Medium · Earlier preview can crash
When two preview dialogs for the same DocSheet remain active and the later one closes first, m_printPrinter is shared and reset or overwritten by the later request, so the earlier dialog's accepted handler reads its printer, possibly after deletion, missing its save result or dereferencing a stale pointer and crashing.
Capture and use each preview's own printer in its accepted handler instead of reading m_printPrinter.
Also at reader/uiframe/DocSheet.cpp:1035, reader/uiframe/DocSheet.cpp:2091.
Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 2089:
**Earlier preview can crash**
When two preview dialogs for the same `DocSheet` remain active and the later one closes first, `m_printPrinter` is shared and reset or overwritten by the later request, so the earlier dialog's accepted handler reads its printer, possibly after deletion, missing its save result or dereferencing a stale pointer and crashing.
Capture and use each preview's own printer in its accepted handler instead of reading `m_printPrinter`.
Also at `reader/uiframe/DocSheet.cpp:1035`, `reader/uiframe/DocSheet.cpp:2091`.|
|
||
| void DocSheet::onPrintRequested(DPrinter *printer, const QVector<int> &pageRange) | ||
| { | ||
| m_printPrinter = printer; |
There was a problem hiding this comment.
🟠 High · Direct-path saves skip detection
When DTK handles a setPrintFromPath() print without emitting paintRequested, m_printPrinter stays null because its only assignment is in onPrintRequested; the accepted handler then skips the warning, leaving failed saves on this route silent.
Capture the printer independently of paintRequested, or connect failure detection to the direct-path save operation.
Also at reader/uiframe/DocSheet.cpp:2091.
Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 1035:
**Direct-path saves skip detection**
When DTK handles a `setPrintFromPath()` print without emitting `paintRequested`, `m_printPrinter` stays null because its only assignment is in `onPrintRequested`; the accepted handler then skips the warning, leaving failed saves on this route silent.
Capture the printer independently of `paintRequested`, or connect failure detection to the direct-path save operation.
Also at `reader/uiframe/DocSheet.cpp:2091`.
Root Cause Analysis
When a user prints a document to PDF and saves to a directory without write permission,
DPrintPreviewDialog(DTK) silently fails the file write internally and closes the dialog without any error signal. The root cause is that DTK'sDPrintPreviewDialogonly emitspaintRequestedsignals — there are no error/failure/saved/result signals (confirmed via Qt meta-object introspection).DocSheet::onPopPrintDialog()only connectspaintRequestedand has no mechanism to detect save failures, so the user gets no feedback when saving fails.Fix Approach
Add indirect failure detection in
DocSheet::onPopPrintDialog(): save theDPrinter*pointer (set inonPrintRequested()) as a member variable, connectQDialog::acceptedto a lambda that checks whetheroutputFileName()is set and the file does not exist at that path — if so, show aDMessageBoxwarning. This is a symptom-level patch; the root-cause fix (adding save-result signals to DTK) is out of scope for this repository.Change Safety Assessment
Code Safety
QDialog::acceptedsignal connection (lambda), a member variable assignment in twoonPrintRequestedoverloads, and a new private memberm_printPrinterinDocSheet.h. No existing function signatures, public APIs, or call paths are modified.Business Impact Scope
Affected module: Print Preview. User scenario: saving a PDF to a no-permission directory now shows an error dialog instead of silently closing. Normal print operations (physical printer, saving to writable directories) are unaffected.
Verification Suggestion
DMessageBoxwarning appears.根因分析
用户在打印预览中保存 PDF 到无权限目录时,DTK 的
DPrintPreviewDialog内部写入文件失败后静默关闭对话框,不发出任何错误信号。根因是DPrintPreviewDialog仅有paintRequested信号,无 error/failure/saved/result 信号(经 Qt 元对象内省确认)。DocSheet::onPopPrintDialog()仅连接paintRequested,无法检测保存失败,导致用户无任何反馈。修复方案
在
DocSheet::onPopPrintDialog()中增加间接失败检测:将onPrintRequested()中获取的DPrinter*指针保存为成员变量,连接QDialog::accepted信号到 lambda,检查outputFileName()非空且文件不存在时弹出DMessageBox警告。此为症状层补丁;根因层修复(DTK 增加保存结果信号)超出本仓库范围。改动安全评估
代码安全评估
QDialog::accepted信号连接(lambda)、两个onPrintRequested重载中的成员变量赋值、DocSheet.h新增私有成员m_printPrinter。不修改任何现有函数签名、公开 API 或调用路径。业务影响范围
受影响模块:打印预览。用户场景:保存 PDF 到无权限目录时会弹出错误提示,而非静默关闭。正常打印操作(物理打印机、保存到可写目录)不受影响。
验证建议
DMessageBox警告。Summary by Sourcery
Bug Fixes: