Skip to content

Commit

Permalink
fix: printCount not decrease on low dtk version
Browse files Browse the repository at this point in the history
On low dtk verison, dprintpreviewdialog return same value
whatever accept/reject. dtk fixes it in 5.6.9
Add print flag on paint function() to detect print behavior
on low verion.

Log: Fix printCount not decrease on low dtk version
Bug: https://pms.uniontech.com/bug-view-241949.html
  • Loading branch information
rb-union committed Feb 2, 2024
1 parent cd195ac commit 0ae4232
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
48 changes: 41 additions & 7 deletions libimageviewer/widgets/printhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,24 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
return;
}

m_re->m_paths.clear();
m_re->m_imgs.clear();
m_re->clearPrintState();
m_re->setPaths(paths);

m_re->m_paths = paths;
QStringList tempExsitPaths; // 保存存在的图片路径
for (const QString &path : paths) {
QString errMsg;
QImageReader imgReadreder(path);
if (imgReadreder.imageCount() > 1) {
for (int imgindex = 0; imgindex < imgReadreder.imageCount(); imgindex++) {
imgReadreder.jumpToImage(imgindex);
m_re->m_imgs << imgReadreder.read();
m_re->appendImage(imgReadreder.read());
}
} else {
// QImage不应该多次赋值,所以换到这里来,修复style问题
QImage img;
LibUnionImage_NameSpace::loadStaticImageFromFile(path, img, errMsg);
if (!img.isNull()) {
m_re->m_imgs << img;
m_re->appendImage(img);
}
}
tempExsitPaths << paths;
Expand Down Expand Up @@ -108,14 +107,19 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
int ret = QDialog::Accepted;
#endif

// DTKWidget 在 5.6.9 版本前,无论是否打印,只会返回相同值 0 ,区分版本判断 (DTKWIDGET_CLASS_DWaterMarkHelper在 5.6.9 提供)
// 没有直接以 DTKCore(DTK_VERSION_CHECK) 版本判断,DTKCore 和 DTKWidget 版本可能不同
#ifndef DTKWIDGET_CLASS_DWaterMarkHelper
if (m_re->isPrinted()) {
#else
if (QDialog::Accepted == ret) {
#endif
if (!tempExsitPaths.isEmpty()) {
PermissionConfig::instance()->triggerPrint(tempExsitPaths.first());
}
}

m_re->m_paths.clear();
m_re->m_imgs.clear();
m_re->clearPrintState();
}

RequestedSlot::RequestedSlot(QObject *parent)
Expand All @@ -125,6 +129,32 @@ RequestedSlot::RequestedSlot(QObject *parent)

RequestedSlot::~RequestedSlot() {}

void RequestedSlot::clearPrintState()
{
m_paths.clear();
m_imgs.clear();
m_printed = false;
}

/**
@brief 设置打印文件路径 `paths`
*/
void RequestedSlot::setPaths(const QStringList &paths)
{
m_paths = paths;
}

/**
@brief 追加打印图片数据 `img`
*/
void RequestedSlot::appendImage(const QImage &img)
{
m_imgs << img;
}

/**
@brief dtk打印组件请求绘制页面,将打印信息绘制到 `_printer` 中
*/
void RequestedSlot::paintRequestSync(DPrinter *_printer)
{
// 由于之前再度修改了打印的逻辑,导致了相同图片不在被显示,多余多页tiff来说不合理
Expand Down Expand Up @@ -154,4 +184,8 @@ void RequestedSlot::paintRequestSync(DPrinter *_printer)
}
}
painter.end();

if (!m_printed && 0 != indexNum) {
m_printed = true;
}
}
14 changes: 11 additions & 3 deletions libimageviewer/widgets/printhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ class RequestedSlot : public QObject
explicit RequestedSlot(QObject *parent = nullptr);
~RequestedSlot();

private slots:
void paintRequestSync(DPrinter *_printer);
// 清理打印状态,当前是否触发打印
void clearPrintState();
inline bool isPrinted() { return m_printed; }

public:
void setPaths(const QStringList &paths);
void appendImage(const QImage &img);

private:
Q_SLOT void paintRequestSync(DPrinter *_printer);

private:
QStringList m_paths;
QList<QImage> m_imgs;
bool m_printed = false;
};

class PrintHelper : public QObject
Expand Down

0 comments on commit 0ae4232

Please sign in to comment.