Commit 82852109 authored by Thomas Zander's avatar Thomas Zander

* make the required methods on KisPaintop pure virtual so we can see if someone

forgets to implement it.
* Use the KoPluginLoader for the paintop registry; less code duplication.
* remove the check of parent->inherits("KisPaintOpRegistry") which is broken by
design as a plugin _will_ only get loaded one time by design.  And it
breaks since the koPluginLoader is the parent, not the registry.

svn path=/trunk/koffice/; revision=655535
parent 663bc3e2
......@@ -127,8 +127,8 @@ public:
* @param painter the painter used to draw
*/
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter) = 0;
virtual QString id() const { return "abstractpaintop"; }
virtual QString name() const { return i18n("Abstract PaintOp"); }
virtual QString id() const = 0;
virtual QString name() const = 0;
/**
* The filename of the pixmap we can use to represent this paintop in the ui.
......
......@@ -27,7 +27,9 @@
#include <kparts/componentfactory.h>
#include <kservicetypetrader.h>
#include "KoGenericRegistry.h"
#include <KoGenericRegistry.h>
#include <KoPluginLoader.h>
#include "kis_types.h"
#include "kis_paintop_registry.h"
#include "kis_paintop.h"
......@@ -40,33 +42,6 @@ KisPaintOpRegistry * KisPaintOpRegistry::m_singleton = 0;
KisPaintOpRegistry::KisPaintOpRegistry()
{
Q_ASSERT(KisPaintOpRegistry::m_singleton == 0);
KisPaintOpRegistry::m_singleton = this;
KService::List offers = KServiceTypeTrader::self()->query(QString::fromLatin1("Krita/Paintop"),
QString::fromLatin1("(Type == 'Service') and "
"([X-Krita-Version] == 3)"));
KService::List::ConstIterator iter;
for(iter = offers.begin(); iter != offers.end(); ++iter)
{
KService::Ptr service = *iter;
int errCode = 0;
KParts::Plugin* plugin =
KService::createInstance<KParts::Plugin> ( service, this, QStringList(), &errCode);
if ( plugin )
kDebug(41006) << "found plugin " << service->property("Name").toString() << "\n";
else {
kDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
if( errCode == KLibLoader::ErrNoLibrary)
{
kWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
}
}
}
}
KisPaintOpRegistry::~KisPaintOpRegistry()
......@@ -78,6 +53,7 @@ KisPaintOpRegistry* KisPaintOpRegistry::instance()
if(KisPaintOpRegistry::m_singleton == 0)
{
KisPaintOpRegistry::m_singleton = new KisPaintOpRegistry();
KoPluginLoader::instance()->load("Krita/Paintop", "(Type == 'Service') and ([X-Krita-Version] == 3)");
Q_CHECK_PTR(KisPaintOpRegistry::m_singleton);
}
return KisPaintOpRegistry::m_singleton;
......@@ -90,18 +66,14 @@ KisPaintOp * KisPaintOpRegistry::paintOp(const KoID & id, const KisPaintOpSettin
KisPaintOp * KisPaintOpRegistry::paintOp(const QString & id, const KisPaintOpSettings * settings, KisPainter * painter) const
{
// return paintOp(KoID(id, ""), settings, painter);
if (painter == 0) {
kWarning() << " KisPaintOpRegistry::paintOp painter is null";
return 0;
}
KisPaintOpFactorySP f = value(id);
if (f) {
if (f)
return f->createOp(settings, painter);
}
else {
return 0;
}
return 0;
}
KisPaintOpSettings * KisPaintOpRegistry::settings(const KoID& id, QWidget * parent, const KoInputDevice& inputDevice) const
......
......@@ -43,7 +43,8 @@ public:
virtual ~KisCPaintOpFactory();
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("paintCPaint", i18n("Chinese Brush")); }
virtual QString id() const { return "paintCPaint"; }
virtual QString name() const { return i18n("Chinese Brush"); }
virtual KisPaintOpSettings *settings(QWidget * parent, const KoInputDevice& inputDevice);
private:
......
......@@ -45,19 +45,12 @@ DefaultPaintOpsPlugin::DefaultPaintOpsPlugin(QObject *parent, const QStringList
{
setComponentData(DefaultPaintOpsPluginFactory::componentData());
// This is not a gui plugin; only load it when the doc is created.
if ( parent->inherits("KisPaintOpRegistry") )
{
KisPaintOpRegistry * r = dynamic_cast<KisPaintOpRegistry*>(parent);
// Add hard-coded paint ops. Plugin paintops will add
// themselves in the plugin initialization code.
r->add (KisPaintOpFactorySP( new KisAirbrushOpFactory ));
r->add (KisPaintOpFactorySP( new KisBrushOpFactory ));
r->add (KisPaintOpFactorySP( new KisDuplicateOpFactory ));
r->add (KisPaintOpFactorySP( new KisEraseOpFactory ));
r->add (KisPaintOpFactorySP( new KisPenOpFactory ));
}
KisPaintOpRegistry *r = KisPaintOpRegistry::instance();
r->add (KisPaintOpFactorySP( new KisAirbrushOpFactory ));
r->add (KisPaintOpFactorySP( new KisBrushOpFactory ));
r->add (KisPaintOpFactorySP( new KisDuplicateOpFactory ));
r->add (KisPaintOpFactorySP( new KisEraseOpFactory ));
r->add (KisPaintOpFactorySP( new KisPenOpFactory ));
}
DefaultPaintOpsPlugin::~DefaultPaintOpsPlugin()
......
......@@ -35,7 +35,8 @@ public:
virtual ~KisAirbrushOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("airbrush", i18n("Pixel Airbrush")); }
virtual QString id() const { return "airbrush"; }
virtual QString name() const { return i18n("Pixel Airbrush"); }
virtual QString pixmap() { return "airbrush.png"; }
};
......
......@@ -40,7 +40,8 @@ public:
virtual ~KisBrushOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("paintbrush", i18n("Pixel Brush")); }
virtual QString id() const { return "paintbrush"; }
virtual QString name() const { return i18n("Pixel Brush"); }
virtual QString pixmap() { return "paintbrush.png"; }
virtual KisPaintOpSettings *settings(QWidget * parent, const KoInputDevice& inputDevice);
};
......
......@@ -36,7 +36,8 @@ public:
virtual ~KisConvolveOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("convolve", i18n("Convolve")); }
virtual QString id() const { return "convolve"; }
virtual QString name() const { return i18n("Convolve"); }
};
......
......@@ -35,7 +35,8 @@ public:
virtual ~KisDuplicateOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("duplicate", i18n("Duplicate")); }
virtual QString id() const { return "duplicate"; }
virtual QString name() const { return i18n("Duplicate"); }
virtual bool userVisible(KoColorSpace *) { return false; }
};
......
......@@ -35,7 +35,8 @@ public:
virtual ~KisEraseOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("eraser", i18n("Pixel Eraser")); }
virtual QString id() const { return "eraser"; }
virtual QString name() const { return i18n("Pixel Eraser"); }
virtual QString pixmap() { return "eraser.png"; }
};
......
......@@ -37,7 +37,8 @@ public:
virtual ~KisPenOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id(){ return KoID("pen", i18n("Pixel Pencil")); }
virtual QString id() const { return "pen"; }
virtual QString name() const { return i18n("Pixel Pencil"); }
virtual QString pixmap() { return "pencil.png"; }
};
......
......@@ -34,7 +34,8 @@ class KisDynamicOpFactory : public KisPaintOpFactory {
virtual ~KisDynamicOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("dynamicbrush", i18n("Dynamic Brush")); }
virtual QString id() const { return "dynamicbrush"; }
virtual QString name() const{ return i18n("Dynamic Brush"); }
virtual QString pixmap() { return "dynamicbrush.png"; }
virtual KisPaintOpSettings *settings(QWidget * parent, const KoInputDevice& inputDevice);
private:
......
......@@ -34,7 +34,8 @@ public:
virtual ~KisSmearyOpFactory() {}
virtual KisPaintOp * createOp(const KisPaintOpSettings *settings, KisPainter * painter);
virtual KoID id() { return KoID("paintSmeary", i18n("Smeary Brush")); }
virtual QString id() const { return "paintSmeary"; }
virtual QString name() const { return i18n("Smeary Brush"); }
virtual bool userVisible(KoColorSpace * ) { return false; }
virtual QString pixmap() { return ""; }
......
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