Users

Using eXaro
Writing plugins

Writing plugins

You may have seen how easy is to embed eXaro in your application, now you will see how easy is to write your own plugins. Writing plugins for eXaro require only a subclass of Report::ItemInterface. The following example will show you how to create a simple rectangle.

rect.h

#ifndef RECT_H
#define RECT_H
#include <iteminterface.h>

class Rectangle : public Report::ItemInterface
{
	Q_OBJECT
	Q_INTERFACES(Report::ItemInterface);

public:
	Rectangle(QGraphicsItem* parent = 0, QObject* parentObject = 0);

	QRectF boundingRect() const;
	void paint(QPainter * painter,
	           const QStyleOptionGraphicsItem * option,
	           QWidget * widget = 0);

	QString toolBoxText();
	QString toolBoxGroup();

	QObject * createInstance(QGraphicsItem* parent = 0,
	                         QObject* parentObject = 0);

};
#endif

rect.cpp

#include <QtCore>
#include <QBrush>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include "rect.h"
Rectangle::Rectangle(QGraphicsItem* parent, QObject* parentObject)
		: ItemInterface(parent, parentObject)
{
}

QRectF Rectangle::boundingRect() const
{
	return QRectF(0, 0, width(), height());//return the boundingRect()
}

void Rectangle::paint(QPainter * painter,
                      const QStyleOptionGraphicsItem * option,
                      QWidget * widget)
{
	if (option->type != QStyleOption::SO_GraphicsItem)
		emit beforePrint(this);

	Q_UNUSED(widget);

	QRectF rect = (option->type == QStyleOption::SO_GraphicsItem)
	              ? boundingRect() : option->exposedRect;

//if the item is in designer(option->type==QStyleOption::SO_GraphicsItem)
	if (option->type == QStyleOption::SO_GraphicsItem)
		drawSelection(painter, rect);

	setupPainter(painter); // sets the painter brush, pen and font

	adjustRect(rect);

	painter->drawRect(rect); // draw the rectangle !!

	if (option->type != QStyleOption::SO_GraphicsItem)
		emit afterPrint(this);

}

QString Rectangle::toolBoxText()
{
	return tr("Rect");
}

QString Rectangle::toolBoxGroup()
{
	return tr("Shapes");
}

QObject * Rectangle::createInstance(QGraphicsItem* parent,
                                    QObject* parentObject)
{
	return new Rectangle(parent, parentObject);
}

Q_EXPORT_PLUGIN2(rectangle, Rectangle)

rect.pro

TEMPLATE = lib

CONFIG += dll \
 plugin \
 exceptions \
 rtti \
 uitools

TARGET = Rect


HEADERS += rect.h

SOURCES += rect.cpp

QT += sql \
 xml \
 script

DESTDIR = .

INCLUDEPATH += $$[EXARO_INSTALL_HEADERS]

LIBS += -L$$[EXARO_INSTALL_LIBS] -lReport

target.path = $$[EXARO_INSTALL_PLUGINS]/report

INSTALLS += target