Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeFactoryBase Class Referenceabstract

#include <KoShapeFactoryBase.h>

+ Inheritance diagram for KoShapeFactoryBase:

Public Member Functions

virtual KoShapecreateDefaultShape (KoDocumentResourceManager *documentResources=0) const
 
virtual KoShapecreateShape (const KoProperties *params, KoDocumentResourceManager *documentResources=0) const
 
virtual QList< KoShapeConfigWidgetBase * > createShapeOptionPanels ()
 
QString family () const
 
bool hidden () const
 
QString iconName () const
 
QString id () const
 
 KoShapeFactoryBase (const QString &id, const QString &name, const QString &deferredPluginName=QString())
 
int loadingPriority () const
 lower prio means the shape is more generic and will be checked later
 
QString name () const
 
virtual void newDocumentResourceManager (KoDocumentResourceManager *manager) const
 
QList< QPair< QString, QStringList > > odfElements () const
 
 Private (const QString &_id, const QString &_name, const QString &_deferredPluginName)
 
virtual bool supports (const QDomElement &element, KoShapeLoadingContext &context) const =0
 
QList< KoShapeTemplatetemplates () const
 
QString toolTip () const
 
 ~KoShapeFactoryBase () override
 
 ~Private ()
 

Public Attributes

KoDeferredShapeFactoryBasedeferredFactory
 
QString deferredPluginName
 
QString family
 
bool hidden
 
QString iconName
 
const QString id
 
int loadingPriority
 
const QString name
 
QMutex pluginLoadingMutex
 
QList< QPointer< KoDocumentResourceManager > > resourceManagers
 
QList< KoShapeTemplatetemplates
 
QString tooltip
 
QList< QPair< QString, QStringList > > xmlElements
 

Protected Member Functions

void addTemplate (const KoShapeTemplate &params)
 
void setFamily (const QString &family)
 
void setHidden (bool hidden)
 
void setIconName (const char *iconName)
 
void setLoadingPriority (int priority)
 
void setToolTip (const QString &tooltip)
 
void setXmlElementNames (const QString &nameSpace, const QStringList &elementNames)
 
void setXmlElements (const QList< QPair< QString, QStringList > > &elementNamesList)
 

Private Slots

void pruneDocumentResourceManager (QObject *)
 called whenever a document KoDocumentResourceManager is deleted
 

Private Member Functions

void getDeferredPlugin ()
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

A factory for KoShape objects. The baseclass for all shape plugins. Each plugin that ships a KoShape should also ship a factory. That factory will extend this class and set variable data like a toolTip and icon in the constructor of that extending class.

An example usage would be:

class MyShapeFactory : public KoShapeFactoryBase {
public:
MyShapeFactory()
: KoShapeFactoryBase("MyShape", i18n("My Shape")) {
setToolTip(i18n("A nice shape"));
}
~MyShapeFactory() {}
// more methods here
};

After you created the factory you should create a plugin that can announce the factory to the KoShapeRegistry. See the KoPluginLoader as well.

Definition at line 31 of file KoShapeFactoryBase.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoShapeFactoryBase::~Private ( )
inline

Definition at line 44 of file KoShapeFactoryBase.cpp.

44 {
45 Q_FOREACH (const KoShapeTemplate & t, templates)
46 delete t.properties;
47 templates.clear();
48 }
QList< KoShapeTemplate > templates

References KoShapeTemplate::properties.

◆ KoShapeFactoryBase()

KoShapeFactoryBase::KoShapeFactoryBase ( const QString & id,
const QString & name,
const QString & deferredPluginName = QString() )

Create the new factory

Parameters
ida string that will be used internally for referencing the shape
namethe user visible name of the shape this factory creates.

Definition at line 66 of file KoShapeFactoryBase.cpp.

◆ ~KoShapeFactoryBase()

KoShapeFactoryBase::~KoShapeFactoryBase ( )
override

Definition at line 71 of file KoShapeFactoryBase.cpp.

72{
73 delete d;
74}

References d.

Member Function Documentation

◆ addTemplate()

void KoShapeFactoryBase::addTemplate ( const KoShapeTemplate & params)
protected

Add a template with the properties of a specific type of shape this factory can generate using the createShape() method. The factory will take ownership of the properties object to which the member properties of params points to and destroy it only in its own destructor.

Parameters
paramsthe new template this factory knows to produce

Definition at line 106 of file KoShapeFactoryBase.cpp.

107{
108 KoShapeTemplate tmplate = params;
109 tmplate.id = d->id;
110 d->templates.append(tmplate);
111}
QString id
The id of the shape.

References d, and KoShapeTemplate::id.

◆ createDefaultShape()

KoShape * KoShapeFactoryBase::createDefaultShape ( KoDocumentResourceManager * documentResources = 0) const
virtual

This method should be implemented by factories to create a shape that the user gets when doing a base insert. For example from a script. The created shape should have its values set to good defaults that the user can then adjust further if needed. Including the KoShape:setShapeId(), with the Id from this factory The default shape position is not relevant, it will be moved by the caller.

Parameters
documentResourcesthe resources manager that has all the document wide resources which can be used to create the object.
Returns
a new shape
See also
createShape() newDocumentResourceManager()

Reimplemented in KoPathShapeFactory, KoSvgTextShapeFactory, KisShapeSelectionFactory, ImageShapeFactory, EllipseShapeFactory, EnhancedPathShapeFactory, RectangleShapeFactory, SpiralShapeFactory, StarShapeFactory, and KarbonCalligraphicShapeFactory.

Definition at line 170 of file KoShapeFactoryBase.cpp.

171{
172 if (!d->deferredPluginName.isEmpty()) {
173 const_cast<KoShapeFactoryBase*>(this)->getDeferredPlugin();
174 Q_ASSERT(d->deferredFactory);
175 if (d->deferredFactory) {
176 return d->deferredFactory->createDefaultShape(documentResources);
177 }
178 }
179 return 0;
180}

References d, and getDeferredPlugin().

◆ createShape()

KoShape * KoShapeFactoryBase::createShape ( const KoProperties * params,
KoDocumentResourceManager * documentResources = 0 ) const
virtual

This method should be implemented by factories to create a shape based on a set of properties that are specifically made for this shape-type. This method should also set this factories shapeId on the shape using KoShape::setShapeId() The default implementation just ignores 'params' and calls createDefaultShape()

Returns
a new shape
Parameters
paramsthe parameters to use when creating the shape
documentResourcesthe resources manager that has all the document wide resources which can be used to create the object.
See also
createDefaultShape() newDocumentResourceManager() addTemplate()
KoShapeTemplate::properties

Reimplemented in ImageShapeFactory, KoSvgTextShapeFactory, EnhancedPathShapeFactory, RectangleShapeFactory, and StarShapeFactory.

Definition at line 182 of file KoShapeFactoryBase.cpp.

184{
185 if (!d->deferredPluginName.isEmpty()) {
186 const_cast<KoShapeFactoryBase*>(this)->getDeferredPlugin();
187 Q_ASSERT(d->deferredFactory);
188 if (d->deferredFactory) {
189 return d->deferredFactory->createShape(properties, documentResources);
190 }
191 }
192 return createDefaultShape(documentResources);
193}
virtual KoShape * createDefaultShape(KoDocumentResourceManager *documentResources=0) const

References createDefaultShape(), d, and getDeferredPlugin().

◆ createShapeOptionPanels()

virtual QList< KoShapeConfigWidgetBase * > KoShapeFactoryBase::createShapeOptionPanels ( )
inlinevirtual

Create a list of option panels to show on creating a new shape. The shape type this factory creates may have general or specific setting panels that will be shown after inserting a new shape. The first item in the list will be shown as the first tab in the list of panels, behind all app specific panels. This is a separate list as set by setOptionPanels() and fetched by panelFactories()

Reimplemented in ImageShapeFactory, EllipseShapeFactory, RectangleShapeFactory, SpiralShapeFactory, and StarShapeFactory.

Definition at line 95 of file KoShapeFactoryBase.h.

◆ family()

QString KoShapeFactoryBase::family ( ) const

return the non-visible name of the family the default shape belongs to.

Returns
the family name.

◆ getDeferredPlugin()

void KoShapeFactoryBase::getDeferredPlugin ( )
private

Definition at line 195 of file KoShapeFactoryBase.cpp.

196{
197 QMutexLocker(&d->pluginLoadingMutex);
198 if (d->deferredFactory) return;
199
200 const QList<KoJsonTrader::Plugin> offers =
201 KoJsonTrader::instance()->query("Krita/Deferred", QString());
202 Q_ASSERT(offers.size() > 0);
203
204 Q_FOREACH (const KoJsonTrader::Plugin &pluginLoader, offers) {
205 KPluginFactory *factory = qobject_cast<KPluginFactory *>(pluginLoader.instance());
206 KoDeferredShapeFactoryBase *plugin = factory->create<KoDeferredShapeFactoryBase>(this, QVariantList());
207
208 if (plugin && plugin->deferredPluginName() == d->deferredPluginName) {
209 d->deferredFactory = plugin;
210 }
211 }
212}
virtual QString deferredPluginName()=0
static KoJsonTrader * instance()
QList< Plugin > query(const QString &servicetype, const QString &mimetype)
QObject * instance() const

References d, KoDeferredShapeFactoryBase::deferredPluginName(), KoJsonTrader::instance(), KoJsonTrader::Plugin::instance(), and KoJsonTrader::query().

◆ hidden()

bool KoShapeFactoryBase::hidden ( ) const

The hidden boolean requests if the shape should be hidden in the shape selector or shown with all its templates. The default is false

See also
setHidden()

◆ iconName()

QString KoShapeFactoryBase::iconName ( ) const

return the basename of the icon for a selector of shapes

Returns
the basename of the icon for a selector of shapes

◆ id()

QString KoShapeFactoryBase::id ( ) const

return the id for the shape this factory creates.

Returns
the id for the shape this factory creates.

◆ loadingPriority()

int KoShapeFactoryBase::loadingPriority ( ) const

lower prio means the shape is more generic and will be checked later

◆ name()

QString KoShapeFactoryBase::name ( ) const

return the user visible (and translated) name to be seen by the user.

Returns
the user visible (and translated) name to be seen by the user.

◆ newDocumentResourceManager()

void KoShapeFactoryBase::newDocumentResourceManager ( KoDocumentResourceManager * manager) const
virtual

This method is called whenever there is a new document resource manager that is created. The factory may reimplement this in order to get existing resources or put factory specific resources in. In case the factory creates new resources it is advised to parent them to the manager (which is a QObject) for memory management purposes.

FIXME: this method is only used by Tables. We should refactor so it is no longer necessary.

NOTE: this actually is also used somehow to create the image collection for the picture shape?

NOTE: we store the documentmanagers in a list, and remove them from the list on delete.

Parameters
managerthe new manager

Reimplemented in KoPathShapeFactory.

Definition at line 164 of file KoShapeFactoryBase.cpp.

165{
166 d->resourceManagers.append(manager);
167 connect(manager, SIGNAL(destroyed(QObject*)), this, SLOT(pruneDocumentResourceManager(QObject*)));
168}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void pruneDocumentResourceManager(QObject *)
called whenever a document KoDocumentResourceManager is deleted

References connect(), d, and pruneDocumentResourceManager().

◆ odfElements()

QList< QPair< QString, QStringList > > KoShapeFactoryBase::odfElements ( ) const

The list of namespaces to the supported elements the factory supports.

Definition at line 101 of file KoShapeFactoryBase.cpp.

102{
103 return d->xmlElements;
104}

References d.

◆ Private()

KoShapeFactoryBase::Private ( const QString & _id,
const QString & _name,
const QString & _deferredPluginName )
inline

Definition at line 34 of file KoShapeFactoryBase.cpp.

35 : deferredFactory(0),
36 deferredPluginName(_deferredPluginName),
37 id(_id),
38 name(_name),
40 hidden(false)
41 {
42 }
KoDeferredShapeFactoryBase * deferredFactory

◆ pruneDocumentResourceManager

void KoShapeFactoryBase::pruneDocumentResourceManager ( QObject * )
privateslot

called whenever a document KoDocumentResourceManager is deleted

Definition at line 214 of file KoShapeFactoryBase.cpp.

215{
217 Q_FOREACH(QPointer<KoDocumentResourceManager> rm, d->resourceManagers) {
218 if (rm) {
219 rms << rm;
220 }
221 }
222 d->resourceManagers = rms;
223}

References d.

◆ setFamily()

void KoShapeFactoryBase::setFamily ( const QString & family)
protected

Set the family name of the default shape

Parameters
familythe family name of the default shape this factory creates. for example "funny", "arrows", "geometrics". Use "" for default

Definition at line 123 of file KoShapeFactoryBase.cpp.

124{
125 d->family = family;
126}

References d, and family.

◆ setHidden()

void KoShapeFactoryBase::setHidden ( bool hidden)
protected

The hidden boolean requests if the shape should be hidden in the shape selector or shown with all its templates. The default is false

See also
hidden()

Definition at line 159 of file KoShapeFactoryBase.cpp.

160{
161 d->hidden = hidden;
162}

References d, and hidden.

◆ setIconName()

void KoShapeFactoryBase::setIconName ( const char * iconName)
protected

Set an icon to be used in a selector of shapes

Parameters
iconNamethe basename (without extension) of the icon

Definition at line 118 of file KoShapeFactoryBase.cpp.

119{
120 d->iconName = QLatin1String(iconName);
121}

References d, and iconName.

◆ setLoadingPriority()

void KoShapeFactoryBase::setLoadingPriority ( int priority)
protected

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.

Definition at line 138 of file KoShapeFactoryBase.cpp.

139{
140 d->loadingPriority = priority;
141}

References d.

◆ setToolTip()

void KoShapeFactoryBase::setToolTip ( const QString & tooltip)
protected

Set the tooltip to be used for a selector of shapes

Parameters
tooltipthe tooltip

Definition at line 113 of file KoShapeFactoryBase.cpp.

114{
115 d->tooltip = tooltip;
116}

References d, and tooltip.

◆ setXmlElementNames()

void KoShapeFactoryBase::setXmlElementNames ( const QString & nameSpace,
const QStringList & elementNames )
protected

Set the namespace and element tags used for quick checking whether this shapefactory is able to create a shape from xml identified by this element name.

Parameters
nameSpacethe ODF name space (like urn:oasis:names:tc:opendocument:xmlns:text:1.0, take it from KoXmlNS.h)
elementNamesthe name of the element itself, like "path"

Definition at line 143 of file KoShapeFactoryBase.cpp.

144{
145 d->xmlElements.clear();
146 d->xmlElements.append(QPair<QString, QStringList>(nameSpace, names));
147}

References d.

◆ setXmlElements()

void KoShapeFactoryBase::setXmlElements ( const QList< QPair< QString, QStringList > > & elementNamesList)
protected

Set the namespaces and according element tags used for quick checking whether this shapefactory is able to create a shape from xml identified by this element name.

Parameters
elementNamesListcontaining a list of namespace (like urn:oasis:names:tc:opendocument:xmlns:text:1.0, take it from KoXmlNS.h) to a list of elementName of the element itself, like "path"

Definition at line 149 of file KoShapeFactoryBase.cpp.

150{
151 d->xmlElements = elementNamesList;
152}

References d.

◆ supports()

virtual bool KoShapeFactoryBase::supports ( const QDomElement & element,
KoShapeLoadingContext & context ) const
pure virtual

returns true if this shapeFactory is able to load the ODF type started at argument element. ('draw:line' / 'draw:frame' / etc)

Implemented in KoSvgTextShapeFactory, KisShapeSelectionFactory, ImageShapeFactory, EllipseShapeFactory, EnhancedPathShapeFactory, RectangleShapeFactory, SpiralShapeFactory, StarShapeFactory, KarbonCalligraphicShapeFactory, and KoPathShapeFactory.

◆ templates()

QList< KoShapeTemplate > KoShapeFactoryBase::templates ( ) const

Return all the templates this factory knows about. Each template shows a different way to create a shape this factory is specialized in.

◆ toolTip()

QString KoShapeFactoryBase::toolTip ( ) const

return a translated tooltip Text for a selector of shapes

Returns
a translated tooltip Text

Definition at line 76 of file KoShapeFactoryBase.cpp.

77{
78 return d->tooltip;
79}

References d.

Member Data Documentation

◆ d

Private* const KoShapeFactoryBase::d
private

Definition at line 277 of file KoShapeFactoryBase.h.

◆ deferredFactory

KoDeferredShapeFactoryBase* KoShapeFactoryBase::deferredFactory

Definition at line 50 of file KoShapeFactoryBase.cpp.

◆ deferredPluginName

QString KoShapeFactoryBase::deferredPluginName

Definition at line 52 of file KoShapeFactoryBase.cpp.

◆ family

QString KoShapeFactoryBase::family

Definition at line 56 of file KoShapeFactoryBase.cpp.

◆ hidden

bool KoShapeFactoryBase::hidden

Definition at line 61 of file KoShapeFactoryBase.cpp.

◆ iconName

QString KoShapeFactoryBase::iconName

Definition at line 58 of file KoShapeFactoryBase.cpp.

◆ id

QString KoShapeFactoryBase::id

Definition at line 54 of file KoShapeFactoryBase.cpp.

◆ loadingPriority

int KoShapeFactoryBase::loadingPriority

Definition at line 59 of file KoShapeFactoryBase.cpp.

◆ name

QString KoShapeFactoryBase::name

Definition at line 55 of file KoShapeFactoryBase.cpp.

◆ pluginLoadingMutex

QMutex KoShapeFactoryBase::pluginLoadingMutex

Definition at line 51 of file KoShapeFactoryBase.cpp.

◆ resourceManagers

QList<QPointer<KoDocumentResourceManager> > KoShapeFactoryBase::resourceManagers

Definition at line 62 of file KoShapeFactoryBase.cpp.

◆ templates

QList< KoShapeTemplate > KoShapeFactoryBase::templates

Definition at line 53 of file KoShapeFactoryBase.cpp.

◆ tooltip

QString KoShapeFactoryBase::tooltip

Definition at line 57 of file KoShapeFactoryBase.cpp.

◆ xmlElements

QList<QPair<QString, QStringList> > KoShapeFactoryBase::xmlElements

Definition at line 60 of file KoShapeFactoryBase.cpp.


The documentation for this class was generated from the following files: