1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2001 S.R. Haque <srhaque@iee.org>. |
4 | SPDX-FileCopyrightText: 2002 David Faure <david@mandrakesoft.com> |
5 | SPDX-FileCopyrightText: 2004 Arend van Beelen jr. <arend@auton.nl> |
6 | |
7 | SPDX-License-Identifier: LGPL-2.0-only |
8 | */ |
9 | |
10 | #ifndef KFIND_P_H |
11 | #define KFIND_P_H |
12 | |
13 | #include "kfind.h" |
14 | |
15 | #include <QDialog> |
16 | #include <QHash> |
17 | #include <QList> |
18 | #include <QPointer> |
19 | #include <QString> |
20 | |
21 | class KFindPrivate |
22 | { |
23 | Q_DECLARE_PUBLIC(KFind) |
24 | |
25 | public: |
26 | KFindPrivate(KFind *qq) |
27 | : q_ptr(qq) |
28 | , findDialog(nullptr) |
29 | , currentId(0) |
30 | , customIds(false) |
31 | , patternChanged(false) |
32 | , matchedPattern(QLatin1String("" )) |
33 | , emptyMatch(nullptr) |
34 | { |
35 | } |
36 | |
37 | virtual ~KFindPrivate() |
38 | { |
39 | if (dialog) { |
40 | dialog->deleteLater(); |
41 | } |
42 | dialog = nullptr; |
43 | data.clear(); |
44 | delete emptyMatch; |
45 | emptyMatch = nullptr; |
46 | } |
47 | |
48 | struct Match { |
49 | Match() |
50 | : dataId(-1) |
51 | , index(-1) |
52 | , matchedLength(-1) |
53 | { |
54 | } |
55 | bool isNull() const |
56 | { |
57 | return index == -1; |
58 | } |
59 | Match(int _dataId, int _index, int _matchedLength) |
60 | : dataId(_dataId) |
61 | , index(_index) |
62 | , matchedLength(_matchedLength) |
63 | { |
64 | Q_ASSERT(index != -1); |
65 | } |
66 | |
67 | int dataId; |
68 | int index; |
69 | int matchedLength; |
70 | }; |
71 | |
72 | struct Data { |
73 | Data() |
74 | { |
75 | } |
76 | Data(int id, const QString &text, bool dirty = false) |
77 | : text(text) |
78 | , id(id) |
79 | , dirty(dirty) |
80 | { |
81 | } |
82 | |
83 | QString text; |
84 | int id = -1; |
85 | bool dirty = false; |
86 | }; |
87 | |
88 | void init(const QString &pattern); |
89 | void startNewIncrementalSearch(); |
90 | |
91 | void slotFindNext(); |
92 | void slotDialogClosed(); |
93 | |
94 | KFind *const q_ptr; |
95 | QPointer<QWidget> findDialog; |
96 | int currentId; |
97 | bool customIds : 1; |
98 | bool patternChanged : 1; |
99 | QString matchedPattern; |
100 | QHash<QString, Match> incrementalPath; |
101 | Match *emptyMatch; |
102 | QList<Data> data; // used like a vector, not like a linked-list |
103 | |
104 | QString pattern; |
105 | QDialog *dialog; |
106 | long options; |
107 | unsigned matches; |
108 | |
109 | QString text; // the text set by setData |
110 | int index; |
111 | int matchedLength; |
112 | bool dialogClosed : 1; |
113 | bool lastResult : 1; |
114 | }; |
115 | |
116 | #endif // KFIND_P_H |
117 | |