Открыть боковую панель
Aurora OS
Libraries
AmberPDF QML Plugin
Коммиты
297cea9e
Коммит
297cea9e
создал
Дек 06, 2023
по автору
OMP Education
Зафиксировано автором
k.sagalakova
Фев 15, 2024
Просмотр файлов
[View] Add preload all pages.
Co-Authored-By:
Anton Zernin
<
a.zernin@omp.ru
>
владелец
ea6ba86e
Изменения
8
Скрыть пробелы
Построчно
Рядом
plugin/src/interface/basedocument.h
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef BASEDOCUMENT_H
...
...
@@ -41,6 +41,7 @@ public:
virtual
QString
path
()
const
;
virtual
QSizeF
pageSize
(
int
pageNumber
)
const
=
0
;
virtual
int
count
()
const
=
0
;
virtual
void
loadAllPages
()
=
0
;
virtual
QSharedPointer
<
BasePage
>
loadPage
(
int
pageIndex
)
=
0
;
virtual
void
startLoadBookmarks
()
const
=
0
;
virtual
QVector
<
BaseBookmark
*>
bookmarks
()
const
=
0
;
...
...
plugin/src/pageswithnotesmodel.cpp
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022
-
2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-
2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#include
"interface/basedocument.h"
...
...
@@ -68,6 +68,12 @@ void PagesWithNotesModel::setNewData(BaseDocument *provider)
endResetModel
();
}
void
PagesWithNotesModel
::
preLoadAllNotes
()
{
if
(
m_documentProvider
)
m_documentProvider
->
loadAllPages
();
}
void
PagesWithNotesModel
::
_addPage
(
int
pageIndex
)
{
if
(
m_documentProvider
==
nullptr
)
...
...
plugin/src/pageswithnotesmodel.h
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022
-
2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-
2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef PAGESWITHNOTESMODEL_H
...
...
@@ -29,6 +29,9 @@ public:
void
setNewData
(
BaseDocument
*
newData
);
public
slots
:
void
preLoadAllNotes
();
private
slots
:
void
_addPage
(
int
pageIndex
);
...
...
plugin/src/pdfium-provider/pagepreloader.cpp
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#include
<QMutexLocker>
...
...
@@ -9,9 +9,11 @@
QMutex
PagePreloader
::
m_mutex
;
PagePreloader
::
PagePreloader
(
QSharedPointer
<
PdfDocument
>
document
,
int
pageIndex
)
:
PagePreloader
::
PagePreloader
(
QSharedPointer
<
PdfDocument
>
document
,
int
pageIndex
,
int
countPages
)
:
m_document
(
document
),
m_pageIndex
(
pageIndex
)
m_pageIndex
(
pageIndex
),
m_count
(
countPages
),
m_isCanceled
(
false
)
{
}
PagePreloader
::~
PagePreloader
()
=
default
;
...
...
@@ -23,11 +25,22 @@ void PagePreloader::run()
return
;
}
QMutexLocker
lock
(
&
m_mutex
);
auto
pageFuture
=
m_document
->
page
(
m_pageIndex
);
pageFuture
.
waitForFinished
();
if
(
pageFuture
.
isFinished
()
&&
!
pageFuture
.
isCanceled
())
emit
done
(
m_pageIndex
,
BaseDocument
::
PageLoadStatus
::
Success
);
else
emit
done
(
m_pageIndex
,
BaseDocument
::
PageLoadStatus
::
Fail
);
for
(
int
i
=
0
;
i
<
m_count
;
i
++
)
{
if
(
m_isCanceled
)
break
;
QMutexLocker
lock
(
&
m_mutex
);
auto
pageFuture
=
m_document
->
page
(
m_pageIndex
+
i
);
pageFuture
.
waitForFinished
();
if
(
pageFuture
.
isFinished
()
&&
!
pageFuture
.
isCanceled
())
emit
done
(
m_pageIndex
+
i
,
BaseDocument
::
PageLoadStatus
::
Success
);
else
emit
done
(
m_pageIndex
+
i
,
BaseDocument
::
PageLoadStatus
::
Fail
);
}
}
void
PagePreloader
::
cancel
()
{
m_isCanceled
=
true
;
}
plugin/src/pdfium-provider/pagepreloader.h
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef PAGEPRELOADER_H
...
...
@@ -17,10 +17,11 @@ class PagePreloader : public QObject, public QRunnable
Q_OBJECT
public:
PagePreloader
(
QSharedPointer
<
PdfDocument
>
document
,
int
pageIndex
);
PagePreloader
(
QSharedPointer
<
PdfDocument
>
document
,
int
pageIndex
,
int
countPages
=
1
);
~
PagePreloader
()
override
;
void
run
()
override
;
void
cancel
();
signals:
void
done
(
int
,
BaseDocument
::
PageLoadStatus
);
...
...
@@ -28,6 +29,8 @@ signals:
private:
QSharedPointer
<
PdfDocument
>
m_document
;
int
m_pageIndex
;
int
m_count
;
bool
m_isCanceled
;
static
QMutex
m_mutex
;
};
...
...
plugin/src/pdfium-provider/pagessizesloader.cpp
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#include
<amberpdf/pdfdocument.h>
...
...
@@ -12,8 +12,8 @@ PagesSizesLoader::PagesSizesLoader(QSharedPointer<PdfDocument> pdfiumDocument) :
void
PagesSizesLoader
::
run
()
{
auto
pagesCount
=
m_pdfiumDocument
->
pageCount
();
m_pageSizes
.
clear
();
for
(
int
i
=
0
;
i
<
pagesCount
;
++
i
)
{
auto
sizeFuture
=
m_pdfiumDocument
->
pageSize
(
i
);
sizeFuture
.
waitForFinished
();
...
...
plugin/src/pdfium-provider/pdfdocumentitem.cpp
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#include
<QFile>
#include
<QFutureWatcher>
#include
<QSizeF>
#include
<QThreadPool>
#include
<QVector>
#include
<QPair>
#include
<amberpdf/pdfdocument.h>
#include
<amberpdf/pdfbookmark.h>
...
...
@@ -23,7 +25,11 @@ PdfDocumentItem::PdfDocumentItem(QObject *parent) : BaseDocument(parent)
m_status
=
DocumentStatus
::
Null
;
}
PdfDocumentItem
::~
PdfDocumentItem
()
=
default
;
PdfDocumentItem
::~
PdfDocumentItem
()
{
if
(
m_preloaderAllPage
)
m_preloaderAllPage
->
cancel
();
}
QString
PdfDocumentItem
::
path
()
const
{
...
...
@@ -43,6 +49,55 @@ int PdfDocumentItem::count() const
return
m_pdfiumDocument
?
m_pdfiumDocument
->
pageCount
()
:
-
1
;
}
void
PdfDocumentItem
::
loadAllPages
()
{
if
(
m_preloaderAllPage
)
return
;
QVector
<
int
>
notLoadedPage
;
for
(
int
i
=
0
;
i
<
count
();
i
++
)
{
if
(
!
m_loadedPages
.
contains
(
i
)
&&
!
m_pagesInProcess
.
contains
(
i
))
notLoadedPage
.
append
(
i
);
}
if
(
notLoadedPage
.
empty
())
{
return
;
}
QVector
<
QPair
<
int
,
int
>>
rangesToLoad
;
int
startPage
=
notLoadedPage
[
0
];
int
endPage
=
startPage
;
for
(
int
i
=
1
;
i
<
notLoadedPage
.
size
();
++
i
)
{
if
(
notLoadedPage
[
i
]
==
endPage
+
1
)
{
endPage
=
notLoadedPage
[
i
];
}
else
{
rangesToLoad
.
push_back
(
QPair
(
startPage
,
endPage
));
startPage
=
endPage
=
notLoadedPage
[
i
];
}
}
rangesToLoad
.
push_back
(
QPair
(
startPage
,
endPage
));
for
(
const
auto
&
range
:
rangesToLoad
)
{
m_preloaderAllPage
=
new
PagePreloader
(
m_pdfiumDocument
,
range
.
first
,
range
.
second
-
range
.
first
);
connect
(
m_preloaderAllPage
,
&
PagePreloader
::
done
,
this
,
[
&
]
(
int
loadedPageIndex
,
PageLoadStatus
loadStatus
)
{
if
(
loadStatus
==
PageLoadStatus
::
Success
)
{
if
(
!
m_loadedPages
.
contains
(
loadedPageIndex
))
m_loadedPages
.
insert
(
loadedPageIndex
,
QSharedPointer
<
BasePage
>
(
new
PdfPageItem
(
m_pdfiumDocument
->
page
(
loadedPageIndex
))));
}
emit
pageLoaded
(
loadedPageIndex
,
loadStatus
);
});
QThreadPool
::
globalInstance
()
->
start
(
m_preloaderAllPage
,
-
1
);
for
(
int
i
=
range
.
first
;
i
<
range
.
second
;
i
++
)
m_pagesInProcess
.
insert
(
i
);
}
}
QSharedPointer
<
BasePage
>
PdfDocumentItem
::
loadPage
(
int
pageIndex
)
{
if
(
pageIndex
<
0
||
pageIndex
>=
count
())
...
...
plugin/src/pdfium-provider/pdfdocumentitem.h
Просмотр файла @
297cea9e
// SPDX-FileCopyrightText: 2022 Open Mobile Platform LLC <community@omp.ru>
// SPDX-FileCopyrightText: 2022
-2023
Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef PDFDOCUMENTITEM_H
...
...
@@ -9,9 +9,11 @@
#include
<QHash>
#include
<QSet>
#include
<QVector>
#include
<QPointer>
#include
"basedocument.h"
#include
"pdfpageitem.h"
#include
"pagepreloader.h"
class
PdfPage
;
class
PdfDocument
;
...
...
@@ -26,6 +28,7 @@ public:
QString
path
()
const
override
;
QSizeF
pageSize
(
int
pageNumber
)
const
override
;
int
count
()
const
override
;
void
loadAllPages
()
override
;
QSharedPointer
<
BasePage
>
loadPage
(
int
pageIndex
)
override
;
void
startLoadBookmarks
()
const
override
;
QVector
<
BaseBookmark
*>
bookmarks
()
const
override
;
...
...
@@ -35,14 +38,16 @@ public:
public
slots
:
void
setPath
(
const
QString
&
path
)
override
;
private:
void
onPagePreloaderDone
(
int
loadedPageIndex
,
PageLoadStatus
loadStatus
);
private:
QSharedPointer
<
PdfDocument
>
m_pdfiumDocument
;
QHash
<
int
,
QSizeF
>
m_pageSizes
;
QHash
<
int
,
QSharedPointer
<
BasePage
>>
m_loadedPages
;
QSet
<
int
>
m_pagesInProcess
;
QVector
<
BaseBookmark
*>
m_baseBookmarks
;
void
onPagePreloaderDone
(
int
loadedPageIndex
,
PageLoadStatus
loadStatus
);
QPointer
<
PagePreloader
>
m_preloaderAllPage
;
};
#endif // PDFDOCUMENTITEM_H
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать