-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnsrpagescache.h
122 lines (104 loc) · 2.61 KB
/
nsrpagescache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __NSRPAGESCACHE_H__
#define __NSRPAGESCACHE_H__
/**
* @file nsrpagescache.h
* @author Alexander Saprykin
* @brief Rendered pages cache
*/
#include "nsrrenderedpage.h"
#include <QObject>
#include <QHash>
#include <QList>
/**
* @class NSRPagesCache nsrpagescache.h
* @brief Class for rendered pages cache
*
* By default cache size is limited to 100 MB.
*/
class NSRPagesCache : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor with parameter
* @param parent Parent object.
*/
NSRPagesCache (QObject *parent = 0);
/**
* @brief Destructor
*/
virtual ~NSRPagesCache ();
/**
* @brief Checks whether page is in cache
* @param number Page number (from 1).
* @return True if page is in cache, false otherwise.
*/
bool isPageExists (int number) const;
/**
* @brief Gets cached page
* @param number Page number (from 1).
* @return Cached page is exists, empty page otherwise.
*/
NSRRenderedPage getPage (int number) const;
/**
* @brief Gets used memory for pages cache
* @return Used memory for pages cache, bytes.
* @since 1.4.3
*/
inline qint64 getUsedMemory () const {
return _usedMemory;
}
/**
* @brief Gets max memory allowed for pages cache
* @return Max memory allowed for pages cache, bytes.
* @since 1.4.3
*/
inline qint64 getMaxMemory () const {
return _maxMemory;
}
/**
* @brief Sets max memory allowed fior pages cache
* @param maxMemory Max memory allowed for pages cache, bytes.
* @since 1.4.3
*/
void setMaxMemory (qint64 maxMemory);
/**
* @brief Adds page into cache
* @param page Rendered page.
* @note If page with the same number is in cache it will be
* replaced.
*/
void addPage (const NSRRenderedPage &page);
/**
* @brief Removes page from the cache
* @param number Page number (from 1).
*/
void removePage (int number);
/**
* @brief Clears cache and remove all pages.
*/
void clearStorage ();
/**
* @brief Updates page scroll positions
* @param number Page number (from 1).
* @param pos Image positions, in px.
* @param textPos Text view position, in px.
*/
void updatePagePositions (int number,
const QPointF& pos,
const QPointF& textPos);
/**
* @brief Removes pages without images (text only)
*/
void removePagesWithoutImages ();
/**
* @brief Removes pages with images.
*/
void removePagesWithImages ();
private:
QHash<int, NSRRenderedPage> _hash; /**< Pages cache */
QList<int> _pages; /**< Pages numbers */
qint64 _usedMemory; /**< Memory used by pages, bytes */
qint64 _maxMemory; /**< Max memory allowed, bytes */
};
#endif /* __NSRPAGESCACHE_H__ */