0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00
LimeReport/limereport/bands/lrgroupbands.cpp

210 lines
7.6 KiB
C++
Raw 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 "lrgroupbands.h"
2016-02-17 10:11:00 +03:00
#include "lrdatasourcemanager.h"
#include "lrglobal.h"
2016-02-17 10:11:00 +03:00
const QString xmlTagHeader = QLatin1String("GroupHeader");
const QString xmlTagFooter = QLatin1String("GroupFooter");
namespace {
2016-02-17 10:11:00 +03:00
LimeReport::BaseDesignIntf* createHeader(QObject* owner, LimeReport::BaseDesignIntf* parent)
{
return new LimeReport::GroupBandHeader(owner, parent);
2016-02-17 10:11:00 +03:00
}
bool VARIABLE_IS_NOT_USED registredHeader
= LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagHeader,
LimeReport::ItemAttribs(QObject::tr("GroupHeader"), LimeReport::Const::bandTAG),
createHeader);
2016-02-17 10:11:00 +03:00
LimeReport::BaseDesignIntf* createFooter(QObject* owner, LimeReport::BaseDesignIntf* parent)
{
return new LimeReport::GroupBandFooter(owner, parent);
2016-02-17 10:11:00 +03:00
}
bool VARIABLE_IS_NOT_USED registredFooter
= LimeReport::DesignElementsFactory::instance().registerCreator(
2016-02-17 10:11:00 +03:00
xmlTagFooter,
LimeReport::ItemAttribs(QObject::tr("GroupFooter"), LimeReport::Const::bandTAG),
createFooter);
2016-02-17 10:11:00 +03:00
} // namespace
2016-02-17 10:11:00 +03:00
namespace LimeReport {
2016-02-17 10:11:00 +03:00
GroupBandHeader::GroupBandHeader(QObject* owner, QGraphicsItem* parent):
BandDesignIntf(BandDesignIntf::GroupHeader, xmlTagHeader, owner, parent),
m_groupFiledName(""),
m_groupStarted(false),
m_resetPageNumber(false)
2016-02-17 10:11:00 +03:00
{
setBandTypeText(tr("GroupHeader"));
setFixedPos(false);
setMarkerColor(bandColor());
}
bool GroupBandHeader::isUnique() const { return false; }
2016-02-17 10:11:00 +03:00
// bool GroupBandHeader::tryToKeepTogether()
2016-02-17 10:11:00 +03:00
//{
// return m_tryToKeepTogether;
//}
BaseDesignIntf* GroupBandHeader::createSameTypeItem(QObject* owner, QGraphicsItem* parent)
2016-02-17 10:11:00 +03:00
{
return new GroupBandHeader(owner, parent);
}
2016-02-17 10:28:27 +03:00
void GroupBandHeader::startGroup(DataSourceManager* dataManager)
2016-02-17 10:11:00 +03:00
{
m_groupStarted = true;
2016-02-17 10:18:19 +03:00
QString lineVar = QLatin1String("line_") + objectName().toLower();
dataManager->setReportVariable(lineVar, 1);
2016-02-17 10:18:19 +03:00
QString datasourceName = findDataSourceName(parentBand());
if (dataManager->containsDatasource(datasourceName)) {
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds && ds->columnIndexByName(m_groupFiledName) != -1)
m_groupFieldValue = ds->data(m_groupFiledName);
2016-02-17 10:11:00 +03:00
}
if (!m_condition.isEmpty())
m_conditionValue = calcCondition(dataManager);
2016-02-17 10:11:00 +03:00
}
QColor GroupBandHeader::bandColor() const { return QColor(Qt::darkBlue); }
2016-02-17 10:11:00 +03:00
QString GroupBandHeader::findDataSourceName(BandDesignIntf* parentBand)
{
if (!parentBand)
return "";
if (!parentBand->datasourceName().isEmpty())
return parentBand->datasourceName();
else
return findDataSourceName(parentBand->parentBand());
}
QString GroupBandHeader::condition() const { return m_condition; }
void GroupBandHeader::setCondition(const QString& condition) { m_condition = condition; }
QString GroupBandHeader::calcCondition(DataSourceManager* dataManager)
{
QString result = m_condition;
if (!m_condition.isEmpty()) {
result = expandUserVariables(result, FirstPass, NoEscapeSymbols, dataManager);
result = expandScripts(result, dataManager);
result = expandDataFields(result, NoEscapeSymbols, dataManager);
}
return result;
}
2016-02-17 10:28:27 +03:00
bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager)
2016-02-17 10:11:00 +03:00
{
if (!m_groupStarted)
return false;
if ((m_groupFiledName.isNull() || m_groupFiledName.isEmpty()) && condition().isEmpty()) {
dataManager->putError(tr("Group field not found"));
return false;
}
if (!m_condition.isEmpty()) {
return m_conditionValue != calcCondition(dataManager);
} else {
QString datasourceName = findDataSourceName(parentBand());
if (dataManager->containsDatasource(datasourceName)) {
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds) {
if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull())
return false;
if (!ds->data(m_groupFiledName).isValid())
return false;
return ds->data(m_groupFiledName) != m_groupFieldValue;
}
} else {
2017-06-28 16:58:01 +03:00
dataManager->putError(tr("Datasource \"%1\" not found!").arg(datasourceName));
}
2016-02-17 10:11:00 +03:00
}
return false;
}
bool GroupBandHeader::isStarted()
{
return m_groupStarted; //! m_groupFieldValue.isNull();
2016-02-17 10:11:00 +03:00
}
void GroupBandHeader::closeGroup()
{
m_groupFieldValue = QVariant();
m_conditionValue = "";
m_groupStarted = false;
2016-02-17 10:11:00 +03:00
}
int GroupBandHeader::index() { return bandIndex(); }
2016-02-17 10:11:00 +03:00
bool GroupBandHeader::startNewPage() const { return BandDesignIntf::startNewPage(); }
2016-02-17 10:39:17 +03:00
void GroupBandHeader::setStartNewPage(bool startNewPage)
{
BandDesignIntf::setStartNewPage(startNewPage);
}
bool GroupBandHeader::resetPageNumber() const { return m_resetPageNumber; }
2016-02-17 10:28:27 +03:00
void GroupBandHeader::setResetPageNumber(bool resetPageNumber)
{
m_resetPageNumber = resetPageNumber;
}
GroupBandFooter::GroupBandFooter(QObject* owner, QGraphicsItem* parent):
BandDesignIntf(BandDesignIntf::GroupFooter, xmlTagFooter, owner, parent)
2016-02-17 10:11:00 +03:00
{
setBandTypeText(tr("GroupFooter"));
setFixedPos(false);
setMarkerColor(bandColor());
}
bool GroupBandFooter::isUnique() const { return false; }
2016-02-17 10:11:00 +03:00
QColor GroupBandFooter::bandColor() const { return QColor(Qt::darkBlue); }
2016-02-17 10:11:00 +03:00
BaseDesignIntf* GroupBandFooter::createSameTypeItem(QObject* owner, QGraphicsItem* parent)
2016-02-17 10:11:00 +03:00
{
return new GroupBandFooter(owner, parent);
2016-02-17 10:11:00 +03:00
}
} // namespace LimeReport