File indexing completed on 2024-12-22 04:12:00
0001 /* 0002 * SPDX-FileCopyrightText: 2018 boud <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef DUMMYRESOURCE_H 0007 #define DUMMYRESOURCE_H 0008 0009 #include "KoResource.h" 0010 #include <QDebug> 0011 #include <QRandomGenerator64> 0012 #include <KoMD5Generator.h> 0013 #include <KisResourceTypes.h> 0014 0015 class DummyResource : public KoResource { 0016 public: 0017 DummyResource(const QString &f, const QString &resourceType = ResourceType::PaintOpPresets) 0018 : KoResource(f) 0019 , m_resourceType(resourceType) 0020 { 0021 QRandomGenerator64 qrg; 0022 QByteArray ba(1024, '0'); 0023 for (int i = 0; i < 1024 / 8; i+=8) { 0024 quint64 v = qrg.generate64(); 0025 ba[i] = v; 0026 } 0027 0028 m_something = QString::fromUtf8(ba); 0029 0030 setMD5Sum(KoMD5Generator::generateHash(ba)); 0031 0032 QImage img(512, 512, QImage::Format_RGB32); 0033 img.fill(Qt::blue); 0034 setImage(img); 0035 0036 setValid(true); 0037 } 0038 0039 DummyResource(const DummyResource &rhs) 0040 : KoResource(rhs), 0041 m_something(rhs.m_something) 0042 { 0043 } 0044 0045 KoResourceSP clone() const override 0046 { 0047 return KoResourceSP(new DummyResource(*this)); 0048 } 0049 0050 bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override 0051 { 0052 Q_UNUSED(resourcesInterface); 0053 0054 if (!dev->isOpen()) { 0055 dev->open(QIODevice::ReadOnly); 0056 } 0057 m_something = QString::fromUtf8(dev->readAll()); 0058 setValid(true); 0059 return true; 0060 } 0061 0062 bool saveToDevice(QIODevice *dev) const override 0063 { 0064 if (!dev->isOpen()) { 0065 dev->open(QIODevice::WriteOnly); 0066 } 0067 dev->write(m_something.toUtf8()); 0068 return true; 0069 } 0070 0071 void setSomething(const QString &something) 0072 { 0073 m_something = something; 0074 } 0075 0076 QString something() const 0077 { 0078 return m_something; 0079 } 0080 0081 QPair<QString, QString> resourceType() const override { 0082 return QPair<QString, QString>(m_resourceType, ""); 0083 } 0084 0085 private: 0086 0087 QString m_something; 0088 QString m_resourceType; 0089 }; 0090 0091 #endif // DUMMYRESOURCE_H