MuseScore  3.4
Music composition and notation
scorelistmodel.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2018 Werner Schweer
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 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __SCORELISTMODEL_H__
14 #define __SCORELISTMODEL_H__
15 
16 namespace Ms {
17 
18 class MasterScore;
19 class Score;
20 class ScoreTab;
21 
22 //---------------------------------------------------------
23 // ScoreListModel
24 //---------------------------------------------------------
25 
26 class ScoreListModel : public QAbstractListModel {
27  Q_OBJECT
28 
29  QVector<int> _usedRoles;
30  const QList<MasterScore*>* _scoreList;
31  ScoreTab* _tab; // currently used for tracking changes in score list
32 
33  public:
34  ScoreListModel(const QList<MasterScore*>* scoreList, ScoreTab* tab, QObject* parent = nullptr);
35 
36  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
37  QVariant data(const QModelIndex& index, int role) const override;
38 
39  Score* getScore(int idx) const;
40 
41  public slots:
42  void tabInserted(int idx);
43  void tabRemoved(int idx);
44  void tabRenamed(int idx);
45  void tabMoved(int from, int to);
46  };
47 
48 //---------------------------------------------------------
49 // ScoreVersion
50 //---------------------------------------------------------
51 
52 typedef int ScoreVersionIndex;
53 
54 struct ScoreVersion {
56  QString name;
57  ScoreVersionIndex index;
58  QFileInfo fileInfo;
59  bool recent;
60 
61  constexpr static ScoreVersionIndex INDEX_CURRENT = -1;
62  constexpr static ScoreVersionIndex INDEX_LAST_SAVED = -2;
63  constexpr static ScoreVersionIndex INDEX_SESSION_START = -3;
64 
65  ScoreVersion(Score* score, const QString& name, ScoreVersionIndex index, const QFileInfo& fileInfo, bool recent)
66  : score(score), name(name), index(index), fileInfo(fileInfo), recent(recent) {}
67  ScoreVersion(Score* score, const QString& name, ScoreVersionIndex index, bool recent)
68  : score(score), name(name), index(index), recent(recent) {}
69  };
70 
71 //---------------------------------------------------------
72 // ScoreVersionListModel
73 //---------------------------------------------------------
74 
75 class ScoreVersionListModel : public QAbstractListModel {
76  Q_OBJECT
77 
79  std::vector<ScoreVersion> _versions;
80 
81  public:
82  ScoreVersionListModel(MasterScore* score, QObject* parent = nullptr);
83 
84  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
85  QVariant data(const QModelIndex& index, int role) const override;
86 
87  const MasterScore* score() const { return _score; }
88  const ScoreVersion& getScoreVersion(int idx) const { return _versions[idx]; };
89  int getPosition(ScoreVersionIndex index) const;
90 
91  public slots:
92  void update();
93  void setScore(MasterScore* s);
94  };
95 
96 } // namespace Ms
97 #endif
void tabMoved(int from, int to)
Definition: scorelistmodel.cpp:114
MasterScore * _score
Definition: scorelistmodel.h:78
ScoreVersion(Score *score, const QString &name, ScoreVersionIndex index, bool recent)
Definition: scorelistmodel.h:67
Definition: score.h:1227
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: scorelistmodel.cpp:45
QFileInfo fileInfo
Definition: scorelistmodel.h:58
ScoreTab * _tab
Definition: scorelistmodel.h:31
int ScoreVersionIndex
Definition: scorelistmodel.h:52
Definition: scoretab.h:47
Definition: scorelistmodel.h:54
Definition: score.h:391
Score * score
Definition: scorelistmodel.h:55
const MasterScore * score() const
Definition: scorelistmodel.h:87
Definition: scorelistmodel.h:75
ScoreVersionIndex index
Definition: scorelistmodel.h:57
QVector< int > _usedRoles
Definition: scorelistmodel.h:29
bool recent
Definition: scorelistmodel.h:59
ScoreListModel(const QList< MasterScore *> *scoreList, ScoreTab *tab, QObject *parent=nullptr)
Definition: scorelistmodel.cpp:29
std::vector< ScoreVersion > _versions
Definition: scorelistmodel.h:79
Definition: scorelistmodel.h:26
Definition: aeolus.cpp:26
const ScoreVersion & getScoreVersion(int idx) const
Definition: scorelistmodel.h:88
ScoreVersion(Score *score, const QString &name, ScoreVersionIndex index, const QFileInfo &fileInfo, bool recent)
Definition: scorelistmodel.h:65
void tabInserted(int idx)
Definition: scorelistmodel.cpp:86
void tabRemoved(int idx)
Definition: scorelistmodel.cpp:95
QVariant data(const QModelIndex &index, int role) const override
Definition: scorelistmodel.cpp:56
Score * getScore(int idx) const
Definition: scorelistmodel.cpp:75
QString name
Definition: scorelistmodel.h:56
const QList< MasterScore * > * _scoreList
Definition: scorelistmodel.h:30
void tabRenamed(int idx)
Definition: scorelistmodel.cpp:104