Skip to content

Commit

Permalink
chore: 代码优化
Browse files Browse the repository at this point in the history
 代码优化

Log: 代码优化

Bug:
  • Loading branch information
LeiYu-uniontech committed Oct 20, 2020
1 parent b50644c commit 5a6b125
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/browser/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ void BrowserPage::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio

void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation, const bool &renderLater, const bool &force)
{
if (m_page == nullptr)
m_page = m_parent->page(itemIndex());
loadPage();

if (!force && renderLater && qFuzzyCompare(scaleFactor, m_scaleFactor) && rotation == m_rotation)
return;
Expand Down
6 changes: 2 additions & 4 deletions src/browser/SheetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ QImage SheetBrowser::firstThumbnail(const QString &filePath)

int fileType = Dr::fileType(filePath);

int status = -1;
if (Dr::PDF == fileType)
document = deepin_reader::PDFDocument::loadDocument(filePath, QString(), status);
document = deepin_reader::PDFDocument::loadDocument(filePath, QString());
else if (Dr::DjVu == fileType)
document = deepin_reader::DjVuDocument::loadDocument(filePath);

Expand Down Expand Up @@ -168,9 +167,8 @@ bool SheetBrowser::open(const Dr::FileType &fileType, const QString &filePath, c
{
m_filePassword = password;

int status = -1;
if (Dr::PDF == fileType)
m_document = deepin_reader::PDFDocument::loadDocument(filePath, password, status);
m_document = deepin_reader::PDFDocument::loadDocument(filePath, password);
else if (Dr::DjVu == fileType)
m_document = deepin_reader::DjVuDocument::loadDocument(filePath);

Expand Down
20 changes: 13 additions & 7 deletions src/document/PDFModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ Annotation *PDFPage::moveIconAnnotation(Annotation *annot, const QRectF &rect)
}

PDFDocument::PDFDocument(DPdfDoc *document) :
m_mutex(),
m_document(document)
m_document(document),
m_mutex()
{
}

Expand Down Expand Up @@ -382,14 +382,20 @@ Properties PDFDocument::properties() const
return m_fileProperties;
}

PDFDocument *PDFDocument::loadDocument(const QString &filePath, const QString &password, int &status)
PDFDocument *PDFDocument::loadDocument(const QString &filePath, const QString &password)
{
status = DPdfDoc::tryLoadFile(filePath, password);
if (status == DPdfDoc::SUCCESS) {
DPdfDoc *document = new DPdfDoc(filePath, password);
DPdfDoc *document = new DPdfDoc(filePath, password);
if (document->status() == DPdfDoc::SUCCESS)
return new deepin_reader::PDFDocument(document);
else {
delete document;
return nullptr;
}
return nullptr;
}

int PDFDocument::tryLoadDocument(const QString &filePath, const QString &password)
{
return DPdfDoc::tryLoadFile(filePath, password);
}

}
Expand Down
12 changes: 7 additions & 5 deletions src/document/PDFModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PDFPage : public Page

QSizeF sizeF() const override;

QImage render(const qreal & scaleFactor) const override;
QImage render(const qreal &scaleFactor) const override;

QImage render(Dr::Rotation rotation, const double scaleFactor, const QRectF &boundingRect = QRectF()) const override;

Expand Down Expand Up @@ -142,17 +142,19 @@ class PDFDocument : public Document

Properties properties() const override;

static deepin_reader::PDFDocument *loadDocument(const QString &filePath, const QString &password, int &status);
static PDFDocument *loadDocument(const QString &filePath, const QString &password);

static int tryLoadDocument(const QString &filePath, const QString &password);

private:
Q_DISABLE_COPY(PDFDocument)

PDFDocument(DPdfDoc *document);

mutable QMutex m_mutex;
explicit PDFDocument(DPdfDoc *document);

DPdfDoc *m_document = nullptr;

mutable QMutex m_mutex;

mutable Properties m_fileProperties;

mutable Outline m_outline;
Expand Down
12 changes: 2 additions & 10 deletions src/uiframe/DocSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,18 +907,12 @@ void DocSheet::showEncryPage()
bool DocSheet::needPassword()
{
int status = -1;
Document *document = nullptr;
if (Dr::PDF == m_fileType)
document = deepin_reader::PDFDocument::loadDocument(filePath(), QString(), status);
status = deepin_reader::PDFDocument::tryLoadDocument(filePath(), QString());

if (status == Document::PASSWORD_ERROR)
return true;

if (nullptr == document)
return false;

delete document;

return false;
}

Expand Down Expand Up @@ -946,12 +940,10 @@ QString DocSheet::getPageLabelByIndex(const int &index)
bool DocSheet::tryPassword(QString password)
{
int status = -1;
Document *document = nullptr;
if (Dr::PDF == m_fileType)
document = deepin_reader::PDFDocument::loadDocument(filePath(), password, status);
status = deepin_reader::PDFDocument::tryLoadDocument(filePath(), password);

if (status == Document::SUCCESS) {
delete document;
return true;
}
return false;
Expand Down

0 comments on commit 5a6b125

Please sign in to comment.