pqPythonFileIO.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 pqPythonFileIO_h
6 #define pqPythonFileIO_h
7 
8 #include "pqPythonModule.h"
9 
10 #include "pqPythonUtils.h"
11 
12 #include "vtkType.h" // For vtkTypeUInt32
13 
14 #include <QAction>
15 #include <QDir>
16 #include <QObject>
17 #include <QString>
18 
19 #include <iostream>
20 
21 class QTextEdit;
22 
28 class PQPYTHON_EXPORT pqPythonFileIO : public QObject
29 {
30  Q_OBJECT
31 public:
35  pqPythonFileIO() = delete;
36 
42  pqPythonFileIO(QWidget* parent, QTextEdit& text);
43 
49  ~pqPythonFileIO() override;
50 
57  bool saveOnClose();
58 
65  bool openFile(const QString& filename, vtkTypeUInt32 location = 0x10 /*vtkPVSession::CLIENT*/);
66 
70  void setDefaultSaveDirectory(const QString& dir) { this->DefaultSaveDirectory = dir; }
71 
75  const QString& getFilename() const { return this->File.Name; }
76 
80  vtkTypeUInt32 getLocation() const { return this->File.Location; }
81 
85  bool isDirty() const;
86 
87 Q_SIGNALS:
91  void bufferErased();
92 
96  void fileOpened(const QString&);
97 
101  void fileSaved(const QString&);
102 
107  void contentChanged();
108 
109 public Q_SLOTS:
113  void setModified(bool modified);
114 
120  bool save();
121 
126  bool saveAs();
127 
131  bool saveAsMacro();
132 
136  bool saveAsScript();
137 
138 private:
139  struct PythonFile
140  {
141  PythonFile() = default;
142 
143  PythonFile(const QString& str, const vtkTypeUInt32 location, QTextEdit* textEdit)
144  : Name(str)
145  , Location(location)
146  , Text(textEdit)
147  {
148  }
149 
150  bool operator!=(const PythonFile& other) const { return this->Name != other.Name; }
151 
152  bool writeToFile() const;
153 
154  bool readFromFile(QString& str) const;
155 
156  void start();
157 
158  void removeSwap() const;
159 
160  QString Name = "";
161  vtkTypeUInt32 Location = 0x10 /*vtkPVSession::CLIENT*/;
162  QTextEdit* Text = nullptr;
163  } File;
164 
165  bool saveBuffer(const QString& file, vtkTypeUInt32 location);
166 
167  QTextEdit& TextEdit;
168 
172  QString DefaultSaveDirectory = QDir::homePath();
173 };
174 
175 #endif // pqPythonFileIO_h
Text
location
vtkTypeUInt32 getLocation() const
Returns the location of the file that the editor acts on.
#define PQPYTHON_EXPORT
const QString & getFilename() const
Returns the filename the editor acts on.
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
void setDefaultSaveDirectory(const QString &dir)
Sets the default save directory.
Handles loading (resp.