File indexing completed on 2024-02-25 04:03:55

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     }
0047 
0048     struct Match {
0049         Match()
0050             : dataId(-1)
0051             , index(-1)
0052             , matchedLength(-1)
0053         {
0054         }
0055         bool isNull() const
0056         {
0057             return index == -1;
0058         }
0059         Match(int _dataId, int _index, int _matchedLength)
0060             : dataId(_dataId)
0061             , index(_index)
0062             , matchedLength(_matchedLength)
0063         {
0064             Q_ASSERT(index != -1);
0065         }
0066 
0067         int dataId;
0068         int index;
0069         int matchedLength;
0070     };
0071 
0072     struct Data {
0073         Data()
0074         {
0075         }
0076         Data(int id, const QString &text, bool dirty = false)
0077             : text(text)
0078             , id(id)
0079             , dirty(dirty)
0080         {
0081         }
0082 
0083         QString text;
0084         int id = -1;
0085         bool dirty = false;
0086     };
0087 
0088     void init(const QString &pattern);
0089     void startNewIncrementalSearch();
0090 
0091     void slotFindNext();
0092     void slotDialogClosed();
0093 
0094     KFind *const q_ptr;
0095     QPointer<QWidget> findDialog;
0096     int currentId;
0097     bool customIds : 1;
0098     bool patternChanged : 1;
0099     QString matchedPattern;
0100     QHash<QString, Match> incrementalPath;
0101     Match *emptyMatch;
0102     QList<Data> data; // used like a vector, not like a linked-list
0103 
0104     QString pattern;
0105     QDialog *dialog;
0106     long options;
0107     unsigned matches;
0108 
0109     QString text; // the text set by setData
0110     int index;
0111     int matchedLength;
0112     bool dialogClosed : 1;
0113     bool lastResult : 1;
0114 };
0115 
0116 #endif // KFIND_P_H