mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 08:29:07 +03:00
Rulers and inches support has been added
This commit is contained in:
@@ -160,6 +160,7 @@ void QObjectPropertyModel::translatePropertyName()
|
||||
tr("fontLetterSpacing");
|
||||
tr("hideText");
|
||||
tr("option3");
|
||||
tr("units");
|
||||
}
|
||||
|
||||
void QObjectPropertyModel::clearObjectsList()
|
||||
|
@@ -143,6 +143,8 @@ void EnumPropItem::translateEnumItemName()
|
||||
tr("TitleAlignCenter");
|
||||
tr("Layout");
|
||||
tr("Table");
|
||||
tr("Millimeters");
|
||||
tr("Inches");
|
||||
}
|
||||
|
||||
void EnumPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
|
102
limereport/objectinspector/propertyItems/lrmarginpropitem.cpp
Normal file
102
limereport/objectinspector/propertyItems/lrmarginpropitem.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "lrmarginpropitem.h"
|
||||
#include <QDoubleSpinBox>
|
||||
#include <limits>
|
||||
#include "lrbasedesignintf.h"
|
||||
|
||||
namespace {
|
||||
LimeReport::ObjectPropItem * createMarginPropItem(
|
||||
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
|
||||
{
|
||||
return new LimeReport::MarginPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
bool VARIABLE_IS_NOT_USED registredTopMargin = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("topMargin","LimeReport::PageItemDesignIntf"),
|
||||
QObject::tr("margin"),createMarginPropItem
|
||||
);
|
||||
bool VARIABLE_IS_NOT_USED registredRightMargin = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("rightMargin","LimeReport::PageItemDesignIntf"),
|
||||
QObject::tr("margin"),createMarginPropItem
|
||||
);
|
||||
bool VARIABLE_IS_NOT_USED registredBottomMargin = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("bottomMargin","LimeReport::PageItemDesignIntf"),
|
||||
QObject::tr("margin"),createMarginPropItem
|
||||
);
|
||||
bool VARIABLE_IS_NOT_USED registredLeftMargin = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("leftMargin","LimeReport::PageItemDesignIntf"),
|
||||
QObject::tr("margin"),createMarginPropItem
|
||||
);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
|
||||
QString MarginPropItem::displayValue() const
|
||||
{
|
||||
LimeReport::BaseDesignIntf * item = dynamic_cast<LimeReport::BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
|
||||
return QString("%1 %2").arg(propertyValue().toDouble(), 0, 'f', 2)
|
||||
.arg(QObject::tr("mm"));
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return QString("%1 %2").arg((propertyValue().toDouble() * Const::mmFACTOR) / (item->unitFactor() * 10), 0, 'f', 2)
|
||||
.arg(QObject::tr("''"));
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *MarginPropItem::createProperyEditor(QWidget *parent) const
|
||||
{
|
||||
QDoubleSpinBox *editor= new QDoubleSpinBox(parent);
|
||||
editor->setMaximum(std::numeric_limits<qreal>::max());
|
||||
editor->setMinimum(std::numeric_limits<qreal>::max()*-1);
|
||||
editor->setSuffix(" "+unitShortName());
|
||||
return editor;
|
||||
}
|
||||
|
||||
void MarginPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
{
|
||||
QDoubleSpinBox *editor =qobject_cast<QDoubleSpinBox*>(propertyEditor);
|
||||
editor->setValue(valueInUnits(propertyValue().toReal()));
|
||||
}
|
||||
|
||||
void MarginPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
model->setData(index, valueInReportUnits(qobject_cast<QDoubleSpinBox*>(propertyEditor)->value()));
|
||||
setValueToObject(propertyName(), propertyValue());
|
||||
}
|
||||
|
||||
qreal MarginPropItem::valueInUnits(qreal value) const
|
||||
{
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return value;
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return (value * Const::mmFACTOR) / (item->unitFactor() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
qreal MarginPropItem::valueInReportUnits(qreal value) const
|
||||
{
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return value;
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return (value * (item->unitFactor() * 10)) / Const::mmFACTOR;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QString MarginPropItem::unitShortName() const
|
||||
{
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return QObject::tr("mm");
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return QObject::tr("''");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
28
limereport/objectinspector/propertyItems/lrmarginpropitem.h
Normal file
28
limereport/objectinspector/propertyItems/lrmarginpropitem.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef LRMARGINPROPITEM_H
|
||||
#define LRMARGINPROPITEM_H
|
||||
|
||||
#include "lrobjectpropitem.h"
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
class MarginPropItem : public ObjectPropItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MarginPropItem():ObjectPropItem(){}
|
||||
MarginPropItem(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){}
|
||||
QString displayValue() const;
|
||||
QWidget* createProperyEditor(QWidget *parent) const;
|
||||
void setPropertyEditorData(QWidget * propertyEditor, const QModelIndex &) const;
|
||||
void setModelData(QWidget * propertyEditor, QAbstractItemModel * model, const QModelIndex & index);
|
||||
private:
|
||||
qreal valueInUnits(qreal value) const;
|
||||
qreal valueInReportUnits(qreal value) const;
|
||||
QString unitShortName() const;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
|
||||
#endif // LRMARGINPROPITEM_H
|
@@ -38,8 +38,9 @@ namespace{
|
||||
{
|
||||
return new LimeReport::QRealPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
|
||||
bool VARIABLE_IS_NOT_USED registred = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("qreal",""),QObject::tr("qreal"),createQRealPropItem);
|
||||
bool VARIABLE_IS_NOT_USED registredDouble = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("double",""),QObject::tr("qreal"),createQRealPropItem);
|
||||
bool VARIABLE_IS_NOT_USED registredDouble = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("double",""),QObject::tr("qreal"),createQRealPropItem);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
@@ -61,7 +62,6 @@ void QRealPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelI
|
||||
void QRealPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
model->setData(index,qobject_cast<QDoubleSpinBox*>(propertyEditor)->value());
|
||||
//object()->setProperty(propertyName().toLatin1(),propertyValue());
|
||||
setValueToObject(propertyName(),propertyValue());
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,4 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LRQREALPROPITEM_H
|
||||
|
@@ -45,14 +45,14 @@ namespace{
|
||||
){
|
||||
return new LimeReport::RectPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
LimeReport::ObjectPropItem * createReqtMMItem(
|
||||
LimeReport::ObjectPropItem * createReqtUnitItem(
|
||||
QObject*object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly
|
||||
){
|
||||
return new LimeReport::RectMMPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
return new LimeReport::RectUnitPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
bool VARIABLE_IS_NOT_USED registredRectProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("QRect",""),QObject::tr("QRect"),createReqtItem);
|
||||
bool VARIABLE_IS_NOT_USED registredRectFProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("QRectF",""),QObject::tr("QRectF"),createReqtItem);
|
||||
bool VARIABLE_IS_NOT_USED registredRectMMProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("geometry","LimeReport::BaseDesignIntf"),QObject::tr("geometry"),createReqtMMItem);
|
||||
bool VARIABLE_IS_NOT_USED registredRectMMProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("geometry","LimeReport::BaseDesignIntf"),QObject::tr("geometry"),createReqtUnitItem);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
@@ -63,9 +63,8 @@ template<class T> QString rectToString(T rect)
|
||||
}
|
||||
|
||||
QRectF modifyRect(QRectF rect, const QString& name, qreal itemValue){
|
||||
|
||||
if (name=="x"){qreal width=rect.width(); rect.setX(itemValue);rect.setWidth(width);}
|
||||
if (name=="y"){qreal heigh=rect.height(); rect.setY(itemValue);rect.setHeight(heigh);}
|
||||
if (name=="x"){qreal width=rect.width(); rect.setX(itemValue); rect.setWidth(width);}
|
||||
if (name=="y"){qreal heigh=rect.height(); rect.setY(itemValue); rect.setHeight(heigh);}
|
||||
if (name=="height"){rect.setHeight(itemValue);}
|
||||
if (name=="width"){rect.setWidth(itemValue);}
|
||||
|
||||
@@ -89,118 +88,153 @@ QString LimeReport::RectPropItem::displayValue() const
|
||||
switch(propertyValue().type()){
|
||||
case QVariant::Rect:
|
||||
return rectToString(propertyValue().toRect());
|
||||
break;
|
||||
case QVariant::RectF:
|
||||
return rectToString(propertyValue().toRect());
|
||||
break;
|
||||
default :
|
||||
return ObjectPropItem::displayValue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
LimeReport::RectMMPropItem::RectMMPropItem(QObject *object, ObjectsList* objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent, bool /*readonly*/):
|
||||
LimeReport::RectUnitPropItem::RectUnitPropItem(QObject *object, ObjectsList* objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent, bool /*readonly*/):
|
||||
ObjectPropItem(object, objects, name, displayName, value,parent)
|
||||
{
|
||||
QRectF rect=value.toRect();
|
||||
QRectF rect= value.toRect();
|
||||
LimeReport::BandDesignIntf* band = dynamic_cast<LimeReport::BandDesignIntf*>(object);
|
||||
LimeReport::PageItemDesignIntf *page = dynamic_cast<LimeReport::PageItemDesignIntf*>(object);
|
||||
if(band){
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "x","x",rect.x()/10,this,true));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "y","y",rect.y()/10,this,true));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "width",tr("width"), rect.width()/10,this,true));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "height",tr("height"), rect.height()/10,this,false));
|
||||
} else if(page){
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, 0, "x","x",rect.x()/10,this,true));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, 0, "y","y",rect.y()/10,this,true));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, 0,"width", tr("width"), rect.width()/10,this,false));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, 0, "height", tr("height"), rect.height()/10,this,false));
|
||||
LimeReport::PageItemDesignIntf* page = dynamic_cast<LimeReport::PageItemDesignIntf*>(object);
|
||||
LimeReport::BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object);
|
||||
|
||||
if (band){
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "x", "x", rect.x(), this, true));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "y", "y", rect.y(), this, true));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "width", tr("width"), rect.width(), this, true));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "height", tr("height"), rect.height(), this, false));
|
||||
} else if (page){
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, 0, "x", "x", rect.x(), this, true));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, 0, "y", "y",rect.y(), this, true));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, 0,"width", tr("width"), rect.width(), this, false));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, 0, "height", tr("height"), rect.height(), this, false));
|
||||
} else {
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "x","x",rect.x()/10,this,false));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "y","y",rect.y()/10,this,false));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "width", tr("width"), rect.width()/10,this,false));
|
||||
this->appendItem(new LimeReport::RectMMValuePropItem(object, objects, "height", tr("height"), rect.height()/10,this,false));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "x", "x", rect.x(), this, false));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "y", "y", rect.y(), this, false));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "width", tr("width"), rect.width(), this, false));
|
||||
this->appendItem(new LimeReport::RectUnitValuePropItem(object, objects, "height", tr("height"), rect.height(), this, false));
|
||||
}
|
||||
LimeReport::BaseDesignIntf * item = dynamic_cast<LimeReport::BaseDesignIntf*>(object);
|
||||
|
||||
if (item){
|
||||
connect(item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)),this,SLOT(itemGeometryChanged(QObject*,QRectF,QRectF)));
|
||||
connect(item,SIGNAL(posChanged(QObject*,QPointF,QPointF)),this,SLOT(itemPosChanged(QObject*,QPointF,QPointF)));
|
||||
connect(item,SIGNAL(posChanging(QObject*,QPointF,QPointF)),this,SLOT(itemPosChanged(QObject*,QPointF,QPointF)));
|
||||
}
|
||||
|
||||
}
|
||||
QString LimeReport::RectMMPropItem::displayValue() const
|
||||
QString LimeReport::RectUnitPropItem::displayValue() const
|
||||
{
|
||||
QRectF rect = propertyValue().toRectF();
|
||||
return QString("[%1,%2] %3x%4 mm")
|
||||
.arg(rect.x()/10,0,'f',2)
|
||||
.arg(rect.y()/10,0,'f',2)
|
||||
.arg(rect.width()/10,0,'f',2)
|
||||
.arg(rect.height()/10,0,'f',2);
|
||||
QRectF rect = rectInUnits(propertyValue().toRectF());
|
||||
return QString("[%1,%2] %3x%4 %5")
|
||||
.arg(rect.x(), 0, 'f', 2)
|
||||
.arg(rect.y(), 0,'f', 2)
|
||||
.arg(rect.width(), 0, 'f', 2)
|
||||
.arg(rect.height(), 0, 'f', 2)
|
||||
.arg(unitShortName());
|
||||
}
|
||||
|
||||
LimeReport::RectMMValuePropItem::RectMMValuePropItem(QObject *object, ObjectsList* objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent, bool readonly
|
||||
LimeReport::RectUnitValuePropItem::RectUnitValuePropItem(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 * LimeReport::RectMMValuePropItem::createProperyEditor(QWidget *parent) const
|
||||
QWidget * LimeReport::RectUnitValuePropItem::createProperyEditor(QWidget *parent) const
|
||||
{
|
||||
QDoubleSpinBox *editor= new QDoubleSpinBox(parent);
|
||||
editor->setMaximum(100000);
|
||||
editor->setSuffix(" mm");
|
||||
editor->setSuffix(" "+unitShortName());
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
return editor;
|
||||
}
|
||||
|
||||
void LimeReport::RectMMValuePropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
void LimeReport::RectUnitValuePropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
{
|
||||
QDoubleSpinBox *editor = qobject_cast<QDoubleSpinBox*>(propertyEditor);
|
||||
editor->setValue(propertyValue().toDouble());
|
||||
editor->setValue(valueInUnits(propertyValue().toReal()));
|
||||
}
|
||||
|
||||
void LimeReport::RectMMValuePropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
void LimeReport::RectUnitValuePropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
model->setData(index,qobject_cast<QDoubleSpinBox*>(propertyEditor)->value());
|
||||
model->setData(index,valueInReportUnits(qobject_cast<QDoubleSpinBox*>(propertyEditor)->value()));
|
||||
QRectF rect=object()->property(parent()->propertyName().toLatin1()).toRectF();
|
||||
object()->setProperty(parent()->propertyName().toLatin1(),modifyRect(rect,propertyName(),propertyValue().toReal()*10));
|
||||
object()->setProperty(parent()->propertyName().toLatin1(), modifyRect(rect, propertyName(), propertyValue().toReal()));
|
||||
}
|
||||
|
||||
QString LimeReport::RectMMValuePropItem::displayValue() const
|
||||
qreal LimeReport::RectUnitValuePropItem::valueInUnits(qreal value) const
|
||||
{
|
||||
return QString::number(propertyValue().toReal())+" "+QObject::tr("mm");
|
||||
}
|
||||
|
||||
void LimeReport::RectMMPropItem::itemPosChanged(QObject* /*object*/, QPointF newPos, QPointF oldPos)
|
||||
{
|
||||
if (newPos.x()!=oldPos.x()){
|
||||
setValue("x",newPos.x());
|
||||
}
|
||||
if (newPos.y()!=oldPos.y()){
|
||||
setValue("y",newPos.y());
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return value / item->unitFactor();
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return value / (item->unitFactor() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
void LimeReport::RectMMPropItem::itemGeometryChanged(QObject * /*object*/, QRectF newGeometry, QRectF oldGeometry)
|
||||
qreal LimeReport::RectUnitValuePropItem::valueInReportUnits(qreal value) const
|
||||
{
|
||||
if (newGeometry.x()!=oldGeometry.x()){
|
||||
setValue("x",newGeometry.x());
|
||||
}
|
||||
if (newGeometry.y()!=oldGeometry.y()){
|
||||
setValue("y",newGeometry.y());
|
||||
}
|
||||
if (newGeometry.width()!=oldGeometry.width()){
|
||||
setValue("width",newGeometry.width());
|
||||
}
|
||||
if (newGeometry.height()!=oldGeometry.height()){
|
||||
setValue("height",newGeometry.height());
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return value * item->unitFactor();
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return value * (item->unitFactor() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
void LimeReport::RectMMPropItem::setValue(const QString &name, qreal value)
|
||||
QString LimeReport::RectUnitValuePropItem::unitShortName() const
|
||||
{
|
||||
if (name!=""){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return QObject::tr("mm");
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return QObject::tr("''");
|
||||
}
|
||||
}
|
||||
|
||||
QString LimeReport::RectUnitValuePropItem::displayValue() const
|
||||
{
|
||||
return QString("%1 %2").arg(valueInUnits(propertyValue().toReal()), 0, 'f', 2).arg(unitShortName());
|
||||
}
|
||||
|
||||
void LimeReport::RectUnitPropItem::itemPosChanged(QObject* /*object*/, QPointF newPos, QPointF oldPos)
|
||||
{
|
||||
if (newPos.x() != oldPos.x()){
|
||||
setValue("x", newPos.x());
|
||||
}
|
||||
if (newPos.y() != oldPos.y()){
|
||||
setValue("y", newPos.y());
|
||||
}
|
||||
}
|
||||
|
||||
void LimeReport::RectUnitPropItem::itemGeometryChanged(QObject * /*object*/, QRectF newGeometry, QRectF oldGeometry)
|
||||
{
|
||||
if (newGeometry.x() != oldGeometry.x()){
|
||||
setValue("x", newGeometry.x());
|
||||
}
|
||||
if (newGeometry.y() != oldGeometry.y()){
|
||||
setValue("y", newGeometry.y());
|
||||
}
|
||||
if (newGeometry.width() != oldGeometry.width()){
|
||||
setValue("width", newGeometry.width());
|
||||
}
|
||||
if (newGeometry.height() != oldGeometry.height()){
|
||||
setValue("height", newGeometry.height());
|
||||
}
|
||||
}
|
||||
|
||||
void LimeReport::RectUnitPropItem::setValue(const QString &name, qreal value)
|
||||
{
|
||||
if (name != ""){
|
||||
LimeReport::ObjectPropItem* propItem = findChild(name);
|
||||
if (propItem) {
|
||||
propItem->setPropertyValue(value/10);
|
||||
setPropertyValue(LimeReport::modifyRect(propertyValue().toRectF(),name,value));
|
||||
LimeReport::QObjectPropertyModel *itemModel=dynamic_cast<LimeReport::QObjectPropertyModel *>(model());
|
||||
propItem->setPropertyValue(value);
|
||||
setPropertyValue(LimeReport::modifyRect(propertyValue().toRectF(), name, value));
|
||||
LimeReport::QObjectPropertyModel *itemModel = dynamic_cast<LimeReport::QObjectPropertyModel *>(model());
|
||||
if (itemModel) {
|
||||
itemModel->itemDataChanged(modelIndex());
|
||||
if (propItem->modelIndex().isValid())
|
||||
@@ -209,3 +243,31 @@ void LimeReport::RectMMPropItem::setValue(const QString &name, qreal value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QRectF LimeReport::RectUnitPropItem::rectInUnits(QRectF rect) const
|
||||
{
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return QRectF(rect.x() / item->unitFactor(),
|
||||
rect.y() / item->unitFactor(),
|
||||
rect.width() / item->unitFactor(),
|
||||
rect.height() / item->unitFactor());
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return QRectF(rect.x() / (item->unitFactor() * 10),
|
||||
rect.y() / (item->unitFactor() * 10),
|
||||
rect.width() / (item->unitFactor() * 10),
|
||||
rect.height() / (item->unitFactor() * 10));
|
||||
}
|
||||
}
|
||||
|
||||
QString LimeReport::RectUnitPropItem::unitShortName() const
|
||||
{
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object());
|
||||
switch (item->unitType()) {
|
||||
case LimeReport::BaseDesignIntf::Millimeters:
|
||||
return QObject::tr("mm");
|
||||
case LimeReport::BaseDesignIntf::Inches:
|
||||
return QObject::tr("''");
|
||||
}
|
||||
}
|
||||
|
@@ -43,28 +43,35 @@ public:
|
||||
QString displayValue() const;
|
||||
};
|
||||
|
||||
class RectMMPropItem : public ObjectPropItem{
|
||||
class RectUnitPropItem : public ObjectPropItem{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RectMMPropItem():ObjectPropItem(){}
|
||||
RectMMPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true);
|
||||
RectUnitPropItem():ObjectPropItem(){}
|
||||
RectUnitPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true);
|
||||
QString displayValue() const;
|
||||
public slots:
|
||||
void itemPosChanged(QObject* /*object*/, QPointF newPos, QPointF oldPos);
|
||||
void itemGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
|
||||
private:
|
||||
void setValue(const QString& propertyName, qreal propertyValue);
|
||||
void setValue(const QString& propertyName, qreal propertyValue);
|
||||
QRectF rectInUnits(QRectF rect) const;
|
||||
QString unitShortName() const;
|
||||
};
|
||||
|
||||
class RectMMValuePropItem : public ObjectPropItem{
|
||||
class RectUnitValuePropItem : public ObjectPropItem{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RectMMValuePropItem():ObjectPropItem(){}
|
||||
RectMMValuePropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly );
|
||||
RectUnitValuePropItem():ObjectPropItem(){}
|
||||
RectUnitValuePropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly );
|
||||
QString displayValue() const;
|
||||
QWidget* createProperyEditor(QWidget *) const;
|
||||
void setPropertyEditorData(QWidget *, const QModelIndex &) const;
|
||||
void setModelData(QWidget *, QAbstractItemModel *, const QModelIndex &);
|
||||
private:
|
||||
qreal valueInUnits(qreal value) const;
|
||||
qreal valueInReportUnits(qreal value) const;
|
||||
QString unitShortName() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user