mirror of
https://github.com/fralx/LimeReport.git
synced 2025-10-01 11:31:10 +03:00
SVGItem has been added
This commit is contained in:
48
limereport/objectinspector/editors/lrsvgeditor.cpp
Normal file
48
limereport/objectinspector/editors/lrsvgeditor.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "lrsvgeditor.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QFileDialog>
|
||||
#include "lrimageeditor.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
SvgEditor::SvgEditor(QWidget* parent)
|
||||
:QWidget(parent)
|
||||
{
|
||||
m_button.setIcon(QIcon(":items/ImageItem"));
|
||||
m_clearButton.setIcon(QIcon(":items/clear.png"));
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->addWidget(&m_button);
|
||||
layout->addWidget(&m_clearButton);
|
||||
layout->setSpacing(1);
|
||||
layout->setContentsMargins(1,0,1,1);
|
||||
setLayout(layout);
|
||||
setFocusProxy(&m_button);
|
||||
setAutoFillBackground(true);
|
||||
connect(&m_button,SIGNAL(clicked()),this,SLOT(slotButtonClicked()));
|
||||
connect(&m_clearButton,SIGNAL(clicked()),this,SLOT(slotClearButtonClicked()));
|
||||
}
|
||||
|
||||
QByteArray SvgEditor::image()
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void SvgEditor::slotButtonClicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "", "SVG| *.svg");
|
||||
if (!fileName.isEmpty()){
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)){
|
||||
m_image = file.readAll();
|
||||
}
|
||||
}
|
||||
emit editingFinished();
|
||||
}
|
||||
|
||||
void SvgEditor::slotClearButtonClicked()
|
||||
{
|
||||
m_image = QByteArray();
|
||||
emit editingFinished();
|
||||
}
|
||||
|
||||
}
|
29
limereport/objectinspector/editors/lrsvgeditor.h
Normal file
29
limereport/objectinspector/editors/lrsvgeditor.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef SVGEDITOR_H
|
||||
#define SVGEDITOR_H
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class SvgEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SvgEditor(QWidget *parent=0);
|
||||
QByteArray image();
|
||||
void setImage(const QByteArray& image){m_image=image;}
|
||||
signals:
|
||||
void editingFinished();
|
||||
private slots:
|
||||
void slotButtonClicked();
|
||||
void slotClearButtonClicked();
|
||||
private:
|
||||
QPushButton m_button;
|
||||
QPushButton m_clearButton;
|
||||
QByteArray m_image;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // SVGEDITOR_H
|
@@ -68,6 +68,14 @@ namespace{
|
||||
bool VARIABLE_IS_NOT_USED registredBarcodeFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("field","LimeReport::BarcodeItem"),QObject::tr("field"),createFieldPropItem
|
||||
);
|
||||
|
||||
bool VARIABLE_IS_NOT_USED registredSVGItemDatasouceProp = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("datasource","LimeReport::SVGItem"),QObject::tr("datasource"),createDatasourcePropItem
|
||||
);
|
||||
|
||||
bool VARIABLE_IS_NOT_USED registredSVGFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("field","LimeReport::SVGItem"),QObject::tr("field"),createFieldPropItem
|
||||
);
|
||||
}
|
||||
|
||||
QWidget* LimeReport::DatasourcePropItem::createProperyEditor(QWidget *parent) const{
|
||||
|
42
limereport/objectinspector/propertyItems/lrsvgpropitem.cpp
Normal file
42
limereport/objectinspector/propertyItems/lrsvgpropitem.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "lrsvgpropitem.h"
|
||||
#include "editors/lrsvgeditor.h"
|
||||
|
||||
namespace{
|
||||
LimeReport::ObjectPropItem * createSvgPropItem(
|
||||
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
|
||||
{
|
||||
return new LimeReport::SvgPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
bool VARIABLE_IS_NOT_USED registredImageProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("image","LimeReport::SVGItem"),QObject::tr("image"),createSvgPropItem);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
QWidget* SvgPropItem::createProperyEditor(QWidget *parent) const
|
||||
{
|
||||
return new SvgEditor(parent);
|
||||
}
|
||||
|
||||
QString SvgPropItem::displayValue() const
|
||||
{
|
||||
return (propertyValue().isNull()) ? "" : QObject::tr("image");
|
||||
}
|
||||
|
||||
void SvgPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
{
|
||||
SvgEditor *editor = qobject_cast<SvgEditor*>(propertyEditor);
|
||||
editor->setImage(propertyValue().value<QByteArray>());
|
||||
}
|
||||
|
||||
void SvgPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
model->setData(index,qobject_cast<SvgEditor*>(propertyEditor)->image());
|
||||
object()->setProperty(propertyName().toLatin1(),propertyValue());
|
||||
}
|
||||
|
||||
QIcon SvgPropItem::iconValue() const
|
||||
{
|
||||
return QIcon(QPixmap::fromImage(propertyValue().value<QImage>()));
|
||||
}
|
||||
|
||||
}
|
23
limereport/objectinspector/propertyItems/lrsvgpropitem.h
Normal file
23
limereport/objectinspector/propertyItems/lrsvgpropitem.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef SVGPROPITEM_H
|
||||
#define SVGPROPITEM_H
|
||||
|
||||
#include "lrobjectpropitem.h"
|
||||
namespace LimeReport{
|
||||
|
||||
class SvgPropItem : public ObjectPropItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SvgPropItem():ObjectPropItem(){}
|
||||
SvgPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly)
|
||||
:ObjectPropItem(object, objects, name, displayName, value, parent, readonly){}
|
||||
QWidget* createProperyEditor(QWidget *parent) const;
|
||||
QString displayValue() const;
|
||||
void setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const;
|
||||
void setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index);
|
||||
virtual QIcon iconValue() const;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // SVGPROPITEM_H
|
Reference in New Issue
Block a user