[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] /: Initial api for async report items
From:       Jaroslaw Staniek <staniek () kde ! org>
Date:       2011-09-30 22:30:28
Message-ID: 20110930223028.897F0A60BE () git ! kde ! org
[Download RAW message or body]

Git commit ab1218e6072789aacce40478050acb26aa8538ec by Jaroslaw Staniek, on behalf of \
Adam Pigg. Committed on 27/09/2011 at 22:46.
Pushed by staniek into branch 'master'.

Initial api for async report items

M  +3    -1    libs/koreport/CMakeLists.txt
A  +21   -0    libs/koreport/common/KoReportASyncItemBase.cpp     [License: LGPL \
(v2.1+)] A  +46   -0    libs/koreport/common/KoReportASyncItemBase.h     [License: \
LGPL (v2.1+)] A  +66   -0    libs/koreport/renderer/KoReportASyncItemManager.cpp     \
[License: LGPL (v2.1+)] A  +61   -0    \
libs/koreport/renderer/KoReportASyncItemManager.h     [License: LGPL (v2.1+)] M  +23  \
-2    libs/koreport/renderer/KoReportPreRenderer.cpp M  +2    -2    \
plugins/reporting/maps/KoReportItemMaps.h

http://commits.kde.org/calligra/ab1218e6072789aacce40478050acb26aa8538ec

diff --git a/libs/koreport/CMakeLists.txt b/libs/koreport/CMakeLists.txt
index 2b8d64e..d0737c9 100644
--- a/libs/koreport/CMakeLists.txt
+++ b/libs/koreport/CMakeLists.txt
@@ -12,11 +12,12 @@ include_directories( ${KOMAIN_INCLUDES}
 )
 
 #build a shared library
-set(koreport_LIB_SRCS
+set(koreport_LIB_SRCS 
     common/krutils.cpp
     common/krpos.cpp
     common/krsize.cpp
     common/KoReportItemBase.cpp
+    common/KoReportASyncItemBase.cpp
     common/krsectiondata.cpp
     common/labelsizeinfo.cpp
     common/reportpageoptions.cpp
@@ -31,6 +32,7 @@ set(koreport_LIB_SRCS
 
     renderer/KoReportPrintRenderer.cpp
     renderer/KoReportPreRenderer.cpp
+    renderer/KoReportASyncItemManager.cpp
     renderer/KoReportScreenRenderer.cpp
     renderer/KoReportHTMLTableRenderer.cpp
     renderer/KoReportHTMLCSSRenderer.cpp
diff --git a/libs/koreport/common/KoReportASyncItemBase.cpp \
b/libs/koreport/common/KoReportASyncItemBase.cpp new file mode 100644
index 0000000..1ff8021
--- /dev/null
+++ b/libs/koreport/common/KoReportASyncItemBase.cpp
@@ -0,0 +1,21 @@
+/*
+    <one line to give the library's name and an idea of what it does.>
+    Copyright (C) 2011  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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#include "KoReportASyncItemBase.h"
diff --git a/libs/koreport/common/KoReportASyncItemBase.h \
b/libs/koreport/common/KoReportASyncItemBase.h new file mode 100644
index 0000000..a2780a0
--- /dev/null
+++ b/libs/koreport/common/KoReportASyncItemBase.h
@@ -0,0 +1,46 @@
+/*
+    <one line to give the library's name and an idea of what it does.>
+    Copyright (C) 2011  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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#ifndef KOREPORTASYNCITEMBASE_H
+#define KOREPORTASYNCITEMBASE_H
+
+#include <KoReportItemBase.h>
+
+
+
+class KOREPORT_EXPORT KoReportASyncItemBase : public KoReportItemBase
+{
+    Q_OBJECT
+public:
+    
+    virtual int render(OROPage* page, OROSection* section,  QPointF offset, QVariant \
data, KRScriptHandler *script) = 0; +    
+protected:    
+    
+signals:
+    void finishedRendering();
+    
+public:
+    
+private:
+    
+};
+
+#endif // KOREPORTASYNCITEMBASE_H
diff --git a/libs/koreport/renderer/KoReportASyncItemManager.cpp \
b/libs/koreport/renderer/KoReportASyncItemManager.cpp new file mode 100644
index 0000000..667b293
--- /dev/null
+++ b/libs/koreport/renderer/KoReportASyncItemManager.cpp
@@ -0,0 +1,66 @@
+/*
+    <one line to give the library's name and an idea of what it does.>
+    Copyright (C) 2011  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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#include "KoReportASyncItemManager.h"
+#include "common/KoReportASyncItemBase.h"
+
+KoReportASyncItemManager::KoReportASyncItemManager(QObject* parent): QObject(parent)
+{
+
+}
+
+KoReportASyncItemManager::~KoReportASyncItemManager()
+{
+
+}
+
+void KoReportASyncItemManager::addItem(KoReportASyncItemBase* item, OROPage* page, \
OROSection* section, QPointF offset, QVariant data, KRScriptHandler* script) +{
+    RenderData *rdata = new RenderData();
+    rdata->item = item;
+    rdata->page = page;
+    rdata->section = section;
+    rdata->offset = offset;
+    rdata->data = data;
+    rdata->script = script;
+    
+    m_renderList.enqueue(rdata);
+    
+    connect(item, SIGNAL(finishedRendering()), this, SLOT(itemFinished()));
+}
+
+void KoReportASyncItemManager::itemFinished()
+{
+    if (m_renderList.count() > 0) {
+        RenderData *rdata = m_renderList.dequeue();
+    } else {
+        emit(finished());
+    }
+}
+
+void KoReportASyncItemManager::startRendering()
+{
+    if (m_renderList.count() > 0) {
+        RenderData *rdata = m_renderList.dequeue();
+        rdata->item->render(rdata->page, rdata->section, rdata->offset, rdata->data, \
rdata->script); +    } else {
+        emit(finished());
+    }
+}
diff --git a/libs/koreport/renderer/KoReportASyncItemManager.h \
b/libs/koreport/renderer/KoReportASyncItemManager.h new file mode 100644
index 0000000..2472839
--- /dev/null
+++ b/libs/koreport/renderer/KoReportASyncItemManager.h
@@ -0,0 +1,61 @@
+/*
+    <one line to give the library's name and an idea of what it does.>
+    Copyright (C) 2011  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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#ifndef KOREPORTASYNCITEMMANAGER_H
+#define KOREPORTASYNCITEMMANAGER_H
+
+#include <QObject>
+#include "KoReportASyncItemBase.h"
+#include <qqueue.h>
+
+class RenderData {
+public:
+    KoReportASyncItemBase* item;
+    OROPage* page;
+    OROSection* section;
+    QPointF offset;
+    QVariant data;
+    KRScriptHandler* script;
+};
+
+class KoReportASyncItemManager : public QObject
+{
+    Q_OBJECT
+    
+public:
+    KoReportASyncItemManager(QObject *parent);
+    virtual ~KoReportASyncItemManager();
+    
+    void addItem(KoReportASyncItemBase *item, OROPage *page, OROSection *section, \
QPointF offset, QVariant data, KRScriptHandler *script); +    
+    void startRendering();
+    
+private:
+    QQueue<RenderData*> m_renderList;
+    
+private slots:
+    void itemFinished();
+    
+signals:
+    void finished();
+    
+};
+
+#endif // KOREPORTASYNCITEMMANAGER_H
diff --git a/libs/koreport/renderer/KoReportPreRenderer.cpp \
b/libs/koreport/renderer/KoReportPreRenderer.cpp index ddc971b..6d4939e 100644
--- a/libs/koreport/renderer/KoReportPreRenderer.cpp
+++ b/libs/koreport/renderer/KoReportPreRenderer.cpp
@@ -33,6 +33,7 @@
 #include "scripting/krscripthandler.h"
 #include <krreportdata.h>
 #include <krdetailsectiondata.h>
+#include "KoReportASyncItemManager.h"
 
 //
 // KoReportPreRendererPrivate
@@ -78,6 +79,11 @@ public:
     ///Scripting Stuff
     KRScriptHandler *m_scriptHandler;
     void initEngine();
+    
+    KoReportASyncItemManager* asyncManager;
+    
+private slots:
+    void asyncItemsFinished();
 
 signals:
     void enteredGroup(const QString&, const QVariant&);
@@ -97,6 +103,9 @@ KoReportPreRendererPrivate::KoReportPreRendererPrivate()
     m_pageCounter = 0;
     m_maxHeight = m_maxWidth = 0.0;
     m_kodata = 0;
+    asyncManager = new KoReportASyncItemManager(this);
+    
+    connect(asyncManager, SIGNAL(finished()), this, SLOT(asyncItemsFinished()));
 }
 
 KoReportPreRendererPrivate::~KoReportPreRendererPrivate()
@@ -386,9 +395,14 @@ qreal KoReportPreRendererPrivate::renderSection(const \
KRSectionData & sectionDat  QVariant itemData = \
m_kodata->value(ob->itemDataSource());  
         if (ob->supportsSubQuery()) {
-            itemHeight = ob->render(m_page, sec, offset, m_kodata, m_scriptHandler);
+           itemHeight = ob->render(m_page, sec, offset, m_kodata, m_scriptHandler);
         } else {
-            itemHeight = ob->render(m_page, sec, offset, itemData, m_scriptHandler);
+            KoReportASyncItemBase *async_ob = \
dynamic_cast<KoReportASyncItemBase*>(ob); +            if (async_ob){
+                asyncManager->addItem(async_ob, m_page, sec, offset, itemData, \
m_scriptHandler); +            } else {
+                itemHeight = ob->render(m_page, sec, offset, itemData, \
m_scriptHandler); +            }
         }
 
         if (itemHeight > sectionHeight) {
@@ -420,6 +434,11 @@ void KoReportPreRendererPrivate::initEngine()
     connect(this, SIGNAL(renderingSection(KRSectionData*, OROPage*, QPointF)), \
m_scriptHandler, SLOT(slotEnteredSection(KRSectionData*, OROPage*, QPointF)));  }
 
+void KoReportPreRendererPrivate::asyncItemsFinished(){
+    kDebug() << "Finished rendering async items";
+}
+
+
 //===========================KoReportPreRenderer===============================
 
 KoReportPreRenderer::KoReportPreRenderer(const QDomElement & pDocument) : d(new \
KoReportPreRendererPrivate()) @@ -617,6 +636,8 @@ ORODocument* \
KoReportPreRenderer::generate()  
         tb->setText(d->m_scriptHandler->evaluate(tb->text()).toString());
     }
+    
+    d->asyncManager->startRendering();
 
     d->m_scriptHandler->displayErrors();
 
diff --git a/plugins/reporting/maps/KoReportItemMaps.h \
b/plugins/reporting/maps/KoReportItemMaps.h index 7dd346f..e94e048 100644
--- a/plugins/reporting/maps/KoReportItemMaps.h
+++ b/plugins/reporting/maps/KoReportItemMaps.h
@@ -17,7 +17,7 @@
  */
 #ifndef KRIMAGEDATA_H
 #define KRIMAGEDATA_H
-#include <KoReportItemBase.h>
+#include <KoReportASyncItemBase.h>
 #include <QRect>
 #include <QPainter>
 #include <qdom.h>
@@ -45,7 +45,7 @@ class Maps;
 /**
  @author
 */
-class KoReportItemMaps : public KoReportItemBase
+class KoReportItemMaps : public KoReportASyncItemBase
 {
     Q_OBJECT
 public:


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic