~ubuntu-branches/ubuntu/wily/qpdfview/wily

« back to all changes in this revision

Viewing changes to sources/searchtask.h

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2015-03-22 11:42:36 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20150322114236-81p4twy532ytw10m
Tags: 0.4.14-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
Copyright 2012-2013 Adam Reichold
 
3
Copyright 2012-2015 Adam Reichold
4
4
 
5
5
This file is part of qpdfview.
6
6
 
41
41
public:
42
42
    explicit SearchTask(QObject* parent = 0);
43
43
 
44
 
    bool wasCanceled() const;
45
 
    int progress() const;
 
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; }
46
50
 
47
51
    void run();
48
52
 
53
57
 
54
58
public slots:
55
59
    void start(const QVector< Model::Page* >& pages,
56
 
               const QString& text, bool matchCase, int beginAtPage = 1);
 
60
               const QString& text, bool matchCase, bool wholeWords, int beginAtPage = 1);
57
61
 
58
 
    void cancel();
 
62
    void cancel() { setCancellation(); }
59
63
 
60
64
private:
61
65
    Q_DISABLE_COPY(SearchTask)
63
67
    QAtomicInt m_wasCanceled;
64
68
    mutable QAtomicInt m_progress;
65
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
 
66
86
    QVector< Model::Page* > m_pages;
67
87
 
68
88
    QString m_text;
69
89
    bool m_matchCase;
 
90
    bool m_wholeWords;
70
91
    int m_beginAtPage;
71
92
 
72
93
};
73
94
 
 
95
#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
 
96
 
 
97
inline void SearchTask::setCancellation()
 
98
{
 
99
    m_wasCanceled.storeRelease(Canceled);
 
100
}
 
101
 
 
102
inline void SearchTask::resetCancellation()
 
103
{
 
104
    m_wasCanceled.storeRelease(NotCanceled);
 
105
}
 
106
 
 
107
inline bool SearchTask::testCancellation()
 
108
{
 
109
    return m_wasCanceled.load() != NotCanceled;
 
110
}
 
111
 
 
112
inline int SearchTask::loadCancellation() const
 
113
{
 
114
    return m_wasCanceled.load();
 
115
}
 
116
 
 
117
inline void SearchTask::releaseProgress(int value)
 
118
{
 
119
    m_progress.storeRelease(value);
 
120
}
 
121
 
 
122
inline int SearchTask::acquireProgress() const
 
123
{
 
124
    return m_progress.loadAcquire();
 
125
}
 
126
 
 
127
inline int SearchTask::loadProgress() const
 
128
{
 
129
    return m_progress.load();
 
130
}
 
131
 
 
132
#else
 
133
 
 
134
inline void SearchTask::setCancellation()
 
135
{
 
136
    m_wasCanceled.fetchAndStoreRelease(Canceled);
 
137
}
 
138
 
 
139
inline void SearchTask::resetCancellation()
 
140
{
 
141
    m_wasCanceled.fetchAndStoreRelease(NotCanceled);
 
142
}
 
143
 
 
144
inline bool SearchTask::testCancellation()
 
145
{
 
146
    return !m_wasCanceled.testAndSetRelaxed(NotCanceled, NotCanceled);
 
147
}
 
148
 
 
149
inline int SearchTask::loadCancellation() const
 
150
{
 
151
    return m_wasCanceled;
 
152
}
 
153
 
 
154
inline void SearchTask::releaseProgress(int value)
 
155
{
 
156
    m_progress.fetchAndStoreRelease(value);
 
157
}
 
158
 
 
159
inline int SearchTask::acquireProgress() const
 
160
{
 
161
    return m_progress.fetchAndAddAcquire(0);
 
162
}
 
163
 
 
164
inline int SearchTask::loadProgress() const
 
165
{
 
166
    return m_progress;
 
167
}
 
168
 
 
169
#endif // QT_VERSION
 
170
 
74
171
} // qpdfview
75
172
 
76
173
#endif // SEARCHTHREAD_H