source: terepaima/terepaima-0.4.16/sources/searchtask.h @ 8663130

desarrollostretch
Last change on this file since 8663130 was 1f4adec, checked in by aosorio <aosorio@…>, 8 years ago

Agregado proyecto base, esto luego del dh_make -f

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2
3Copyright 2012-2015 Adam Reichold
4
5This file is part of qpdfview.
6
7qpdfview is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12qpdfview is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22#ifndef SEARCHTASK_H
23#define SEARCHTASK_H
24
25#include <QRectF>
26#include <QThread>
27#include <QVector>
28
29namespace qpdfview
30{
31
32namespace Model
33{
34class Page;
35}
36
37class SearchTask : public QThread
38{
39    Q_OBJECT
40
41public:
42    explicit SearchTask(QObject* parent = 0);
43
44    bool wasCanceled() const { return loadCancellation() != NotCanceled; }
45    int progress() const { return acquireProgress(); }
46
47    const QString& text() const { return m_text; }
48    bool matchCase() const { return m_matchCase; }
49    bool wholeWords() const { return m_wholeWords; }
50
51    void run();
52
53signals:
54    void progressChanged(int progress);
55
56    void resultsReady(int index, const QList< QRectF >& results);
57
58public slots:
59    void start(const QVector< Model::Page* >& pages,
60               const QString& text, bool matchCase, bool wholeWords, int beginAtPage = 1);
61
62    void cancel() { setCancellation(); }
63
64private:
65    Q_DISABLE_COPY(SearchTask)
66
67    QAtomicInt m_wasCanceled;
68    mutable QAtomicInt m_progress;
69
70    enum
71    {
72        NotCanceled = 0,
73        Canceled = 1
74    };
75
76    void setCancellation();
77    void resetCancellation();
78    bool testCancellation();
79    int loadCancellation() const;
80
81    void releaseProgress(int value);
82    int acquireProgress() const;
83    int loadProgress() const;
84
85
86    QVector< Model::Page* > m_pages;
87
88    QString m_text;
89    bool m_matchCase;
90    bool m_wholeWords;
91    int m_beginAtPage;
92
93};
94
95#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
96
97inline void SearchTask::setCancellation()
98{
99    m_wasCanceled.storeRelease(Canceled);
100}
101
102inline void SearchTask::resetCancellation()
103{
104    m_wasCanceled.storeRelease(NotCanceled);
105}
106
107inline bool SearchTask::testCancellation()
108{
109    return m_wasCanceled.load() != NotCanceled;
110}
111
112inline int SearchTask::loadCancellation() const
113{
114    return m_wasCanceled.load();
115}
116
117inline void SearchTask::releaseProgress(int value)
118{
119    m_progress.storeRelease(value);
120}
121
122inline int SearchTask::acquireProgress() const
123{
124    return m_progress.loadAcquire();
125}
126
127inline int SearchTask::loadProgress() const
128{
129    return m_progress.load();
130}
131
132#else
133
134inline void SearchTask::setCancellation()
135{
136    m_wasCanceled.fetchAndStoreRelease(Canceled);
137}
138
139inline void SearchTask::resetCancellation()
140{
141    m_wasCanceled.fetchAndStoreRelease(NotCanceled);
142}
143
144inline bool SearchTask::testCancellation()
145{
146    return !m_wasCanceled.testAndSetRelaxed(NotCanceled, NotCanceled);
147}
148
149inline int SearchTask::loadCancellation() const
150{
151    return m_wasCanceled;
152}
153
154inline void SearchTask::releaseProgress(int value)
155{
156    m_progress.fetchAndStoreRelease(value);
157}
158
159inline int SearchTask::acquireProgress() const
160{
161    return m_progress.fetchAndAddAcquire(0);
162}
163
164inline int SearchTask::loadProgress() const
165{
166    return m_progress;
167}
168
169#endif // QT_VERSION
170
171} // qpdfview
172
173#endif // SEARCHTHREAD_H
Note: See TracBrowser for help on using the repository browser.