diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/searchtextlocator.h')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/searchtextlocator.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.h b/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.h new file mode 100644 index 0000000..0cfdb44 --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/searchtextlocator.h @@ -0,0 +1,75 @@ +#ifndef SEARCHTEXTLOCATOR_H +#define SEARCHTEXTLOCATOR_H + +#include "guiSQLiteStudio_global.h" +#include <QObject> +#include <QTextDocument> + +class GUI_API_EXPORT SearchTextLocator : public QObject +{ + Q_OBJECT + + public: + struct GUI_API_EXPORT Occurrance + { + int start; + int end; + }; + + SearchTextLocator(QTextDocument* document, QObject* parent = nullptr); + + QString getLookupString() const; + void setLookupString(const QString& value); + + QString getReplaceString() const; + void setReplaceString(const QString& value); + + bool getCaseSensitive() const; + void setCaseSensitive(bool value); + + bool getRegularExpression() const; + void setRegularExpression(bool value); + + bool getSearchBackwards() const; + void setSearchBackwards(bool value); + + int getStartPosition() const; + void setStartPosition(int value); + + void reset(); + + private: + QTextDocument::FindFlags getFlags(); + void notFound(); + QTextCursor findInWholeDoc(QTextDocument::FindFlags flags); + void replaceCurrent(); + + QTextDocument* document = nullptr; + int initialStartPosition; + int lastMatchStart = -1; + int lastMatchEnd = -1; + bool afterDocPositionSwitch = false; + + // Config parameters + QString lookupString; + QString replaceString; + bool caseSensitive = false; + bool regularExpression = false; + bool searchBackwards = false; + int startPosition = 0; + + public slots: + bool find(QTextDocument::FindFlags flags = 0); + void findNext(); + void findPrev(); + bool replaceAndFind(); + void replaceAll(); + void cursorMoved(); + + signals: + void found(int start, int end); + void reachedEnd(); + void replaceAvailable(bool available); +}; + +#endif // SEARCHTEXTLOCATOR_H |
