pqPythonUndoCommand.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef pqPythonUndoCommand_h
5 #define pqPythonUndoCommand_h
6 
7 #include "pqPythonModule.h"
8 
9 #include <QTextEdit>
10 #include <QUndoCommand>
11 
12 #include <functional>
13 #include <iostream>
14 #include <stack>
15 #include <vector>
16 
18 
28 {
29  pqPythonTextHistoryEntry() = default;
30 
31  pqPythonTextHistoryEntry(const QString& txt, const std::int32_t cursorPos)
32  : content(txt)
33  , cursorPosition(cursorPos)
34  {
35  }
36 
40  QString content = "";
41 
45  std::int32_t cursorPosition = -1;
46 
50  bool isEmpty() const noexcept { return cursorPosition == -1; }
51 };
52 
60 class PQPYTHON_EXPORT pqPythonUndoCommand : public QUndoCommand
61 {
62 public:
66  pqPythonUndoCommand(QTextEdit& text, pqPythonSyntaxHighlighter* highlighter,
67  pqPythonTextHistoryEntry& lastHistoryEntry,
68  const pqPythonTextHistoryEntry&& currentHistoryEntry);
69 
73  void undo() override;
74 
78  void redo() override;
79 
84  {
85  return this->CurrentHistoryEntry;
86  }
87 
88 private:
93  void swapImpl(const pqPythonTextHistoryEntry& h);
94 
96  QTextEdit& Text;
97 
98  pqPythonSyntaxHighlighter* Highlighter;
99 
115  pqPythonTextHistoryEntry& TextLastHystoryEntry;
116 
117  const pqPythonTextHistoryEntry LastHistoryEntry;
118 
119  const pqPythonTextHistoryEntry CurrentHistoryEntry;
120 };
121 
122 #endif // pqPythonUndoCommand_h
Text
bool isEmpty() const noexcept
Returns true is the entry is empty.
const pqPythonTextHistoryEntry & getCurrentHistoryEntry() const
Returns the current history entry.
pqPythonTextHistoryEntry(const QString &txt, const std::int32_t cursorPos)
The python text editor undo/redo command.
#define PQPYTHON_EXPORT
pqPythonTextHistoryEntry()=default
This class is a helper object to attach to a QTextEdit to add Python syntax highlighting to the text ...
std::int32_t cursorPosition
The absolute cursor position within pqPythonUndoCommand::Text.
#define const
Definition: zconf.h:238
QString content
The raw text.