1 /* 2 MIDI Sequencer C++ library 3 Copyright (C) 2006-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net> 4 5 This library is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This library 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, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef DRUMGRIDMODEL_H 20 #define DRUMGRIDMODEL_H 21 22 #include <QAbstractTableModel> 23 #include <QStringList> 24 25 class DrumGridModel : public QAbstractTableModel 26 { 27 Q_OBJECT 28 29 public: 30 explicit DrumGridModel(QObject *parent = nullptr); 31 32 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 33 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 34 35 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 36 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 37 38 void loadKeyNames(); 39 void fillSampleData(); 40 41 void clearPattern(); 42 void addPatternData(int key, const QStringList& row); 43 void endOfPattern(); 44 QStringList patternData(int row); 45 QString patternKey(int row); 46 QString patternHit(int row, int col); 47 void updatePatternColumns(int columns); 48 49 static const QString DEFVAL; 50 51 public slots: 52 void changeCell(const QModelIndex &index); 53 void changeCell(const QModelIndex &index, const QString& newValue); 54 55 private: 56 int m_columns; 57 QString m_lastValue; 58 QMap<int,QString> m_keyNames; 59 QList<QStringList> m_modelData; 60 QList<QStringList> m_tempData; 61 QList<int> m_keys; 62 QList<int> m_tempKeys; 63 }; 64 65 #endif /* DRUMGRIDMODEL_H */ 66