pqPythonEditorActions.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 pqPythonEditorActions_h
6 #define pqPythonEditorActions_h
7 
8 #include "pqPythonUtils.h"
9 
10 #include <QAction>
11 #include <QMenu>
12 #include <QPointer>
13 
14 #include <array>
15 #include <cstddef>
16 #include <vector>
17 
18 class pqPythonManager;
19 
27 template <typename E>
29 {
30  static_assert(static_cast<int>(E::END), "The input enum must end with END");
31  static_assert(static_cast<int>(E::END) != 0, "At least one action is required");
32 
33  using Type = E;
34 
40  {
41  for (int i = 0; i < static_cast<int>(Type::END); ++i)
42  {
43  this->Actions[static_cast<Type>(i)] = new QAction();
44  }
45  }
46 
50  const QAction& operator[](const Type action) const { return *this->Actions[action]; }
51 
55  QAction& operator[](const Type action) { return *this->Actions[action]; }
56 
61 };
62 
74 {
81 
85  enum class GeneralActionType : std::uint8_t
86  {
87  // File IO Actions
88  NewFile,
89  OpenFile,
90  SaveFile,
91  SaveFileAs,
94  DeleteAll,
95 
96  // Undo/Redo Actions
97  Undo,
98  Redo,
99 
100  // Text Actions
101  Copy,
102  Cut,
103  Paste,
104 
105  // Editor Actions
107  Exit,
108  Run,
109 
110  END
111  };
112 
117  enum class ScriptActionType : std::uint8_t
118  {
119  Open,
120  Load,
121  Delete,
122  Run,
123 
124  END
125  };
126 
128 
133 
135 
139  std::vector<ScriptAction> ScriptActions;
140 
144  const QAction& operator[](const GeneralActionType action) const
145  {
146  return this->GeneralActions[action];
147  }
148 
152  QAction& operator[](const GeneralActionType action) { return this->GeneralActions[action]; }
153 
159  void updateScriptsList(pqPythonManager* python_mgr);
160 
166 
171  template <class T>
172  static void connect(pqPythonEditorActions&, T*);
173 
178  template <class T>
179  static void disconnect(pqPythonEditorActions&, T*);
180 };
181 
182 #endif // pqPythonEditorActions_h
EditorActionGroup::operator[]
const QAction & operator[](const Type action) const
const accessor to an action
Definition: pqPythonEditorActions.h:50
pqPythonEditorActions::GeneralActionType::CloseCurrentTab
@ CloseCurrentTab
pqPythonEditorActions::ScriptActionType::Load
@ Load
EditorActionGroup::operator[]
QAction & operator[](const Type action)
accessor to an action
Definition: pqPythonEditorActions.h:55
EditorActionGroup
A template group of action.
Definition: pqPythonEditorActions.h:28
pqPythonEditorActions::GeneralActionType::Paste
@ Paste
pqPythonEditorActions::connect
static void connect(pqPythonEditorActions &, T *)
Connects the pqPythonEditorActions to the type T.
EnumArray
Stack array using an enum as indexer.
Definition: pqPythonUtils.h:61
pqPythonEditorActions::GeneralActionType::Copy
@ Copy
EditorActionGroup< GeneralActionType >::Type
GeneralActionType Type
Definition: pqPythonEditorActions.h:33
pqPythonEditorActions::GeneralActionType::Undo
@ Undo
EditorActionGroup::EditorActionGroup
EditorActionGroup()
Default constructor allocates all the actions listed in the enum.
Definition: pqPythonEditorActions.h:39
pqPythonEditorActions::GeneralActionType::END
@ END
pqPythonEditorActions::GeneralActionType::Exit
@ Exit
pqPythonEditorActions::GeneralActionType::Cut
@ Cut
pqPythonEditorActions::GeneralActionType::Redo
@ Redo
pqPythonEditorActions::GeneralActionType::SaveFileAs
@ SaveFileAs
pqPythonEditorActions::ScriptActionType::END
@ END
pqPythonEditorActions
Definition: pqPythonEditorActions.h:73
pqPythonEditorActions::ScriptActionType::Open
@ Open
EditorActionGroup::Actions
EnumArray< Type, QPointer< QAction > > Actions
The array of actions.
Definition: pqPythonEditorActions.h:60
pqPythonEditorActions::GeneralActionType::SaveFile
@ SaveFile
pqPythonEditorActions::operator[]
const QAction & operator[](const GeneralActionType action) const
const accessor to an action
Definition: pqPythonEditorActions.h:144
pqPythonEditorActions::GeneralActionType::NewFile
@ NewFile
pqPythonEditorActions::disconnect
static void disconnect(pqPythonEditorActions &, T *)
Disconnects the pqPythonEditorActions to the type T.
pqPythonEditorActions::ScriptActions
std::vector< ScriptAction > ScriptActions
The variable sized array of script actions.
Definition: pqPythonEditorActions.h:139
pqPythonEditorActions::GeneralActionType
GeneralActionType
General editor actions.
Definition: pqPythonEditorActions.h:85
pqPythonEditorActions::GeneralActionType::OpenFile
@ OpenFile
pqPythonEditorActions::ScriptActionType::Delete
@ Delete
pqPythonEditorActions::ScriptActionType::Run
@ Run
pqPythonEditorActions::ScriptActionType
ScriptActionType
Specialized actions for the scripting part of the editor.
Definition: pqPythonEditorActions.h:117
pqPythonEditorActions::updateScriptsList
void updateScriptsList(pqPythonManager *python_mgr)
Updates the list of actions by listing the files contained into the default Script dir.
pqPythonEditorActions::GeneralActionType::Run
@ Run
pqPythonEditorActions::GeneralActionType::DeleteAll
@ DeleteAll
pqPythonEditorActions::pqPythonEditorActions
pqPythonEditorActions()
Default constructor initialize the tooltip and text of the various actions.
pqPythonEditorActions::FillQMenu
void FillQMenu(EnumArray< ScriptAction::Type, QMenu * > menus)
Fill the input menus with the current actions listed by this object.
pqPythonEditorActions::operator[]
QAction & operator[](const GeneralActionType action)
accessor to an action
Definition: pqPythonEditorActions.h:152
pqPythonEditorActions::GeneralActionType::SaveFileAsMacro
@ SaveFileAsMacro
pqPythonManager
pqPythonManager is a class to facilitate the use of a python interpreter by various paraview GUI comp...
Definition: pqPythonManager.h:28
pqPythonEditorActions::GeneralActionType::SaveFileAsScript
@ SaveFileAsScript
pqPythonEditorActions::GeneralActions
TGeneralAction GeneralActions
The list of general actions.
Definition: pqPythonEditorActions.h:132
pqPythonUtils.h