File indexing completed on 2024-05-19 04:55:57
0001 /** 0002 * \file starratingmappingsmodel.h 0003 * Star rating mappings configuration table model. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 2 Jan 2018 0008 * 0009 * Copyright (C) 2018-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QAbstractTableModel> 0030 #include "kid3api.h" 0031 0032 /** 0033 * Star rating mappings configuration table model. 0034 */ 0035 class KID3_CORE_EXPORT StarRatingMappingsModel : public QAbstractTableModel { 0036 Q_OBJECT 0037 public: 0038 /** 0039 * Constructor. 0040 * @param parent parent widget 0041 */ 0042 explicit StarRatingMappingsModel(QObject* parent = nullptr); 0043 0044 /** 0045 * Destructor. 0046 */ 0047 ~StarRatingMappingsModel() override = default; 0048 0049 /** 0050 * Get item flags for index. 0051 * @param index model index 0052 * @return item flags 0053 */ 0054 Qt::ItemFlags flags(const QModelIndex& index) const override; 0055 0056 /** 0057 * Get data for a given role. 0058 * @param index model index 0059 * @param role item data role 0060 * @return data for role 0061 */ 0062 QVariant data(const QModelIndex& index, 0063 int role = Qt::DisplayRole) const override; 0064 0065 /** 0066 * Set data for a given role. 0067 * @param index model index 0068 * @param value data value 0069 * @param role item data role 0070 * @return true if successful 0071 */ 0072 bool setData(const QModelIndex& index, const QVariant& value, 0073 int role = Qt::EditRole) override; 0074 0075 /** 0076 * Get data for header section. 0077 * @param section column or row 0078 * @param orientation horizontal or vertical 0079 * @param role item data role 0080 * @return header data for role 0081 */ 0082 QVariant headerData(int section, Qt::Orientation orientation, 0083 int role = Qt::DisplayRole) const override; 0084 0085 /** 0086 * Set data for header section. 0087 * Not supported. 0088 * @return false 0089 */ 0090 bool setHeaderData(int, Qt::Orientation, const QVariant&, 0091 int = Qt::EditRole) override { return false; } 0092 0093 /** 0094 * Get number of rows. 0095 * @param parent parent model index, invalid for table models 0096 * @return number of rows, 0097 * if parent is valid number of children (0 for table models) 0098 */ 0099 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0100 0101 /** 0102 * Get number of columns. 0103 * @param parent parent model index, invalid for table models 0104 * @return number of columns, 0105 * if parent is valid number of children (0 for table models) 0106 */ 0107 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0108 0109 /** 0110 * Insert rows. 0111 * @param row rows are inserted before this row, if 0 at the begin, 0112 * if rowCount() at the end 0113 * @param count number of rows to insert 0114 * @param parent parent model index, invalid for table models 0115 * @return true if successful 0116 */ 0117 bool insertRows(int row, int count, 0118 const QModelIndex& parent = QModelIndex()) override; 0119 0120 /** 0121 * Remove rows. 0122 * @param row rows are removed starting with this row 0123 * @param count number of rows to remove 0124 * @param parent parent model index, invalid for table models 0125 * @return true if successful 0126 */ 0127 bool removeRows(int row, int count, 0128 const QModelIndex& parent = QModelIndex()) override; 0129 0130 /** 0131 * Set the model from the star count mappings. 0132 * @param maps star count mappings 0133 */ 0134 void setMappings(const QList<QPair<QString, QVector<int> > >& maps); 0135 0136 /** 0137 * Get the start count mappings from the model. 0138 * @return star count mappings 0139 */ 0140 QList<QPair<QString, QVector<int> > > getMappings() const; 0141 0142 private: 0143 void makeRowValid(int row); 0144 0145 QList<QPair<QString, QVector<int> > > m_maps; 0146 };