1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999, 2000 Carsten Pfeiffer <pfeiffer@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KCOMPLETIONMATCHES_H |
9 | #define KCOMPLETIONMATCHES_H |
10 | |
11 | #include <kcompletion_export.h> |
12 | #include <ksortablelist.h> |
13 | |
14 | #include <QStringList> |
15 | #include <memory> |
16 | |
17 | class KCompletionMatchesWrapper; |
18 | class KCompletionMatchesPrivate; |
19 | |
20 | typedef KSortableList<QString> KCompletionMatchesList; |
21 | |
22 | /** |
23 | * @class KCompletionMatches kcompletionmatches.h KCompletionMatches |
24 | * |
25 | * This structure is returned by KCompletion::allWeightedMatches(). |
26 | * It also keeps the weight of the matches, allowing |
27 | * you to modify some matches or merge them with matches |
28 | * from another call to allWeightedMatches(), and sort the matches |
29 | * after that in order to have the matches ordered correctly. |
30 | * |
31 | * Example (a simplified example of what Konqueror's completion does): |
32 | * \code |
33 | * KCompletionMatches matches = completion->allWeightedMatches(location); |
34 | * if(!location.startsWith("www.")) |
35 | matches += completion->allWeightedmatches("www." + location"); |
36 | * matches.removeDuplicates(); |
37 | * QStringList list = matches.list(); |
38 | * \endcode |
39 | * |
40 | * @short List for keeping matches returned from KCompletion |
41 | */ |
42 | class KCOMPLETION_EXPORT KCompletionMatches : public KCompletionMatchesList |
43 | { |
44 | public: |
45 | Q_DECLARE_PRIVATE(KCompletionMatches) |
46 | /** |
47 | * Default constructor. |
48 | * @param sort if false, the matches won't be sorted before the conversion, |
49 | * use only if you're sure the sorting is not needed |
50 | */ |
51 | KCompletionMatches(bool sort); |
52 | |
53 | /** |
54 | * copy constructor. |
55 | */ |
56 | KCompletionMatches(const KCompletionMatches &); |
57 | |
58 | /** |
59 | * assignment operator. |
60 | */ |
61 | KCompletionMatches &operator=(const KCompletionMatches &); |
62 | |
63 | /** |
64 | * @internal |
65 | */ |
66 | KCompletionMatches(const KCompletionMatchesWrapper &matches); |
67 | |
68 | /** |
69 | * default destructor. |
70 | */ |
71 | ~KCompletionMatches(); |
72 | /** |
73 | * Removes duplicate matches. Needed only when you merged several matches |
74 | * results and there's a possibility of duplicates. |
75 | */ |
76 | void removeDuplicates(); |
77 | /** |
78 | * Returns the matches as a QStringList. |
79 | * @param sort if false, the matches won't be sorted before the conversion, |
80 | * use only if you're sure the sorting is not needed |
81 | * @return the list of matches |
82 | */ |
83 | QStringList list(bool sort = true) const; |
84 | /** |
85 | * If sorting() returns false, the matches aren't sorted by their weight, |
86 | * even if true is passed to list(). |
87 | * @return true if the matches won't be sorted |
88 | */ |
89 | bool sorting() const; |
90 | |
91 | private: |
92 | std::unique_ptr<KCompletionMatchesPrivate> const d_ptr; |
93 | }; |
94 | |
95 | #endif // KCOMPLETIONMATCHES_H |
96 | |