Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions reader/document/XpsDocumentAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,14 @@ QImage XpsDocumentAdapter::renderPage(int pageIndex, int width, int height, cons

ensurePageCache();

QMutexLocker lock(&m_mutex);
if (pageIndex < 0 || pageIndex >= m_pageSizes.size()) {
qCWarning(appLog) << "Render request out of bounds" << pageIndex;
return QImage();
QSizeF logicalSize;
{
QMutexLocker lock(&m_mutex);
if (pageIndex < 0 || pageIndex >= m_pageSizes.size()) {
qCWarning(appLog) << "Render request out of bounds" << pageIndex;
return QImage();
}
logicalSize = m_pageSizes.at(pageIndex);
}

qCDebug(appLog) << "Rendering XPS page" << pageIndex << "@" << width << "x" << height << "slice" << slice;
Expand All @@ -647,8 +651,6 @@ QImage XpsDocumentAdapter::renderPage(int pageIndex, int width, int height, cons
logGError(QStringLiteral("gxps_document_get_page failed"), pageError.get());
return QImage();
}

const QSizeF logicalSize = m_pageSizes.at(pageIndex);
if (logicalSize.isEmpty() || logicalSize.width() <= 0.0 || logicalSize.height() <= 0.0) {
qCWarning(appLog) << "Invalid logical size for XPS page" << logicalSize;
return QImage();
Expand Down
43 changes: 39 additions & 4 deletions reader/sidebar/SideBarImageViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "Application.h"
#include "ddlog.h"

#include <QTimer>

Check warning on line 12 in reader/sidebar/SideBarImageViewModel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 13 in reader/sidebar/SideBarImageViewModel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSet>

Check warning on line 14 in reader/sidebar/SideBarImageViewModel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <algorithm>

Check warning on line 15 in reader/sidebar/SideBarImageViewModel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <algorithm> not found. Please note: Cppcheck does not need standard library headers to get proper results.

ImagePageInfo_t::ImagePageInfo_t(int index): pageIndex(index)
{
Expand Down Expand Up @@ -41,6 +43,11 @@
{
qCDebug(appLog) << "SideBarImageViewModel created for document:" << (sheet ? sheet->filePath() : "null");
connect(m_sheet, &DocSheet::sigPageModified, this, &SideBarImageViewModel::onUpdateImage);

m_batchUpdateTimer = new QTimer(this);
m_batchUpdateTimer->setSingleShot(true);
m_batchUpdateTimer->setInterval(100);
connect(m_batchUpdateTimer, &QTimer::timeout, this, &SideBarImageViewModel::onBatchUpdateTimer);
}

void SideBarImageViewModel::resetData()
Expand Down Expand Up @@ -297,8 +304,36 @@
pixmap.setDevicePixelRatio(dApp->devicePixelRatio());
m_sheet->setThumbnail(index, pixmap);

const QList<QModelIndex> &modelIndexlst = getModelIndexForPageIndex(index);
qCDebug(appLog) << "Notifying" << modelIndexlst.size() << "views of data change";
for (const QModelIndex &modelIndex : modelIndexlst)
emit dataChanged(modelIndex, modelIndex);
m_pendingUpdatePages.insert(index);
if (!m_batchUpdateTimer->isActive()) {
m_batchUpdateTimer->start();
}
}

void SideBarImageViewModel::onBatchUpdateTimer()
{
if (m_pendingUpdatePages.isEmpty()) {
return;
}

qCDebug(appLog) << "Batch updating" << m_pendingUpdatePages.size() << "thumbnails";

QList<QModelIndex> allModelIndexes;
for (int pageIndex : m_pendingUpdatePages) {
const QList<QModelIndex> &modelIndexlst = getModelIndexForPageIndex(pageIndex);
allModelIndexes.append(modelIndexlst);
}

if (!allModelIndexes.isEmpty()) {
std::sort(allModelIndexes.begin(), allModelIndexes.end(),
[](const QModelIndex &a, const QModelIndex &b) {
return a.row() < b.row();
});

for (const QModelIndex &modelIndex : allModelIndexes) {
emit dataChanged(modelIndex, modelIndex);
}
}

m_pendingUpdatePages.clear();
}
12 changes: 12 additions & 0 deletions reader/sidebar/SideBarImageViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#ifndef SIDEBARIMAGEVIEWMODEL_H
#define SIDEBARIMAGEVIEWMODEL_H

#include <QAbstractListModel>

Check warning on line 9 in reader/sidebar/SideBarImageViewModel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QAbstractListModel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMap>

Check warning on line 10 in reader/sidebar/SideBarImageViewModel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 11 in reader/sidebar/SideBarImageViewModel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSet>

Check warning on line 12 in reader/sidebar/SideBarImageViewModel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace deepin_reader {
class Annotation;
Expand Down Expand Up @@ -201,12 +203,22 @@
*/
bool setData(const QModelIndex &index, const QVariant &data, int role) override;

private slots:
/**
* @brief onBatchUpdateTimer
* 批量更新定时器触发
*/
void onBatchUpdateTimer();

private:
QObject *m_parent = nullptr;
DocSheet *m_sheet = nullptr;
QList<ImagePageInfo_t> m_pagelst;
QMap<int, bool> m_cacheBookMarkMap;
static QMap<QObject *, QVector<QPixmap>> g_sheetPixmapMap;

QTimer *m_batchUpdateTimer = nullptr;
QSet<int> m_pendingUpdatePages;
};

#endif // SIDEBARIMAGEVIEWMODEL_H