diff --git a/src/items/check/KReportItemCheck.h b/src/items/check/KReportItemCheck.h
index eef7a02e..9a8eaea9 100644
--- a/src/items/check/KReportItemCheck.h
+++ b/src/items/check/KReportItemCheck.h
@@ -1,63 +1,63 @@
/* This file is part of the KDE project
* Copyright (C) 2009-2010 by Adam Pigg (adam@piggz.co.uk)
*
* 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 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTITEMCHECKBOX_H
#define KREPORTITEMCHECKBOX_H
#include "KReportItemBase.h"
class QDomNode;
namespace Scripting
{
class CheckBox;
}
class KReportItemCheckBox : public KReportItemBase
{
Q_OBJECT
public:
KReportItemCheckBox();
explicit KReportItemCheckBox(const QDomNode &element);
virtual ~KReportItemCheckBox();
virtual QString typeName() const;
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
virtual QString itemDataSource()const;
protected:
KProperty * m_controlSource;
KProperty* m_checkStyle;
KProperty* m_foregroundColor;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_staticValue;
bool value() const;
- void setValue(bool);
+ void setValue(bool v);
KReportLineStyle lineStyle();
private:
virtual void createProperties();
friend class Scripting::CheckBox;
};
#endif // KREPORTITEMCHECKBOX_H
diff --git a/src/plugins/chart/KReportItemChart.h b/src/plugins/chart/KReportItemChart.h
index 2da8ef85..f6c6325f 100644
--- a/src/plugins/chart/KReportItemChart.h
+++ b/src/plugins/chart/KReportItemChart.h
@@ -1,116 +1,116 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* 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 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KRCHARTDATA_H
#define KRCHARTDATA_H
#include
#include "KReportItemBase.h"
#include "KReportSize.h"
#include "KReportPosition.h"
#include "KReportData.h"
namespace Scripting
{
class Chart;
}
/**
*/
class KReportItemChart : public KReportItemBase
{
Q_OBJECT
public:
KReportItemChart();
explicit KReportItemChart(QDomNode *element);
~KReportItemChart();
virtual QString typeName() const;
virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportData *data, KReportScriptHandler *script);
KDChart::Widget *widget() {
return m_chartWidget;
}
/**
@brief Perform the query for the chart and set the charts data
*/
void populateData();
void setConnection(const KReportData *c);
/**
@brief Set the value of a field from the master (report) data set
This data will be used when retrieving the data for the chart
as the values in a 'where' clause.
*/
void setLinkData(QString, QVariant);
/**
@brief Return the list of master fields
The caller will use this to set the current value for each field
at that stage in the report
*/
QStringList masterFields() const;
/**
@brief The chart object is a complex object that uses its own data source
@return true
*/
virtual bool supportsSubQuery() const { return true; }
protected:
KProperty * m_dataSource;
KProperty * m_font;
KProperty * m_chartType;
KProperty * m_chartSubType;
KProperty * m_threeD;
KProperty * m_colorScheme;
KProperty * m_aa;
KProperty * m_xTitle;
KProperty * m_yTitle;
KProperty *m_backgroundColor;
KProperty *m_displayLegend;
KProperty *m_legendPosition;
KProperty *m_legendOrientation;
KProperty *m_linkMaster;
KProperty *m_linkChild;
KDChart::Widget *m_chartWidget;
- void set3D(bool);
- void setAA(bool);
- void setColorScheme(const QString &);
- void setAxis(const QString&, const QString&);
+ void set3D(bool td);
+ void setAA(bool aa);
+ void setColorScheme(const QString &cs);
+ void setAxis(const QString &xa, const QString &ya);
void setBackgroundColor(const QColor&);
- void setLegend(bool, const QStringList &legends = QStringList());
+ void setLegend(bool le, const QStringList &legends = QStringList());
private:
virtual void createProperties();
const KReportData *m_reportData;
friend class Scripting::Chart;
QMap m_links; //Map of field->value for child/master links
};
#endif
diff --git a/src/plugins/chart/KReportScriptChart.h b/src/plugins/chart/KReportScriptChart.h
index a6987460..5b059a17 100644
--- a/src/plugins/chart/KReportScriptChart.h
+++ b/src/plugins/chart/KReportScriptChart.h
@@ -1,158 +1,158 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* 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 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef SCRIPTINGKRSCRIPTCHART_H
#define SCRIPTINGKRSCRIPTCHART_H
#include
#include
#include
#include
class KReportItemChart;
namespace Scripting
{
/**
*/
class Chart : public QObject
{
Q_OBJECT
public:
explicit Chart(KReportItemChart *);
~Chart();
public Q_SLOTS:
/**
* Get the position of the barcode
* @return position in points
*/
QPointF position();
/**
* Sets the position of the barcode in points
* @param Position
*/
void setPosition(const QPointF&);
/**
* Get the size of the barcode
* @return size in points
*/
QSizeF size();
/**
* Set the size of the barcode in points
* @param Size
*/
void setSize(const QSizeF&);
/**
* The data source for the chart
* @return Datasource
*/
QString dataSource();
/**
* Set the data source for the chart
* @param datasource
*/
void setDataSource(const QString &);
/**
* The 3d status of the chart
* @return 3d
*/
bool threeD();
/**
* Set the 3d status of the chart
* @param 3d
*/
- void setThreeD(bool);
+ void setThreeD(bool td);
/**
* The visibility status of the legend
* @return visibility
*/
bool legendVisible();
/**
* Sets the visibility of the legend
* @param visible
*/
- void setLegendVisible(bool);
+ void setLegendVisible(bool v);
/**
* The color scheme used by the chart
* @return scheme, 0=default, 2=rainbow 3=subdued
*/
int colorScheme();
/**
* Sets the colorscheme of the chart
* @param scheme 0=default, 2=rainbow 3=subdued
*/
void setColorScheme(int);
/**
* The background color of the chart
* @return backgroundcolor
*/
QColor backgroundColor();
/**
* Sets the background color of the chart
* @param backgroundcolor
*/
void setBackgroundColor(const QColor &);
/**
* The title of the X Axis
* @return xTitle
*/
QString xAxisTitle();
/**
* Set the title of the X Axis
* @param xTitle
*/
void setXAxisTitle(const QString &);
/**
* The title of the Y Axis
* @return yTitle
*/
QString yAxisTitle();
/**
* Set the title of the Y Axis
* @param yTitle
*/
void setYAxisTitle(const QString &);
private:
KReportItemChart* m_chart;
};
}
#endif
diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp
index 02c3c08f..4b66df1b 100644
--- a/src/renderer/KReportPreRenderer.cpp
+++ b/src/renderer/KReportPreRenderer.cpp
@@ -1,697 +1,697 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* 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 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportPreRenderer.h"
#include "KReportPreRenderer_p.h"
#include "KReportAsyncItemManager_p.h"
#include "KReportOneRecordDataSource_p.h"
#include "KReportRenderObjects.h"
#include "KReportDataSource.h"
#include "KReportItemBase.h"
#include "KReportDocument.h"
#include "KReportDetailSectionData.h"
#include "KReportLabelSizeInfo.h"
#include "KReportPageSize.h"
#include "KReportUtils_p.h"
#ifdef KREPORT_SCRIPTING
#include "scripting/KReportScriptHandler.h"
#include "scripting/KReportGroupTracker.h"
#endif
#include
#include
#include "kreport_debug.h"
KReportPreRendererPrivate::KReportPreRendererPrivate(KReportPreRenderer *preRenderer)
: m_preRenderer(preRenderer)
{
m_valid = false;
m_document = 0;
m_reportDocument = 0;
m_page = 0;
m_yOffset = 0.0;
m_topMargin = m_bottomMargin = 0.0;
m_leftMargin = m_rightMargin = 0.0;
m_pageCounter = 0;
m_maxHeight = m_maxWidth = 0.0;
m_oneRecord = new KReportPrivate::OneRecordDataSource();
m_dataSource = 0;
#ifdef KREPORT_SCRIPTING
m_scriptHandler = 0;
#endif
asyncManager = new KReportPrivate::AsyncItemManager(this);
connect(asyncManager, SIGNAL(finished()), this, SLOT(asyncItemsFinished()));
}
KReportPreRendererPrivate::~KReportPreRendererPrivate()
{
delete m_reportDocument;
delete m_document;
delete m_oneRecord;
m_postProcText.clear();
}
void KReportPreRendererPrivate::createNewPage()
{
//kreportDebug();
if (m_pageCounter > 0)
- finishCurPage();
+ finishCurPage(false);
m_pageCounter++;
#ifdef KREPORT_SCRIPTING
//Update the page count script value
m_scriptHandler->setPageNumber(m_pageCounter);
m_scriptHandler->newPage();
#endif
m_page = new OROPage(0);
m_document->addPage(m_page);
//! @todo calculate past page
bool lastPage = false;
m_yOffset = m_topMargin;
if (m_pageCounter == 1 && m_reportDocument->m_pageHeaderFirst)
renderSection(*(m_reportDocument->m_pageHeaderFirst));
else if (lastPage == true && m_reportDocument->m_pageHeaderLast)
renderSection(*(m_reportDocument->m_pageHeaderLast));
else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageHeaderOdd)
renderSection(*(m_reportDocument->m_pageHeaderOdd));
else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageHeaderAny)
renderSection(*(m_reportDocument->m_pageHeaderAny));
else if (m_reportDocument->m_pageHeaderAny)
renderSection(*(m_reportDocument->m_pageHeaderAny));
}
qreal KReportPreRendererPrivate::finishCurPageSize(bool lastPage)
{
qreal retval = 0.0;
if (lastPage && m_reportDocument->m_pageFooterLast)
retval = renderSectionSize(* (m_reportDocument->m_pageFooterLast));
else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst)
retval = renderSectionSize(* (m_reportDocument->m_pageFooterFirst));
else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd)
retval = renderSectionSize(* (m_reportDocument->m_pageFooterOdd));
else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven)
retval = renderSectionSize(* (m_reportDocument->m_pageFooterEven));
else if (m_reportDocument->m_pageFooterAny)
retval = renderSectionSize(* (m_reportDocument->m_pageFooterAny));
//kreportDebug() << retval;
return retval;
}
qreal KReportPreRendererPrivate::finishCurPage(bool lastPage)
{
qreal offset = m_maxHeight - m_bottomMargin;
qreal retval = 0.0;
//kreportDebug() << offset;
if (lastPage && m_reportDocument->m_pageFooterLast) {
//kreportDebug() << "Last Footer";
m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterLast));
retval = renderSection(* (m_reportDocument->m_pageFooterLast));
} else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) {
//kreportDebug() << "First Footer";
m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterFirst));
retval = renderSection(* (m_reportDocument->m_pageFooterFirst));
} else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) {
//kreportDebug() << "Odd Footer";
m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterOdd));
retval = renderSection(* (m_reportDocument->m_pageFooterOdd));
} else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) {
//kreportDebug() << "Even Footer";
m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterEven));
retval = renderSection(* (m_reportDocument->m_pageFooterEven));
} else if (m_reportDocument->m_pageFooterAny) {
//kreportDebug() << "Any Footer";
m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterAny));
retval = renderSection(* (m_reportDocument->m_pageFooterAny));
}
return retval;
}
void KReportPreRendererPrivate::renderDetailSection(KReportDetailSectionData *detailData)
{
if (detailData->m_detailSection) {
if (m_dataSource/* && !curs->eof()*/) {
QStringList keys;
QStringList keyValues;
QList shownGroups;
KReportDetailGroupSectionData * grp = 0;
bool status = m_dataSource->moveFirst();
int recordCount = m_dataSource->recordCount();
//kreportDebug() << "Record Count:" << recordCount;
for (int i = 0; i < (int) detailData->m_groupList.count(); ++i) {
grp = detailData->m_groupList[i];
//If the group has a header or footer, then emit a change of group value
if(grp->m_groupFooter || grp->m_groupHeader) {
// we get here only if group is *shown*
shownGroups << i;
keys.append(grp->m_column);
if (!keys.last().isEmpty())
keyValues.append(m_dataSource->value(m_dataSource->fieldNumber(keys.last())).toString());
else
keyValues.append(QString());
//Tell interested parties we're about to render a header
emit(enteredGroup(keys.last(), keyValues.last()));
}
if (grp->m_groupHeader)
renderSection(*(grp->m_groupHeader));
}
while (status) {
const qint64 pos = m_dataSource->at();
//kreportDebug() << "At:" << l << "Y:" << m_yOffset << "Max Height:" << m_maxHeight;
if ((renderSectionSize(*detailData->m_detailSection)
+ finishCurPageSize((pos + 1 == recordCount))
+ m_bottomMargin + m_yOffset) >= m_maxHeight)
{
//kreportDebug() << "Next section is too big for this page";
if (pos > 0) {
m_dataSource->movePrevious();
createNewPage();
m_dataSource->moveNext();
}
}
renderSection(*(detailData->m_detailSection));
if (m_dataSource)
status = m_dataSource->moveNext();
if (status == true && keys.count() > 0) {
// check to see where it is we need to start
int pos = -1; // if it's still -1 by the time we are done then no keyValues changed
for (int i = 0; i < keys.count(); ++i) {
if (keyValues[i] != m_dataSource->value(m_dataSource->fieldNumber(keys[i])).toString()) {
pos = i;
break;
}
}
// don't bother if nothing has changed
if (pos != -1) {
// roll back the query and go ahead if all is good
status = m_dataSource->movePrevious();
if (status == true) {
// print the footers as needed
// any changes made in this for loop need to be duplicated
// below where the footers are finished.
bool do_break = false;
for (int i = shownGroups.count() - 1; i >= 0; i--) {
if (do_break)
createNewPage();
do_break = false;
grp = detailData->m_groupList[shownGroups.at(i)];
if (grp->m_groupFooter) {
- if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight)
+ if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight)
createNewPage();
renderSection(*(grp->m_groupFooter));
}
if (KReportDetailGroupSectionData::BreakAfterGroupFooter == grp->m_pagebreak)
do_break = true;
}
// step ahead to where we should be and print the needed headers
// if all is good
status = m_dataSource->moveNext();
if (do_break)
createNewPage();
if (status == true) {
for (int i = 0; i < shownGroups.count(); ++i) {
grp = detailData->m_groupList[shownGroups.at(i)];
if (grp->m_groupHeader) {
- if (renderSectionSize(*(grp->m_groupHeader)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) {
+ if (renderSectionSize(*(grp->m_groupHeader)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight) {
m_dataSource->movePrevious();
createNewPage();
m_dataSource->moveNext();
}
if (!keys[i].isEmpty())
keyValues[i] = m_dataSource->value(m_dataSource->fieldNumber(keys[i])).toString();
//Tell interested parties thak key values changed
renderSection(*(grp->m_groupHeader));
}
}
}
}
}
}
}
if (keys.size() > 0 && m_dataSource->movePrevious()) {
// finish footers
// duplicated changes from above here
for (int i = shownGroups.count() - 1; i >= 0; i--) {
grp = detailData->m_groupList[shownGroups.at(i)];
if (grp->m_groupFooter) {
- if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight)
+ if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight)
createNewPage();
renderSection(*(grp->m_groupFooter));
emit(exitedGroup(keys[i], keyValues[i]));
}
}
}
}
if (KReportDetailSectionData::BreakAtEnd == detailData->m_pageBreak)
createNewPage();
}
}
qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & sectionData)
{
qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX();
int itemHeight = 0;
if (sectionData.objects().count() == 0)
return intHeight;
QList objects = sectionData.objects();
foreach(KReportItemBase *ob, objects) {
QPointF offset(m_leftMargin, m_yOffset);
QVariant itemData = m_dataSource->value(ob->itemDataSource());
//ASync objects cannot alter the section height
KReportAsyncItemBase *async_ob = qobject_cast(ob);
if (!async_ob) {
itemHeight = ob->renderSimpleData(0, 0, offset, itemData, m_scriptHandler);
if (itemHeight > intHeight) {
intHeight = itemHeight;
}
}
}
return intHeight;
}
qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & sectionData)
{
qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX();
int itemHeight = 0;
//kreportDebug() << "Name: " << sectionData.name() << " Height: " << sectionHeight
// << "Objects: " << sectionData.objects().count();
emit(renderingSection(const_cast(§ionData), m_page, QPointF(m_leftMargin, m_yOffset)));
//Create a pre-rendered section for this section and add it to the document
OROSection *sec = new OROSection(m_document);
sec->setHeight(sectionData.height());
sec->setBackgroundColor(sectionData.backgroundColor());
sec->setType(sectionData.type());
m_document->addSection(sec);
//Render section background
ORORect* bg = new ORORect();
bg->setPen(QPen(Qt::NoPen));
bg->setBrush(sectionData.backgroundColor());
qreal w = m_page->document()->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportPrivate::dpiX()).right() - m_leftMargin;
bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight));
m_page->insertPrimitive(bg, true);
QList objects = sectionData.objects();
foreach(KReportItemBase *ob, objects) {
QPointF offset(m_leftMargin, m_yOffset);
QVariant itemData = m_dataSource->value(ob->itemDataSource());
if (ob->supportsSubQuery()) {
itemHeight = ob->renderReportData(m_page, sec, offset, m_dataSource, m_scriptHandler);
} else {
KReportAsyncItemBase *async_ob = qobject_cast(ob);
if (async_ob){
//kreportDebug() << "async object";
asyncManager->addItem(async_ob, m_page, sec, offset, itemData, m_scriptHandler);
} else {
//kreportDebug() << "sync object";
itemHeight = ob->renderSimpleData(m_page, sec, offset, itemData, m_scriptHandler);
}
}
if (itemHeight > sectionHeight) {
sectionHeight = itemHeight;
}
}
for (int i = 0; i < m_page->primitiveCount(); ++i) {
OROPrimitive *prim = m_page->primitive(i);
if (OROTextBox *text = dynamic_cast(prim)) {
if (text->requiresPostProcessing()) {
m_postProcText.append(text);
}
}
}
m_yOffset += sectionHeight;
return sectionHeight;
}
#ifdef KREPORT_SCRIPTING
void KReportPreRendererPrivate::initEngine()
{
delete m_scriptHandler;
m_scriptHandler = new KReportScriptHandler(m_dataSource, m_reportDocument);
connect(this, SIGNAL(enteredGroup(QString,QVariant)), m_scriptHandler, SLOT(slotEnteredGroup(QString,QVariant)));
connect(this, SIGNAL(exitedGroup(QString,QVariant)), m_scriptHandler, SLOT(slotExitedGroup(QString,QVariant)));
connect(this, SIGNAL(renderingSection(KReportSectionData*,OROPage*,QPointF)), m_scriptHandler, SLOT(slotEnteredSection(KReportSectionData*,OROPage*,QPointF)));
}
#endif
void KReportPreRendererPrivate::asyncItemsFinished()
{
//kreportDebug() << "Finished rendering async items";
asyncManager->deleteLater();
emit finishedAllASyncItems();
}
bool KReportPreRendererPrivate::generateDocument()
{
if (!m_dataSource) {
m_dataSource = m_oneRecord;
}
if (!m_valid || !m_reportDocument) {
return false;
}
// Do this check now so we don't have to undo a lot of work later if it fails
KReportLabelSizeInfo label;
if (m_reportDocument->pageSize() == QLatin1String("Labels")) {
label = KReportLabelSizeInfo::find(m_reportDocument->labelType());
if (label.isNull()) {
return false;
}
}
//kreportDebug() << "Creating Document";
m_document = new ORODocument(m_reportDocument->title());
m_pageCounter = 0;
m_yOffset = 0.0;
//kreportDebug() << "Calculating Margins";
if (!label.isNull()) {
if (m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) {
m_topMargin = (label.startY() / 100.0);
m_bottomMargin = 0;
m_rightMargin = 0;
m_leftMargin = (label.startX() / 100.0);
} else {
m_topMargin = (label.startX() / 100.0);
m_bottomMargin = 0;
m_rightMargin = 0;
m_leftMargin = (label.startY() / 100.0);
}
} else {
m_topMargin = m_reportDocument->pageLayout().marginsPoints().top();
m_bottomMargin = m_reportDocument->pageLayout().marginsPoints().bottom();
m_rightMargin = m_reportDocument->pageLayout().marginsPoints().right();
m_leftMargin = m_reportDocument->pageLayout().marginsPoints().left();
//kreportDebug() << "Margins:" << m_topMargin << m_bottomMargin << m_rightMargin << m_leftMargin;
}
//kreportDebug() << "Calculating Page Size";
QPageLayout layout = m_reportDocument->pageLayout();
// This should reflect the information of the report page size
if (m_reportDocument->pageSize() == QLatin1String("Custom")) {
m_maxWidth = m_reportDocument->pageLayout().fullRectPoints().width();
m_maxHeight = m_reportDocument->pageLayout().fullRectPoints().height();
} else {
if (!label.isNull()) {
m_maxWidth = label.width();
m_maxHeight = label.height();
m_reportDocument->pageLayout().setPageSize(QPageSize(KReportPageSize::pageSize(label.paper())));
} else {
// lookup the correct size information for the specified size paper
QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).size();
m_maxWidth = pageSizePx.width();
m_maxHeight = pageSizePx.height();
}
}
if (m_reportDocument->pageLayout().orientation() == QPageLayout::Landscape) {
qreal tmp = m_maxWidth;
m_maxWidth = m_maxHeight;
m_maxHeight = tmp;
}
//kreportDebug() << "Page Size:" << m_maxWidth << m_maxHeight;
m_document->setPageLayout(m_reportDocument->pageLayout());
m_dataSource->setSorting(m_reportDocument->m_detailSection->m_sortedFields);
if (!m_dataSource->open()) {
return false;
}
#ifdef KREPORT_SCRIPTING
initEngine();
connect(m_scriptHandler, SIGNAL(groupChanged(QMap)),
m_preRenderer, SIGNAL(groupChanged(QMap)));
//Loop through all abjects that have been registered, and register them with the script handler
if (m_scriptHandler) {
QMapIterator i(m_scriptObjects);
while (i.hasNext()) {
i.next();
m_scriptHandler->registerScriptObject(i.value(), i.key());
}
//execute the script, if it fails, abort and return the empty document
if (!m_scriptHandler->trigger()) {
m_scriptHandler->displayErrors();
return m_document;
}
}
#endif
createNewPage();
if (!label.isNull()) {
// Label Print Run
// remember the initial margin setting as we will be modifying
// the value and restoring it as we move around
qreal margin = m_leftMargin;
m_yOffset = m_topMargin;
qreal w = (label.width() / 100.0);
qreal wg = (label.xGap() / 100.0);
qreal h = (label.height() / 100.0);
qreal hg = (label.yGap() / 100.0);
int numCols = label.columns();
int numRows = label.rows();
qreal tmp;
// flip the value around if we are printing landscape
if (!m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) {
w = (label.height() / 100.0);
wg = (label.yGap() / 100.0);
h = (label.width() / 100.0);
hg = (label.xGap() / 100.0);
numCols = label.rows();
numRows = label.columns();
}
KReportDetailSectionData * detailData = m_reportDocument->m_detailSection;
if (detailData->m_detailSection) {
KReportDataSource *mydata = m_dataSource;
if (mydata && mydata->recordCount() > 0) { /* && !((query = orqThis->getQuery())->eof()))*/
if (!mydata->moveFirst()) {
return false;
}
int row = 0;
int col = 0;
do {
tmp = m_yOffset; // store the value as renderSection changes it
renderSection(*(detailData->m_detailSection));
m_yOffset = tmp; // restore the value that renderSection modified
col++;
m_leftMargin += w + wg;
if (col >= numCols) {
m_leftMargin = margin; // reset back to original value
col = 0;
row++;
m_yOffset += h + hg;
if (row >= numRows) {
m_yOffset = m_topMargin;
row = 0;
createNewPage();
}
}
} while (mydata->moveNext());
}
}
} else {
// Normal Print Run
if (m_reportDocument->m_reportHeader) {
renderSection(*(m_reportDocument->m_reportHeader));
}
if (m_reportDocument->m_detailSection) {
renderDetailSection(m_reportDocument->m_detailSection);
}
if (m_reportDocument->m_reportFooter) {
if (renderSectionSize(*(m_reportDocument->m_reportFooter)) + finishCurPageSize(true) + m_bottomMargin + m_yOffset >= m_maxHeight) {
createNewPage();
}
renderSection(*(m_reportDocument->m_reportFooter));
}
}
finishCurPage(true);
#ifdef KREPORT_SCRIPTING
// _postProcText contains those text boxes that need to be updated
// with information that wasn't available at the time it was added to the document
m_scriptHandler->setPageTotal(m_document->pageCount());
for (int i = 0; i < m_postProcText.size(); i++) {
OROTextBox * tb = m_postProcText.at(i);
m_scriptHandler->setPageNumber(tb->page()->pageNumber() + 1);
tb->setText(m_scriptHandler->evaluate(tb->text()).toString());
}
#endif
asyncManager->startRendering();
#ifdef KREPORT_SCRIPTING
m_scriptHandler->displayErrors();
#endif
if (!m_dataSource->close()) {
return false;
}
#ifdef KREPORT_SCRIPTING
delete m_scriptHandler;
m_scriptHandler = 0;
#endif
if (m_dataSource != m_oneRecord) {
delete m_dataSource;
m_dataSource = 0;
}
m_postProcText.clear();
return true;
}
//===========================KReportPreRenderer===============================
KReportPreRenderer::KReportPreRenderer(const QDomElement &document) : d(new KReportPreRendererPrivate(this))
{
setDocument(document);
connect(d, &KReportPreRendererPrivate::finishedAllASyncItems, this, &KReportPreRenderer::finishedAllASyncItems);
}
KReportPreRenderer::~KReportPreRenderer()
{
delete d;
}
void KReportPreRenderer::setName(const QString &n)
{
d->m_reportDocument->setName(n);
}
bool KReportPreRenderer::isValid() const
{
if (d && d->m_valid)
return true;
return false;
}
ORODocument* KReportPreRenderer::document()
{
return d->m_document;
}
bool KReportPreRenderer::generateDocument()
{
// delete d->m_document;
if (!d->generateDocument()) {
delete d->m_document;
d->m_document = 0;
}
return d->m_document;
}
void KReportPreRenderer::setSourceData(KReportDataSource *dataSource)
{
if (d && dataSource != d->m_dataSource) {
delete d->m_dataSource;
d->m_dataSource = dataSource;
}
}
bool KReportPreRenderer::setDocument(const QDomElement &document)
{
delete d->m_document;
d->m_valid = false;
if (document.tagName() != QLatin1String("report:content")) {
kreportWarning() << "report schema is invalid";
return false;
}
d->m_reportDocument = new KReportDocument(document);
d->m_valid = d->m_reportDocument->isValid();
return isValid();
}
#ifdef KREPORT_SCRIPTING
void KReportPreRenderer::registerScriptObject(QObject* obj, const QString& name)
{
//kreportDebug() << name;
d->m_scriptObjects[name] = obj;
}
KReportScriptHandler *KReportPreRenderer::scriptHandler()
{
return d->m_scriptHandler;
}
#endif
const KReportDocument* KReportPreRenderer::reportData() const
{
return d->m_reportDocument;
}
diff --git a/src/renderer/KReportPreRenderer_p.h b/src/renderer/KReportPreRenderer_p.h
index 14475df6..dd658a31 100644
--- a/src/renderer/KReportPreRenderer_p.h
+++ b/src/renderer/KReportPreRenderer_p.h
@@ -1,101 +1,101 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* 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 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTPRERENDERER_P_H
#define KREPORTPRERENDERER_P_H
#include "config-kreport.h"
#include "KReportRenderObjects.h"
#include "KReportAsyncItemManager_p.h"
#include "KReportDetailSectionData.h"
#include
namespace KReportPrivate{
class OneRecordDataSource;
}
class KReportPreRenderer;
/*! This class is the private class that houses all the internal
variables so we can provide a cleaner interface to the user
without presenting to them things that they don't need to see
and may change over time. */
class KReportPreRendererPrivate : public QObject
{
Q_OBJECT
public:
KReportPreRendererPrivate(KReportPreRenderer *preRenderer);
virtual ~KReportPreRendererPrivate();
KReportPreRenderer * const m_preRenderer;
bool m_valid;
ORODocument* m_document;
OROPage* m_page;
KReportDocument* m_reportDocument;
qreal m_yOffset; // how far down the current page are we
qreal m_topMargin; // value stored in the correct units
qreal m_bottomMargin; // -- same as above --
qreal m_leftMargin; // -- same as above --
qreal m_rightMargin; // -- same as above --
qreal m_maxHeight; // -- same as above --
qreal m_maxWidth; // -- same as above --
int m_pageCounter; // what page are we currently on?
KReportDataSource* m_dataSource;
KReportPrivate::OneRecordDataSource *m_oneRecord;
QList m_postProcText;
#ifdef KREPORT_SCRIPTING
QMap m_scriptObjects;
#endif
void createNewPage();
- qreal finishCurPage(bool = false);
- qreal finishCurPageSize(bool = false);
+ qreal finishCurPage(bool lastPage);
+ qreal finishCurPageSize(bool lastPage);
void renderDetailSection(KReportDetailSectionData *detailData);
qreal renderSection(const KReportSectionData &);
qreal renderSectionSize(const KReportSectionData &);
///Scripting Stuff
KReportScriptHandler *m_scriptHandler;
#ifdef KREPORT_SCRIPTING
void initEngine();
#endif
//! Generates m_document. Returns true on success.
//! @note m_document is not removed on failure, caller should remove it.
bool generateDocument();
KReportPrivate::AsyncItemManager* asyncManager;
private Q_SLOTS:
void asyncItemsFinished();
Q_SIGNALS:
void enteredGroup(const QString&, const QVariant&);
void exitedGroup(const QString&, const QVariant&);
void renderingSection(KReportSectionData*, OROPage*, QPointF);
void finishedAllASyncItems();
};
#endif // __KOREPORTPRERENDERER_P_H__