Commit c1fb1319 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Make all KisSerializeConfiguration objects shared pointers

This is a huge and dangerous refactoring: I think we will find
double delete crashes for some time to come, though starting krita,
painting, filtering and closing work without problems. We were
leaking these configuration objects all over the place, though, since
there was no ownership defined.
parent a6f04886
......@@ -40,12 +40,12 @@
void KisBContrastBenchmark::initTestCase()
{
m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();
m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();
m_device = new KisPaintDevice(m_colorSpace);
m_color = KoColor(m_colorSpace);
srand(31524744);
int r,g,b;
KisSequentialIterator it(m_device, QRect(0, 0, GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT));
......@@ -53,11 +53,11 @@ void KisBContrastBenchmark::initTestCase()
r = rand() % 255;
g = rand() % 255;
b = rand() % 255;
m_color.fromQColor(QColor(r,g,b));
memcpy(it.rawData(), m_color.data(), m_colorSpace->pixelSize());
} while (it.nextPixel());
}
void KisBContrastBenchmark::cleanupTestCase()
......@@ -68,7 +68,7 @@ void KisBContrastBenchmark::cleanupTestCase()
void KisBContrastBenchmark::benchmarkFilter()
{
KisFilterSP filter = KisFilterRegistry::instance()->value("brightnesscontrast");
KisFilterConfiguration * kfc = filter->defaultConfiguration(m_device);
KisFilterConfigurationSP kfc = filter->defaultConfiguration(m_device);
// Get the predefined configuration from a file
QFile file(QString(FILES_DATA_DIR) + QDir::separator() + filter->id() + ".cfg");
......
......@@ -66,7 +66,7 @@ void KisBlurBenchmark::cleanupTestCase()
void KisBlurBenchmark::benchmarkFilter()
{
KisFilterSP filter = KisFilterRegistry::instance()->value("blur");
KisFilterConfiguration * kfc = filter->defaultConfiguration(m_device);
KisFilterConfigurationSP kfc = filter->defaultConfiguration(m_device);
// Get the predefined configuration from a file
QFile file(QString(FILES_DATA_DIR) + QDir::separator() + filter->id() + ".cfg");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
......
......@@ -47,7 +47,7 @@ private:
KisSelectionSP m_selection;
KisPaintDeviceSP m_device;
KisFilterSP m_filter;
KisFilterConfiguration *m_configuration;
KisFilterConfigurationSP m_configuration;
};
#endif
......@@ -67,7 +67,7 @@ void KisLevelFilterBenchmark::cleanupTestCase()
void KisLevelFilterBenchmark::benchmarkFilter()
{
KisFilterSP filter = KisFilterRegistry::instance()->value("levels");
//KisFilterConfiguration * kfc = filter->defaultConfiguration(m_device);
//KisFilterConfigurationSP kfc = filter->defaultConfiguration(m_device);
KisColorTransformationConfiguration * kfc= new KisColorTransformationConfiguration("levels", 1);
......
......@@ -24,7 +24,7 @@ KisLockedProperties::KisLockedProperties()
m_lockedProperties = new KisPropertiesConfiguration();
}
KisLockedProperties::KisLockedProperties(KisPropertiesConfiguration *p)
KisLockedProperties::KisLockedProperties(KisPropertiesConfigurationSP p)
{
m_lockedProperties = new KisPropertiesConfiguration();
QMap<QString, QVariant>::Iterator i;
......@@ -35,9 +35,9 @@ KisLockedProperties::KisLockedProperties(KisPropertiesConfiguration *p)
KisLockedProperties::~KisLockedProperties()
{
delete m_lockedProperties;
}
void KisLockedProperties::addToLockedProperties(KisPropertiesConfiguration *p)
void KisLockedProperties::addToLockedProperties(KisPropertiesConfigurationSP p)
{
QMapIterator<QString, QVariant> i(p->getProperties());
while (i.hasNext()) {
......@@ -45,9 +45,10 @@ void KisLockedProperties::addToLockedProperties(KisPropertiesConfiguration *p)
m_lockedProperties->setProperty(i.key(), QVariant(i.value()));
}
}
void KisLockedProperties::removeFromLockedProperties(KisPropertiesConfiguration *p)
void KisLockedProperties::removeFromLockedProperties(KisPropertiesConfigurationSP p)
{
KisPropertiesConfiguration *temp = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP temp = new KisPropertiesConfiguration();
QMapIterator<QString, QVariant> i(m_lockedProperties->getProperties());
while (i.hasNext()) {
i.next();
......@@ -63,12 +64,13 @@ void KisLockedProperties::removeFromLockedProperties(KisPropertiesConfiguration
}
}
bool KisLockedProperties::hasProperty(const QString &p)
{
return m_lockedProperties->hasProperty(p);
}
KisPropertiesConfiguration *KisLockedProperties::lockedProperties()
KisPropertiesConfigurationSP KisLockedProperties::lockedProperties()
{
return m_lockedProperties;
}
......
......@@ -32,25 +32,21 @@ class KisLockedProperties
{
public:
KisLockedProperties();
KisLockedProperties(KisPropertiesConfiguration *p);
KisLockedProperties(KisPropertiesConfigurationSP p);
~KisLockedProperties();
/**Whenever any setting is made locked**/
void addToLockedProperties(KisPropertiesConfiguration *p);
void addToLockedProperties(KisPropertiesConfigurationSP p);
/**Whenever any property is unlocked**/
void removeFromLockedProperties(KisPropertiesConfiguration *p);
void removeFromLockedProperties(KisPropertiesConfigurationSP p);
bool hasProperty(const QString &p);
KisPropertiesConfiguration *lockedProperties();
KisPropertiesConfigurationSP lockedProperties();
private:
KisPropertiesConfiguration* m_lockedProperties;
KisPropertiesConfigurationSP m_lockedProperties;
};
......
......@@ -33,16 +33,16 @@ KisLockedPropertiesProxy::KisLockedPropertiesProxy(KisLockedProperties* p)
m_lockedProperties = p;
}
KisLockedPropertiesProxy::KisLockedPropertiesProxy(const KisPropertiesConfiguration *p, KisLockedProperties *l)
KisLockedPropertiesProxy::KisLockedPropertiesProxy(KisPropertiesConfigurationSP p, KisLockedProperties *l)
{
m_lockedProperties = l;
m_parent = p;
m_lockedProperties = l;
}
QVariant KisLockedPropertiesProxy::getProperty(const QString &name) const
{
KisPropertiesConfiguration* temp = const_cast<KisPropertiesConfiguration*>(m_parent);
KisPaintOpSettings* t = dynamic_cast<KisPaintOpSettings*>(temp);
KisPropertiesConfigurationSP temp = KisPropertiesConfigurationSP(m_parent);
KisPaintOpSettingsSP t = dynamic_cast<KisPaintOpSettings*>(temp.data());
if (t->preset()) {
// restores the dirty state on returns automagically
......@@ -59,7 +59,7 @@ QVariant KisLockedPropertiesProxy::getProperty(const QString &name) const
return m_lockedProperties->lockedProperties()->getProperty(name);
} else {
if (m_parent->hasProperty(name + "_previous")) {
KisPropertiesConfiguration* temp = const_cast<KisPropertiesConfiguration*>(m_parent);
KisPropertiesConfigurationSP temp = m_parent;
temp->setProperty(name, m_parent->getProperty(name + "_previous"));
temp->removeProperty(name + "_previous");
}
......@@ -71,8 +71,8 @@ QVariant KisLockedPropertiesProxy::getProperty(const QString &name) const
void KisLockedPropertiesProxy::setProperty(const QString & name, const QVariant & value)
{
KisPropertiesConfiguration* temp = const_cast<KisPropertiesConfiguration*>(m_parent);
KisPaintOpSettings* t = dynamic_cast<KisPaintOpSettings*>(temp);
KisPropertiesConfigurationSP temp = m_parent;
KisPaintOpSettingsSP t = dynamic_cast<KisPaintOpSettings*>(temp.data());
if (t->preset()) {
// restores the dirty state on returns automagically
KisPaintOpPreset::DirtyStateSaver dirtyStateSaver(t->preset().data());
......@@ -87,6 +87,7 @@ void KisLockedPropertiesProxy::setProperty(const QString & name, const QVariant
return;
}
}
Q_UNUSED(dirtyStateSaver);
}
t->setProperty(name, value);
}
......
......@@ -21,7 +21,6 @@
#include "kis_properties_configuration.h"
/**
* This class acts as a proxy for all transfers between KisLockedPropertiesServer
* and KisPaintOpSettings while using setConfiguration and writeConfiguration
......@@ -41,15 +40,19 @@ class KisLockedPropertiesProxy: public KisPropertiesConfiguration
{
public:
KisLockedPropertiesProxy() ;
KisLockedPropertiesProxy(KisLockedProperties* p);
KisLockedPropertiesProxy(const KisPropertiesConfiguration *, KisLockedProperties *);
KisLockedPropertiesProxy(KisLockedProperties *p);
KisLockedPropertiesProxy(KisPropertiesConfigurationSP , KisLockedProperties *);
using KisPropertiesConfiguration::getProperty;
QVariant getProperty(const QString &name) const;
using KisPropertiesConfiguration::setProperty;
void setProperty(const QString & name, const QVariant & value);
private:
Q_DISABLE_COPY(KisLockedPropertiesProxy)
KisLockedProperties *m_lockedProperties;
const KisPropertiesConfiguration *m_parent;
KisPropertiesConfigurationSP m_parent;
};
typedef KisSharedPtr<KisLockedPropertiesProxy> KisLockedPropertiesProxySP;
#endif // KIS_LOCKED_PROPERTIES_PROXY_H
......@@ -36,11 +36,11 @@ KisLockedPropertiesServer::~KisLockedPropertiesServer()
delete m_lockedProperties;
}
KisLockedPropertiesProxy* KisLockedPropertiesServer::createLockedPropertiesProxy(const KisPropertiesConfiguration* config)
KisLockedPropertiesProxySP KisLockedPropertiesServer::createLockedPropertiesProxy(const KisPropertiesConfigurationSP config)
{
KisLockedPropertiesProxy* m = new KisLockedPropertiesProxy(config, lockedProperties());
return m;
return new KisLockedPropertiesProxy(config, lockedProperties());
}
KisLockedPropertiesServer* KisLockedPropertiesServer::instance()
{
if (s_instance) {
......@@ -49,18 +49,22 @@ KisLockedPropertiesServer* KisLockedPropertiesServer::instance()
return NULL;
}
KisLockedProperties* KisLockedPropertiesServer::lockedProperties()
{
return m_lockedProperties;
}
void KisLockedPropertiesServer::addToLockedProperties(KisPropertiesConfiguration *p)
void KisLockedPropertiesServer::addToLockedProperties(KisPropertiesConfigurationSP p)
{
lockedProperties()->addToLockedProperties(p);
}
void KisLockedPropertiesServer::removeFromLockedProperties(KisPropertiesConfiguration *p)
void KisLockedPropertiesServer::removeFromLockedProperties(KisPropertiesConfigurationSP p)
{
lockedProperties()->removeFromLockedProperties(p);
}
void KisLockedPropertiesServer::setPropertiesFromLocked(bool value)
{
m_propertiesFromLocked = value;
......
......@@ -40,11 +40,11 @@ public:
static KisLockedPropertiesServer* instance();
KisLockedProperties* lockedProperties();
void addToLockedProperties(KisPropertiesConfiguration *p);
void removeFromLockedProperties(KisPropertiesConfiguration *p);
void addToLockedProperties(KisPropertiesConfigurationSP p);
void removeFromLockedProperties(KisPropertiesConfigurationSP p);
void setPropertiesFromLocked(bool value);
bool propertiesFromLocked();
KisLockedPropertiesProxy* createLockedPropertiesProxy(const KisPropertiesConfiguration*);
KisLockedPropertiesProxySP createLockedPropertiesProxy(const KisPropertiesConfigurationSP);
bool hasProperty(const QString &p);
private:
......
......@@ -30,11 +30,11 @@ KisPaintOpConfigWidget::KisPaintOpConfigWidget(QWidget * parent, Qt::WFlags f)
KisPaintOpConfigWidget::~KisPaintOpConfigWidget() {
}
void KisPaintOpConfigWidget::writeConfiguration(KisPropertiesConfiguration *config) const {
void KisPaintOpConfigWidget::writeConfiguration(KisPropertiesConfigurationSP config) const {
KisPaintOpSettings::setLodUserAllowed(config, m_userAllowedLod);
}
void KisPaintOpConfigWidget::setConfiguration(const KisPropertiesConfiguration * config) {
void KisPaintOpConfigWidget::setConfiguration(const KisPropertiesConfigurationSP config) {
m_userAllowedLod = KisPaintOpSettings::isLodUserAllowed(config);
emit sigUserChangedLodAvailability(m_userAllowedLod);
}
......
......@@ -24,6 +24,7 @@
#include "kis_config_widget.h"
#include "kis_image.h"
#include <kis_debug.h>
#include <kis_properties_configuration.h>
class KisPaintopLodLimitations;
......@@ -42,8 +43,8 @@ public:
* Write the settings in this widget to the given properties
* configuration, which is cleared first.
*/
virtual void writeConfiguration(KisPropertiesConfiguration *config) const;
virtual void setConfiguration(const KisPropertiesConfiguration * config);
virtual void writeConfiguration(KisPropertiesConfigurationSP config) const;
virtual void setConfiguration(const KisPropertiesConfigurationSP config);
virtual KisPaintopLodLimitations lodLimitations() const = 0;
......
......@@ -40,13 +40,14 @@
#include<kis_types.h>
struct Q_DECL_HIDDEN KisPaintOpSettings::Private {
Private() : disableDirtyNotifications(false) {}
Private()
: disableDirtyNotifications(false)
{}
QPointer<KisPaintOpConfigWidget> settingsWidget;
QString modelName;
KisPaintOpPresetWSP preset;
bool disableDirtyNotifications;
class DirtyNotificationsLocker {
......@@ -80,6 +81,15 @@ KisPaintOpSettings::~KisPaintOpSettings()
{
}
KisPaintOpSettings::KisPaintOpSettings(const KisPaintOpSettings &rhs)
: KisPropertiesConfiguration(rhs)
, d(new Private)
{
d->settingsWidget = 0;
d->preset = rhs.preset();
d->modelName = rhs.modelName();
}
void KisPaintOpSettings::setOptionsWidget(KisPaintOpConfigWidget* widget)
{
d->settingsWidget = widget;
......@@ -264,12 +274,12 @@ QString KisPaintOpSettings::indirectPaintingCompositeOp() const
return COMPOSITE_ALPHA_DARKEN;
}
QPainterPath KisPaintOpSettings::brushOutline(const KisPaintInformation &info, OutlineMode mode) const
QPainterPath KisPaintOpSettings::brushOutline(const KisPaintInformation &info, OutlineMode mode)
{
QPainterPath path;
if (mode == CursorIsOutline || mode == CursorIsCircleOutline || mode == CursorTiltOutline) {
path = ellipseOutline(10, 10, 1.0, 0);
if (mode == CursorTiltOutline) {
QPainterPath tiltLine;
QLineF tiltAngle(QPointF(0.0,0.0), QPointF(0.0,3.0));
......@@ -340,12 +350,12 @@ void KisPaintOpSettings::onPropertyChanged()
}
bool KisPaintOpSettings::isLodUserAllowed(const KisPropertiesConfiguration *config)
bool KisPaintOpSettings::isLodUserAllowed(const KisPropertiesConfigurationSP config)
{
return config->getBool("lodUserAllowed", true);
}
void KisPaintOpSettings::setLodUserAllowed(KisPropertiesConfiguration *config, bool value)
void KisPaintOpSettings::setLodUserAllowed(KisPropertiesConfigurationSP config, bool value)
{
config->setProperty("lodUserAllowed", value);
}
......@@ -25,7 +25,6 @@
#include <QImage>
#include <QScopedPointer>
#include "kis_shared.h"
#include "kis_properties_configuration.h"
#include <brushengine/kis_paint_information.h>
......@@ -45,14 +44,14 @@ class KisPaintOpConfigWidget;
* property of KisPaintOpPreset. Whenever the settings are changed/modified from the original -- the preset is
* set to dirty.
*/
class KRITAIMAGE_EXPORT KisPaintOpSettings : public KisPropertiesConfiguration, public KisShared
class KRITAIMAGE_EXPORT KisPaintOpSettings : public KisPropertiesConfiguration
{
public:
KisPaintOpSettings();
virtual ~KisPaintOpSettings();
KisPaintOpSettings(const KisPaintOpSettings &rhs);
/**
*
......@@ -139,7 +138,7 @@ public:
* Outline mode has to be passed to the paintop which builds the outline as some paintops have to paint outline
* always like clone paintop indicating the duplicate position
*/
virtual QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode) const;
virtual QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode);
/**
* Useful for simple elliptical brush outline.
......@@ -242,8 +241,8 @@ public:
*/
void setProperty(const QString & name, const QVariant & value);
static bool isLodUserAllowed(const KisPropertiesConfiguration *config);
static void setLodUserAllowed(KisPropertiesConfiguration *config, bool value);
static bool isLodUserAllowed(const KisPropertiesConfigurationSP config);
static void setLodUserAllowed(KisPropertiesConfigurationSP config, bool value);
protected:
/**
......@@ -262,4 +261,6 @@ private:
const QScopedPointer<Private> d;
};
typedef KisSharedPtr<KisPaintOpSettings> KisPaintOpSettingsSP;
#endif
......@@ -66,9 +66,9 @@ public:
}
private:
KisFilterConfiguration* createConfiguration(const QString &name, const QString &data)
KisFilterConfigurationSP createConfiguration(const QString &name, const QString &data)
{
KisFilterConfiguration *config;
KisFilterConfigurationSP config;
if (m_useGeneratorRegistry) {
KisGeneratorSP generator = KisGeneratorRegistry::instance()->value(name);
......
......@@ -32,13 +32,20 @@ struct Q_DECL_HIDDEN KisColorTransformationConfiguration::Private {
qDeleteAll(colorTransformation);
}
// XXX: Threadlocal storage!!!
QMap<QThread*, KoColorTransformation*> colorTransformation;
QMutex mutex;
};
KisColorTransformationConfiguration::KisColorTransformationConfiguration(const QString & name, qint32 version)
: KisFilterConfiguration(name, version)
, d(new Private())
: KisFilterConfiguration(name, version)
, d(new Private())
{
}
KisColorTransformationConfiguration::KisColorTransformationConfiguration(const KisColorTransformationConfiguration &rhs)
: KisFilterConfiguration(rhs)
, d(new Private())
{
}
......@@ -47,12 +54,13 @@ KisColorTransformationConfiguration::~KisColorTransformationConfiguration()
delete d;
}
KoColorTransformation* KisColorTransformationConfiguration::colorTransformation(const KoColorSpace *cs, const KisColorTransformationFilter * filter) const
KoColorTransformation* KisColorTransformationConfiguration::colorTransformation(const KoColorSpace *cs, const KisColorTransformationFilter *filter) const
{
QMutexLocker locker(&d->mutex);
KoColorTransformation *transformation = d->colorTransformation.value(QThread::currentThread(), 0);
if (!transformation) {
transformation = filter->createTransformation(cs, this);
KisFilterConfigurationSP config(const_cast<KisColorTransformationConfiguration*>(this));
transformation = filter->createTransformation(cs, config);
d->colorTransformation.insert(QThread::currentThread(), transformation);
}
locker.unlock();
......
......@@ -18,19 +18,24 @@
#ifndef _KIS_COLOR_TRANSFORMATION_CONFIGURATION_H_
#define _KIS_COLOR_TRANSFORMATION_CONFIGURATION_H_
#include "filter/kis_filter_configuration.h"
#include "kis_filter_configuration.h"