File indexing completed on 2024-04-28 11:46:02

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 S.R. Haque <srhaque@iee.org>.
0004     SPDX-FileCopyrightText: 2002 David Faure <david@mandrakesoft.com>
0005     SPDX-FileCopyrightText: 2004 Arend van Beelen jr. <arend@auton.nl>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-only
0008 */
0009 
0010 #ifndef KFIND_P_H
0011 #define KFIND_P_H
0012 
0013 #include "kfind.h"
0014 
0015 #include <QDialog>
0016 #include <QHash>
0017 #include <QList>
0018 #include <QPointer>
0019 #include <QString>
0020 
0021 class KFindPrivate
0022 {
0023     Q_DECLARE_PUBLIC(KFind)
0024 
0025 public:
0026     KFindPrivate(KFind *qq)
0027         : q_ptr(qq)
0028         , findDialog(nullptr)
0029         , currentId(0)
0030         , customIds(false)
0031         , patternChanged(false)
0032         , matchedPattern(QLatin1String(""))
0033         , emptyMatch(nullptr)
0034     {
0035     }
0036 
0037     virtual ~KFindPrivate()
0038     {
0039         if (dialog) {
0040             dialog->deleteLater();
0041         }
0042         dialog = nullptr;
0043         data.clear();
0044         delete emptyMatch;
0045         emptyMatch = nullptr;
0046 #if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(5, 70)
0047         delete regExp;
0048 #endif
0049     }
0050 
0051     struct Match {
0052         Match()
0053             : dataId(-1)
0054             , index(-1)
0055             , matchedLength(-1)
0056         {
0057         }
0058         bool isNull() const
0059         {
0060             return index == -1;
0061         }
0062         Match(int _dataId, int _index, int _matchedLength)
0063             : dataId(_dataId)
0064             , index(_index)
0065             , matchedLength(_matchedLength)
0066         {
0067             Q_ASSERT(index != -1);
0068         }
0069 
0070         int dataId;
0071         int index;
0072         int matchedLength;
0073     };
0074 
0075     struct Data {
0076         Data()
0077         {
0078         }
0079         Data(int id, const QString &text, bool dirty = false)
0080             : text(text)
0081             , id(id)
0082             , dirty(dirty)
0083         {
0084         }
0085 
0086         QString text;
0087         int id = -1;
0088         bool dirty = false;
0089     };
0090 
0091     void init(const QString &pattern);
0092     void startNewIncrementalSearch();
0093 
0094     void slotFindNext();
0095     void slotDialogClosed();
0096 
0097     KFind *const q_ptr;
0098     QPointer<QWidget> findDialog;
0099     int currentId;
0100     bool customIds : 1;
0101     bool patternChanged : 1;
0102     QString matchedPattern;
0103     QHash<QString, Match> incrementalPath;
0104     Match *emptyMatch;
0105     QList<Data> data; // used like a vector, not like a linked-list
0106 
0107 #if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(5, 70)
0108     QRegExp *regExp;
0109 #endif
0110 
0111     QString pattern;
0112     QDialog *dialog;
0113     long options;
0114     unsigned matches;
0115 
0116     QString text; // the text set by setData
0117     int index;
0118     int matchedLength;
0119     bool dialogClosed : 1;
0120     bool lastResult : 1;
0121 };
0122 
0123 #endif // KFIND_P_H