LimeReport/limereport/lrreportengine.cpp

2166 lines
63 KiB
C++
Raw Permalink Normal View History

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