File indexing completed on 2024-05-19 04:56:09
0001 /** 0002 * \file trackdatamodel.h 0003 * Model for table with track data. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 15 May 2011 0008 * 0009 * Copyright (C) 2011-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 <QList> 0031 #include "trackdata.h" 0032 #include "kid3api.h" 0033 0034 class CoreTaggedFileIconProvider; 0035 0036 /** 0037 * Model for table with track data. 0038 */ 0039 class KID3_CORE_EXPORT TrackDataModel : public QAbstractTableModel { 0040 Q_OBJECT 0041 public: 0042 /** Additional track properties extending Frame::Type. */ 0043 enum TrackProperties { 0044 FT_FirstTrackProperty = Frame::FT_UnknownFrame + 1, 0045 FT_FilePath = FT_FirstTrackProperty, 0046 FT_Duration, 0047 FT_ImportDuration, 0048 FT_FileName 0049 }; 0050 0051 /** 0052 * Constructor. 0053 * @param colorProvider colorProvider 0054 * @param parent parent widget 0055 */ 0056 explicit TrackDataModel(CoreTaggedFileIconProvider* colorProvider, 0057 QObject* parent = nullptr); 0058 0059 /** 0060 * Destructor. 0061 */ 0062 ~TrackDataModel() override = default; 0063 0064 /** 0065 * Get item flags for index. 0066 * @param index model index 0067 * @return item flags 0068 */ 0069 Qt::ItemFlags flags(const QModelIndex& index) const override; 0070 0071 /** 0072 * Get data for a given role. 0073 * @param index model index 0074 * @param role item data role 0075 * @return data for role 0076 */ 0077 QVariant data(const QModelIndex& index, 0078 int role = Qt::DisplayRole) const override; 0079 0080 /** 0081 * Set data for a given role. 0082 * @param index model index 0083 * @param value data value 0084 * @param role item data role 0085 * @return true if successful 0086 */ 0087 bool setData(const QModelIndex& index, const QVariant& value, 0088 int role = Qt::EditRole) override; 0089 0090 /** 0091 * Get data for header section. 0092 * @param section column or row 0093 * @param orientation horizontal or vertical 0094 * @param role item data role 0095 * @return header data for role 0096 */ 0097 QVariant headerData(int section, Qt::Orientation orientation, 0098 int role = Qt::DisplayRole) const override; 0099 0100 /** 0101 * Set data for header section. 0102 * Not supported. 0103 * @return false 0104 */ 0105 bool setHeaderData(int, Qt::Orientation, const QVariant&, 0106 int = Qt::EditRole) override { return false; } 0107 0108 /** 0109 * Get number of rows. 0110 * @param parent parent model index, invalid for table models 0111 * @return number of rows, 0112 * if parent is valid number of children (0 for table models) 0113 */ 0114 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0115 0116 /** 0117 * Get number of columns. 0118 * @param parent parent model index, invalid for table models 0119 * @return number of columns, 0120 * if parent is valid number of children (0 for table models) 0121 */ 0122 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0123 0124 /** 0125 * Insert rows. 0126 * @param row rows are inserted before this row, if 0 at the begin, 0127 * if rowCount() at the end 0128 * @param count number of rows to insert 0129 * @param parent parent model index, invalid for table models 0130 * @return true if successful 0131 */ 0132 bool insertRows(int row, int count, 0133 const QModelIndex& parent = QModelIndex()) override; 0134 0135 /** 0136 * Remove rows. 0137 * @param row rows are removed starting with this row 0138 * @param count number of rows to remove 0139 * @param parent parent model index, invalid for table models 0140 * @return true if successful 0141 */ 0142 bool removeRows(int row, int count, 0143 const QModelIndex& parent = QModelIndex()) override; 0144 0145 /** 0146 * Insert columns. 0147 * @param column columns are inserted before this column, if 0 at the begin, 0148 * if columnCount() at the end 0149 * @param count number of columns to insert 0150 * @param parent parent model index, invalid for table models 0151 * @return true if successful 0152 */ 0153 bool insertColumns(int column, int count, 0154 const QModelIndex& parent = QModelIndex()) override; 0155 /** 0156 * Remove columns. 0157 * @param column columns are removed starting with this column 0158 * @param count number of columns to remove 0159 * @param parent parent model index, invalid for table models 0160 * @return true if successful 0161 */ 0162 bool removeColumns(int column, int count, 0163 const QModelIndex& parent = QModelIndex()) override; 0164 0165 /** 0166 * Set the check state of all tracks in the table. 0167 * 0168 * @param checked true to check the tracks 0169 */ 0170 void setAllCheckStates(bool checked); 0171 0172 /** 0173 * Set time difference check configuration. 0174 * 0175 * @param enable true to enable check 0176 * @param maxDiff maximum allowed time difference 0177 */ 0178 void setTimeDifferenceCheck(bool enable, int maxDiff); 0179 0180 /** 0181 * Calculate accuracy of imported track data. 0182 * @return accuracy in percent, -1 if unknown. 0183 */ 0184 int calculateAccuracy() const; 0185 0186 /** 0187 * Get frame for index. 0188 * @param index model index 0189 * @return frame, 0 if no frame. 0190 */ 0191 const Frame* getFrameOfIndex(const QModelIndex& index) const; 0192 0193 /** 0194 * Set track data. 0195 * @param trackDataVector track data 0196 */ 0197 void setTrackData(const ImportTrackDataVector& trackDataVector); 0198 0199 /** 0200 * Get track data. 0201 * @return track data 0202 */ 0203 ImportTrackDataVector getTrackData() const; 0204 0205 /** 0206 * Constant reference to track data. 0207 * @return track data 0208 */ 0209 const ImportTrackDataVector& trackData() const { return m_trackDataVector; } 0210 0211 /** 0212 * Get the frame type for a column. 0213 * @param column model column 0214 * @return frame type of Frame::Type or TrackDataModel::TrackProperties, 0215 * -1 if column invalid. 0216 */ 0217 int frameTypeForColumn(int column) const; 0218 0219 /** 0220 * Get column for a frame type. 0221 * @param frameType frame type of Frame::Type or 0222 * TrackDataModel::TrackProperties. 0223 * @return model column, -1 if not found. 0224 */ 0225 int columnForFrameType(int frameType) const; 0226 0227 private: 0228 ImportTrackDataVector m_trackDataVector; 0229 QList<Frame::ExtendedType> m_frameTypes; 0230 CoreTaggedFileIconProvider* m_colorProvider; 0231 int m_maxDiff; 0232 bool m_diffCheckEnabled; 0233 };