Commit 48b51523 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Make arguments refs, add the agreed-upon api to the shape factory

class, start a unittest. Next make it work :-).

svn path=/trunk/koffice/; revision=664172
parent 68321206
......@@ -16,18 +16,23 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <klocale.h>
#include <KoXmlReader.h>
#include <KoXmlNS.h>
#include "KoPathShapeFactory.h"
#include "KoPathShape.h"
#include "KoLineBorder.h"
#include <klocale.h>
KoPathShapeFactory::KoPathShapeFactory(QObject *parent, const QStringList&)
: KoShapeFactory(parent, KoPathShapeId, i18n("A simple path shape"))
: KoShapeFactory(parent, KoPathShapeId, i18n("A simple path shape"))
{
setToolTip("A simple path shape");
setIcon("pathshape");
setOdfElementName(KoXmlNS::draw, "path");
setLoadingPriority( 0 );
}
KoShape * KoPathShapeFactory::createDefaultShape() const {
......@@ -46,3 +51,9 @@ KoShape * KoPathShapeFactory::createShape(const KoProperties * params) const {
return new KoPathShape();
}
bool KoPathShapeFactory::supports(const KoXmlElement & e) const
{
Q_UNUSED( e );
return false;
}
......@@ -24,6 +24,8 @@
#include "KoShape.h"
#include "KoShapeFactory.h"
#include "KoXmlReader.h"
/// Factory for path shapes
class KoPathShapeFactory : public KoShapeFactory
{
......@@ -33,6 +35,7 @@ public:
~KoPathShapeFactory() {}
KoShape * createDefaultShape() const;
KoShape * createShape(const KoProperties * params) const;
bool supports(const KoXmlElement & e) const;
};
#endif
......@@ -23,27 +23,17 @@
#include "KoPathShape.h"
// #include <QFlags>
// #include <QPainterPath>
// #include <QSet>
// #include <QMap>
// #include <QList>
//
// #include "KoShape.h"
//
// #define KoPathShapeId "KoPathShape"
/**
* @brief A KoPointGroup represents points in a path that should be treated as one
*
* In svg it is possible when you use a close and the create a new subpath not using
* a moveTo that the new subpath starts at the same point as the last subpath. As
* every point can only have 2 control points we have this class to group points
* together which should be handled as one in e.g. a move.
* In svg it is possible when you use a close and the create a new subpath not using
* a moveTo that the new subpath starts at the same point as the last subpath. As
* every point can only have 2 control points we have this class to group points
* together which should be handled as one in e.g. a move.
*/
class KoPointGroup
{
public:
public:
KoPointGroup() {}
~KoPointGroup() {}
......@@ -53,9 +43,9 @@ public:
void add( KoPathPoint * point );
/**
* @brief Remove a point from the group
*
*
* This also remove the pointer to the group in the point.
* When the second last point is removed from the group, the
* When the second last point is removed from the group, the
* group removes also the last point and deletes itself.
*/
void remove( KoPathPoint * point );
......
......@@ -31,10 +31,12 @@ public:
}
QList<KoShapeTemplate> templates;
QList<KoShapeConfigFactory*> configPanels;
const QString id, name;
const QString id;
const QString name;
QString tooltip;
QString iconName;
quint32 loadingPriority;
QString odfNameSpace;
QString odfElementName;
};
......@@ -62,7 +64,7 @@ QString KoShapeFactory::name() const {
return d->name;
}
int KoShapeFactory::loadingPriority() const
quint32 KoShapeFactory::loadingPriority() const
{
return d->loadingPriority;
}
......@@ -72,10 +74,16 @@ QString KoShapeFactory::odfElementName() const
return d->odfElementName;
}
bool KoShapeFactory::supports(KoXmlElement e) const
const QString & KoShapeFactory::odfNameSpace() const
{
return d->odfNameSpace;
}
bool KoShapeFactory::supports(const KoXmlElement & e) const
{
Q_UNUSED( e );
// XXX: Implement
// XXX: Remove this and replace with a pure virtual once
// everything has implemented it.
return false;
}
......@@ -108,4 +116,15 @@ const QList<KoShapeTemplate> KoShapeFactory::templates() const {
return d->templates;
}
void KoShapeFactory::setLoadingPriority( quint32 priority )
{
d->loadingPriority = priority;
}
void KoShapeFactory::setOdfElementName( const QString & nameSpace, const QString & name )
{
d->odfNameSpace = nameSpace;
d->odfElementName = name;
}
#include "KoShapeFactory.moc"
......@@ -175,15 +175,19 @@ public:
QString name() const;
/// lower prio means the shape is more generic and will be checked later
int loadingPriority() const;
quint32 loadingPriority() const;
// The namespace that the elements supported by the shape created
// by this factory should be in.
const QString & odfNameSpace() const;
/// the name used for quick checking if this shapeFactory is able to
/// load Odf data identified by the element name.
QString odfElementName() const;
virtual QString odfElementName() const;
/// returns true if this shapeFactory is able to load the ODF type
/// started at argument element. ('draw:line' / 'draw:frame' / etc)
bool supports(KoXmlElement e) const;
bool supports(const KoXmlElement & e) const;
protected:
......@@ -193,11 +197,13 @@ protected:
* @param params the new template this factory knows to produce
*/
void addTemplate(KoShapeTemplate &params);
/**
* Set the tooltip to be used for a selector of shapes
* @param tooltip the tooltip
*/
void setToolTip(const QString & tooltip);
/**
* Set an icon to be used in a selector of shapes
* @param iconName the basename (without extension) of the icon
......@@ -205,6 +211,26 @@ protected:
*/
void setIcon(const QString & iconName);
/**
* Set the loading priority for this icon; higher priority means
* the shape is more specific which means it will be earlier in
* the queue to try loading a particular odf element.
*/
void setLoadingPriority( quint32 priority );
/**
* Set the name used for quick checking whether this shapefactory
* is able to create a shape from xml identified by this element
* name.
*
* @param nameSpace the ODF name space (like
* urn:oasis:names:tc:opendocument:xmlns:text:1.0,
* take it from KoXmlNS.h)
* @param elementName the name of the elment itself, like "draw"
*
*/
void setOdfElementName( const QString & nameSpace, const QString & elementName );
private:
class Private;
Private * const d;
......
......@@ -67,7 +67,7 @@ KoShapeRegistry* KoShapeRegistry::instance()
return KoShapeRegistry::m_singleton;
}
KoShape * KoShapeRegistry::createShapeFromOdf(KoShapeLoadingContext *context, KoXmlElement e) const
KoShape * KoShapeRegistry::createShapeFromOdf(KoShapeLoadingContext *context, const KoXmlElement & e) const
{
Q_UNUSED( context );
Q_UNUSED( e );
......
......@@ -60,7 +60,7 @@ public:
*
* @returns the shape or 0 if no shape could be created
*/
KoShape * createShapeFromOdf(KoShapeLoadingContext *context, KoXmlElement e) const;
KoShape * createShapeFromOdf(KoShapeLoadingContext *context, const KoXmlElement & e) const;
private:
KoShapeRegistry();
......
......@@ -125,15 +125,28 @@ add_test(libs-flake-TestShapePainting ${EXECUTABLE_OUTPUT_PATH}/TestShapePaintin
########### next target ###############
set(TestKoShapeRegistry_test_SRCS TestShapePainting.cpp )
set(TestKoShapeFactory_test_SRCS TestShapePainting.cpp )
kde4_automoc(${TestKoShapeRegistry_test_SRCS})
kde4_automoc(${TestKoShapeFactory_test_SRCS})
kde4_add_executable(TestKoShapeRegistry RUN_UNINSTALLED ${TestKoShapeRegistry_test_SRCS})
kde4_add_executable(TestKoShapeFactory RUN_UNINSTALLED ${TestKoShapeFactory_test_SRCS})
target_link_libraries(TestKoShapeRegistry ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
target_link_libraries(TestKoShapeFactory ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
add_test(libs-flake-TestKoShapeRegistry ${EXECUTABLE_OUTPUT_PATH}/TestKoShapeRegistry)
add_test(libs-flake-TestKoShapeFactory ${EXECUTABLE_OUTPUT_PATH}/TestKoShapeFactory)
########### next target ###############
set(TestKoShapeFactory_test_SRCS TestShapePainting.cpp )
kde4_automoc(${TestKoShapeFactory_test_SRCS})
kde4_add_executable(TestKoShapeFactory RUN_UNINSTALLED ${TestKoShapeFactory_test_SRCS})
target_link_libraries(TestKoShapeFactory ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
add_test(libs-flake-TestKoShapeFactory ${EXECUTABLE_OUTPUT_PATH}/TestKoShapeFactory)
########### next target ###############
endif(KDE4_BUILD_TESTS)
......@@ -70,10 +70,10 @@ void TestKoShapeRegistry::testCreateEmptyShape()
int errorLine = 0;
int errorColumn = 0;
QVERIFY( doc.setContent( &xmldevice, true, &errorMsg, &errorLine, &errorColumn ), true );
QVERIFY( errorMsg.isEmpty(), true );
QVERIFY( errorLine, 0 );
QVERIFY( errorColumn, 0 );
QCOMPARE( doc.setContent( &xmldevice, true, &errorMsg, &errorLine, &errorColumn ), true );
QCOMPARE( errorMsg.isEmpty(), true );
QCOMPARE( errorLine, 0 );
QCOMPARE( errorColumn, 0 );
KoXmlElement contentElement = doc.documentElement();
KoXmlElement bodyElement = contentElement.firstChild().toElement();
......
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