MuseScore  3.4
Music composition and notation
workspace.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2011 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __WORKSPACE_H__
21 #define __WORKSPACE_H__
22 
23 #include <unordered_map>
24 
25 namespace Ms {
26 
27 struct PaletteTree;
28 class XmlReader;
29 class XmlWriter;
30 
31 //---------------------------------------------------------
32 // Workspace
33 //---------------------------------------------------------
34 class Workspace : public QObject {
35  Q_OBJECT
36 
37  static QList<QPair<QAction*, QString>> actionToStringList;
38  static QList<QPair<QMenu*, QString>> menuToStringList;
39 
40  static void writeMenuBar(XmlWriter& xml, QMenuBar* mb = 0);
41  static void writeMenu(XmlWriter& xml, QMenu* menu);
42  static void addRemainingFromMenu(QMenu* menu);
43 
44  void readMenu(XmlReader& e, QMenu* menu);
45 
46  static QString findStringFromAction(QAction* action);
47  static QAction* findActionFromString(QString string);
48  static QString findStringFromMenu(QMenu* menu);
49 
50  QString _name;
53  QString _path;
54  bool _dirty;
55  bool _readOnly;
56 
57  QTimer _saveTimer;
58 
62 
63  void readGlobalToolBar();
64  void readGlobalMenuBar();
65  void readGlobalGUIState();
66 
67  private slots:
68  void ensureWorkspaceSaved();
69 
70  public slots:
71  void setDirty(bool val);
72  void setDirty() { setDirty(true); }
73 
74  public:
75  Workspace();
76  Workspace(const QString& n, const QString& p, bool d, bool r)
77  : _name(n), _path(p), _dirty(d), _readOnly(r) {}
78 
79  QString path() const { return _path; }
80  void setPath(const QString& s) { _path = s; }
81  QString name() const { return _name; }
82  void setName(const QString& s) { _name = s; }
83  const QString& translatableName() const { return _translatableName; }
84  void setTranslatableName(QString trName) { _translatableName = trName; }
85  void rename(const QString& s);
86  bool dirty() const { return _dirty; }
87 
88  void save();
89  void write();
90  void read(XmlReader&);
91  void read();
92  bool readOnly() const { return _readOnly; }
93  void setReadOnly(bool val) { _readOnly = val; }
94  void reset();
95 
96  const Workspace* sourceWorkspace() const;
97  void setSourceWorkspaceName(const QString& sourceWorkspaceName) { _sourceWorkspaceName = sourceWorkspaceName; }
99 
100  std::unique_ptr<PaletteTree> getPaletteTree() const;
101 
102  static void addActionAndString(QAction* action, QString string);
103  static void addRemainingFromMenuBar(QMenuBar* mb);
104  static void addMenuAndString(QMenu* menu, QString string);
105  static QMenu* findMenuFromString(QString string);
106 
108  void setSaveComponents(bool s) { saveComponents = s; }
109  bool getSaveToolbars() { return saveToolbars; }
110  void setSaveToolbars(bool s) { saveToolbars = s; }
111  bool getSaveMenuBar() { return saveMenuBar; }
112  void setSaveMenuBar(bool s) { saveMenuBar = s; }
113 
114  static void writeGlobalMenuBar(QMenuBar* mb);
115  static void writeGlobalToolBar();
116  static void writeGlobalGUIState();
117  };
118 
120  private:
121  static void initWorkspaces();
122 
123  public:
124  static Workspace* createNewWorkspace(const QString& name);
125  static void refreshWorkspaces();
126 
127  static QString makeUserWorkspacePath(const QString& name);
128  static void readWorkspaceFile(const QString& path, std::function<void(XmlReader&)> readWorkspace);
129  static void retranslate(QList<Workspace*>& workspacesList);
130  static void retranslateAll();
131 
132  static Workspace* findByName(const QString& name) {
133  for (auto w : m_workspaces) {
134  if (w->name() == name)
135  return w;
136  }
137  return nullptr;
138  }
139 
140  static Workspace* findByTranslatableName(const QString& name) {
141  for (auto w : m_workspaces) {
142  if (w->translatableName() == name)
143  return w;
144  }
145  return nullptr;
146  }
147 
148  static void remove(Workspace* workspace);
149  static const QList<Workspace*>& workspaces() {
150  if (isWorkspacesListDirty || m_workspaces.isEmpty())
151  initWorkspaces();
152  return m_workspaces;
153  }
154 
155  static const QList<Workspace*>& visibleWorkspaces() {
156  if (isWorkspacesListDirty || m_visibleWorkspaces.isEmpty())
157  initWorkspaces();
158  return m_visibleWorkspaces;
159  }
160 
161  //replace with `const Workspace*` in future
162  static Workspace* currentWorkspace() { return m_currentWorkspace; }
163  static void setCurrentWorkspace(Workspace* currWorkspace) { m_currentWorkspace = currWorkspace; }
164 
165  static void initCurrentWorkspace();
166  static bool isDefaultWorkspace(Workspace* workspace);
167  static bool isDefaultEditedWorkspace(Workspace* workspace);
168  static QString defaultWorkspaceTranslatableName(const QString& editedWorkspaceName);
169 
170  static void clearWorkspaces();
171 
172  public:
173  static std::vector<QString> defaultWorkspaces;
174  static std::vector<QString> defaultEditedWorkspaces;
175 
176  private:
177  static QList<Workspace*> m_workspaces;
178  static QList<Workspace*> m_visibleWorkspaces;
181  };
182 
183 }
184 #endif
185 
static void addActionAndString(QAction *action, QString string)
Definition: workspace.cpp:1315
Definition: xml.h:67
Definition: workspace.h:34
QString _sourceWorkspaceName
Definition: workspace.h:52
static std::vector< QString > defaultEditedWorkspaces
Definition: workspace.h:174
QString name() const
Definition: workspace.h:81
bool _dirty
Definition: workspace.h:54
static void writeMenuBar(XmlWriter &xml, QMenuBar *mb=0)
Definition: workspace.cpp:580
QString path() const
Definition: workspace.h:79
const QString & translatableName() const
Definition: workspace.h:83
bool getSaveMenuBar()
Definition: workspace.h:111
bool _readOnly
Definition: workspace.h:55
bool readOnly() const
Definition: workspace.h:92
static QAction * findActionFromString(QString string)
Definition: workspace.cpp:1361
void save()
Definition: workspace.cpp:1112
void setName(const QString &s)
Definition: workspace.h:82
Definition: workspace.h:119
bool saveComponents
Definition: workspace.h:59
static void writeGlobalToolBar()
Definition: workspace.cpp:490
Workspace()
Definition: workspace.cpp:306
QTimer _saveTimer
Definition: workspace.h:57
static Workspace * currentWorkspace()
Definition: workspace.h:162
void setPath(const QString &s)
Definition: workspace.h:80
static QList< QPair< QMenu *, QString > > menuToStringList
Definition: workspace.h:38
static void addRemainingFromMenu(QMenu *menu)
Definition: workspace.cpp:1344
void read()
Definition: workspace.cpp:670
static const QList< Workspace * > & workspaces()
Definition: workspace.h:149
void readMenu(XmlReader &e, QMenu *menu)
Definition: workspace.cpp:892
static bool isWorkspacesListDirty
Definition: workspace.h:180
static void writeMenu(XmlWriter &xml, QMenu *menu)
Definition: workspace.cpp:611
static Workspace * m_currentWorkspace
Definition: workspace.h:179
static void addRemainingFromMenuBar(QMenuBar *mb)
Definition: workspace.cpp:1327
static Workspace * findByName(const QString &name)
Definition: workspace.h:132
void setReadOnly(bool val)
Definition: workspace.h:93
void setSaveToolbars(bool s)
Definition: workspace.h:110
std::unique_ptr< PaletteTree > getPaletteTree() const
Definition: workspace.cpp:707
static const QList< Workspace * > & visibleWorkspaces()
Definition: workspace.h:155
static void setCurrentWorkspace(Workspace *currWorkspace)
Definition: workspace.h:163
void write()
Definition: workspace.cpp:341
static void writeGlobalGUIState()
Definition: workspace.cpp:540
static void addMenuAndString(QMenu *menu, QString string)
Definition: workspace.cpp:1387
void setSourceWorkspaceName(const QString &sourceWorkspaceName)
Definition: workspace.h:97
static QList< Workspace * > m_workspaces
Definition: workspace.h:177
bool dirty() const
Definition: workspace.h:86
void setSaveMenuBar(bool s)
Definition: workspace.h:112
static void writeGlobalMenuBar(QMenuBar *mb)
Definition: workspace.cpp:451
Definition: aeolus.cpp:26
QString _path
Definition: workspace.h:53
void setSaveComponents(bool s)
Definition: workspace.h:108
Definition: xml.h:218
QString sourceWorkspaceName()
Definition: workspace.h:98
void readGlobalGUIState()
Definition: workspace.cpp:1035
Definition: xmlwriter.h:26
void ensureWorkspaceSaved()
Definition: workspace.cpp:1065
static QMenu * findMenuFromString(QString string)
Definition: workspace.cpp:1399
static QList< Workspace * > m_visibleWorkspaces
Definition: workspace.h:178
QString _name
Definition: workspace.h:50
Workspace(const QString &n, const QString &p, bool d, bool r)
Definition: workspace.h:76
static QList< QPair< QAction *, QString > > actionToStringList
Definition: workspace.h:37
Definition: xmlreader.h:28
void rename(const QString &s)
Definition: workspace.cpp:1425
QString _translatableName
Definition: workspace.h:51
const Workspace * sourceWorkspace() const
Definition: workspace.cpp:1249
static std::vector< QString > defaultWorkspaces
Definition: workspace.h:173
bool getSaveComponents()
Definition: workspace.h:107
bool saveToolbars
Definition: workspace.h:60
void setTranslatableName(QString trName)
Definition: workspace.h:84
void readGlobalMenuBar()
Definition: workspace.cpp:917
static QString findStringFromMenu(QMenu *menu)
Definition: workspace.cpp:1412
bool getSaveToolbars()
Definition: workspace.h:109
void reset()
Reset the workspace to the state of the source workspace.
Definition: workspace.cpp:697
void readGlobalToolBar()
Definition: workspace.cpp:971
static QString findStringFromAction(QAction *action)
Definition: workspace.cpp:1374
static Workspace * findByTranslatableName(const QString &name)
Definition: workspace.h:140
void setDirty()
Definition: workspace.h:72
bool saveMenuBar
Definition: workspace.h:61