Warning, file /office/calligra/libs/main/KoFindBase.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 0022 0023 #ifndef KOFINDBASE_H 0024 #define KOFINDBASE_H 0025 0026 #include <QObject> 0027 0028 #include "KoFindMatch.h" 0029 #include "komain_export.h" 0030 0031 class KoFindOptionSet; 0032 /** 0033 * Base class for searching and finding strings in a document. 0034 * 0035 * This class provides the base API that needs to be implemented 0036 * when searching in a document. Each application should create an 0037 * instance of a concrete implementation of this class to support 0038 * searching. Which concrete implementation to create depends on 0039 * the type of data that is being searched. 0040 */ 0041 class KOMAIN_EXPORT KoFindBase : public QObject 0042 { 0043 Q_OBJECT 0044 public: 0045 typedef QList<KoFindMatch> KoFindMatchList; 0046 0047 explicit KoFindBase(QObject *parent = 0); 0048 ~KoFindBase() override; 0049 0050 /** 0051 * Retrieve a list of all matches that were found since the 0052 * last call to find(). 0053 * 0054 * \return A list of all matches that were found. 0055 */ 0056 const KoFindMatchList &matches() const; 0057 0058 /** 0059 * Check whether any matches were found since the last call to 0060 * find(). 0061 * 0062 * \return true if any matches were found, false if otherwise. 0063 */ 0064 bool hasMatches() const; 0065 0066 /** 0067 * Retrieve the current active match. 0068 * 0069 * The current match is the match which has currently been centred 0070 * on in the GUI. 0071 * 0072 * \return The current active match. 0073 */ 0074 KoFindMatch currentMatch() const; 0075 0076 /** 0077 * Retrieve the current set of options. 0078 */ 0079 KoFindOptionSet *options() const; 0080 0081 public Q_SLOTS: 0082 /** 0083 * Search for a string in the document associated with this 0084 * KoFindBase instance. 0085 * 0086 * \param pattern The string to search for. 0087 */ 0088 virtual void find(const QString &pattern); 0089 /** 0090 * Find the next match, if there is more than one match. 0091 * This function will wrap around if the end of the document 0092 * was reached. 0093 */ 0094 virtual void findNext(); 0095 /** 0096 * Find the previous match, if there is more than one match. 0097 * This function will wrap around if the end of the document 0098 * was reached. 0099 */ 0100 virtual void findPrevious(); 0101 /** 0102 * Finished with searching. 0103 * 0104 * This clears all highlighting and other markers. 0105 */ 0106 virtual void finished(); 0107 /** 0108 * Replace the current match with a new value. 0109 * 0110 * \param value The new value to change the current match to. 0111 */ 0112 virtual void replaceCurrent(const QVariant &value); 0113 /** 0114 * Replace all occurrences of the currently matched text 0115 * with the new value. 0116 * 0117 * \param value The new value to change the matches to. 0118 */ 0119 virtual void replaceAll(const QVariant &value); 0120 0121 Q_SIGNALS: 0122 /** 0123 * Emitted whenever a match is found. The argument is the first 0124 * match if there are more then one. 0125 */ 0126 void matchFound(const KoFindMatch &match); 0127 /** 0128 * Emitted when the canvas should be redrawn due to a change in 0129 * the underlying list of matches. 0130 */ 0131 void updateCanvas(); 0132 /** 0133 * Emitted when there is no match found for the current pattern. 0134 */ 0135 void noMatchFound(); 0136 /** 0137 * Emitted whenever a call to findNext/findPrevious wraps around. 0138 * 0139 * \param direction True if searched wrapped while searching forward, 0140 * false if searching backward. 0141 */ 0142 void wrapAround(bool direction); 0143 /** 0144 * Emitted after find() was called and matches were found. 0145 */ 0146 void hasMatchesChanged(bool hasMatches); 0147 0148 protected: 0149 /** 0150 * Set the list of matches. 0151 * 0152 * \param matches The new list of matches to set. 0153 */ 0154 void setMatches(const KoFindMatchList &matches); 0155 0156 /** 0157 * Set the current index. 0158 * 0159 * This index indicates the currently active match. 0160 */ 0161 void setCurrentMatch(int index); 0162 0163 /** 0164 * Retrieve the index of the current match. 0165 * 0166 * \return The index of the current match. 0167 */ 0168 int currentMatchIndex(); 0169 0170 /** 0171 * This method should be implemented to do the actual searching. 0172 * 0173 * \param pattern The pattern to search for. 0174 */ 0175 virtual void findImplementation(const QString &pattern, KoFindMatchList &matchList) = 0; 0176 0177 /** 0178 * This method should be implemented to do the actual replacing. 0179 * 0180 * \param match The match that should be replaced. 0181 * \param value The new value to replace the match with. 0182 */ 0183 virtual void replaceImplementation(const KoFindMatch &match, const QVariant &value) = 0; 0184 0185 /** 0186 * Clean up the current matches. 0187 * 0188 * This can be used to remove highlighting or other 0189 * modifications and will be called whenever the list of matches 0190 * needs to be cleaned. 0191 */ 0192 virtual void clearMatches(); 0193 0194 /** 0195 * Set the current option set. 0196 * 0197 * \param newOptions The new option set. 0198 */ 0199 void setOptions(KoFindOptionSet *newOptions); 0200 0201 private: 0202 class Private; 0203 Private * const d; 0204 }; 0205 0206 #endif // KOFINDBASE_H