Krita

Resource.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #include "Resource.h"
7 #include <KoResource.h>
8 #include <QByteArray>
9 #include <QBuffer>
10 
11 #include <KoPattern.h>
12 #include <KoAbstractGradient.h>
13 #include <kis_brush.h>
14 #include <kis_paintop_preset.h>
15 #include <KoColorSet.h>
16 #include <kis_workspace_resource.h>
17 #include <KisResourceLocator.h>
18 
19 struct Resource::Private {
20  Private() {}
21 
22  int id {-1};
23  QString type;
24  QString name;
26  QImage image;
27 };
28 
29 Resource::Resource(int resourceId, const QString &type, const QString &name, const QString &filename, const QImage &image, QObject *parent)
30  : QObject(parent)
31  , d(new Private())
32 {
33  d->id = resourceId;
34  d->type = type;
35  d->name = name;
36  d->filename = filename;
37  d->image = image;
38 }
39 
40 Resource::Resource(KoResourceSP resource, const QString &type, QObject *parent)
41  : QObject(parent)
42  , d(new Private())
43 {
44  d->id = resource->resourceId();
45  d->type = type;
46  d->name = resource->name();
47  d->filename = resource->filename();
48  d->image = resource->image();
49 }
50 
51 Resource::~Resource()
52 {
53 }
54 
55 Resource::Resource(const Resource &rhs)
56  : QObject()
57  , d(new Private())
58 {
59  d->id = rhs.d->id;
60  d->type = rhs.d->type;
61  d->name = rhs.d->name;
62  d->filename = rhs.d->filename;
63  d->image = rhs.d->image;
64 }
65 
66 bool Resource::operator==(const Resource &other) const
67 {
68  return (d->id == other.d->id);
69 }
70 
71 bool Resource::operator!=(const Resource &other) const
72 {
73  return !(operator==(other));
74 }
75 
76 Resource Resource::operator=(const Resource &rhs)
77 {
78  Resource res(rhs.d->id,
79  rhs.d->type,
80  rhs.d->name,
81  rhs.d->filename,
82  rhs.d->image);
83  return res;
84 }
85 
87 {
88  return d->type;
89 }
90 
92 {
93  return d->name;
94 }
95 
97 {
98  d->name = value;
99 }
100 
102 {
103  return d->filename;
104 }
105 
106 
108 {
109  return d->image;
110 }
111 
113 {
114  d->image = image;
115 }
116 
117 KoResourceSP Resource::resource() const
118 {
119  KoResourceSP res = KisResourceLocator::instance()->resourceForId(d->id);
120  Q_ASSERT(res);
121  return res;
122 }
123 
124 
125 
126 
127 
128 
QString filename() const
The filename of the resource, if present.
Definition: Resource.cpp:101
Type type(const QSqlDatabase &db)
A Resource represents a gradient, pattern, brush tip, brush preset, palette or workspace definition.
Definition: Resource.h:30
QString name() const
The user-visible name of the resource.
Definition: Resource.cpp:91
QString type() const
Return the type of this resource.
Definition: Resource.cpp:86
QImage image() const
An image that can be used to represent the resource in the user interface.
Definition: Resource.cpp:107
void setName(QString value)
setName changes the user-visible name of the current resource.
Definition: Resource.cpp:96
void setImage(QImage image)
Change the image for this resource.
Definition: Resource.cpp:112
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Dec 4 2022 04:12:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.