Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPresetShadowUpdater.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <KisViewManager.h>
10
12
13#include <kis_paintop_preset.h>
17
18#include <kis_image.h>
19#include <kis_spontaneous_job.h>
20
26
27
28class ShadowUpdatePresetJob : public QObject, public KisSpontaneousJob
29{
30 Q_OBJECT
31public:
32
33 ShadowUpdatePresetJob(KisPaintOpPresetSP preset, int sequenceNumber)
34 : m_preset(preset),
35 m_sequenceNumber(sequenceNumber)
36 {
37 }
38
39 void run() override {
41
42 KoResourceCacheInterfaceSP cacheInterface =
44
45 m_preset->regenerateResourceCache(cacheInterface);
46
47 Q_EMIT sigCacheGenerationFinished(m_sequenceNumber, cacheInterface);
48 }
49
50 bool overrides(const KisSpontaneousJob *_otherJob) override {
51 const ShadowUpdatePresetJob *otherJob =
52 dynamic_cast<const ShadowUpdatePresetJob*>(_otherJob);
53
54 return otherJob;
55 }
56
57 int levelOfDetail() const override {
58 return 0;
59 }
60
61 QString debugName() const override {
62 QString result;
63 QDebug dbg(&result);
64 dbg << "ShadowUpdatePresetJob" << m_preset;
65 return result;
66 }
67
68Q_SIGNALS:
69 void sigCacheGenerationFinished(int sequenceNumber,
70 KoResourceCacheInterfaceSP cacheInterface);
71private:
74};
75
94
96 : m_d(new Private)
97{
98 m_d->view = view;
99 connect(&m_d->updateStartCompressor, SIGNAL(timeout()),
100 this, SLOT(slotStartPresetPreparation()));
101}
102
106
108{
110 m_d->currentPreset = value.value<KisPaintOpPresetSP>();
111
112 m_d->proxyConnections.clear();
113
114 if (m_d->currentPreset) {
115 m_d->currentUpdateProxy = m_d->currentPreset->updateProxy();
116 m_d->proxyConnections.addConnection(
117 m_d->currentUpdateProxy, SIGNAL(sigSettingsChangedUncompressedEarlyWarning()),
118 this, SLOT(slotPresetChanged()));
120 } else {
121 m_d->view->canvasResourceProvider()->resourceManager()->
123 QVariant::fromValue(KoResourceCacheInterfaceSP()));
124 }
125 } else if (m_d->currentPreset) {
128
129 if (m_d->currentPreset->requiredCanvasResources().contains(key)) {
131 }
132 }
133}
134
136{
137 m_d->sequenceNumber++;
138 m_d->updateStartCompressor.start();
139
140 m_d->view->canvasResourceProvider()->resourceManager()->
142 QVariant::fromValue(KoResourceCacheInterfaceSP()));
143
144}
145
147{
148 if (m_d->currentPreset) {
149 KisImageSP image = m_d->view->image();
150 if (image) {
151 KisPaintOpPresetSP preset =
152 m_d->currentPreset->cloneWithResourcesSnapshot(
154 m_d->view->canvasResourceProvider()->resourceManager()->canvasResourcesInterface(),
155 nullptr);
156
157 ShadowUpdatePresetJob *job = new ShadowUpdatePresetJob(preset, m_d->sequenceNumber);
158
159 connect(job, SIGNAL(sigCacheGenerationFinished(int, KoResourceCacheInterfaceSP)),
161
162 image->addSpontaneousJob(job);
163 } else {
166
167 KoResourceCacheInterfaceSP cacheInterface =
169
170 m_d->currentPreset->regenerateResourceCache(cacheInterface);
171 slotCacheGenerationFinished(m_d->sequenceNumber, cacheInterface);
172 }
173 }
174}
175
177{
178 if (sequenceNumber == m_d->sequenceNumber) {
179 m_d->view->canvasResourceProvider()->resourceManager()->
181 QVariant::fromValue(cacheInterface));
182 }
183}
184
185#include "KisPresetShadowUpdater.moc"
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisResourcesInterfaceSP instance()
void addSpontaneousJob(KisSpontaneousJob *spontaneousJob)
void slotCacheGenerationFinished(int sequenceNumber, KoResourceCacheInterfaceSP cacheInterface)
void slotCanvasResourceChanged(int key, const QVariant &value)
KisPresetShadowUpdater(KisViewManager *view)
const QScopedPointer< Private > m_d
bool overrides(const KisSpontaneousJob *_otherJob) override
int levelOfDetail() const override
void sigCacheGenerationFinished(int sequenceNumber, KoResourceCacheInterfaceSP cacheInterface)
QString debugName() const override
ShadowUpdatePresetJob(KisPaintOpPresetSP preset, int sequenceNumber)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
QSharedPointer< KoResourceCacheInterface > KoResourceCacheInterfaceSP
QSharedPointer< T > toQShared(T *ptr)
@ CurrentPaintOpPresetCache
the cache associated with the currently active preset (this cache may be different per canvas if the ...
QPointer< KisPaintOpPresetUpdateProxy > currentUpdateProxy
KisSignalAutoConnectionsStore proxyConnections