#include "lrmarginpropitem.h" #include #include #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(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() * item->ppm()) / (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::max()); editor->setMinimum(std::numeric_limits::max()*-1); editor->setSuffix(" "+unitShortName()); return editor; } void MarginPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const { QDoubleSpinBox *editor =qobject_cast(propertyEditor); editor->setValue(valueInUnits(propertyValue().toReal())); } void MarginPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index) { model->setData(index, valueInReportUnits(qobject_cast(propertyEditor)->value())); setValueToObject(propertyName(), propertyValue()); } qreal MarginPropItem::valueInUnits(qreal value) const { BaseDesignIntf* item = dynamic_cast(object()); switch (item->unitType()) { case LimeReport::BaseDesignIntf::Millimeters: return value; case LimeReport::BaseDesignIntf::Inches: return (value * item->ppm()) / (item->unitFactor() * 10); } } qreal MarginPropItem::valueInReportUnits(qreal value) const { BaseDesignIntf* item = dynamic_cast(object()); switch (item->unitType()) { case LimeReport::BaseDesignIntf::Millimeters: return value; case LimeReport::BaseDesignIntf::Inches: return (value * (item->unitFactor() * 10)) / item->ppm(); } } QString MarginPropItem::unitShortName() const { BaseDesignIntf* item = dynamic_cast(object()); switch (item->unitType()) { case LimeReport::BaseDesignIntf::Millimeters: return QObject::tr("mm"); case LimeReport::BaseDesignIntf::Inches: return QObject::tr("''"); } } } // namespace LimeReport