KTextWidgets 5.109.0
kreplace.h
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
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#ifndef KREPLACE_H
10#define KREPLACE_H
11
12#include "kfind.h"
13
14#include "ktextwidgets_export.h"
15
16class KReplacePrivate;
17
89class KTEXTWIDGETS_EXPORT KReplace : public KFind
90{
91 Q_OBJECT
92
93public:
98 KReplace(const QString &pattern, const QString &replacement, long options, QWidget *parent = nullptr);
105 KReplace(const QString &pattern, const QString &replacement, long options, QWidget *parent, QWidget *replaceDialog);
106
107 ~KReplace() override;
108
116 int numReplacements() const;
117
123 void resetCounts() override;
124
130 Result replace();
131
139 QDialog *replaceNextDialog(bool create = false);
140
147
161 static int replace(QString &text, const QString &pattern, const QString &replacement, int index, long options, int *replacedLength);
162
163#if KTEXTWIDGETS_ENABLE_DEPRECATED_SINCE(5, 70)
177 static int replace(QString &text, const QRegExp &pattern, const QString &replacement, int index, long options, int *replacedLength);
178#endif
179
194 bool shouldRestart(bool forceAsking = false, bool showNumMatches = true) const override;
195
200 void displayFinalDialog() const override;
201
202Q_SIGNALS:
203#if KTEXTWIDGETS_ENABLE_DEPRECATED_SINCE(5, 83)
220 KTEXTWIDGETS_DEPRECATED_VERSION(5, 83, "Use the KReplace::textReplaced(const QString &, int, int, int) signal instead.")
221 void replace(const QString &text, int replacementIndex, int replacedLength, int matchedLength); // clazy:exclude=overloaded-signal
222#endif
223
240 void textReplaced(const QString &text, int replacementIndex, int replacedLength, int matchedLength);
241
242private:
243 Q_DECLARE_PRIVATE_D(KFind::d, KReplace)
244#if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(5, 79)
245 QT_WARNING_PUSH
246 QT_WARNING_DISABLE_CLANG("-Wunused-private-field")
247 // Unused, kept for ABI compatibility
248 const void *__ktextwidgets_d_do_not_use;
249 QT_WARNING_POP
250#endif
251};
252#endif
A generic implementation of the "find" function.
Definition kfind.h:94
A generic implementation of the "replace" function.
Definition kreplace.h:90
void resetCounts() override
Call this to reset the numMatches & numReplacements counts.
QDialog * replaceNextDialog(bool create=false)
Return (or create) the dialog that shows the "find next?" prompt.
void textReplaced(const QString &text, int replacementIndex, int replacedLength, int matchedLength)
Connect to this signal to implement updating of replaced text during the replace operation.
KReplace(const QString &pattern, const QString &replacement, long options, QWidget *parent, QWidget *replaceDialog)
This is the recommended constructor if you also use KReplaceDialog (non-modal).
int numReplacements() const
Return the number of replacements made (i.e.
Result replace()
Walk the text fragment (e.g.
void closeReplaceNextDialog()
Close the "replace next?" dialog.
bool shouldRestart(bool forceAsking=false, bool showNumMatches=true) const override
Returns true if we should restart the search from scratch.
static int replace(QString &text, const QString &pattern, const QString &replacement, int index, long options, int *replacedLength)
Searches the given text for pattern; if a match is found it is replaced with replacement and the inde...
void displayFinalDialog() const override
Displays the final dialog telling the user how many replacements were made.
KReplace(const QString &pattern, const QString &replacement, long options, QWidget *parent=nullptr)
Only use this constructor if you don't use KFindDialog, or if you use it as a modal dialog.