Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reports/kexireportview.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Kexi Report Plugin | 2 | * Kexi Report Plugin | ||
3 | * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) | 3 | * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) | ||
4 | * Copyright (C) 2014-2017 Jarosław Staniek <staniek@kde.org> | 4 | * Copyright (C) 2014-2018 Jarosław Staniek <staniek@kde.org> | ||
5 | * | 5 | * | ||
6 | * This library is free software; you can redistribute it and/or | 6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | 7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | 9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | 10 | * | ||
11 | * This library is distributed in the hope that it will be useful, | 11 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Line(s) | 350 | { | |||
353 | if (tempData()->reportSchemaChangedInPreviousView) { | 353 | if (tempData()->reportSchemaChangedInPreviousView) { | ||
354 | tempData()->reportSchemaChangedInPreviousView = false; | 354 | tempData()->reportSchemaChangedInPreviousView = false; | ||
355 | 355 | | |||
356 | delete m_preRenderer; | 356 | delete m_preRenderer; | ||
357 | 357 | | |||
358 | //qDebug() << tempData()->reportDefinition.tagName(); | 358 | //qDebug() << tempData()->reportDefinition.tagName(); | ||
359 | m_preRenderer = new KReportPreRenderer(tempData()->reportDefinition); | 359 | m_preRenderer = new KReportPreRenderer(tempData()->reportDefinition); | ||
360 | if (m_preRenderer->isValid()) { | 360 | if (m_preRenderer->isValid()) { | ||
361 | KReportDataSource *reportData = 0; | 361 | KexiDBReportDataSource *reportData = nullptr; | ||
362 | if (!tempData()->connectionDefinition.isNull()) { | 362 | if (!tempData()->connectionDefinition.isNull()) { | ||
363 | reportData = createDataSource(tempData()->connectionDefinition); | 363 | reportData = createDataSource(tempData()->connectionDefinition); | ||
364 | } | 364 | } | ||
365 | m_preRenderer->setDataSource(reportData); | 365 | m_preRenderer->setDataSource(reportData); | ||
366 | m_preRenderer->setScriptSource(qobject_cast<KexiReportPart*>(part())); | 366 | m_preRenderer->setScriptSource(qobject_cast<KexiReportPart*>(part())); | ||
367 | 367 | | |||
368 | m_preRenderer->setName(window()->partItem()->name()); | 368 | m_preRenderer->setName(window()->partItem()->name()); | ||
369 | 369 | | |||
370 | //Add a kexi object to provide kexidb and extra functionality | 370 | //Add a kexi object to provide kexidb and extra functionality | ||
371 | //! @todo KEXI3 if we want this if(!m_kexi) { | 371 | //! @todo KEXI3 if we want this if(!m_kexi) { | ||
372 | // m_kexi = new KexiScriptAdaptor(); | 372 | // m_kexi = new KexiScriptAdaptor(); | ||
373 | // } | 373 | // } | ||
374 | // m_preRenderer->registerScriptObject(m_kexi, "Kexi"); | 374 | // m_preRenderer->registerScriptObject(m_kexi, "Kexi"); | ||
375 | //If using a kexidb source, add a functions scripting object | 375 | //If using a kexidb source, add a functions scripting object | ||
376 | if (tempData()->connectionDefinition.attribute("type") == "internal") { | 376 | if (reportData && tempData()->connectionDefinition.attribute("type") == "internal") { | ||
377 | m_functions = new KRScriptFunctions(reportData, KexiMainWindowIface::global()->project()->dbConnection()); | 377 | m_functions = new KRScriptFunctions(reportData); | ||
378 | 378 | | |||
379 | m_preRenderer->registerScriptObject(m_functions, "field"); | 379 | m_preRenderer->registerScriptObject(m_functions, "field"); | ||
380 | connect(m_preRenderer, SIGNAL(groupChanged(QMap<QString, QVariant>)), | 380 | connect(m_preRenderer, SIGNAL(groupChanged(QMap<QString, QVariant>)), | ||
381 | m_functions, SLOT(setGroupData(QMap<QString, QVariant>))); | 381 | m_functions, SLOT(setGroupData(QMap<QString, QVariant>))); | ||
382 | } | 382 | } | ||
383 | connect(m_preRenderer, SIGNAL(finishedAllASyncItems()), this, SLOT(finishedAllASyncItems())); | 383 | connect(m_preRenderer, SIGNAL(finishedAllASyncItems()), this, SLOT(finishedAllASyncItems())); | ||
384 | 384 | | |||
385 | if (!m_preRenderer->generateDocument()) { | 385 | if (!m_preRenderer->generateDocument()) { | ||
386 | qWarning() << "Could not generate report document"; | 386 | qWarning() << "Could not generate report document"; | ||
387 | return false; | 387 | return false; | ||
388 | } | 388 | } | ||
389 | 389 | | |||
390 | m_reportView->setDocument(m_preRenderer->document()); | 390 | m_reportView->setDocument(m_preRenderer->document()); | ||
391 | #ifndef KEXI_MOBILE | 391 | #ifndef KEXI_MOBILE | ||
392 | m_pageSelector->setRecordCount(m_reportView->pageCount()); | 392 | m_pageSelector->setRecordCount(m_reportView->pageCount()); | ||
393 | m_pageSelector->setCurrentRecordNumber(1); | 393 | m_pageSelector->setCurrentRecordNumber(1); | ||
394 | #endif | 394 | #endif | ||
395 | } else { | 395 | } else { | ||
396 | KMessageBox::error(this, xi18n("Report schema appears to be invalid or corrupt"), xi18n("Opening failed")); | 396 | KMessageBox::error(this, xi18n("Report schema appears to be invalid or corrupt"), xi18n("Opening failed")); | ||
397 | } | 397 | } | ||
398 | } | 398 | } | ||
399 | return true; | 399 | return true; | ||
400 | } | 400 | } | ||
401 | 401 | | |||
402 | KReportDataSource* KexiReportView::createDataSource(const QDomElement &e) | 402 | KexiDBReportDataSource* KexiReportView::createDataSource(const QDomElement &e) | ||
403 | { | 403 | { | ||
404 | if (e.attribute("type") == "internal" && !e.attribute("source").isEmpty()) { | 404 | if (e.attribute("type") == "internal" && !e.attribute("source").isEmpty()) { | ||
405 | return new KexiDBReportDataSource(e.attribute("source"), e.attribute("class"), tempData()); | 405 | return new KexiDBReportDataSource(e.attribute("source"), e.attribute("class"), tempData()); | ||
406 | } | 406 | } | ||
407 | return nullptr; | 407 | return nullptr; | ||
408 | } | 408 | } | ||
409 | 409 | | |||
410 | KexiReportPartTempData* KexiReportView::tempData() const | 410 | KexiReportPartTempData* KexiReportView::tempData() const | ||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |