Commit e730f9df authored by Boudewijn Rempt's avatar Boudewijn Rempt

Remove paintop factories that cannot produce settings on startup

BUG:287453 must be caused by some paintop factory that cannot create a
settings object. Be much stricter about that and check whether factories
can create a default settings object on startup.
parent 21e8abe3
......@@ -39,6 +39,10 @@
#include "kis_image.h"
struct KisPaintOpPreset::Private {
Private()
: settings(0)
{}
KisPaintOpSettingsSP settings;
QImage image;
};
......@@ -48,7 +52,6 @@ KisPaintOpPreset::KisPaintOpPreset()
: KoResource(QString())
, m_d(new Private)
{
m_d->settings = 0;
}
KisPaintOpPreset::KisPaintOpPreset(const QString & fileName)
......
......@@ -30,6 +30,7 @@
#include <KoGenericRegistry.h>
#include <KoPluginLoader.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoCompositeOp.h>
#include <KoID.h>
......@@ -60,8 +61,23 @@ KisPaintOpRegistry* KisPaintOpRegistry::instance()
K_GLOBAL_STATIC(KisPaintOpRegistry, s_instance);
if (!s_instance.exists()) {
KoPluginLoader::instance()->load("Krita/Paintop", "(Type == 'Service') and ([X-Krita-Version] == 5)");
KisImageSP img = new KisImage(0, 0, 0, 0, 0, KoColorSpaceRegistry::instance()->alpha8());
QStringList toBeRemoved;
foreach(const QString id, s_instance->keys()) {
s_instance->get(id)->processAfterLoading();
KisPaintOpFactory *factory = s_instance->get(id);
if (!factory->settings(img)) {
toBeRemoved << id;
}
else {
factory->processAfterLoading();
}
}
kWarning() << "The following brush engines do not provide a default brush and are removed" << toBeRemoved;
foreach(const QString id, toBeRemoved) {
s_instance->remove(id);
}
}
return s_instance;
......@@ -103,7 +119,7 @@ KisPaintOp * KisPaintOpRegistry::paintOp(const KisPaintOpPresetSP preset, KisPai
KisPaintOpSettingsSP KisPaintOpRegistry::settings(const KoID& id, KisImageWSP image) const
{
KisPaintOpFactory* f = value(id.id());
KisPaintOpFactory *f = value(id.id());
Q_ASSERT(f);
if (f) {
KisPaintOpSettingsSP settings = f->settings(image);
......@@ -120,6 +136,10 @@ KisPaintOpPresetSP KisPaintOpRegistry::defaultPreset(const KoID& id, KisImageWSP
KisPaintOpSettingsSP s = settings(id, image);
if (s.isNull()) {
return 0;
}
preset->setSettings(s);
preset->setPaintOp(id);
Q_ASSERT(!preset->paintOp().id().isEmpty());
......
......@@ -366,20 +366,25 @@ KoID KisPaintopBox::defaultPaintOp()
KisPaintOpPresetSP KisPaintopBox::defaultPreset(const KoID& paintOp)
{
QString defaultName = paintOp.id() + ".kpp";
QString path = KGlobal::mainComponent().dirs()->findResource("kis_defaultpresets", defaultName);
QString path = KGlobal::mainComponent().dirs()->findResource("kis_defaultpresets", defaultName);
KisPaintOpPresetSP preset = new KisPaintOpPreset(path);
if(!preset->load())
return KisPaintOpRegistry::instance()->defaultPreset(paintOp, m_view->image());
if (!preset->load()) {
preset = KisPaintOpRegistry::instance()->defaultPreset(paintOp, m_view->image());
}
Q_ASSERT(preset);
Q_ASSERT(preset->valid());
return preset;
}
KisPaintOpPresetSP KisPaintopBox::activePreset(const KoID& paintOp)
{
if(m_paintOpPresetMap[paintOp] == 0)
if (m_paintOpPresetMap[paintOp] == 0) {
m_paintOpPresetMap[paintOp] = defaultPreset(paintOp);
}
return m_paintOpPresetMap[paintOp];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment