Commit 586aa715 authored by Thomas Zander's avatar Thomas Zander

Cleanups and fixes

svn path=/trunk/koffice/; revision=550813
parent e2f860c2
......@@ -24,6 +24,8 @@
#include "KoCommand.h"
#include "KoCanvasBase.h"
#include <kdebug.h>
KoCreateShapeStrategy::KoCreateShapeStrategy( KoCreateShapesTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
: KoShapeRubberSelectStrategy(tool, canvas, clicked)
, m_tool(tool)
......@@ -33,7 +35,11 @@ KoCreateShapeStrategy::KoCreateShapeStrategy( KoCreateShapesTool *tool, KoCanvas
KCommand* KoCreateShapeStrategy::createCommand() {
KoShapeFactory *factory = KoShapeRegistry::instance()->get(
static_cast<KoCreateShapesTool*>(m_parent)->shapeId());
Q_ASSERT(factory);
if(! factory) {
kWarning(30001) << "Application requested a shape that is not registred '" <<
static_cast<KoCreateShapesTool*>(m_parent)->shapeId() << "'" << endl;
return 0;
}
KoShape *shape = factory->createDefaultShape();
QRectF rect = selectRect();
shape->setPosition(rect.topLeft());
......
......@@ -72,18 +72,18 @@ public:
* Each shape-type has an Id; as found in KoShapeFactory::id().id(), to choose which
* shape this tool should actually create; set the id before the user starts to
* create the new shape.
* @param id the Id part from a KoID of the to be generated shape
* @param id the SHAPEID of the to be generated shape
*/
void setShapeId(QString id) { m_shapeId = id; }
void setShapeId(int id) { m_shapeId = id; }
/**
* return the shape Id that is to be created.
* @return the shape Id that is to be created.
*/
const QString& shapeId() const { return m_shapeId; }
int shapeId() const { return m_shapeId; }
private:
KoShapeControllerBase *m_shapeController;
QString m_shapeId;
int m_shapeId;
};
#endif
......@@ -30,6 +30,7 @@ class KoPathShapeFactory : public KoShapeFactory
public:
/// constructor
KoPathShapeFactory();
~KoPathShapeFactory() {}
KoShape * createDefaultShape();
KoShape * createShape(KoProperties * params) const;
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const;
......
......@@ -29,6 +29,7 @@ class KoRectangleShapeFactory : public KoShapeFactory
public:
/// constructor
KoRectangleShapeFactory();
~KoRectangleShapeFactory() {}
KoShape * createDefaultShape();
KoShape * createShape(KoProperties * params) const;
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const;
......
......@@ -18,14 +18,6 @@
*/
#include "KoShapeFactory.h"
// #include <QString>
// #include <QWidget>
// #include <QPixmap>
// #include <QList>
//
// #include <KoProperties.h>
// #include <KoID.h>
// #include "KoShape.h"
KoShapeFactory::KoShapeFactory(int id, const QString name)
: m_id(id)
......@@ -64,3 +56,5 @@ void KoShapeFactory::setIcon(const QPixmap & icon) {
int KoShapeFactory::shapeId() const {
return m_id;
}
#include "KoShapeFactory.moc"
......@@ -25,9 +25,10 @@
#include <QPixmap>
#include <QList>
//#include <KoProperties.h>
#include <KoID.h>
#include <koffice_export.h>
class KoShape;
class KoProperties;
......@@ -36,7 +37,7 @@ class KoProperties;
* particular variant of a shape object, together with a name, a description
* and a pixmap for use in the user interface.
*/
struct KoShapeTemplate {
struct FLAKE_EXPORT KoShapeTemplate {
QString name;
QString description;
......@@ -48,7 +49,8 @@ struct KoShapeTemplate {
/**
* The shape factory can create a KoShape without needing a tool or a direct new().
*/
class KoShapeFactory {
class FLAKE_EXPORT KoShapeFactory : public QObject {
Q_OBJECT
public:
/// Factory for shapes
......
......@@ -40,30 +40,37 @@ KoShapeRegistry::KoShapeRegistry()
KService::List offers = KServiceTypeTrader::self()->query(QString::fromLatin1("KOffice/Shape"),
QString::fromLatin1("(Type == 'Service') and "
"([X-Flake-Version] == 1)"));
kDebug(30008) << "KoShapeRegistry searching for plugins, " << offers.count() << " found\n";
KService::List::ConstIterator iter;
for(iter = offers.begin(); iter != offers.end(); ++iter)
{
KService::Ptr service = *iter;
foreach(KService::Ptr service, offers) {
int errCode = 0;
// Create a plugin: the plugin will register the necessary
// factory classes with us.
KParts::Plugin* plugin =
KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, QStringList(), &errCode);
if ( plugin )
kDebug() << "found plugin " << service->property("Name").toString() << "\n";
KoShapeFactory* plugin =
KParts::ComponentFactory::createInstanceFromService<KoShapeFactory>(
service, this, QStringList(), &errCode );
if ( plugin ) {
kDebug(30008) <<"found plugin '"<< service->property("Name").toString() << "'\n";
add(plugin);
}
else {
kDebug() << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
if( errCode == KParts::ComponentFactory::ErrNoLibrary)
{
kWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
QString err;
switch (errCode) {
case KParts::ComponentFactory::ErrNoServiceFound:
err = "No Service Found"; break;
case KParts::ComponentFactory::ErrServiceProvidesNoLibrary:
err = "Service provides no library"; break;
case KParts::ComponentFactory::ErrNoLibrary:
err = KLibLoader::self()->lastErrorMessage(); break;
case KParts::ComponentFactory::ErrNoFactory:
err = "No factory found"; break;
case KParts::ComponentFactory::ErrNoComponent:
err = "No Component"; break;
default:
err = "Unknown error";
}
kWarning(30008) <<"loading plugin '" << service->property("Name").toString() <<
"' failed, "<< err << "("<< errCode << ")\n";
}
}
// Also add our hard-coded dumb test shapes
add( new KoRectangleShapeFactory() );
add( new KoPathShapeFactory() );
......
......@@ -51,8 +51,6 @@ private:
private:
static KoShapeRegistry *m_singleton;
};
#endif // FLAKESHAPES_H
......@@ -96,6 +96,15 @@ public:
return p;
}
/**
* Get a single entry based on a integer based id.
* @param id the integer ID as used by Tools and Shapes.
*/
T get(int id) const
{
return get(KoID(QString::number(id), ""));
}
/**
* Get a single entry based on the identifying part of KoID, not the
* the descriptive part.
......
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