File indexing completed on 2024-05-05 04:43:21

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2011  Adam Pigg <adam@piggz.co.uk>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0017 */
0018 
0019 
0020 #include "KReportAsyncItemManager_p.h"
0021 #include "KReportAsyncItemBase.h"
0022 #include "kreport_debug.h"
0023 
0024 #include <QPointF>
0025 
0026 namespace KReportPrivate {
0027 
0028 class RenderData {
0029 public:
0030     KReportAsyncItemBase* item;
0031     OROPage* page;
0032     OROSection* section;
0033     QPointF offset;
0034     QVariant data;
0035     KReportScriptHandler* script;
0036 };
0037 
0038 AsyncItemManager::AsyncItemManager(QObject *parent) : QObject(parent), m_curPage(nullptr)
0039 {
0040 }
0041 
0042 AsyncItemManager::~AsyncItemManager()
0043 {
0044 
0045 }
0046 
0047 void AsyncItemManager::addItem(KReportAsyncItemBase* item, OROPage* page, OROSection* section, QPointF offset, QVariant data, KReportScriptHandler* script)
0048 {
0049     RenderData *rdata = new RenderData();
0050     rdata->item = item;
0051     rdata->page = page;
0052     rdata->section = section;
0053     rdata->offset = offset;
0054     rdata->data = data;
0055 
0056 #ifdef KREPORT_SCRIPTING
0057     rdata->script = script;
0058 #else
0059     Q_UNUSED(script);
0060 #endif
0061     m_renderList.enqueue(rdata);
0062 
0063     //Just connect the first instance
0064     if (!m_itemList.contains(item)) {
0065         m_itemList.append(item);
0066         connect(item, SIGNAL(finishedRendering()), this, SLOT(itemFinished()));
0067     }
0068     //kreportDebug() << m_renderList.count();
0069 }
0070 
0071 void AsyncItemManager::itemFinished()
0072 {
0073     m_curPage->document()->updated(m_curPage->pageNumber());
0074     //kreportDebug();
0075     if (m_renderList.count() > 0) {
0076         RenderData *rdata = m_renderList.dequeue();
0077         m_curPage = rdata->page;
0078         rdata->item->renderSimpleData(rdata->page, rdata->section, rdata->offset, rdata->data, rdata->script);
0079     } else {
0080         emit(finished());
0081     }
0082 }
0083 
0084 void AsyncItemManager::startRendering()
0085 {
0086     //kreportDebug();
0087     if (m_renderList.count() > 0) {
0088         RenderData *rdata = m_renderList.dequeue();
0089         m_curPage = rdata->page;
0090         rdata->item->renderSimpleData(rdata->page, rdata->section, rdata->offset, rdata->data, rdata->script);
0091     } else {
0092         emit(finished());
0093     }
0094 }
0095 
0096 }