Re: Reports: problem with pageTotal()
Dag Andersen <[email protected]> Fri, 3 Dec 2010 08:38:03 +0100
| Newsgroups | gmane.comp.kde.devel.koffice |
|---|---|
| Message-ID | <[email protected]> |
Fredag 03 december 2010 07:32:27 skrev Adam Pigg: > Unfortunately, i didnt have a lot of time last night to look at it. > > On first glance, it seems the new code may be much slower when there > are lots of pages/objects, as it loops over every object in every page > looking for ones that require post-processing. The old (commented) > code created a list of objects requiring post-processing, as this is > likely to be ~no-pages. > > Could you try for something like this before the freeze, or i can have > a go this evening. If not, it could go into trunk like this, as its > probably better working than not, and can be sped up later. New patch follows. This one registers primitives that needs post processing with the ORODocument, so should be as fast as possible. > > Cheers > > Adam > > On Thu, Dec 2, 2010 at 2:59 PM, Dag Andersen <[email protected]> wrote: > > Torsdag 02 december 2010 13:57:12 skrev Jaroslaw Staniek: > >> On 2 December 2010 12:58, Dag Andersen <[email protected]> wrote: > >> > Torsdag 02 december 2010 10:09:30 skrev Dag Andersen: > >> >> In kplato I define a report with fields for page number (working) and > >> >> total number of pages (not working). I specify control sources like > >> >> this: =constants.PageNumber() > >> >> =constants.PageTotal() > >> >> > >> >> The page total field in the generated report shows: > >> >> constants.PageTotal() > >> >> > >> >> Any hints? > >> > > >> > Seems this was only half finished, att patch fixes it for me. > >> > Could you commit if it is ok Jaroslaw? > >> > >> Would you like to review this, Adam? > >> Formally, is this patch suitable for applying to trunk or to essen? > > > > imvho, this is a bug as the functionallity is partially there, it just > > doesn't work. Thus it's a bug and should be fixed. > > -- > > Mvh. > > Dag Andersen > > _______________________________________________ > koffice-devel mailing list > [email protected] > https://mail.kde.org/mailman/listinfo/koffice-devel -- Mvh. Dag Andersen _______________________________________________ koffice-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/koffice-devel
postprocess.diff
(text/x-patch, 4.3 KB)
Index: items/field/KoReportItemField.cpp
===================================================================
--- items/field/KoReportItemField.cpp (revision 1202520)
+++ items/field/KoReportItemField.cpp (working copy)
@@ -219,9 +219,12 @@
}
tb->setText(str);
- if (page)
+ if (page) {
page->addPrimitive(tb);
-
+ if (tb->requiresPostProcessing()) {
+ page->addNeedsPostProcessing(tb);
+ }
+ }
if (section) {
OROPrimitive *clone = tb->clone();
clone->setPosition(m_pos.toScene());
Index: renderer/KoReportPreRenderer.cpp
===================================================================
--- renderer/KoReportPreRenderer.cpp (revision 1202520)
+++ renderer/KoReportPreRenderer.cpp (working copy)
@@ -65,7 +65,6 @@
int m_recordCount;
KoReportData* m_kodata;
- QList<OROTextBox*> m_postProcText;
void createNewPage();
qreal finishCurPage(bool = false);
@@ -105,8 +104,6 @@
delete m_reportData;
m_reportData = 0;
}
-
- m_postProcText.clear();
}
void KoReportPreRendererPrivate::createNewPage()
@@ -399,17 +396,7 @@
if (itemHeight > sectionHeight) {
sectionHeight = itemHeight;
- }
-
-#if 0 //!TODO Handle post processing of text data
- if (ob->type() == OROTextBox::TextBox) {
- OROTextBox *text = dynamic_cast<OROTextBox*>(ob);
- if (text->requiresPostProcessing()) {
- m_postProcText.append(text);
- }
-
-#endif
-
+ }
}
m_yOffset += sectionHeight;
@@ -614,16 +601,17 @@
}
d->finishCurPage(true);
- // _postProcText contains those text boxes that need to be updated
+ // post process primitives that need to be updated
// with information that wasn't available at the time it was added to the document
d->m_scriptHandler->setPageTotal(d->m_document->pages());
- for (int i = 0; i < d->m_postProcText.size(); i++) {
- OROTextBox * tb = d->m_postProcText.at(i);
-
- d->m_scriptHandler->setPageNumber(tb->page()->page() + 1);
-
- tb->setText(d->m_scriptHandler->evaluate(tb->text()).toString());
+ foreach (OROPrimitive *p, d->m_document->needsPostProcessing()) {
+ if (p->type() == OROTextBox::TextBox) {
+ // only handles textbox primitives atm
+ OROTextBox *tb = static_cast<OROTextBox*>(p);
+ d->m_scriptHandler->setPageNumber(tb->page()->page() + 1);
+ tb->setText(d->m_scriptHandler->evaluate(tb->text()).toString());
+ }
}
d->m_scriptHandler->displayErrors();
@@ -631,7 +619,6 @@
d->m_kodata->close();
delete d->m_scriptHandler;
delete d->m_kodata;
- d->m_postProcText.clear();
ORODocument * pDoc = d->m_document;
d->m_document = 0;
Index: common/renderobjects.h
===================================================================
--- common/renderobjects.h (revision 1202520)
+++ common/renderobjects.h (working copy)
@@ -76,11 +76,16 @@
return m_pageOptions;
};
+ QList<OROPrimitive*> needsPostProcessing() const;
+ void addNeedsPostProcessing(OROPrimitive *primitive);
+
protected:
QString m_title;
QList<OROPage*> m_pages;
QList<OROSection*> m_sections;
ReportPageOptions m_pageOptions;
+
+ QList<OROPrimitive*> m_needsPostProcessing;
};
//
@@ -109,6 +114,8 @@
OROPrimitive* primitive(int);
void addPrimitive(OROPrimitive*, bool = false);
+ void addNeedsPostProcessing(OROPrimitive *primitive);
+
protected:
ORODocument * m_document;
QList<OROPrimitive*> m_primitives;
Index: common/renderobjects.cpp
===================================================================
--- common/renderobjects.cpp (revision 1202520)
+++ common/renderobjects.cpp (working copy)
@@ -78,6 +78,16 @@
m_pageOptions = options;
}
+QList<OROPrimitive*> ORODocument::needsPostProcessing() const
+{
+ return m_needsPostProcessing;
+}
+
+void ORODocument::addNeedsPostProcessing(OROPrimitive *primitive)
+{
+ m_needsPostProcessing.append(primitive);
+}
+
//
// OROPage
//
@@ -132,6 +142,13 @@
}
}
+void OROPage::addNeedsPostProcessing(OROPrimitive *primitive)
+{
+ if (m_document) {
+ m_document->addNeedsPostProcessing(primitive);
+ }
+}
+
//
// OROSection
//