0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
LimeReport/limereport/items/lrbarcodeitem.cpp

362 lines
11 KiB
C++
Raw Permalink Normal View History

2016-02-17 10:11:00 +03:00
/***************************************************************************
* This file is part of the Lime Report project *
2021-08-18 20:21:36 +03:00
* Copyright (C) 2021 by Alexander Arin *
2016-02-17 10:11:00 +03:00
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrbarcodeitem.h"
2016-02-17 10:11:00 +03:00
#include "lrdesignelementsfactory.h"
#include "lrglobal.h"
#include "qzint.h"
2016-02-17 10:11:00 +03:00
namespace {
2016-02-17 10:11:00 +03:00
const QString xmlTag = "BarcodeItem";
LimeReport::BaseDesignIntf* createBarcodeItem(QObject* owner, LimeReport::BaseDesignIntf* parent)
{
return new LimeReport::BarcodeItem(owner, parent);
}
bool VARIABLE_IS_NOT_USED registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, LimeReport::ItemAttribs(QObject::tr("Barcode Item"), "Item"), createBarcodeItem);
} // namespace
namespace LimeReport {
BarcodeItem::BarcodeItem(QObject* owner, QGraphicsItem* parent):
ContentItemDesignIntf(xmlTag, owner, parent),
m_designTestValue("1"),
m_barcodeType(CODE128),
m_foregroundColor(Qt::black),
m_backgroundColor(Qt::white),
m_whitespace(10),
m_angle(Angle0),
m_barcodeWidth(0),
m_securityLevel(0),
m_pdf417CodeWords(928),
m_inputMode(UNICODE_INPUT_MODE),
m_hideText(false),
m_option3(0),
m_hideIfEmpty(false)
{
2016-02-17 10:11:00 +03:00
}
BarcodeItem::~BarcodeItem() { }
2016-02-17 10:11:00 +03:00
BaseDesignIntf* BarcodeItem::createSameTypeItem(QObject* owner, QGraphicsItem* parent)
2016-02-17 10:11:00 +03:00
{
return new BarcodeItem(owner, parent);
2016-02-17 10:11:00 +03:00
}
void BarcodeItem::paint(QPainter* ppainter, const QStyleOptionGraphicsItem* option, QWidget* widget)
2016-02-17 10:11:00 +03:00
{
ppainter->save();
Zint::QZint bc;
if (itemMode() & DesignMode)
bc.setText(m_designTestValue);
else
bc.setText(m_content);
bc.setInputMode(m_inputMode);
2016-02-17 10:11:00 +03:00
bc.setSymbol(m_barcodeType);
bc.setWhitespace(m_whitespace);
bc.setFgColor(m_foregroundColor);
bc.setBgColor(m_backgroundColor);
bc.setWidth(m_barcodeWidth);
bc.setSecurityLevel(m_securityLevel);
bc.setPdf417CodeWords(m_pdf417CodeWords);
bc.setHideText(m_hideText);
bc.setOption3(m_option3);
2016-02-17 10:11:00 +03:00
if (isSelected())
ppainter->setOpacity(Const::SELECTION_OPACITY);
2016-02-17 10:11:00 +03:00
QRectF bcRect;
switch (m_angle) {
case Angle0:
bcRect = rect();
break;
case Angle90:
ppainter->translate(width(), 0);
2016-02-17 10:11:00 +03:00
ppainter->rotate(90);
bcRect = QRectF(0, 0, height(), width());
2016-02-17 10:11:00 +03:00
break;
case Angle180:
bcRect = rect();
ppainter->translate(width(), height());
2016-02-17 10:11:00 +03:00
ppainter->rotate(180);
break;
case Angle270:
ppainter->translate(0, height());
2016-02-17 10:11:00 +03:00
ppainter->rotate(270);
bcRect = QRectF(0, 0, height(), width());
2016-02-17 10:11:00 +03:00
break;
}
bc.render(*ppainter, bcRect);
2016-02-17 10:11:00 +03:00
ppainter->restore();
ItemDesignIntf::paint(ppainter, option, widget);
2016-02-17 10:11:00 +03:00
}
void BarcodeItem::setContent(const QString& content)
2016-02-17 10:11:00 +03:00
{
if (m_content != content) {
2016-02-17 10:11:00 +03:00
QString oldValue = m_content;
m_content = content;
2016-02-17 10:11:00 +03:00
update();
notify("content", oldValue, m_content);
2016-02-17 10:11:00 +03:00
}
}
QString BarcodeItem::datasource() const { return m_datasource; }
void BarcodeItem::setDatasource(const QString& datasource)
{
if (m_datasource != datasource) {
QString oldValue = m_datasource;
m_datasource = datasource;
update();
notify("datasource", oldValue, datasource);
}
}
QString BarcodeItem::field() const { return m_field; }
void BarcodeItem::setField(const QString& field)
{
if (m_field != field) {
QString oldValue = m_field;
m_field = field;
update();
notify("field", oldValue, field);
}
}
2016-02-17 10:11:00 +03:00
void BarcodeItem::setBarcodeType(BarcodeItem::BarcodeType value)
{
if (m_barcodeType != value) {
2016-02-17 10:11:00 +03:00
BarcodeType oldValue = m_barcodeType;
m_barcodeType = value;
update();
notify("barcodeType", oldValue, value);
2016-02-17 10:11:00 +03:00
}
}
void BarcodeItem::setDesignTestValue(QString value)
{
if (m_designTestValue != value) {
2016-02-17 10:11:00 +03:00
QString oldValue = m_designTestValue;
m_designTestValue = value;
2016-02-17 10:11:00 +03:00
update();
notify("testValue", oldValue, value);
2016-02-17 10:11:00 +03:00
}
}
void BarcodeItem::setForegroundColor(QColor value)
{
if (m_foregroundColor != value) {
2016-02-17 10:11:00 +03:00
QColor oldValue = m_foregroundColor;
m_foregroundColor = value;
2016-02-17 10:11:00 +03:00
update();
notify("foregroundColor", oldValue, value);
2016-02-17 10:11:00 +03:00
}
}
void BarcodeItem::setBackgroundColor(QColor value)
{
if (m_backgroundColor != value) {
2016-02-17 10:11:00 +03:00
QColor oldValue = m_backgroundColor;
m_backgroundColor = value;
2016-02-17 10:11:00 +03:00
update();
notify("backgroundColor", oldValue, value);
2016-02-17 10:11:00 +03:00
}
}
void BarcodeItem::setWhitespace(int value)
{
if (m_whitespace != value) {
2016-02-17 10:11:00 +03:00
int oldValue = m_whitespace;
m_whitespace = value;
update();
notify("whitespace", oldValue, value);
2016-02-17 10:11:00 +03:00
}
}
BarcodeItem::AngleType BarcodeItem::angle() const { return m_angle; }
2016-02-17 10:11:00 +03:00
void BarcodeItem::setAngle(const AngleType& angle)
2016-02-17 10:11:00 +03:00
{
if (m_angle != angle) {
2016-02-17 10:11:00 +03:00
AngleType oldValue = m_angle;
m_angle = angle;
if (!isLoading()) {
2016-02-17 10:11:00 +03:00
update();
notify("angle", oldValue, angle);
2016-02-17 10:11:00 +03:00
}
}
}
int BarcodeItem::barcodeWidth() const { return m_barcodeWidth; }
2016-02-17 10:11:00 +03:00
void BarcodeItem::setBarcodeWidth(int barcodeWidth)
{
if (m_barcodeWidth != barcodeWidth) {
2016-02-17 10:11:00 +03:00
int oldValue = m_barcodeWidth;
m_barcodeWidth = barcodeWidth;
if (!isLoading()) {
2016-02-17 10:11:00 +03:00
update();
notify("barcodeWidth", oldValue, m_barcodeWidth);
2016-02-17 10:11:00 +03:00
}
}
}
int BarcodeItem::securityLevel() const { return m_securityLevel; }
2016-02-17 10:11:00 +03:00
void BarcodeItem::setSecurityLevel(int securityLevel)
{
if (m_securityLevel != securityLevel) {
2016-02-17 10:11:00 +03:00
int oldValue = m_securityLevel;
m_securityLevel = securityLevel;
if (!isLoading()) {
2016-02-17 10:11:00 +03:00
update();
notify("securityLevel", oldValue, m_securityLevel);
2016-02-17 10:11:00 +03:00
}
}
}
int BarcodeItem::pdf417CodeWords() const { return m_pdf417CodeWords; }
2016-02-17 10:11:00 +03:00
void BarcodeItem::setPdf417CodeWords(int pdf417CodeWords)
{
if (m_pdf417CodeWords != pdf417CodeWords) {
2016-02-17 10:11:00 +03:00
int oldValue = m_pdf417CodeWords;
m_pdf417CodeWords = pdf417CodeWords;
if (!isLoading()) {
2016-02-17 10:11:00 +03:00
update();
notify("pdf417CodeWords", oldValue, m_pdf417CodeWords);
2016-02-17 10:11:00 +03:00
}
}
}
BarcodeItem::InputMode BarcodeItem::inputMode() const { return m_inputMode; }
void BarcodeItem::setInputMode(const InputMode& inputMode)
{
if (m_inputMode != inputMode) {
InputMode oldValue = m_inputMode;
m_inputMode = inputMode;
if (!isLoading()) {
update();
notify("inputMode", oldValue, inputMode);
}
}
}
bool BarcodeItem::hideText() const { return m_hideText; }
void BarcodeItem::setHideText(bool hideText)
{
if (m_hideText != hideText) {
m_hideText = hideText;
if (!isLoading()) {
update();
notify("hideText", !m_hideText, m_hideText);
}
}
}
int BarcodeItem::option3() const { return m_option3; }
void BarcodeItem::setOption3(int option3)
{
if (m_option3 != option3) {
int oldValue = m_option3;
m_option3 = option3;
if (!isLoading()) {
update();
notify("option3", oldValue, m_option3);
}
}
}
bool BarcodeItem::hideIfEmpty() const { return m_hideIfEmpty; }
void BarcodeItem::setHideIfEmpty(bool hideIfEmpty)
{
if (m_hideIfEmpty != hideIfEmpty) {
m_hideIfEmpty = hideIfEmpty;
notify("hideIfEmpty", !m_hideIfEmpty, m_hideIfEmpty);
}
}
bool BarcodeItem::isEmpty() const { return m_content.isEmpty(); }
void BarcodeItem::expandContent(QString data, DataSourceManager* dataManager, RenderPass pass)
{
setContent(expandUserVariables(data, pass, NoEscapeSymbols, dataManager));
setContent(expandScripts(content(), dataManager));
setContent(expandDataFields(content(), NoEscapeSymbols, dataManager));
}
2016-02-17 10:28:27 +03:00
void BarcodeItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
2016-02-17 10:11:00 +03:00
{
if (content().isEmpty()) {
if (!m_datasource.isEmpty() && !m_field.isEmpty()) {
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
if (data.isValid()) {
switch (pass) {
case FirstPass:
expandContent(data.toString(), dataManager, pass);
break;
default:;
}
}
}
}
} else {
switch (pass) {
case FirstPass:
expandContent(content(), dataManager, pass);
break;
default:;
}
2016-02-17 10:11:00 +03:00
}
2016-02-17 10:28:27 +03:00
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
if (isEmpty() && hideIfEmpty())
setVisible(false);
2016-02-17 10:11:00 +03:00
}
bool BarcodeItem::isNeedUpdateSize(RenderPass pass) const
{
return (pass == FirstPass) ? true : false;
2016-02-17 10:11:00 +03:00
}
} // namespace LimeReport