File indexing completed on 2024-05-19 04:56:04
0001 /** 0002 * \file frameobjectmodel.h 0003 * Object model with frame information. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 02 Sep 2014 0008 * 0009 * Copyright (C) 2014-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 <QObject> 0030 #include "frame.h" 0031 0032 class FrameFieldObject; 0033 0034 /** 0035 * Object model with frame information. 0036 */ 0037 class KID3_CORE_EXPORT FrameObjectModel : public QObject { 0038 Q_OBJECT 0039 Q_PROPERTY(QString name READ name CONSTANT) 0040 Q_PROPERTY(QString internalName READ internalName CONSTANT) 0041 Q_PROPERTY(int type READ type CONSTANT) 0042 Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) 0043 Q_PROPERTY(QList<QObject*> fields READ fields NOTIFY fieldsChanged) 0044 public: 0045 /** 0046 * Constructor. 0047 * @param parent parent object 0048 */ 0049 explicit FrameObjectModel(QObject* parent = nullptr); 0050 0051 /** 0052 * Destructor. 0053 */ 0054 ~FrameObjectModel() override = default; 0055 0056 /** 0057 * Get frame name. 0058 * @return translated frame name. 0059 */ 0060 QString name() const; 0061 0062 /** 0063 * Get internal frame name. 0064 * @return internal frame name, e.g. "TXXX - User defined text information" 0065 */ 0066 QString internalName() const; 0067 0068 /** 0069 * Get frame type. 0070 * @return type, type Frame::Type. 0071 */ 0072 int type() const; 0073 0074 /** 0075 * Get frame value. 0076 * @return frame value. 0077 */ 0078 QString value() const; 0079 0080 /** 0081 * Set frame value. 0082 * @param value value 0083 */ 0084 void setValue(const QString& value); 0085 0086 /** 0087 * Get field list. 0088 * @return fields. 0089 */ 0090 QList<QObject*> fields(); 0091 0092 /** 0093 * Set from frame. 0094 * @param frame frame 0095 */ 0096 void setFrame(const Frame& frame); 0097 0098 /** 0099 * Get frame from object information. 0100 * @return frame. 0101 */ 0102 Frame getFrame() const; 0103 0104 /** 0105 * Get binary data from data field. 0106 * @return binary data, empty if not available. 0107 */ 0108 Q_INVOKABLE QByteArray getBinaryData() const; 0109 0110 signals: 0111 /** Emitted when value is changed. */ 0112 void valueChanged(const QString& value); 0113 0114 /** Emitted when any of the fields is changed. */ 0115 void fieldsChanged(); 0116 0117 private: 0118 friend class FrameFieldObject; 0119 0120 Frame m_frame; 0121 }; 0122 0123 /** 0124 * Object with frame field information. 0125 */ 0126 class FrameFieldObject : public QObject { 0127 Q_OBJECT 0128 Q_PROPERTY(QString name READ name CONSTANT) 0129 Q_PROPERTY(int id READ id CONSTANT) 0130 Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) 0131 Q_PROPERTY(int type READ type CONSTANT) 0132 public: 0133 /** 0134 * Constructor. 0135 * @param index index in field list 0136 * @param parent parent object 0137 */ 0138 FrameFieldObject(int index, FrameObjectModel* parent); 0139 0140 /** 0141 * Destructor. 0142 */ 0143 ~FrameFieldObject() override = default; 0144 0145 /** 0146 * Get field name. 0147 * @return translated field name. 0148 */ 0149 QString name() const; 0150 0151 /** 0152 * Get field ID. 0153 * @return id, type Frame::FieldId. 0154 */ 0155 int id() const; 0156 0157 /** 0158 * Get field value. 0159 * @return field value. 0160 */ 0161 QVariant value() const; 0162 0163 /** 0164 * Set field value. 0165 * @param value value 0166 */ 0167 void setValue(const QVariant& value); 0168 0169 /** 0170 * Get frame type. 0171 * @return type, type Frame::Type. 0172 */ 0173 int type() const; 0174 0175 signals: 0176 /** Emitted when the value is changed. */ 0177 void valueChanged(const QVariant& value); 0178 0179 private: 0180 FrameObjectModel* frameObject() const { 0181 return static_cast<FrameObjectModel*>(parent()); 0182 } 0183 0184 const int m_index; 0185 };