pqPythonTextArea.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 
5 #ifndef pqPythonTextArea_h
6 #define pqPythonTextArea_h
7 
8 #include "pqPythonModule.h"
9 
10 #include "pqPythonEditorActions.h"
11 #include "pqPythonUndoCommand.h"
12 #include "pqPythonUtils.h"
13 #include "pqTextLinkerPython.h"
14 
15 #include "vtkType.h" // For vtkTypeUInt32
16 
17 #include <QKeyEvent>
18 #include <QUndoStack>
19 #include <QWidget>
20 
22 class pqPythonFileIO;
24 class QTextEdit;
25 
32 class PQPYTHON_EXPORT pqPythonTextArea : public QWidget
33 {
34  Q_OBJECT
35 
36 public:
41  explicit pqPythonTextArea(QWidget* parent);
42 
46  const QTextEdit* getTextEdit() const { return this->TextEdit; }
47 
51  QTextEdit* getTextEdit() { return this->TextEdit; }
52 
53  const QUndoStack& getUndoStack() const { return this->UndoStack; }
54 
58  bool saveOnClose();
59 
65  bool openFile(const QString& filename, vtkTypeUInt32 location = 0x10 /*vtkPVSession::CLIENT*/);
66 
72  void setDefaultSaveDirectory(const QString& dir);
73 
77  void connectActions(pqPythonEditorActions& actions);
78 
82  void disconnectActions(pqPythonEditorActions& actions);
83 
88  const QString& getFilename() const;
89 
93  bool isEmpty() const;
94 
99  bool isDirty() const;
100 
105  void setText(const QString& text);
106 
112  template <typename T>
113  void linkTo(T* /*obj*/)
114  {
115  static_assert(sizeof(T) == 0, "Only specializations of linkTo(T* t) can be used");
116  }
117 
121  void unlink();
122 
127  bool isLinkedTo(const QObject* obj) const { return this->TextLinker.isLinkedTo(obj); }
128 
132  bool isLinked() const { return this->TextLinker.isLinked(); }
133 
138  QString getLinkedName() const { return this->TextLinker.getSecondObjectName(); }
139 
140 Q_SIGNALS:
145  void bufferErased();
146 
151  void fileOpened(const QString&);
152 
157  void fileSaved(const QString&);
158 
163  void contentChanged();
164 
165 protected:
171  bool eventFilter(QObject* obj, QEvent* event) override;
172 
173 private:
174  void setupActions();
175 
176  void setupMenus();
177 
181  QPointer<QTextEdit> TextEdit;
182 
186  QPointer<pqPythonLineNumberArea> LineNumberArea;
187 
191  QPointer<pqPythonSyntaxHighlighter> SyntaxHighlighter;
192 
196  QPointer<pqPythonFileIO> FileIO;
197 
198  pqTextLinker TextLinker;
199 
203  QUndoStack UndoStack;
204 
210  pqPythonTextHistoryEntry lastEntry;
211 };
212 
213 #include "pqPythonTextArea.txx"
214 
215 #endif // pqPythonTextArea_h
location
QString getLinkedName() const
Returns the linked text name.
const QTextEdit * getTextEdit() const
Returns the underlying text edit.
const QUndoStack & getUndoStack() const
#define PQPYTHON_EXPORT
bool isLinkedTo(const QObject *obj) const
Returns true if the parameter is linked to this text area.
dir
void linkTo(T *)
Link the current text area to an arbitrary QTextEdit like object.
A python text editor widget.
This class is a helper object to attach to a QTextEdit to add Python syntax highlighting to the text ...
Ease of use object that connects two pqLinkedObjectInterface together.
Definition: pqTextLinker.h:24
bool isLinked() const
Returns true if this text area is linked.
QTextEdit * getTextEdit()
Returns the underlying text edit.
Handles loading (resp.
QWidget that displays line number for a QTextEdit.