ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PythonEditor.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // ##########################################################################
11 // # #
12 // # ACLOUDVIEWER PLUGIN: PythonRuntime #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Chris S Brown #
24 // # Thomas Montaigu #
25 // ##########################################################################
26 
27 #include <ui_PythonEditor.h>
28 
29 // Qt
30 #include "EditorSettings.h"
31 #include <CVLog.h>
32 #include <QMainWindow>
33 
34 class CodeEditor;
35 QT_BEGIN_NAMESPACE
36 class QAction;
37 class QMenu;
38 class QMdiArea;
39 class QMdiSubWindow;
40 class QFileSystemModel;
41 class QModelIndex;
42 QT_END_NAMESPACE
43 
45 class PythonInterpreter;
47 
48 #define MAX_RECENT_FILES 10
49 
50 class PythonEditor final : public QMainWindow, public Ui::PythonEditor
51 {
52  Q_OBJECT
53 
54  public:
55  static QString SettingsApplicationName();
56 
57  explicit PythonEditor(PythonInterpreter *interpreter);
58 
59  void changeEvent(QEvent *e) override;
67  bool openFile(const QString &fileName);
68 
69  protected:
70  void closeEvent(QCloseEvent *event) override;
71  Q_SIGNALS:
72  void executionCalled(const std::string &evalStatement, QListWidget *output);
73 
74  protected Q_SLOTS:
75  void newFile();
76  void promptForFileToOpen();
77  // Display a folder selection dialog & fills the
78  // content of the project view with the content of the selected folder
79  void promptForFolderToOpen();
80  void save();
81  void saveAs();
83  void openRecentFile();
84  bool eventFilter(QObject *obj, QEvent *e) override;
85  // Loads the double clicked item from the project view
86  // if its a file
87  void projectTreeDoubleClicked(const QModelIndex &index);
88 
89 #ifndef QT_NO_CLIPBOARD
90  void cut();
91  void copy();
92  void paste();
93 #endif
94  void comment();
95  void uncomment();
96  void indentMore();
97  void indentLess();
98  void updateWindowMenu();
99  void executionStarted();
100  void executionFinished();
102 
103  private:
104  static bool HasRecentFiles();
105 
106  // Initialization functions
107  void setupUi();
108  void createActions();
109  void updateMenus();
110 
111  void runExecute();
112  void readSettings();
113  void writeSettings();
114  bool loadFile(const QString &fileName);
115  void prependToRecentFiles(const QString &fileName);
116  void setRecentFilesVisible(bool visible);
117  CodeEditor *activeChildCodeEditor() const;
118  QMdiSubWindow *findChildCodeEditor(const QString &fileName) const;
119 
120  private: // Members
121  EditorSettings *m_settings{nullptr};
122 
123  QMdiArea *m_mdiArea{nullptr};
124 
125  QMenu *m_windowMenu{nullptr};
126 
127  QAction *m_recentFileActs[MAX_RECENT_FILES] = {nullptr};
128  QAction *m_recentFileSeparator{nullptr};
129  QAction *m_recentFileSubMenuAct{nullptr};
130  QAction *m_closeAct{nullptr};
131  QAction *m_closeAllAct{nullptr};
132  QAction *m_tileAct{nullptr};
133  QAction *m_cascadeAct{nullptr};
134  QAction *m_nextAct{nullptr};
135  QAction *m_previousAct{nullptr};
136  QAction *m_windowMenuSeparatorAct{nullptr};
137 };
MouseEvent event
#define MAX_RECENT_FILES
Definition: PythonEditor.h:48
void promptForFileToOpen()
void executionFinished()
bool eventFilter(QObject *obj, QEvent *e) override
void executionStarted()
void closeEvent(QCloseEvent *event) override
void updateRecentFileActions()
void updateWindowMenu()
CodeEditor * createChildCodeEditor()
PythonEditor(PythonInterpreter *interpreter)
void changeEvent(QEvent *e) override
void executionCalled(const std::string &evalStatement, QListWidget *output)
static QString SettingsApplicationName()
bool openFile(const QString &fileName)
void promptForFolderToOpen()
void projectTreeDoubleClicked(const QModelIndex &index)
void openRecentFile()
Main application interface (for plugins)