Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDerivedResourceConverter Class Referenceabstract

#include <KoDerivedResourceConverter.h>

+ Inheritance diagram for KoDerivedResourceConverter:

Classes

struct  Private
 

Public Member Functions

int key () const
 
 KoDerivedResourceConverter (int key, int sourceKey)
 
virtual bool notifySourceChanged (const QVariant &sourceValue)
 
QVariant readFromSource (const QVariant &value)
 
int sourceKey () const
 
QVariant writeToSource (const QVariant &value, const QVariant &sourceValue, bool *changed)
 
virtual ~KoDerivedResourceConverter ()
 

Protected Member Functions

virtual QVariant fromSource (const QVariant &value)=0
 
virtual QVariant toSource (const QVariant &value, const QVariant &sourceValue)=0
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Defines the abstraction of a derived resource. It should be uploaded to the KoResourceManager during the loading phase. The manager will use it to convert values to/from the source resource.

"Derived" resources are the resources that do not exist themselves. Instead they are contained in some other resources and are updated synchronously with the parent resources as well.

E.g. we store opacity and composite op and opacity in the current paintop preset, which is also a resource. So composite op and opacity are "derived" resources.

The main goal of this class is to make our resources comply with a general Model-View-Controller architecture:

Model: KisPaintOpPreset. It stores opacity, composite op, eraser mode and other "global" properties.

Controller: KoCanvasResourceManager. It controls access to the resources and emits notification signals when they are changed.

View: KisPaintOpBox and other classes that show the resources on screen

Please take into account that according to the MVC design all the access to the model resources should be performed through the controller.

Definition at line 47 of file KoDerivedResourceConverter.h.

Constructor & Destructor Documentation

◆ KoDerivedResourceConverter()

KoDerivedResourceConverter::KoDerivedResourceConverter ( int key,
int sourceKey )
Parameters
keythe unique id of the resource defined by this converter
sourceKeythe id of the parent resource, i.e. where the values are really loaded/saved.

Definition at line 25 of file KoDerivedResourceConverter.cpp.

◆ ~KoDerivedResourceConverter()

KoDerivedResourceConverter::~KoDerivedResourceConverter ( )
virtual

Definition at line 30 of file KoDerivedResourceConverter.cpp.

31{
32}

Member Function Documentation

◆ fromSource()

◆ key()

int KoDerivedResourceConverter::key ( ) const

Definition at line 34 of file KoDerivedResourceConverter.cpp.

35{
36 return m_d->key;
37}

References m_d.

◆ notifySourceChanged()

bool KoDerivedResourceConverter::notifySourceChanged ( const QVariant & sourceValue)
virtual

Definition at line 44 of file KoDerivedResourceConverter.cpp.

45{
46 const QVariant newValue = fromSource(sourceValue);
47
48 const bool valueChanged = m_d->lastKnownValue != newValue || m_d->invisibleChangeHappened;
49 m_d->lastKnownValue = newValue;
50 m_d->invisibleChangeHappened = false;
51
52 return valueChanged;
53}
virtual QVariant fromSource(const QVariant &value)=0

References fromSource(), and m_d.

◆ readFromSource()

QVariant KoDerivedResourceConverter::readFromSource ( const QVariant & value)

Definition at line 55 of file KoDerivedResourceConverter.cpp.

56{
57 const QVariant result = fromSource(sourceValue);
58 m_d->invisibleChangeHappened |= result != m_d->lastKnownValue;
59 m_d->lastKnownValue = result;
60 return m_d->lastKnownValue;
61}

References fromSource(), and m_d.

◆ sourceKey()

int KoDerivedResourceConverter::sourceKey ( ) const

Definition at line 39 of file KoDerivedResourceConverter.cpp.

40{
41 return m_d->sourceKey;
42}

References m_d.

◆ toSource()

virtual QVariant KoDerivedResourceConverter::toSource ( const QVariant & value,
const QVariant & sourceValue )
protectedpure virtual

◆ writeToSource()

QVariant KoDerivedResourceConverter::writeToSource ( const QVariant & value,
const QVariant & sourceValue,
bool * changed )

Some resources may be immutable, that is, writing to them will not alter the value. Example: size property of the Shape Brush (always 1.0)

Definition at line 63 of file KoDerivedResourceConverter.cpp.

66{
67 QVariant newSourceValue = sourceValue;
68 const bool hasChanged = m_d->lastKnownValue != value || m_d->invisibleChangeHappened;
69 m_d->invisibleChangeHappened = false;
70
71 if (hasChanged || value != fromSource(sourceValue)) {
72 newSourceValue = toSource(value, sourceValue);
78 m_d->lastKnownValue = fromSource(newSourceValue);
79 }
80 if (changed) {
81 *changed = hasChanged;
82 }
83 return newSourceValue;
84}
float value(const T *src, size_t ch)
virtual QVariant toSource(const QVariant &value, const QVariant &sourceValue)=0

References fromSource(), m_d, toSource(), and value().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KoDerivedResourceConverter::m_d
private

Definition at line 85 of file KoDerivedResourceConverter.h.


The documentation for this class was generated from the following files: