2016-02-17 10:11:00 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* This file is part of the Lime Report project *
|
2021-08-18 20:21:36 +03:00
|
|
|
* Copyright (C) 2021 by Alexander Arin *
|
2016-02-17 10:11:00 +03:00
|
|
|
* arin_a@bk.ru *
|
|
|
|
* *
|
|
|
|
** GNU General Public License Usage **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
** GNU Lesser General Public License **
|
|
|
|
* *
|
|
|
|
* 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 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this library. *
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
* 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 General Public License for more details. *
|
|
|
|
****************************************************************************/
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QMessageBox>
|
2016-02-17 10:11:00 +03:00
|
|
|
#include <QPrintDialog>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QPrinter>
|
2017-03-05 16:39:50 +03:00
|
|
|
#include <QPrinterInfo>
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2016-02-17 10:11:00 +03:00
|
|
|
#include <QDesktopWidget>
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
|
|
|
#include <QScreen>
|
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrdatasourcemanager.h"
|
|
|
|
#include "lrpagedesignintf.h"
|
2016-02-17 10:11:00 +03:00
|
|
|
#include "lrreportengine.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrreportengine_p.h"
|
|
|
|
#include "time.h"
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QPluginLoader>
|
2017-11-24 00:13:47 +03:00
|
|
|
|
2017-11-27 23:14:05 +03:00
|
|
|
#ifdef HAVE_REPORT_DESIGNER
|
|
|
|
#include "lrdatabrowser.h"
|
|
|
|
#include "lrreportdesignwindow.h"
|
|
|
|
#endif
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2018-06-23 00:04:28 +03:00
|
|
|
#include "lrexporterintf.h"
|
|
|
|
#include "lrexportersfactory.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrpreviewreportwidget.h"
|
|
|
|
#include "lrpreviewreportwidget_p.h"
|
|
|
|
#include "lrpreviewreportwindow.h"
|
|
|
|
#include "lrreportrender.h"
|
|
|
|
#include "serializators/lrxmlreader.h"
|
|
|
|
#include "serializators/lrxmlwriter.h"
|
2017-11-24 00:13:47 +03:00
|
|
|
|
2018-05-07 22:52:28 +03:00
|
|
|
#ifdef BUILD_WITH_EASY_PROFILER
|
2018-02-28 23:19:04 +03:00
|
|
|
#include "easy/profiler.h"
|
2018-03-22 23:00:51 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
#define EASY_BLOCK(...)
|
|
|
|
#define EASY_END_BLOCK
|
2018-03-22 23:00:51 +03:00
|
|
|
#endif
|
2019-05-29 16:32:58 +03:00
|
|
|
#include "lrpreparedpages.h"
|
2018-02-28 23:19:04 +03:00
|
|
|
|
2017-06-12 13:11:00 +03:00
|
|
|
#ifdef HAVE_STATIC_BUILD
|
|
|
|
#include "lrfactoryinitializer.h"
|
|
|
|
#endif
|
2018-05-08 10:58:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
namespace LimeReport {
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
QSettings* ReportEngine::m_settings = 0;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportEnginePrivate::ReportEnginePrivate(QObject* parent):
|
|
|
|
QObject(parent),
|
|
|
|
m_preparedPagesManager(new PreparedPages(&m_preparedPages)),
|
|
|
|
m_fileName(""),
|
|
|
|
m_settings(0),
|
|
|
|
m_ownedSettings(false),
|
|
|
|
m_printer(new QPrinter(QPrinter::HighResolution)),
|
|
|
|
m_printerSelected(false),
|
|
|
|
m_showProgressDialog(true),
|
|
|
|
m_reportName(""),
|
|
|
|
m_activePreview(0),
|
|
|
|
m_previewWindowIcon(":/report/images/logo32"),
|
|
|
|
m_previewWindowTitle(tr("Preview")),
|
|
|
|
m_reportRendering(false),
|
|
|
|
m_resultIsEditable(true),
|
|
|
|
m_passPhrase("HjccbzHjlbyfCkjy"),
|
|
|
|
m_fileWatcher(new QFileSystemWatcher(this)),
|
|
|
|
m_reportLanguage(QLocale::AnyLanguage),
|
|
|
|
m_previewLayoutDirection(Qt::LayoutDirectionAuto),
|
|
|
|
m_designerFactory(0),
|
|
|
|
m_previewScaleType(FitWidth),
|
|
|
|
m_previewScalePercent(0),
|
|
|
|
m_startTOCPage(0),
|
2019-04-15 14:20:44 +03:00
|
|
|
m_previewPageBackgroundColor(Qt::gray),
|
2024-09-04 17:31:16 +03:00
|
|
|
m_saveToFileVisible(true),
|
|
|
|
m_printToPdfVisible(true),
|
2019-04-10 16:23:50 +03:00
|
|
|
m_printVisible(true)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2017-06-12 13:11:00 +03:00
|
|
|
#ifdef HAVE_STATIC_BUILD
|
2017-06-14 12:07:02 +03:00
|
|
|
initResources();
|
2017-06-12 13:11:00 +03:00
|
|
|
initReportItems();
|
2017-11-27 23:14:05 +03:00
|
|
|
#ifdef HAVE_REPORT_DESIGNER
|
2017-06-12 13:11:00 +03:00
|
|
|
initObjectInspectorProperties();
|
2017-11-27 23:14:05 +03:00
|
|
|
#endif
|
2017-06-12 13:11:00 +03:00
|
|
|
initSerializators();
|
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
m_datasources = new DataSourceManager(this);
|
|
|
|
m_datasources->setReportSettings(&m_reportSettings);
|
2018-01-26 17:38:23 +03:00
|
|
|
scriptManager()->setDataManager(m_datasources);
|
2016-06-10 18:05:18 +03:00
|
|
|
m_scriptEngineContext = new ScriptEngineContext(this);
|
2017-08-25 18:01:59 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ICallbackDatasource* tableOfContents
|
|
|
|
= m_datasources->createCallbackDatasource("tableofcontents");
|
|
|
|
connect(tableOfContents, SIGNAL(getCallbackData(LimeReport::CallbackInfo, QVariant&)),
|
|
|
|
m_scriptEngineContext->tableOfContents(),
|
|
|
|
SLOT(slotOneSlotDS(LimeReport::CallbackInfo, QVariant&)));
|
2017-08-25 18:01:59 +03:00
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
m_datasources->setObjectName("datasources");
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(m_datasources, SIGNAL(loadCollectionFinished(QString)), this,
|
|
|
|
SLOT(slotDataSourceCollectionLoaded(QString)));
|
|
|
|
connect(m_fileWatcher, SIGNAL(fileChanged(const QString&)), this,
|
|
|
|
SLOT(slotLoadFromFile(const QString&)));
|
2017-11-24 00:13:47 +03:00
|
|
|
|
2021-04-14 21:21:38 +03:00
|
|
|
#ifndef HAVE_REPORT_DESIGNER
|
|
|
|
|
2017-11-30 21:23:11 +03:00
|
|
|
QDir pluginsDir = QCoreApplication::applicationDirPath();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!pluginsDir.cd("../lib")) {
|
2017-11-30 21:23:11 +03:00
|
|
|
pluginsDir.cd("./lib");
|
2017-11-27 23:14:05 +03:00
|
|
|
}
|
2017-11-24 00:13:47 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pluginsDir != QCoreApplication::applicationDirPath()) {
|
|
|
|
foreach (const QString& pluginName, pluginsDir.entryList(QDir::Files)) {
|
|
|
|
QPluginLoader loader(pluginsDir.absoluteFilePath(pluginName));
|
|
|
|
if (loader.load()) {
|
2021-04-14 21:21:38 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (LimeReportDesignerPluginInterface* designerPlugin
|
|
|
|
= qobject_cast<LimeReportDesignerPluginInterface*>(loader.instance())) {
|
2021-04-14 21:21:38 +03:00
|
|
|
m_designerFactory = designerPlugin;
|
|
|
|
break;
|
|
|
|
}
|
2017-11-24 00:13:47 +03:00
|
|
|
}
|
2021-04-14 21:21:38 +03:00
|
|
|
}
|
2018-06-23 00:04:28 +03:00
|
|
|
}
|
|
|
|
|
2021-04-14 21:21:38 +03:00
|
|
|
#endif
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ReportEnginePrivate::~ReportEnginePrivate()
|
|
|
|
{
|
2016-04-21 17:53:31 +03:00
|
|
|
if (m_designerWindow) {
|
|
|
|
m_designerWindow->close();
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_activePreview) {
|
2016-02-20 13:37:18 +03:00
|
|
|
m_activePreview->close();
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageDesignIntf* page, m_pages)
|
|
|
|
delete page;
|
2016-02-17 10:11:00 +03:00
|
|
|
m_pages.clear();
|
2017-07-29 00:54:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (ReportTranslation* translation, m_translations)
|
2017-07-29 00:54:43 +03:00
|
|
|
delete translation;
|
|
|
|
m_translations.clear();
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_ownedSettings && m_settings)
|
|
|
|
delete m_settings;
|
2019-05-29 16:32:58 +03:00
|
|
|
delete m_preparedPagesManager;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QObject* ReportEnginePrivate::createElement(const QString&, const QString&) { return appendPage(); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QObject* ReportEnginePrivate::elementAt(const QString&, int index) { return pageAt(index); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageDesignIntf* ReportEnginePrivate::createPage(const QString& pageName, bool preview)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
PageDesignIntf* page = new PageDesignIntf();
|
2016-02-17 10:11:00 +03:00
|
|
|
page->setObjectName(pageName);
|
2024-09-04 17:31:16 +03:00
|
|
|
page->pageItem()->setObjectName("Report" + pageName);
|
2019-03-02 01:08:20 +03:00
|
|
|
if (!preview)
|
|
|
|
page->setReportEditor(this);
|
2016-06-24 23:15:59 +03:00
|
|
|
page->setReportSettings(&m_reportSettings);
|
2016-02-17 10:11:00 +03:00
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageDesignIntf* ReportEnginePrivate::appendPage(const QString& pageName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
PageDesignIntf* page = createPage(pageName);
|
|
|
|
m_pages.append(page);
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::deletePage(PageDesignIntf* page)
|
|
|
|
{
|
2016-06-10 18:05:18 +03:00
|
|
|
QList<PageDesignIntf*>::iterator it = m_pages.begin();
|
2024-09-04 17:31:16 +03:00
|
|
|
while (it != m_pages.end()) {
|
2016-06-10 18:05:18 +03:00
|
|
|
if (*it == page) {
|
|
|
|
it = m_pages.erase(it);
|
|
|
|
return true;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
++it;
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageDesignIntf* ReportEnginePrivate::createPreviewPage() { return createPage("preview", true); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ReportEnginePrivate::elementsCount(const QString&) { return m_pages.count(); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::collectionLoadFinished(const QString&)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
|
|
|
page->setReportEditor(this);
|
2016-06-24 23:15:59 +03:00
|
|
|
page->setReportSettings(&m_reportSettings);
|
2024-09-04 17:31:16 +03:00
|
|
|
page->setSceneRect(-Const::SCENE_MARGIN, -Const::SCENE_MARGIN,
|
|
|
|
page->pageItem()->width() + Const::SCENE_MARGIN * 2,
|
|
|
|
page->pageItem()->boundingRect().height() + Const::SCENE_MARGIN * 2);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
emit pagesLoadFinished();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::saveError(QString message) { m_lastError = message; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
void ReportEnginePrivate::showError(QString message)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QMessageBox::critical(0, tr("Error"), message);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-05 01:38:19 +03:00
|
|
|
void ReportEnginePrivate::updateTranslations()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (ReportTranslation* translation, m_translations.values()) {
|
2019-07-24 03:13:23 +03:00
|
|
|
translation->invalidatePages();
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2017-08-05 01:38:19 +03:00
|
|
|
translation->updatePageTranslation(page);
|
|
|
|
}
|
2019-07-24 03:13:23 +03:00
|
|
|
translation->clearInvalidPages();
|
2017-08-05 01:38:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::slotDataSourceCollectionLoaded(const QString& collectionName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
emit datasourceCollectionLoadFinished(collectionName);
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:48:37 +03:00
|
|
|
void ReportEnginePrivate::slotPreviewWindowDestroyed(QObject* window)
|
2016-02-20 13:37:18 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_activePreview == window) {
|
2016-02-20 13:37:18 +03:00
|
|
|
m_activePreview = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::slotDesignerWindowDestroyed(QObject* window)
|
2018-02-28 23:19:04 +03:00
|
|
|
{
|
|
|
|
Q_UNUSED(window)
|
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void ReportEnginePrivate::clearReport()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageDesignIntf* page, m_pages)
|
|
|
|
delete page;
|
2016-02-17 10:11:00 +03:00
|
|
|
m_pages.clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (ReportTranslation* reportTranslation, m_translations)
|
2017-07-29 00:54:43 +03:00
|
|
|
delete reportTranslation;
|
|
|
|
m_translations.clear();
|
2016-02-17 10:11:00 +03:00
|
|
|
m_datasources->clear(DataSourceManager::Owned);
|
2024-09-04 17:31:16 +03:00
|
|
|
m_fileName = "";
|
2016-06-10 18:05:18 +03:00
|
|
|
m_scriptEngineContext->clear();
|
2016-06-24 23:15:59 +03:00
|
|
|
m_reportSettings.setDefaultValues();
|
2016-02-17 10:11:00 +03:00
|
|
|
emit cleared();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter* printer)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!printer && !m_printerSelected) {
|
2019-10-12 22:31:35 +03:00
|
|
|
QPrinterInfo pi;
|
|
|
|
if (!pi.defaultPrinter().isNull())
|
2021-08-24 10:22:30 +03:00
|
|
|
#if QT_VERSION >= 0x050300
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer.data()->setPrinterName(pi.defaultPrinterName());
|
2019-10-12 22:31:35 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
|
2019-10-12 22:31:35 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
QPrintDialog dialog(m_printer.data(), QApplication::activeWindow());
|
|
|
|
m_printerSelected = dialog.exec() != QDialog::Rejected;
|
2019-10-12 22:31:35 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!printer && !m_printerSelected)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
printer = (printer) ? printer : m_printer.data();
|
|
|
|
if (printer && printer->isValid()) {
|
|
|
|
try {
|
|
|
|
if (pages.count() > 0) {
|
|
|
|
internalPrintPages(pages, *printer);
|
2019-10-12 22:31:35 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2019-10-12 22:31:35 +03:00
|
|
|
saveError(exception.what());
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2019-10-12 22:31:35 +03:00
|
|
|
return true;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
return false;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::internalPrintPages(ReportPages pages, QPrinter& printer)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
int currenPage = 1;
|
2019-10-16 02:08:45 +03:00
|
|
|
m_cancelPrinting = false;
|
2024-09-04 17:31:16 +03:00
|
|
|
QMap<QString, QSharedPointer<PrintProcessor>> printProcessors;
|
|
|
|
printProcessors.insert("default", QSharedPointer<PrintProcessor>(new PrintProcessor(&printer)));
|
2019-10-16 02:08:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int pageCount = (printer.printRange() == QPrinter::AllPages)
|
|
|
|
? pages.size()
|
|
|
|
: printer.toPage() - printer.fromPage();
|
2019-10-16 02:08:45 +03:00
|
|
|
|
|
|
|
emit printingStarted(pageCount);
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageItemDesignIntf::Ptr page, pages) {
|
|
|
|
if (!m_cancelPrinting
|
|
|
|
&& ((printer.printRange() == QPrinter::AllPages)
|
|
|
|
|| ((printer.printRange() == QPrinter::PageRange)
|
|
|
|
&& (currenPage >= printer.fromPage()) && (currenPage <= printer.toPage())))) {
|
|
|
|
printProcessors["default"]->printPage(page);
|
|
|
|
emit pagePrintingFinished(currenPage);
|
|
|
|
QApplication::processEvents();
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
2019-10-12 22:31:35 +03:00
|
|
|
|
2020-02-01 20:11:01 +03:00
|
|
|
currenPage++;
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
2019-10-12 22:31:35 +03:00
|
|
|
emit printingFinished();
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::printPages(ReportPages pages, QMap<QString, QPrinter*> printers,
|
|
|
|
bool printToAllPrinters)
|
2019-02-06 23:48:52 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (printers.values().isEmpty())
|
|
|
|
return;
|
2019-10-12 22:31:35 +03:00
|
|
|
m_cancelPrinting = false;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QMap<QString, QSharedPointer<PrintProcessor>> printProcessors;
|
2019-02-06 23:48:52 +03:00
|
|
|
for (int i = 0; i < printers.keys().count(); ++i) {
|
2024-09-04 17:31:16 +03:00
|
|
|
printProcessors.insert(
|
|
|
|
printers.keys()[i],
|
|
|
|
QSharedPointer<PrintProcessor>(new PrintProcessor(printers[printers.keys()[i]])));
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2019-02-06 23:48:52 +03:00
|
|
|
PrintProcessor* defaultProcessor = 0;
|
2019-02-09 23:57:19 +03:00
|
|
|
int currentPrinter = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (printProcessors.contains("default"))
|
|
|
|
defaultProcessor = printProcessors["default"].data();
|
|
|
|
else
|
|
|
|
defaultProcessor = printProcessors.values().at(0).data();
|
2019-10-12 22:31:35 +03:00
|
|
|
|
|
|
|
emit printingStarted(pages.size());
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < pages.size(); ++i) {
|
|
|
|
if (m_cancelPrinting)
|
|
|
|
break;
|
2019-10-12 22:31:35 +03:00
|
|
|
PageItemDesignIntf::Ptr page = pages.at(i);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!printToAllPrinters) {
|
2019-02-09 23:57:19 +03:00
|
|
|
if (printProcessors.contains(page->printerName()))
|
|
|
|
printProcessors[page->printerName()]->printPage(page);
|
2024-09-04 17:31:16 +03:00
|
|
|
else
|
|
|
|
defaultProcessor->printPage(page);
|
2019-02-09 23:57:19 +03:00
|
|
|
} else {
|
|
|
|
printProcessors.values().at(currentPrinter)->printPage(page);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (currentPrinter < printers.values().count() - 1)
|
2019-02-09 23:57:19 +03:00
|
|
|
currentPrinter++;
|
2024-09-04 17:31:16 +03:00
|
|
|
else
|
|
|
|
currentPrinter = 0;
|
2019-02-09 23:57:19 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
emit pagePrintingFinished(i + 1);
|
2019-10-12 22:31:35 +03:00
|
|
|
QApplication::processEvents();
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2019-10-12 22:31:35 +03:00
|
|
|
|
|
|
|
emit printingFinished();
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-01 02:02:51 +03:00
|
|
|
QStringList ReportEnginePrivate::aviableReportTranslations()
|
|
|
|
{
|
|
|
|
QStringList result;
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (QLocale::Language language, aviableLanguages()) {
|
2017-09-01 02:02:51 +03:00
|
|
|
result << QLocale::languageToString(language);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setReportTranslation(const QString& languageName)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (QLocale::Language language, aviableLanguages()) {
|
|
|
|
if (QLocale::languageToString(language).compare(languageName) == 0) {
|
|
|
|
setReportLanguage(language);
|
|
|
|
}
|
2017-09-01 02:02:51 +03:00
|
|
|
}
|
2018-02-28 23:19:04 +03:00
|
|
|
}
|
2017-09-01 02:02:51 +03:00
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
bool ReportEnginePrivate::printReport(QPrinter* printer)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!printer && !m_printerSelected) {
|
2017-03-05 16:39:50 +03:00
|
|
|
QPrinterInfo pi;
|
|
|
|
if (!pi.defaultPrinter().isNull())
|
2021-08-24 10:22:30 +03:00
|
|
|
#if QT_VERSION >= 0x050300
|
2017-03-05 16:39:50 +03:00
|
|
|
m_printer.data()->setPrinterName(pi.defaultPrinterName());
|
2019-01-26 23:30:13 +03:00
|
|
|
#else
|
2021-08-24 10:22:30 +03:00
|
|
|
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
|
2017-04-19 01:04:14 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
QPrintDialog dialog(m_printer.data(), QApplication::activeWindow());
|
|
|
|
m_printerSelected = dialog.exec() != QDialog::Rejected;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!printer && !m_printerSelected)
|
|
|
|
return false;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
printer = (printer) ? printer : m_printer.data();
|
|
|
|
if (printer && printer->isValid()) {
|
|
|
|
try {
|
2018-02-28 23:19:04 +03:00
|
|
|
bool designTime = dataManager()->designTime();
|
2022-03-27 10:08:16 +03:00
|
|
|
dataManager()->setDesignTime(false);
|
2016-06-10 18:05:18 +03:00
|
|
|
ReportPages pages = renderToPages();
|
2018-02-28 23:19:04 +03:00
|
|
|
dataManager()->setDesignTime(designTime);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.count() > 0) {
|
2019-10-12 22:31:35 +03:00
|
|
|
internalPrintPages(pages, *printer);
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2016-06-10 18:05:18 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
}
|
|
|
|
return true;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
return false;
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
|
2019-02-09 23:57:19 +03:00
|
|
|
bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters)
|
2019-02-06 23:48:52 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
try {
|
2019-02-06 23:48:52 +03:00
|
|
|
bool designTime = dataManager()->designTime();
|
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
ReportPages pages = renderToPages();
|
|
|
|
dataManager()->setDesignTime(designTime);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.count() > 0) {
|
2019-10-12 22:31:35 +03:00
|
|
|
printPages(pages, printers, printToAllPrinters);
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2019-02-06 23:48:52 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::printToFile(const QString& fileName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!fileName.isEmpty()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
QFile file(fileName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (file.open(QIODevice::WriteOnly)) {
|
2016-02-17 10:11:00 +03:00
|
|
|
QTextStream out(&file);
|
|
|
|
try {
|
|
|
|
dataManager()->setDesignTime(false);
|
2024-09-04 17:31:16 +03:00
|
|
|
out << renderToString();
|
2016-02-17 10:11:00 +03:00
|
|
|
dataManager()->setDesignTime(true);
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2016-02-17 10:11:00 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::printToPDF(const QString& fileName)
|
2016-02-17 10:19:50 +03:00
|
|
|
{
|
2018-07-11 13:29:12 +03:00
|
|
|
return exportReport("PDF", fileName);
|
2018-06-23 00:04:28 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::exportReport(QString exporterName, const QString& fileName,
|
|
|
|
const QMap<QString, QVariant>& params)
|
2018-06-23 00:04:28 +03:00
|
|
|
{
|
|
|
|
QString fn = fileName;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ExportersFactory::instance().map().contains(exporterName)) {
|
2018-06-23 00:04:28 +03:00
|
|
|
ReportExporterInterface* e = ExportersFactory::instance().objectCreator(exporterName)(this);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (fn.isEmpty()) {
|
2019-12-11 15:01:02 +03:00
|
|
|
QString defaultFileName = reportName().split(".")[0];
|
2018-06-23 00:04:28 +03:00
|
|
|
QString filter = QString("%1 (*.%2)").arg(e->exporterName()).arg(e->exporterFileExt());
|
2024-09-04 17:31:16 +03:00
|
|
|
fn = QFileDialog::getSaveFileName(0, tr("%1 file name").arg(e->exporterName()),
|
|
|
|
defaultFileName, filter);
|
2018-10-14 00:06:27 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!fn.isEmpty()) {
|
2018-10-14 00:06:27 +03:00
|
|
|
QFileInfo fi(fn);
|
|
|
|
if (fi.suffix().isEmpty())
|
|
|
|
fn += QString(".%1").arg(e->exporterFileExt());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (fi.absolutePath().compare(QDir::currentPath()) == 0)
|
2024-07-25 21:44:11 +03:00
|
|
|
fn = defaultExportDir() + fn;
|
2018-10-14 00:06:27 +03:00
|
|
|
bool designTime = dataManager()->designTime();
|
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
ReportPages pages = renderToPages();
|
|
|
|
dataManager()->setDesignTime(designTime);
|
|
|
|
bool result = e->exportPages(pages, fn, params);
|
|
|
|
delete e;
|
|
|
|
return result;
|
2018-06-23 00:04:28 +03:00
|
|
|
}
|
2016-02-17 10:19:50 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hints,
|
|
|
|
QPrinter* printer)
|
2019-05-29 03:41:18 +03:00
|
|
|
{
|
2020-03-19 20:09:35 +03:00
|
|
|
Q_UNUSED(printer)
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.count() > 0) {
|
2019-05-29 04:05:10 +03:00
|
|
|
Q_Q(ReportEngine);
|
2024-09-04 17:31:16 +03:00
|
|
|
PreviewReportWindow* w
|
|
|
|
= new PreviewReportWindow(q, QApplication::activeWindow(), settings());
|
|
|
|
w->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint
|
|
|
|
| Qt::WindowMinMaxButtonsHint);
|
|
|
|
w->setAttribute(Qt::WA_DeleteOnClose, true);
|
2019-05-29 03:41:18 +03:00
|
|
|
w->setWindowModality(Qt::ApplicationModal);
|
2021-02-20 16:16:58 +03:00
|
|
|
w->setPreviewPageBackgroundColor(m_previewPageBackgroundColor);
|
2024-09-04 17:31:16 +03:00
|
|
|
// w->setWindowIcon(QIcon(":/report/images/main.ico"));
|
2019-05-29 03:41:18 +03:00
|
|
|
w->setWindowIcon(m_previewWindowIcon);
|
|
|
|
w->setWindowTitle(m_previewWindowTitle);
|
|
|
|
w->setSettings(settings());
|
|
|
|
w->setPages(pages);
|
|
|
|
w->setLayoutDirection(m_previewLayoutDirection);
|
2019-06-27 10:45:26 +03:00
|
|
|
w->setStyleSheet(styleSheet());
|
2024-09-04 17:31:16 +03:00
|
|
|
// w->setDefaultPrinter()
|
2019-05-29 03:41:18 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->errorsList().isEmpty()) {
|
2019-05-29 03:41:18 +03:00
|
|
|
w->setErrorMessages(dataManager()->errorsList());
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!hints.testFlag(PreviewBarsUserSetting)) {
|
2019-05-29 03:41:18 +03:00
|
|
|
w->setMenuVisible(!hints.testFlag(HidePreviewMenuBar));
|
|
|
|
w->setStatusBarVisible(!hints.testFlag(HidePreviewStatusBar));
|
|
|
|
w->setToolBarVisible(!hints.testFlag(HidePreviewToolBar));
|
|
|
|
}
|
|
|
|
|
|
|
|
w->setHideResultEditButton(resultIsEditable());
|
|
|
|
w->setHidePrintButton(printIsVisible());
|
|
|
|
w->setHideSaveToFileButton(saveToFileIsVisible());
|
|
|
|
w->setHidePrintToPdfButton(printToPdfIsVisible());
|
|
|
|
w->setEnablePrintMenu(printIsVisible() || printToPdfIsVisible());
|
|
|
|
|
|
|
|
m_activePreview = w;
|
|
|
|
|
|
|
|
w->setPreviewScaleType(m_previewScaleType, m_previewScalePercent);
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*)));
|
|
|
|
connect(w, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*)), this,
|
|
|
|
SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*)));
|
2019-05-29 03:41:18 +03:00
|
|
|
w->exec();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::previewReport(PreviewHints hints) { previewReport(0, hints); }
|
2016-08-02 22:33:33 +03:00
|
|
|
|
2019-07-24 03:13:23 +03:00
|
|
|
void ReportEnginePrivate::previewReport(QPrinter* printer, PreviewHints hints)
|
2019-02-20 13:54:26 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
try {
|
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
ReportPages pages = renderToPages();
|
|
|
|
dataManager()->setDesignTime(true);
|
|
|
|
showPreviewWindow(pages, hints, printer);
|
|
|
|
} catch (ReportError& exception) {
|
|
|
|
saveError(exception.what());
|
|
|
|
showError(exception.what());
|
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportDesignWindowInterface* ReportEnginePrivate::getDesignerWindow()
|
2017-11-27 23:14:05 +03:00
|
|
|
{
|
|
|
|
if (!m_designerWindow) {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_designerFactory) {
|
|
|
|
m_designerWindow = m_designerFactory->getDesignerWindow(
|
|
|
|
this, QApplication::activeWindow(), settings());
|
|
|
|
m_designerWindow->setAttribute(Qt::WA_DeleteOnClose, true);
|
2017-11-27 23:14:05 +03:00
|
|
|
m_designerWindow->setWindowIcon(QIcon(":report/images/logo32"));
|
|
|
|
m_designerWindow->setShowProgressDialog(m_showProgressDialog);
|
|
|
|
} else {
|
|
|
|
#ifdef HAVE_REPORT_DESIGNER
|
2024-09-04 17:31:16 +03:00
|
|
|
m_designerWindow = new LimeReport::ReportDesignWindow(
|
|
|
|
this, QApplication::activeWindow(), settings());
|
|
|
|
m_designerWindow->setAttribute(Qt::WA_DeleteOnClose, true);
|
2017-11-27 23:14:05 +03:00
|
|
|
m_designerWindow->setWindowIcon(QIcon(":report/images/logo32"));
|
|
|
|
m_designerWindow->setShowProgressDialog(m_showProgressDialog);
|
|
|
|
#endif
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
}
|
|
|
|
if (m_designerWindow) {
|
2017-11-27 23:14:05 +03:00
|
|
|
m_datasources->updateDatasourceModel();
|
|
|
|
}
|
|
|
|
return m_designerWindow;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PreviewReportWidget* ReportEnginePrivate::createPreviewWidget(QWidget* parent)
|
|
|
|
{
|
2016-03-30 23:21:44 +03:00
|
|
|
|
2017-03-22 14:42:09 +03:00
|
|
|
Q_Q(ReportEngine);
|
|
|
|
PreviewReportWidget* widget = new PreviewReportWidget(q, parent);
|
2024-09-04 17:31:16 +03:00
|
|
|
try {
|
2016-03-30 23:21:44 +03:00
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
ReportPages pages = renderToPages();
|
|
|
|
dataManager()->setDesignTime(true);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.count() > 0)
|
2016-03-30 23:21:44 +03:00
|
|
|
widget->d_ptr->setPages(pages);
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2016-03-30 23:21:44 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
showError(exception.what());
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageDesignIntf* ReportEnginePrivate::createPreviewScene(QObject* parent)
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
PageDesignIntf* result = 0;
|
|
|
|
try {
|
|
|
|
ReportPages pages = renderToPages();
|
|
|
|
result = new PageDesignIntf(parent);
|
|
|
|
result->setPageItems(pages);
|
2019-03-11 22:12:35 +03:00
|
|
|
result->setItemMode(PrintMode);
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2016-02-17 10:11:00 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
showError(exception.what());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:01:30 +03:00
|
|
|
bool ReportEnginePrivate::emitSaveReport()
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
2018-05-23 19:01:30 +03:00
|
|
|
bool result = false;
|
|
|
|
emit onSave(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEnginePrivate::emitSaveReportAs()
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
emit onSaveAs(result);
|
|
|
|
return result;
|
2016-02-17 10:39:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEnginePrivate::emitLoadReport()
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
emit onLoad(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::emitSaveFinished() { emit saveFinished(); }
|
2016-04-21 17:44:58 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::emitLoadFinished() { emit loadFinished(); }
|
2018-05-23 19:01:30 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::emitPrintedToPDF(QString fileName) { emit printedToPDF(fileName); }
|
2018-05-08 16:30:10 +03:00
|
|
|
|
2016-02-17 10:39:17 +03:00
|
|
|
bool ReportEnginePrivate::isSaved()
|
|
|
|
{
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!page->isSaved())
|
|
|
|
return false;
|
2016-02-17 10:39:17 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setCurrentReportsDir(const QString& dirName)
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
|
|
|
if (QDir(dirName).exists())
|
|
|
|
m_reportsDir = dirName;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::setDefaultExportDir(const QString& dirName)
|
2024-07-25 21:44:11 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (QDir(dirName).exists()) {
|
2024-07-25 21:44:11 +03:00
|
|
|
m_exportDir = dirName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::slotLoadFromFile(const QString& fileName)
|
2017-04-20 05:43:48 +03:00
|
|
|
{
|
2018-02-28 23:19:04 +03:00
|
|
|
EASY_BLOCK("ReportEnginePrivate::slotLoadFromFile")
|
2024-09-04 17:31:16 +03:00
|
|
|
PreviewReportWindow* currentPreview = qobject_cast<PreviewReportWindow*>(m_activePreview);
|
2022-03-27 10:08:16 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!QFile::exists(fileName)) {
|
|
|
|
if (hasActivePreview()) {
|
|
|
|
QMessageBox::information(
|
|
|
|
NULL, tr("Report File Change"),
|
|
|
|
tr("The report file \"%1\" has changed names or been deleted.\n\nThis preview "
|
|
|
|
"is no longer valid.")
|
|
|
|
.arg(fileName));
|
2022-03-27 10:08:16 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
clearReport();
|
2022-03-27 10:08:16 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
currentPreview->close();
|
|
|
|
}
|
2022-03-27 10:08:16 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
return false;
|
2017-04-20 05:43:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
clearReport();
|
|
|
|
|
|
|
|
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
|
|
|
|
reader->setPassPhrase(m_passPhrase);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reader->first()) {
|
|
|
|
if (reader->readItem(this)) {
|
|
|
|
m_fileName = fileName;
|
2017-04-20 05:43:48 +03:00
|
|
|
QFileInfo fi(fileName);
|
|
|
|
m_reportName = fi.fileName();
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString dbSettingFileName = fi.absolutePath() + "/" + fi.baseName() + ".db";
|
|
|
|
if (QFile::exists(dbSettingFileName)) {
|
2017-04-20 05:43:48 +03:00
|
|
|
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
|
|
|
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!connection->keepDBCredentials()) {
|
2017-04-20 05:43:48 +03:00
|
|
|
dbcredentals.beginGroup(connection->name());
|
|
|
|
connection->setUserName(dbcredentals.value("user").toString());
|
|
|
|
connection->setPassword(dbcredentals.value("password").toString());
|
|
|
|
dbcredentals.endGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 23:19:04 +03:00
|
|
|
EASY_BLOCK("Connect auto connections")
|
2017-04-20 05:43:48 +03:00
|
|
|
dataManager()->connectAutoConnections();
|
2018-02-28 23:19:04 +03:00
|
|
|
EASY_END_BLOCK;
|
2019-02-05 21:51:46 +03:00
|
|
|
dropChanges();
|
2017-04-20 05:43:48 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (hasActivePreview()) {
|
|
|
|
currentPreview->reloadPreview();
|
2017-04-20 05:43:48 +03:00
|
|
|
}
|
2018-02-28 23:19:04 +03:00
|
|
|
EASY_END_BLOCK;
|
2017-04-20 05:43:48 +03:00
|
|
|
return true;
|
2019-10-16 02:08:45 +03:00
|
|
|
}
|
2017-04-20 05:43:48 +03:00
|
|
|
}
|
|
|
|
m_lastError = reader->lastError();
|
2018-02-28 23:19:04 +03:00
|
|
|
EASY_END_BLOCK;
|
2017-04-20 05:43:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void ReportEnginePrivate::cancelRender()
|
|
|
|
{
|
|
|
|
if (m_reportRender)
|
|
|
|
m_reportRender->cancelRender();
|
2016-12-13 12:47:46 +03:00
|
|
|
m_reportRendering = false;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::cancelPrinting() { m_cancelPrinting = true; }
|
2019-10-12 22:31:35 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QGraphicsScene* ReportEngine::createPreviewScene(QObject* parent)
|
|
|
|
{
|
2016-06-10 18:05:18 +03:00
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->createPreviewScene(parent);
|
|
|
|
}
|
|
|
|
|
2020-01-09 21:22:58 +03:00
|
|
|
void ReportEnginePrivate::designReport(bool showModal)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2017-11-27 23:14:05 +03:00
|
|
|
ReportDesignWindowInterface* designerWindow = getDesignerWindow();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (designerWindow) {
|
2018-02-28 23:19:04 +03:00
|
|
|
dataManager()->setDesignTime(true);
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(designerWindow, SIGNAL(destroyed(QObject*)), this,
|
|
|
|
SLOT(slotDesignerWindowDestroyed(QObject*)));
|
2022-03-27 10:08:16 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
designerWindow->setWindowModality(Qt::NonModal);
|
2016-02-17 10:11:00 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!showModal) {
|
|
|
|
designerWindow->show();
|
|
|
|
;
|
2017-11-27 23:14:05 +03:00
|
|
|
} else {
|
|
|
|
designerWindow->showModal();
|
|
|
|
}
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
qDebug() << (tr("Designer not found!"));
|
2017-11-27 23:14:05 +03:00
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEnginePrivate::setSettings(QSettings* value)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (value) {
|
|
|
|
if (m_ownedSettings && m_settings)
|
2016-02-17 10:11:00 +03:00
|
|
|
delete m_settings;
|
|
|
|
m_settings = value;
|
|
|
|
m_ownedSettings = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QSettings* ReportEnginePrivate::settings()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_settings) {
|
2016-02-17 10:11:00 +03:00
|
|
|
return m_settings;
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
m_settings = new QSettings("LimeReport", QApplication::applicationName());
|
|
|
|
m_ownedSettings = true;
|
2016-02-17 10:11:00 +03:00
|
|
|
return m_settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
// only watch one file at a time
|
2018-02-28 23:19:04 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_fileWatcher->files().isEmpty()) {
|
|
|
|
m_fileWatcher->removePaths(m_fileWatcher->files());
|
|
|
|
}
|
2016-03-19 13:33:49 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (autoLoadPreviewOnChange) {
|
|
|
|
m_fileWatcher->addPath(fileName);
|
|
|
|
}
|
2017-02-16 04:11:39 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool result = slotLoadFromFile(fileName);
|
|
|
|
if (result) {
|
|
|
|
emit loadFinished();
|
|
|
|
}
|
|
|
|
return result;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString& name)
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
clearReport();
|
2016-02-17 10:39:17 +03:00
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data);
|
2017-02-16 04:11:39 +03:00
|
|
|
reader->setPassPhrase(m_passPhrase);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reader->first()) {
|
|
|
|
if (reader->readItem(this)) {
|
2016-02-17 10:39:17 +03:00
|
|
|
m_fileName = "";
|
|
|
|
m_reportName = name;
|
2018-05-23 19:01:30 +03:00
|
|
|
emit loadFinished();
|
2016-02-17 10:39:17 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::loadFromString(const QString& report, const QString& name)
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
|
|
|
clearReport();
|
|
|
|
|
|
|
|
ItemsReaderIntf::Ptr reader = StringXMLreader::create(report);
|
2017-02-16 04:11:39 +03:00
|
|
|
reader->setPassPhrase(m_passPhrase);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reader->first()) {
|
|
|
|
if (reader->readItem(this)) {
|
2016-02-17 10:39:17 +03:00
|
|
|
m_fileName = "";
|
|
|
|
m_reportName = name;
|
2018-05-23 19:01:30 +03:00
|
|
|
emit loadFinished();
|
2016-02-17 10:11:00 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::saveToFile(const QString& fileName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (fileName.isEmpty() & m_fileName.isEmpty())
|
|
|
|
return false;
|
2018-02-07 22:43:31 +03:00
|
|
|
QString fn = fileName.isEmpty() ? m_fileName : fileName;
|
|
|
|
QFileInfo fi(fn);
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
if (fi.suffix().isEmpty())
|
2024-09-04 17:31:16 +03:00
|
|
|
fn += ".lrxml";
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString dbSettingFileName = fi.absolutePath() + "/" + fi.baseName() + ".db";
|
2017-02-16 04:11:39 +03:00
|
|
|
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
|
|
|
|
|
|
|
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!connection->keepDBCredentials()) {
|
2017-02-16 04:11:39 +03:00
|
|
|
dbcredentals.beginGroup(connection->name());
|
2024-09-04 17:31:16 +03:00
|
|
|
dbcredentals.setValue("user", connection->userName());
|
|
|
|
dbcredentals.setValue("password", connection->password());
|
2017-02-16 04:11:39 +03:00
|
|
|
dbcredentals.endGroup();
|
|
|
|
connection->setPassword("");
|
|
|
|
connection->setUserName("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
2017-02-16 04:11:39 +03:00
|
|
|
writer->setPassPhrase(m_passPhrase);
|
2016-02-17 10:11:00 +03:00
|
|
|
writer->putItem(this);
|
2024-09-04 17:31:16 +03:00
|
|
|
m_fileName = fn;
|
2016-02-17 10:11:00 +03:00
|
|
|
bool saved = writer->saveToFile(fn);
|
2017-02-16 04:11:39 +03:00
|
|
|
|
|
|
|
foreach (ConnectionDesc* connection, dataManager()->conections()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!connection->keepDBCredentials()) {
|
2017-02-16 04:11:39 +03:00
|
|
|
dbcredentals.beginGroup(connection->name());
|
|
|
|
connection->setUserName(dbcredentals.value("user").toString());
|
|
|
|
connection->setPassword(dbcredentals.value("password").toString());
|
|
|
|
dbcredentals.endGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (saved) {
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2016-02-17 10:11:00 +03:00
|
|
|
page->setToSaved();
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 21:51:46 +03:00
|
|
|
dropChanges();
|
2020-07-29 04:09:45 +03:00
|
|
|
this->setReportName(fi.baseName());
|
2016-02-17 10:11:00 +03:00
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:39:17 +03:00
|
|
|
QByteArray ReportEnginePrivate::saveToByteArray()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
2017-02-16 04:11:39 +03:00
|
|
|
writer->setPassPhrase(m_passPhrase);
|
2016-02-17 10:39:17 +03:00
|
|
|
writer->putItem(this);
|
|
|
|
QByteArray result = writer->saveToByteArray();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!result.isEmpty()) {
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2016-02-17 10:39:17 +03:00
|
|
|
page->setToSaved();
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 21:51:46 +03:00
|
|
|
dropChanges();
|
2016-02-17 10:39:17 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ReportEnginePrivate::saveToString()
|
|
|
|
{
|
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
2017-02-16 04:11:39 +03:00
|
|
|
writer->setPassPhrase(m_passPhrase);
|
2016-02-17 10:39:17 +03:00
|
|
|
writer->putItem(this);
|
|
|
|
QString result = writer->saveToString();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!result.isEmpty()) {
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2016-02-17 10:39:17 +03:00
|
|
|
page->setToSaved();
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 21:51:46 +03:00
|
|
|
dropChanges();
|
2016-02-17 10:39:17 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
bool ReportEnginePrivate::isNeedToSave()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
|
|
|
if (page->isHasChanges())
|
|
|
|
return true;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
if (dataManager()->hasChanges()) {
|
2019-01-31 21:01:55 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-02-05 21:51:46 +03:00
|
|
|
if (scriptContext()->hasChanges())
|
|
|
|
return true;
|
2016-02-17 10:11:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ReportEnginePrivate::renderToString()
|
|
|
|
{
|
|
|
|
LimeReport::ReportRender render;
|
2018-09-01 12:36:25 +03:00
|
|
|
updateTranslations();
|
2016-02-17 10:11:00 +03:00
|
|
|
dataManager()->connectAllDatabases();
|
|
|
|
dataManager()->setDesignTime(false);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_pages.count()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
render.setDatasources(dataManager());
|
2016-06-10 18:05:18 +03:00
|
|
|
render.setScriptContext(scriptContext());
|
2018-03-07 19:54:57 +03:00
|
|
|
return render.renderPageToString(m_pages.at(0)->pageItem());
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
return QString();
|
2018-07-11 02:42:43 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScaleType ReportEnginePrivate::previewScaleType() { return m_previewScaleType; }
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ReportEnginePrivate::previewScalePercent() { return m_previewScalePercent; }
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPreviewScaleType(const ScaleType& scaleType, int percent)
|
2018-07-11 02:42:43 +03:00
|
|
|
{
|
|
|
|
m_previewScaleType = scaleType;
|
|
|
|
m_previewScalePercent = percent;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::addWatermark(const WatermarkSetting& watermarkSetting)
|
2019-03-30 09:37:40 +03:00
|
|
|
{
|
|
|
|
m_watermarks.append(watermarkSetting);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::clearWatermarks() { m_watermarks.clear(); }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2018-03-07 19:54:57 +03:00
|
|
|
PageItemDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName)
|
2017-07-29 00:54:43 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageItemDesignIntf* page, m_renderingPages) {
|
|
|
|
if (page->objectName().compare(pageName, Qt::CaseInsensitive) == 0)
|
2017-07-29 00:54:43 +03:00
|
|
|
return page;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
IPreparedPages* ReportEnginePrivate::preparedPages() { return m_preparedPagesManager; }
|
2019-05-29 16:32:58 +03:00
|
|
|
|
2019-05-29 03:41:18 +03:00
|
|
|
bool ReportEnginePrivate::showPreparedPages(PreviewHints hints)
|
|
|
|
{
|
2019-07-24 03:13:23 +03:00
|
|
|
return showPreparedPages(0, hints);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEnginePrivate::showPreparedPages(QPrinter* defaultPrinter, PreviewHints hints)
|
|
|
|
{
|
|
|
|
return showPreviewWindow(m_preparedPages, hints, defaultPrinter);
|
2019-05-29 03:41:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEnginePrivate::prepareReportPages()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
try {
|
2019-05-29 03:41:18 +03:00
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
m_preparedPages = renderToPages();
|
|
|
|
dataManager()->setDesignTime(true);
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2019-05-29 03:41:18 +03:00
|
|
|
saveError(exception.what());
|
|
|
|
showError(exception.what());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !m_preparedPages.isEmpty();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::printPreparedPages() { return printPages(m_preparedPages, 0); }
|
2019-06-03 22:30:50 +03:00
|
|
|
|
2017-11-01 22:09:19 +03:00
|
|
|
Qt::LayoutDirection ReportEnginePrivate::previewLayoutDirection()
|
|
|
|
{
|
|
|
|
return m_previewLayoutDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEnginePrivate::setPreviewLayoutDirection(const Qt::LayoutDirection& layoutDirection)
|
|
|
|
{
|
|
|
|
m_previewLayoutDirection = layoutDirection;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPassPhrase(const QString& passPhrase) { m_passPhrase = passPhrase; }
|
2017-02-16 04:11:39 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::reorderPages(const QList<PageDesignIntf*>& reorderedPages)
|
2017-08-19 00:16:55 +03:00
|
|
|
{
|
|
|
|
m_pages.clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageDesignIntf* page, reorderedPages) {
|
2017-08-19 00:16:55 +03:00
|
|
|
m_pages.append(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 22:02:13 +03:00
|
|
|
void ReportEnginePrivate::clearSelection()
|
|
|
|
{
|
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (QGraphicsItem* item, page->selectedItems()) {
|
2017-09-21 22:02:13 +03:00
|
|
|
item->setSelected(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 00:54:43 +03:00
|
|
|
bool ReportEnginePrivate::addTranslationLanguage(QLocale::Language language)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_translations.keys().contains(language)) {
|
2017-08-16 01:18:56 +03:00
|
|
|
ReportTranslation* translation = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_translations.contains(QLocale::AnyLanguage)) {
|
|
|
|
translation = new ReportTranslation(QLocale::AnyLanguage, m_pages);
|
|
|
|
m_translations.insert(QLocale::AnyLanguage, translation);
|
2017-08-16 01:18:56 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
translation = new ReportTranslation(language, m_pages);
|
2017-07-29 00:54:43 +03:00
|
|
|
m_translations.insert(language, translation);
|
|
|
|
return true;
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
m_lastError = tr("Language %1 already exists").arg(QLocale::languageToString(language));
|
2017-07-29 00:54:43 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 01:18:56 +03:00
|
|
|
bool ReportEnginePrivate::removeTranslationLanguage(QLocale::Language language)
|
|
|
|
{
|
|
|
|
return m_translations.remove(language) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEnginePrivate::activateLanguage(QLocale::Language language)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_translations.keys().contains(language))
|
|
|
|
return;
|
2017-07-29 00:54:43 +03:00
|
|
|
ReportTranslation* translation = m_translations.value(language);
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageTranslation* pageTranslation, translation->pagesTranslation()) {
|
2018-03-07 19:54:57 +03:00
|
|
|
PageItemDesignIntf* page = getPageByName(pageTranslation->pageName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page) {
|
|
|
|
foreach (ItemTranslation* itemTranslation, pageTranslation->itemsTranslation) {
|
2018-03-07 19:54:57 +03:00
|
|
|
BaseDesignIntf* item = page->childByName(itemTranslation->itemName);
|
2017-07-29 00:54:43 +03:00
|
|
|
if (item) {
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PropertyTranslation* propertyTranslation,
|
|
|
|
itemTranslation->propertyesTranslation) {
|
2018-09-06 23:07:19 +03:00
|
|
|
if (propertyTranslation->checked)
|
2024-09-04 17:31:16 +03:00
|
|
|
item->setProperty(propertyTranslation->propertyName.toLatin1(),
|
|
|
|
propertyTranslation->value);
|
2017-07-29 00:54:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-16 01:18:56 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:17 +03:00
|
|
|
QList<QLocale::Language> ReportEnginePrivate::designerLanguages()
|
2018-04-10 16:28:48 +03:00
|
|
|
{
|
|
|
|
|
2018-05-15 22:14:17 +03:00
|
|
|
QList<QLocale::Language> result;
|
2019-06-11 21:55:59 +03:00
|
|
|
emit getAvailableDesignerLanguages(&result);
|
2018-05-15 22:14:17 +03:00
|
|
|
return result;
|
2018-04-10 16:28:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QLocale::Language ReportEnginePrivate::currentDesignerLanguage()
|
|
|
|
{
|
2019-06-11 21:55:59 +03:00
|
|
|
QLocale::Language result = emit getCurrentDefaultDesignerLanguage();
|
2018-05-15 22:14:17 +03:00
|
|
|
return result;
|
2018-04-10 16:28:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEnginePrivate::setCurrentDesignerLanguage(QLocale::Language language)
|
|
|
|
{
|
|
|
|
m_currentDesignerLanguage = language;
|
2019-06-11 21:55:59 +03:00
|
|
|
emit currentDefaultDesignerLanguageChanged(language);
|
2018-04-10 16:28:48 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ReportEnginePrivate::styleSheet() const { return m_styleSheet; }
|
2017-12-11 16:48:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setStyleSheet(const QString& styleSheet) { m_styleSheet = styleSheet; }
|
2017-12-11 16:48:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::setReportLanguage(QLocale::Language language)
|
|
|
|
{
|
2017-08-16 01:18:56 +03:00
|
|
|
m_reportLanguage = language;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_translations.keys().contains(language))
|
|
|
|
return false;
|
2017-12-11 16:48:00 +03:00
|
|
|
// activateLanguage(language);
|
2017-07-29 00:54:43 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QList<QLocale::Language> ReportEnginePrivate::aviableLanguages() { return m_translations.keys(); }
|
2017-07-29 00:54:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportTranslation* ReportEnginePrivate::reportTranslation(QLocale::Language language)
|
2017-07-29 00:54:43 +03:00
|
|
|
{
|
|
|
|
return m_translations.value(language);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::resultIsEditable() const { return m_resultIsEditable; }
|
2017-02-03 14:20:30 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setResultEditable(bool value) { m_resultIsEditable = value; }
|
2017-02-03 14:20:30 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::saveToFileIsVisible() const { return m_saveToFileVisible; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setSaveToFileVisible(bool value) { m_saveToFileVisible = value; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::printToPdfIsVisible() const { return m_printToPdfVisible; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPrintToPdfVisible(bool value) { m_printToPdfVisible = value; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::printIsVisible() const { return m_printVisible; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPrintVisible(bool value) { m_printVisible = value; }
|
2019-04-10 16:23:50 +03:00
|
|
|
|
2016-06-24 23:15:59 +03:00
|
|
|
bool ReportEnginePrivate::suppressFieldAndVarError() const
|
|
|
|
{
|
|
|
|
return m_reportSettings.suppressAbsentFieldsAndVarsWarnings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEnginePrivate::setSuppressFieldAndVarError(bool suppressFieldAndVarError)
|
|
|
|
{
|
|
|
|
m_reportSettings.setSuppressAbsentFieldsAndVarsWarnings(suppressFieldAndVarError);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ReportEnginePrivate::baseItemPadding() const { return m_reportSettings.baseItemPadding(); }
|
2024-07-24 22:44:58 +03:00
|
|
|
|
|
|
|
void ReportEnginePrivate::setBaseItemPadding(int baseTextItemPadding)
|
|
|
|
{
|
|
|
|
m_reportSettings.setBaseItemPadding(baseTextItemPadding);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEnginePrivate::isBusy() { return m_reportRendering; }
|
2016-12-13 12:47:46 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ReportEnginePrivate::previewWindowTitle() const { return m_previewWindowTitle; }
|
2016-04-06 22:03:58 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPreviewWindowTitle(const QString& previewWindowTitle)
|
2016-04-06 22:03:58 +03:00
|
|
|
{
|
|
|
|
m_previewWindowTitle = previewWindowTitle;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QColor ReportEnginePrivate::previewWindowPageBackground() { return m_previewPageBackgroundColor; }
|
2019-02-18 15:16:55 +03:00
|
|
|
|
|
|
|
void ReportEnginePrivate::setPreviewWindowPageBackground(QColor color)
|
|
|
|
{
|
|
|
|
m_previewPageBackgroundColor = color;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QIcon ReportEnginePrivate::previewWindowIcon() const { return m_previewWindowIcon; }
|
2016-04-06 22:03:58 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::setPreviewWindowIcon(const QIcon& previewWindowIcon)
|
2016-04-06 22:03:58 +03:00
|
|
|
{
|
|
|
|
m_previewWindowIcon = previewWindowIcon;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageItemDesignIntf* ReportEnginePrivate::createRenderingPage(PageItemDesignIntf* page)
|
|
|
|
{
|
|
|
|
PageItemDesignIntf* result
|
|
|
|
= dynamic_cast<PageItemDesignIntf*>(page->cloneItem(page->itemMode()));
|
2018-03-07 19:54:57 +03:00
|
|
|
ICollectionContainer* co = dynamic_cast<ICollectionContainer*>(result);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (co)
|
|
|
|
co->collectionLoadFinished("children");
|
2018-03-07 19:54:57 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-12 22:55:03 +03:00
|
|
|
void ReportEnginePrivate::initReport()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int index = 0; index < pageCount(); ++index) {
|
|
|
|
PageDesignIntf* page = pageAt(index);
|
|
|
|
if (page != 0) {
|
2018-12-12 22:55:03 +03:00
|
|
|
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
IPainterProxy* proxyItem = dynamic_cast<IPainterProxy*>(item);
|
|
|
|
if (proxyItem) {
|
2018-12-12 22:55:03 +03:00
|
|
|
proxyItem->setExternalPainter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPainter* painter,
|
|
|
|
const QStyleOptionGraphicsItem* options)
|
2018-12-12 22:55:03 +03:00
|
|
|
{
|
|
|
|
emit externalPaint(objectName, painter, options);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
BaseDesignIntf* ReportEnginePrivate::createWatermark(PageDesignIntf* page,
|
|
|
|
WatermarkSetting watermarkSetting)
|
2019-03-30 09:37:40 +03:00
|
|
|
{
|
|
|
|
|
2019-04-06 00:28:02 +03:00
|
|
|
WatermarkHelper watermarkHelper(watermarkSetting);
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
BaseDesignIntf* watermark = page->addReportItem(
|
|
|
|
"TextItem", watermarkHelper.mapToPage(*page->pageItem()), watermarkHelper.sceneSize());
|
|
|
|
if (watermark) {
|
2019-03-30 09:37:40 +03:00
|
|
|
watermark->setProperty("content", watermarkSetting.text());
|
2024-09-04 17:31:16 +03:00
|
|
|
watermark->setProperty("font", watermarkSetting.font());
|
|
|
|
watermark->setProperty("watermark", true);
|
|
|
|
watermark->setProperty("itemLocation", 1);
|
2019-03-30 09:37:40 +03:00
|
|
|
watermark->setProperty("foregroundOpacity", watermarkSetting.opacity());
|
|
|
|
watermark->setProperty("fontColor", watermarkSetting.color());
|
|
|
|
}
|
|
|
|
return watermark;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEnginePrivate::clearRenderingPages()
|
|
|
|
{
|
2020-02-04 11:40:05 +03:00
|
|
|
qDeleteAll(m_renderingPages.begin(), m_renderingPages.end());
|
|
|
|
m_renderingPages.clear();
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
ReportPages ReportEnginePrivate::renderToPages()
|
|
|
|
{
|
2019-01-16 03:58:54 +03:00
|
|
|
int startTOCPage = -1;
|
|
|
|
int pageAfterTOCIndex = -1;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_reportRendering)
|
|
|
|
return ReportPages();
|
2018-12-12 22:55:03 +03:00
|
|
|
initReport();
|
2016-02-17 10:11:00 +03:00
|
|
|
m_reportRender = ReportRender::Ptr(new ReportRender);
|
2018-09-01 12:36:25 +03:00
|
|
|
updateTranslations();
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(m_reportRender.data(), SIGNAL(pageRendered(int)), this,
|
|
|
|
SIGNAL(renderPageFinished(int)));
|
2017-04-20 23:34:32 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_pages.count()) {
|
2018-03-07 19:54:57 +03:00
|
|
|
|
2017-04-20 23:34:32 +03:00
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
m_scriptEngineContext->initDialogs();
|
|
|
|
#endif
|
2016-06-10 18:05:18 +03:00
|
|
|
ReportPages result;
|
2016-12-13 12:47:46 +03:00
|
|
|
m_reportRendering = true;
|
2016-02-17 10:11:00 +03:00
|
|
|
m_reportRender->setDatasources(dataManager());
|
2016-06-10 18:05:18 +03:00
|
|
|
m_reportRender->setScriptContext(scriptContext());
|
2020-02-04 11:40:05 +03:00
|
|
|
clearRenderingPages();
|
2017-04-20 23:34:32 +03:00
|
|
|
foreach (PageDesignIntf* page, m_pages) {
|
2019-03-30 09:37:40 +03:00
|
|
|
|
|
|
|
QVector<BaseDesignIntf*> watermarks;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_watermarks.isEmpty()) {
|
|
|
|
foreach (WatermarkSetting watermarkSetting, m_watermarks) {
|
2019-03-30 09:37:40 +03:00
|
|
|
watermarks.append(createWatermark(page, watermarkSetting));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 19:54:57 +03:00
|
|
|
PageItemDesignIntf* rp = createRenderingPage(page->pageItem());
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qDeleteAll(watermarks.begin(), watermarks.end());
|
2019-03-30 09:37:40 +03:00
|
|
|
watermarks.clear();
|
|
|
|
|
2018-03-07 19:54:57 +03:00
|
|
|
m_renderingPages.append(rp);
|
|
|
|
scriptContext()->baseDesignIntfToScript(rp->objectName(), rp);
|
2016-09-16 01:59:56 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
scriptContext()->qobjectToScript("engine", this);
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineManager::instance().scriptEngine()->pushContext();
|
2019-02-19 02:23:53 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_scriptEngineContext->runInitScript()) {
|
2017-09-01 02:02:51 +03:00
|
|
|
|
2018-09-06 23:07:19 +03:00
|
|
|
dataManager()->clearErrors();
|
|
|
|
dataManager()->connectAllDatabases();
|
|
|
|
dataManager()->setDesignTime(false);
|
|
|
|
dataManager()->updateDatasourceModel();
|
|
|
|
|
2017-09-01 02:02:51 +03:00
|
|
|
activateLanguage(m_reportLanguage);
|
2017-04-20 23:34:32 +03:00
|
|
|
emit renderStarted();
|
2019-03-06 22:16:30 +03:00
|
|
|
m_scriptEngineContext->setReportPages(&result);
|
2017-04-20 23:34:32 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < m_renderingPages.count(); ++i) {
|
2019-01-16 03:58:54 +03:00
|
|
|
PageItemDesignIntf* page = m_renderingPages.at(i);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!page->isTOC() && page->isPrintable()) {
|
2017-08-18 22:55:29 +03:00
|
|
|
page->setReportSettings(&m_reportSettings);
|
2024-09-04 17:31:16 +03:00
|
|
|
result = appendPages(result, m_reportRender->renderPageToPages(page),
|
|
|
|
page->mixWithPriorPage() ? MixPages : AppendPages);
|
|
|
|
} else if (page->isTOC()) {
|
2019-01-16 03:58:54 +03:00
|
|
|
startTOCPage = result.count();
|
2024-09-04 17:31:16 +03:00
|
|
|
pageAfterTOCIndex = i + 1;
|
2019-01-16 03:58:54 +03:00
|
|
|
m_reportRender->createTOCMarker(page->resetPageNumber());
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < m_renderingPages.count(); ++i) {
|
2018-03-07 19:54:57 +03:00
|
|
|
PageItemDesignIntf* page = m_renderingPages.at(i);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->isTOC()) {
|
2017-08-18 22:55:29 +03:00
|
|
|
page->setReportSettings(&m_reportSettings);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (i < m_renderingPages.count()) {
|
2018-03-07 19:54:57 +03:00
|
|
|
PageItemDesignIntf* secondPage = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_renderingPages.count() > (pageAfterTOCIndex))
|
2019-01-16 03:58:54 +03:00
|
|
|
secondPage = m_renderingPages.at(pageAfterTOCIndex);
|
2017-08-31 02:53:34 +03:00
|
|
|
ReportPages pages = m_reportRender->renderTOC(
|
2024-09-04 17:31:16 +03:00
|
|
|
page, true, secondPage && secondPage->resetPageNumber());
|
|
|
|
for (int j = 0; j < pages.count(); ++j) {
|
|
|
|
result.insert(startTOCPage + j, pages.at(j));
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
2017-08-31 02:53:34 +03:00
|
|
|
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
result = appendPages(result, m_reportRender->renderPageToPages(page),
|
|
|
|
page->mixWithPriorPage() ? MixPages : AppendPages);
|
2017-08-31 02:53:34 +03:00
|
|
|
}
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_reportRender->secondRenderPass(result);
|
2017-08-25 18:01:59 +03:00
|
|
|
|
2017-04-20 23:34:32 +03:00
|
|
|
emit renderFinished();
|
|
|
|
m_reportRender.clear();
|
2020-02-04 11:40:05 +03:00
|
|
|
clearRenderingPages();
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
2017-08-18 22:55:29 +03:00
|
|
|
m_reportRendering = false;
|
2020-02-04 11:40:05 +03:00
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineManager::instance().scriptEngine()->popContext();
|
2019-02-19 02:23:53 +03:00
|
|
|
#endif
|
2016-02-17 10:11:00 +03:00
|
|
|
return result;
|
2016-06-10 18:05:18 +03:00
|
|
|
} else {
|
2016-02-20 12:05:57 +03:00
|
|
|
return ReportPages();
|
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2021-02-17 21:53:55 +03:00
|
|
|
ReportPages ReportEnginePrivate::appendPages(ReportPages s1, ReportPages s2, AppendType appendType)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!s1.isEmpty() && s1.size() == s2.size() && appendType == MixPages) {
|
2021-02-17 21:53:55 +03:00
|
|
|
ReportPages result;
|
|
|
|
ReportPages::Iterator s1It;
|
|
|
|
ReportPages::Iterator s2It;
|
2024-09-04 17:31:16 +03:00
|
|
|
for (s1It = s1.begin(), s2It = s2.begin(); s1It != s1.end(); ++s1It, ++s2It) {
|
2021-02-17 21:53:55 +03:00
|
|
|
result.append(*s1It);
|
|
|
|
result.append(*s2It);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
s1.append(s2);
|
|
|
|
return s1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ReportEnginePrivate::lastError() { return m_lastError; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportEngine::ReportEngine(QObject* parent):
|
|
|
|
QObject(parent),
|
|
|
|
d_ptr(new ReportEnginePrivate()),
|
|
|
|
m_showDesignerModal(true)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2024-09-04 17:31:16 +03:00
|
|
|
d->q_ptr = this;
|
2016-02-17 10:11:00 +03:00
|
|
|
connect(d, SIGNAL(renderStarted()), this, SIGNAL(renderStarted()));
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(d, SIGNAL(renderPageFinished(int)), this, SIGNAL(renderPageFinished(int)));
|
2016-02-17 10:11:00 +03:00
|
|
|
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
|
2019-10-12 22:31:35 +03:00
|
|
|
|
|
|
|
connect(d, SIGNAL(printingStarted(int)), this, SIGNAL(printingStarted(int)));
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(d, SIGNAL(pagePrintingFinished(int)), this, SIGNAL(pagePrintingFinished(int)));
|
2019-10-12 22:31:35 +03:00
|
|
|
connect(d, SIGNAL(printingFinished()), this, SIGNAL(printingFinished()));
|
|
|
|
|
2018-05-23 19:01:30 +03:00
|
|
|
connect(d, SIGNAL(onSave(bool&)), this, SIGNAL(onSave(bool&)));
|
|
|
|
connect(d, SIGNAL(onSaveAs(bool&)), this, SIGNAL(onSaveAs(bool&)));
|
2016-02-17 10:39:17 +03:00
|
|
|
connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&)));
|
2016-04-21 17:44:58 +03:00
|
|
|
connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished()));
|
2018-05-23 19:01:30 +03:00
|
|
|
connect(d, SIGNAL(loadFinished()), this, SIGNAL(loadFinished()));
|
2018-06-04 22:31:03 +03:00
|
|
|
connect(d, SIGNAL(cleared()), this, SIGNAL(cleared()));
|
2018-05-08 16:30:10 +03:00
|
|
|
connect(d, SIGNAL(printedToPDF(QString)), this, SIGNAL(printedToPDF(QString)));
|
2022-03-27 10:08:16 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(d, SIGNAL(getAvailableDesignerLanguages(QList<QLocale::Language>*)), this,
|
|
|
|
SIGNAL(getAvailableDesignerLanguages(QList<QLocale::Language>*)));
|
|
|
|
connect(d, SIGNAL(currentDefaultDesignerLanguageChanged(QLocale::Language)), this,
|
|
|
|
SIGNAL(currentDefaultDesignerLanguageChanged(QLocale::Language)));
|
|
|
|
connect(d, SIGNAL(getCurrentDefaultDesignerLanguage()), this,
|
|
|
|
SIGNAL(getCurrentDefaultDesignerLanguage()));
|
2018-05-15 22:17:56 +03:00
|
|
|
|
2018-12-12 22:55:03 +03:00
|
|
|
connect(d, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)),
|
2024-09-04 17:31:16 +03:00
|
|
|
this,
|
|
|
|
SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)));
|
|
|
|
connect(d, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*)), this,
|
|
|
|
SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*)));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportEngine::~ReportEngine() { delete d_ptr; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::printReport(QPrinter* printer)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->printReport(printer);
|
|
|
|
}
|
|
|
|
|
2019-02-09 23:57:19 +03:00
|
|
|
bool ReportEngine::printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters)
|
2019-02-06 23:48:52 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2019-02-09 23:57:19 +03:00
|
|
|
return d->printReport(printers, printToAllPrinters);
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::printPages(ReportPages pages, QPrinter* printer)
|
|
|
|
{
|
2016-06-10 18:05:18 +03:00
|
|
|
Q_D(ReportEngine);
|
2024-09-04 17:31:16 +03:00
|
|
|
return d->printPages(pages, printer);
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::printToFile(const QString& fileName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->printToFile(fileName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::printToPDF(const QString& fileName)
|
2016-02-17 10:19:50 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->printToPDF(fileName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::exportReport(QString exporterName, const QString& fileName,
|
|
|
|
const QMap<QString, QVariant>& params)
|
2018-06-23 00:04:28 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->exportReport(exporterName, fileName, params);
|
|
|
|
}
|
|
|
|
|
2016-08-02 22:33:33 +03:00
|
|
|
void ReportEngine::previewReport(PreviewHints hints)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
if (m_settings)
|
|
|
|
d->setSettings(m_settings);
|
2016-08-02 22:33:33 +03:00
|
|
|
d->previewReport(hints);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::previewReport(QPrinter* printer, PreviewHints hints)
|
2019-02-20 13:54:26 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
if (m_settings)
|
|
|
|
d->setSettings(m_settings);
|
|
|
|
d->previewReport(printer, hints);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void ReportEngine::designReport()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
if (m_settings)
|
|
|
|
d->setSettings(m_settings);
|
2020-01-09 21:22:58 +03:00
|
|
|
d->designReport(showDesignerModal());
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2018-05-08 10:58:43 +03:00
|
|
|
ReportDesignWindowInterface* ReportEngine::getDesignerWindow()
|
2017-11-27 23:14:05 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->getDesignerWindow();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PreviewReportWidget* ReportEngine::createPreviewWidget(QWidget* parent)
|
2016-03-30 23:21:44 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->createPreviewWidget(parent);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setPreviewWindowTitle(const QString& title)
|
2016-04-06 22:03:58 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPreviewWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setPreviewWindowIcon(const QIcon& icon)
|
2016-04-06 22:03:58 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPreviewWindowIcon(icon);
|
|
|
|
}
|
|
|
|
|
2019-02-18 15:16:55 +03:00
|
|
|
void ReportEngine::setPreviewPageBackgroundColor(QColor color)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPreviewWindowPageBackground(color);
|
|
|
|
}
|
|
|
|
|
2017-02-03 14:20:30 +03:00
|
|
|
void ReportEngine::setResultEditable(bool value)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setResultEditable(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::resultIsEditable()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->resultIsEditable();
|
|
|
|
}
|
|
|
|
|
2019-04-10 16:23:50 +03:00
|
|
|
void ReportEngine::setSaveToFileVisible(bool value)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setSaveToFileVisible(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::saveToFileIsVisible()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->saveToFileIsVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEngine::setPrintToPdfVisible(bool value)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPrintToPdfVisible(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::printToPdfIsVisible()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->printToPdfIsVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEngine::setPrintVisible(bool value)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPrintVisible(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::printIsVisible()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->printIsVisible();
|
|
|
|
}
|
|
|
|
|
2016-12-13 12:47:46 +03:00
|
|
|
bool ReportEngine::isBusy()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->isBusy();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setPassPhrase(QString& passPhrase)
|
2017-02-16 04:11:39 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2019-06-11 21:28:58 +03:00
|
|
|
d->setPassPhrase(passPhrase);
|
2017-02-16 04:11:39 +03:00
|
|
|
}
|
|
|
|
|
2019-06-11 21:28:58 +03:00
|
|
|
QList<QLocale::Language> ReportEngine::availableLanguages()
|
2017-07-29 00:54:43 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->aviableLanguages();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::setReportLanguage(QLocale::Language language)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->setReportLanguage(language);
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:17 +03:00
|
|
|
Qt::LayoutDirection ReportEngine::previewLayoutDirection()
|
2018-04-10 16:28:48 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2018-05-15 22:14:17 +03:00
|
|
|
return d->previewLayoutDirection();
|
2018-04-10 16:28:48 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:17 +03:00
|
|
|
void ReportEngine::setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection)
|
2018-04-10 16:28:48 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2018-05-15 22:14:17 +03:00
|
|
|
d->setPreviewLayoutDirection(previewLayoutDirection);
|
2018-04-10 16:28:48 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:17 +03:00
|
|
|
QList<QLocale::Language> ReportEngine::designerLanguages()
|
2018-04-10 16:28:48 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->designerLanguages();
|
|
|
|
}
|
|
|
|
|
|
|
|
QLocale::Language ReportEngine::currentDesignerLanguage()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->currentDesignerLanguage();
|
|
|
|
}
|
|
|
|
|
2018-07-11 02:42:43 +03:00
|
|
|
ScaleType ReportEngine::previewScaleType()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->previewScaleType();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReportEngine::previewScalePercent()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->previewScalePercent();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setPreviewScaleType(const ScaleType& previewScaleType, int percent)
|
2018-07-11 02:42:43 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setPreviewScaleType(previewScaleType, percent);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::addWatermark(const WatermarkSetting& watermarkSetting)
|
2019-03-30 09:37:40 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->addWatermark(watermarkSetting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEngine::clearWatermarks()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->clearWatermarks();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
IPreparedPages* ReportEngine::preparedPages()
|
2019-05-29 03:41:18 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->preparedPages();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::showPreparedPages(PreviewHints hints)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->showPreparedPages(hints);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportEngine::prepareReportPages()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->prepareReportPages();
|
|
|
|
}
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2019-06-03 22:30:50 +03:00
|
|
|
bool ReportEngine::printPreparedPages()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->printPreparedPages();
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void ReportEngine::setShowProgressDialog(bool value)
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->setShowProgressDialog(value);
|
|
|
|
}
|
|
|
|
|
2019-10-16 02:08:45 +03:00
|
|
|
bool ReportEngine::isShowProgressDialog()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->isShowProgressDialog();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
IDataSourceManager* ReportEngine::dataManager()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->dataManagerIntf();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
IScriptEngineManager* ReportEngine::scriptManager()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->scriptManagerIntf();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2017-04-20 05:43:48 +03:00
|
|
|
return d->loadFromFile(fileName, autoLoadPreviewOnChange);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::loadFromByteArray(QByteArray* data)
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->loadFromByteArray(data);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::loadFromString(const QString& data)
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->loadFromString(data);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
QString ReportEngine::reportFileName()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->reportFileName();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setReportFileName(const QString& fileName)
|
2016-04-21 14:58:21 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->setReportFileName(fileName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::saveToFile(const QString& fileName)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->saveToFile(fileName);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:39:17 +03:00
|
|
|
QByteArray ReportEngine::saveToByteArray()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->saveToByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ReportEngine::saveToString()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->saveToString();
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
QString ReportEngine::lastError()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->lastError();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setCurrentReportsDir(const QString& dirName)
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->setCurrentReportsDir(dirName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::setDefaultExportDir(const QString& dirName)
|
2024-07-25 21:44:11 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->setDefaultExportDir(dirName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ReportEngine::setReportName(const QString& name)
|
2016-02-17 10:39:17 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->setReportName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ReportEngine::reportName()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
return d->reportName();
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void ReportEngine::cancelRender()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->cancelRender();
|
|
|
|
}
|
|
|
|
|
2019-10-12 23:25:30 +03:00
|
|
|
void ReportEngine::cancelPrinting()
|
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
|
|
|
d->cancelPrinting();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportEngine::ReportEngine(ReportEnginePrivate& dd, QObject* parent):
|
|
|
|
QObject(parent),
|
|
|
|
d_ptr(&dd),
|
|
|
|
m_showDesignerModal(true)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
Q_D(ReportEngine);
|
2024-09-04 17:31:16 +03:00
|
|
|
d->q_ptr = this;
|
2016-02-17 10:11:00 +03:00
|
|
|
connect(d, SIGNAL(renderStarted()), this, SIGNAL(renderStarted()));
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(d, SIGNAL(renderPageFinished(int)), this, SIGNAL(renderPageFinished(int)));
|
2016-02-17 10:11:00 +03:00
|
|
|
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ReportEngine::showDesignerModal() const { return m_showDesignerModal; }
|
2020-01-09 21:22:58 +03:00
|
|
|
|
|
|
|
void ReportEngine::setShowDesignerModal(bool showDesignerModal)
|
|
|
|
{
|
|
|
|
m_showDesignerModal = showDesignerModal;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineManager* LimeReport::ReportEnginePrivate::scriptManager()
|
|
|
|
{
|
2017-08-25 18:01:59 +03:00
|
|
|
ScriptEngineManager::instance().setContext(scriptContext());
|
2017-08-18 22:55:29 +03:00
|
|
|
ScriptEngineManager::instance().setDataManager(dataManager());
|
|
|
|
return &ScriptEngineManager::instance();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PrintProcessor::PrintProcessor(QPrinter* printer):
|
|
|
|
m_printer(printer),
|
|
|
|
m_painter(0),
|
|
|
|
m_firstPage(true)
|
|
|
|
{
|
|
|
|
m_renderPage.setItemMode(PrintMode);
|
|
|
|
}
|
2019-02-06 23:48:52 +03:00
|
|
|
|
|
|
|
bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
|
|
|
|
{
|
2024-03-31 15:20:09 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_firstPage && !m_painter->isActive())
|
|
|
|
return false;
|
2019-10-14 23:47:14 +03:00
|
|
|
PageDesignIntf* backupPage = dynamic_cast<PageDesignIntf*>(page->scene());
|
2019-02-12 19:28:38 +03:00
|
|
|
|
2019-02-06 23:48:52 +03:00
|
|
|
QPointF backupPagePos = page->pos();
|
2024-09-04 17:31:16 +03:00
|
|
|
page->setPos(0, 0);
|
2019-10-12 22:31:35 +03:00
|
|
|
m_renderPage.setPageItem(page);
|
2024-09-04 17:31:16 +03:00
|
|
|
m_renderPage.setSceneRect(
|
|
|
|
m_renderPage.pageItem()->mapToScene(m_renderPage.pageItem()->rect()).boundingRect());
|
2019-10-12 22:31:35 +03:00
|
|
|
initPrinter(m_renderPage.pageItem());
|
2019-02-06 23:48:52 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_firstPage) {
|
2019-02-06 23:48:52 +03:00
|
|
|
m_printer->newPage();
|
|
|
|
} else {
|
2019-02-12 19:28:38 +03:00
|
|
|
m_painter = new QPainter(m_printer);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_painter->isActive())
|
|
|
|
return false;
|
2019-02-06 23:48:52 +03:00
|
|
|
m_firstPage = false;
|
|
|
|
}
|
|
|
|
|
2024-03-31 15:20:09 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2019-02-06 23:48:52 +03:00
|
|
|
qreal leftMargin, topMargin, rightMargin, bottomMargin;
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer->getPageMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin,
|
|
|
|
QPrinter::Millimeter);
|
2021-08-24 10:22:30 +03:00
|
|
|
#else
|
|
|
|
qreal leftMargin = m_printer->pageLayout().margins().left();
|
|
|
|
qreal topMargin = m_printer->pageLayout().margins().top();
|
|
|
|
qreal rightMargin = m_printer->pageLayout().margins().right();
|
|
|
|
qreal bottomMargin = m_printer->pageLayout().margins().bottom();
|
2024-03-31 15:20:09 +03:00
|
|
|
#endif
|
2021-08-24 10:22:30 +03:00
|
|
|
|
|
|
|
QRectF printerPageRect = m_printer->pageRect(QPrinter::Millimeter);
|
2024-09-04 17:31:16 +03:00
|
|
|
printerPageRect = QRectF(
|
|
|
|
0, 0, (printerPageRect.size().width() + rightMargin + leftMargin) * page->unitFactor(),
|
|
|
|
(printerPageRect.size().height() + bottomMargin + topMargin) * page->unitFactor());
|
2024-03-31 15:20:09 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->printBehavior() == PageItemDesignIntf::Split
|
|
|
|
&& m_printer->pageSize() != static_cast<QPrinter::PageSize>(page->pageSize())
|
|
|
|
&& printerPageRect.width() < page->geometry().width()) {
|
2024-03-31 15:20:09 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->printBehavior() == PageItemDesignIntf::Split
|
|
|
|
&& m_printer->pageLayout().pageSize() != QPageSize((QPageSize::PageSizeId)page->pageSize())
|
|
|
|
&& printerPageRect.width() < page->geometry().width()) {
|
2024-03-31 15:20:09 +03:00
|
|
|
#endif
|
2021-08-24 10:22:30 +03:00
|
|
|
qreal pageWidth = page->geometry().width();
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal pageHeight = page->geometry().height();
|
2021-08-24 10:22:30 +03:00
|
|
|
qreal curHeight = 0;
|
|
|
|
qreal curWidth = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
QRectF currentPrintingRect = printerPageRect;
|
2024-03-31 15:20:09 +03:00
|
|
|
|
2021-08-24 10:22:30 +03:00
|
|
|
bool first = true;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (pageHeight > 0) {
|
|
|
|
while (curWidth < pageWidth) {
|
|
|
|
if (!first)
|
|
|
|
m_printer->newPage();
|
|
|
|
else
|
|
|
|
first = false;
|
2024-03-31 15:20:09 +03:00
|
|
|
m_renderPage.render(m_painter, QRectF(), currentPrintingRect);
|
2021-08-24 10:22:30 +03:00
|
|
|
curWidth += printerPageRect.size().width();
|
2024-09-04 17:31:16 +03:00
|
|
|
currentPrintingRect = QRectF(curWidth, 0,
|
|
|
|
printerPageRect.size().width() > (pageWidth - curWidth)
|
|
|
|
? (pageWidth - curWidth)
|
|
|
|
: printerPageRect.size().width(),
|
|
|
|
pageHeight);
|
2021-08-24 10:22:30 +03:00
|
|
|
}
|
|
|
|
pageHeight -= printerPageRect.size().height();
|
|
|
|
curHeight += printerPageRect.size().height();
|
|
|
|
currentPrintingRect = printerPageRect;
|
|
|
|
currentPrintingRect.adjust(0, curHeight, 0, curHeight);
|
|
|
|
curWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->getSetPageSizeToPrinter()) {
|
2021-08-24 10:22:30 +03:00
|
|
|
QRectF source = page->geometry();
|
|
|
|
QSizeF inchSize = source.size() / (100 * 2.54);
|
2024-09-04 17:31:16 +03:00
|
|
|
QRectF target = QRectF(QPoint(0, 0), inchSize * m_printer->resolution());
|
2021-08-24 10:22:30 +03:00
|
|
|
m_renderPage.render(m_painter, target, source);
|
|
|
|
} else {
|
|
|
|
m_renderPage.render(m_painter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page->setPos(backupPagePos);
|
|
|
|
m_renderPage.removePageItem(page);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (backupPage)
|
|
|
|
backupPage->reactivatePageItem(page);
|
2019-02-06 23:48:52 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintProcessor::initPrinter(PageItemDesignIntf* page)
|
|
|
|
{
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->oldPrintMode()) {
|
|
|
|
m_printer->setPageMargins(page->leftMargin(), page->topMargin(), page->rightMargin(),
|
|
|
|
page->bottomMargin(), QPrinter::Millimeter);
|
2019-02-06 23:48:52 +03:00
|
|
|
m_printer->setOrientation(static_cast<QPrinter::Orientation>(page->pageOrientation()));
|
2024-09-04 17:31:16 +03:00
|
|
|
QSizeF pageSize = (page->pageOrientation() == PageItemDesignIntf::Landscape)
|
|
|
|
? QSizeF(page->sizeMM().height(), page->sizeMM().width())
|
|
|
|
: page->sizeMM();
|
|
|
|
m_printer->setPaperSize(pageSize, QPrinter::Millimeter);
|
2019-02-06 23:48:52 +03:00
|
|
|
} else {
|
|
|
|
m_printer->setFullPage(page->fullPage());
|
2020-05-19 11:48:43 +03:00
|
|
|
if (page->dropPrinterMargins())
|
|
|
|
m_printer->setPageMargins(0, 0, 0, 0, QPrinter::Point);
|
2019-02-06 23:48:52 +03:00
|
|
|
m_printer->setOrientation(static_cast<QPrinter::Orientation>(page->pageOrientation()));
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->pageSize() == PageItemDesignIntf::Custom) {
|
|
|
|
QSizeF pageSize = (page->pageOrientation() == PageItemDesignIntf::Landscape)
|
|
|
|
? QSizeF(page->sizeMM().height(), page->sizeMM().width())
|
|
|
|
: page->sizeMM();
|
2019-02-06 23:48:52 +03:00
|
|
|
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer->setPaperSize(pageSize, QPrinter::Millimeter);
|
2019-02-06 23:48:52 +03:00
|
|
|
} else {
|
|
|
|
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer->setPaperSize(static_cast<QPrinter::PageSize>(page->pageSize()));
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
|
|
|
}
|
2021-08-24 10:22:30 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->oldPrintMode()) {
|
|
|
|
m_printer->setPageMargins(QMarginsF(page->leftMargin(), page->topMargin(),
|
|
|
|
page->rightMargin(), page->bottomMargin()),
|
|
|
|
QPageLayout::Millimeter);
|
2021-08-24 10:22:30 +03:00
|
|
|
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
|
2024-09-04 17:31:16 +03:00
|
|
|
QSizeF pageSize = (page->pageOrientation() == PageItemDesignIntf::Landscape)
|
|
|
|
? QSizeF(page->sizeMM().height(), page->sizeMM().width())
|
|
|
|
: page->sizeMM();
|
2021-08-24 10:22:30 +03:00
|
|
|
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
|
2024-09-04 17:31:16 +03:00
|
|
|
} else {
|
2021-08-24 10:22:30 +03:00
|
|
|
m_printer->setFullPage(page->fullPage());
|
|
|
|
if (page->dropPrinterMargins())
|
|
|
|
m_printer->setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Point);
|
|
|
|
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (page->pageSize() == PageItemDesignIntf::Custom) {
|
|
|
|
QSizeF pageSize = (page->pageOrientation() == PageItemDesignIntf::Landscape)
|
|
|
|
? QSizeF(page->sizeMM().height(), page->sizeMM().width())
|
|
|
|
: page->sizeMM();
|
2021-08-24 10:22:30 +03:00
|
|
|
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
|
2021-08-24 10:22:30 +03:00
|
|
|
} else {
|
|
|
|
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
|
2024-09-04 17:31:16 +03:00
|
|
|
m_printer->setPageSize(QPageSize((QPageSize::PageSizeId)page->pageSize()));
|
2021-08-24 10:22:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-02-06 23:48:52 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal ItemGeometry::x() const { return m_x; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setX(const qreal& x) { m_x = x; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal ItemGeometry::y() const { return m_y; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setY(const qreal& y) { m_y = y; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal ItemGeometry::width() const { return m_width; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setWidth(const qreal& width) { m_width = width; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal ItemGeometry::height() const { return m_height; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setHeight(const qreal& height) { m_height = height; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ItemGeometry::Type ItemGeometry::type() const { return m_type; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setType(const Type& type) { m_type = type; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
Qt::Alignment ItemGeometry::anchor() const { return m_anchor; }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ItemGeometry::setAnchor(const Qt::Alignment& anchor) { m_anchor = anchor; }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString WatermarkSetting::text() const { return m_text; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void WatermarkSetting::setText(const QString& text) { m_text = text; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QFont WatermarkSetting::font() const { return m_font; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void WatermarkSetting::setFont(const QFont& font) { m_font = font; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int WatermarkSetting::opacity() const { return m_opacity; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void WatermarkSetting::setOpacity(const int& opacity) { m_opacity = opacity; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ItemGeometry WatermarkSetting::geometry() const { return m_geometry; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void WatermarkSetting::setGeometry(const ItemGeometry& geometry) { m_geometry = geometry; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QColor WatermarkSetting::color() const { return m_color; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void WatermarkSetting::setColor(const QColor& color) { m_color = color; }
|
2019-03-30 09:37:40 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal WatermarkHelper::sceneX() { return valueToPixels(m_watermark.geometry().x()); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal WatermarkHelper::sceneY() { return valueToPixels(m_watermark.geometry().y()); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal WatermarkHelper::sceneWidth() { return valueToPixels(m_watermark.geometry().width()); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal WatermarkHelper::sceneHeight() { return valueToPixels(m_watermark.geometry().height()); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QPointF WatermarkHelper::scenePos() { return (QPointF(sceneX(), sceneY())); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QSizeF WatermarkHelper::sceneSize() { return (QSizeF(sceneWidth(), sceneHeight())); }
|
2019-04-02 22:56:12 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QPointF WatermarkHelper::mapToPage(const PageItemDesignIntf& page)
|
2019-04-02 22:56:12 +03:00
|
|
|
{
|
|
|
|
qreal startX = 0;
|
|
|
|
qreal startY = 0;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_watermark.geometry().anchor() & Qt::AlignLeft) {
|
2019-04-02 22:56:12 +03:00
|
|
|
startX = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else if (m_watermark.geometry().anchor() & Qt::AlignRight) {
|
2019-04-02 22:56:12 +03:00
|
|
|
startX = page.geometry().width();
|
|
|
|
} else {
|
|
|
|
startX = page.geometry().width() / 2;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_watermark.geometry().anchor() & Qt::AlignTop) {
|
2019-04-02 22:56:12 +03:00
|
|
|
startY = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else if (m_watermark.geometry().anchor() & Qt::AlignBottom) {
|
2019-04-02 22:56:12 +03:00
|
|
|
startY = page.geometry().height();
|
|
|
|
} else {
|
|
|
|
startY = page.geometry().height() / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QPointF(startX + sceneX(), startY + sceneY());
|
|
|
|
}
|
|
|
|
|
2019-04-06 00:28:02 +03:00
|
|
|
qreal WatermarkHelper::valueToPixels(qreal value)
|
2019-04-02 22:56:12 +03:00
|
|
|
{
|
2019-04-06 00:28:02 +03:00
|
|
|
switch (m_watermark.geometry().type()) {
|
2019-06-11 22:18:54 +03:00
|
|
|
case LimeReport::ItemGeometry::Millimeters:
|
2019-04-02 22:56:12 +03:00
|
|
|
return value * Const::mmFACTOR;
|
|
|
|
case LimeReport::ItemGeometry::Pixels:
|
|
|
|
return value;
|
|
|
|
}
|
2020-03-19 20:09:35 +03:00
|
|
|
return -1;
|
2019-04-02 22:56:12 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} // namespace LimeReport
|