File indexing completed on 2024-04-28 03:53:08
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1999, 2000 Carsten Pfeiffer <pfeiffer@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KCOMPLETIONMATCHES_H 0009 #define KCOMPLETIONMATCHES_H 0010 0011 #include <kcompletion_export.h> 0012 #include <ksortablelist.h> 0013 0014 #include <QStringList> 0015 #include <memory> 0016 0017 class KCompletionMatchesWrapper; 0018 class KCompletionMatchesPrivate; 0019 0020 typedef KSortableList<QString> KCompletionMatchesList; 0021 0022 /** 0023 * @class KCompletionMatches kcompletionmatches.h KCompletionMatches 0024 * 0025 * This structure is returned by KCompletion::allWeightedMatches(). 0026 * It also keeps the weight of the matches, allowing 0027 * you to modify some matches or merge them with matches 0028 * from another call to allWeightedMatches(), and sort the matches 0029 * after that in order to have the matches ordered correctly. 0030 * 0031 * Example (a simplified example of what Konqueror's completion does): 0032 * \code 0033 * KCompletionMatches matches = completion->allWeightedMatches(location); 0034 * if(!location.startsWith("www.")) 0035 matches += completion->allWeightedmatches("www." + location"); 0036 * matches.removeDuplicates(); 0037 * QStringList list = matches.list(); 0038 * \endcode 0039 * 0040 * @short List for keeping matches returned from KCompletion 0041 */ 0042 class KCOMPLETION_EXPORT KCompletionMatches : public KCompletionMatchesList 0043 { 0044 public: 0045 Q_DECLARE_PRIVATE(KCompletionMatches) 0046 /** 0047 * Default constructor. 0048 * @param sort if false, the matches won't be sorted before the conversion, 0049 * use only if you're sure the sorting is not needed 0050 */ 0051 KCompletionMatches(bool sort); 0052 0053 /** 0054 * copy constructor. 0055 */ 0056 KCompletionMatches(const KCompletionMatches &); 0057 0058 /** 0059 * assignment operator. 0060 */ 0061 KCompletionMatches &operator=(const KCompletionMatches &); 0062 0063 /** 0064 * @internal 0065 */ 0066 KCompletionMatches(const KCompletionMatchesWrapper &matches); 0067 0068 /** 0069 * default destructor. 0070 */ 0071 ~KCompletionMatches(); 0072 /** 0073 * Removes duplicate matches. Needed only when you merged several matches 0074 * results and there's a possibility of duplicates. 0075 */ 0076 void removeDuplicates(); 0077 /** 0078 * Returns the matches as a QStringList. 0079 * @param sort if false, the matches won't be sorted before the conversion, 0080 * use only if you're sure the sorting is not needed 0081 * @return the list of matches 0082 */ 0083 QStringList list(bool sort = true) const; 0084 /** 0085 * If sorting() returns false, the matches aren't sorted by their weight, 0086 * even if true is passed to list(). 0087 * @return true if the matches won't be sorted 0088 */ 0089 bool sorting() const; 0090 0091 private: 0092 std::unique_ptr<KCompletionMatchesPrivate> const d_ptr; 0093 }; 0094 0095 #endif // KCOMPLETIONMATCHES_H