0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-26 01:24:39 +03:00
LimeReport/limereport/lrreportengine_p.h

270 lines
12 KiB
C
Raw Normal View History

2016-02-17 10:11:00 +03:00
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* 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. *
****************************************************************************/
#ifndef LRREPORTDESIGNINTF_P_H
#define LRREPORTDESIGNINTF_P_H
#include <QObject>
#include <QSharedPointer>
#include <QMainWindow>
2018-04-10 16:28:48 +03:00
#include <QLocale>
2016-02-17 10:11:00 +03:00
#include "lrreportengine.h"
#include "lrcollection.h"
#include "lrglobal.h"
#include "lrdatasourcemanager.h"
#include "lrbanddesignintf.h"
#include "lrreportrender.h"
#include "serializators/lrstorageintf.h"
#include "lrscriptenginemanager.h"
#include "lrreporttranslation.h"
2017-11-24 00:13:47 +03:00
#include "lrdesignerplugininterface.h"
2017-11-27 23:14:05 +03:00
#include "lrreportdesignwindowintrerface.h"
2016-02-17 10:11:00 +03:00
class QFileSystemWatcher;
2016-02-17 10:11:00 +03:00
namespace LimeReport{
class PageDesignIntf;
class PrintRange;
class ReportDesignWindow;
2016-02-17 10:11:00 +03:00
2017-11-24 00:13:47 +03:00
class ReportEnginePrivateInterface {
public:
virtual PageDesignIntf* appendPage(const QString& pageName="") = 0;
virtual bool deletePage(PageDesignIntf *page) = 0;
virtual void reorderPages(const QList<PageDesignIntf *> &reorderedPages) = 0;
virtual int pageCount() = 0;
virtual PageDesignIntf* pageAt(int index) = 0;
virtual void clearReport() = 0;
virtual ScriptEngineContext* scriptContext() = 0;
virtual ScriptEngineManager* scriptManager() = 0;
virtual DataSourceManager* dataManager() = 0;
virtual QString reportFileName() = 0;
virtual void setReportFileName(const QString& reportFileName) = 0;
virtual void emitSaveFinished() = 0;
virtual bool isNeedToSave() = 0;
virtual void emitSaveReport() = 0;
virtual bool saveToFile(const QString& fileName = "") = 0;
2017-11-24 00:13:47 +03:00
virtual bool isSaved() = 0;
virtual QString reportName() = 0;
virtual bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange) = 0;
virtual bool emitLoadReport() = 0;
virtual void clearSelection() = 0;
virtual bool printReport(QPrinter *printer=0) = 0;
virtual void previewReport(PreviewHints hints = PreviewBarsUserSetting) = 0;
virtual void setCurrentReportsDir(const QString& dirName) = 0;
virtual QString currentReportsDir() = 0;
virtual bool suppressFieldAndVarError() const = 0;
virtual void setSuppressFieldAndVarError(bool suppressFieldAndVarError) = 0;
2017-12-11 16:48:00 +03:00
virtual void setStyleSheet(const QString& styleSheet) = 0;
virtual QString styleSheet() const = 0;
virtual QList<QLocale::Language> designerLanguages() = 0;
2018-04-10 16:28:48 +03:00
virtual QLocale::Language currentDesignerLanguage() = 0;
virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0;
2017-11-24 00:13:47 +03:00
};
class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer,
public ReportEnginePrivateInterface
2016-02-17 10:11:00 +03:00
{
Q_OBJECT
Q_DECLARE_PUBLIC(ReportEngine)
Q_PROPERTY(ACollectionProperty pages READ fakeCollectionReader())
2016-06-10 18:05:18 +03:00
Q_PROPERTY(QObject* datasourcesManager READ dataManager)
Q_PROPERTY(QObject* scriptContext READ scriptContext)
Q_PROPERTY(bool suppressFieldAndVarError READ suppressFieldAndVarError WRITE setSuppressFieldAndVarError)
Q_PROPERTY(ATranslationProperty translation READ fakeTranslationReader)
friend class PreviewReportWidget;
2016-02-17 10:11:00 +03:00
public:
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
2017-04-21 23:03:56 +03:00
static void printReport(ReportPages pages, QPrinter &printer);
Q_INVOKABLE QStringList aviableReportTranslations();
Q_INVOKABLE void setReportTranslation(const QString& languageName);
2016-02-17 10:11:00 +03:00
public:
explicit ReportEnginePrivate(QObject *parent = 0);
virtual ~ReportEnginePrivate();
2016-06-10 18:05:18 +03:00
PageDesignIntf* appendPage(const QString& pageName="");
bool deletePage(PageDesignIntf *page);
PageDesignIntf* createPreviewPage();
PageDesignIntf* pageAt(int index){return (index<=(m_pages.count()-1)) ? m_pages.at(index):0;}
int pageCount() {return m_pages.count();}
DataSourceManager* dataManager(){return m_datasources;}
ScriptEngineContext* scriptContext(){return m_scriptEngineContext;}
2017-08-18 22:55:29 +03:00
ScriptEngineManager* scriptManager();
2016-06-10 18:05:18 +03:00
IDataSourceManager* dataManagerIntf(){return m_datasources;}
2016-02-17 10:28:27 +03:00
IScriptEngineManager* scriptManagerIntf(){
ScriptEngineManager::instance().setDataManager(dataManager());
return &ScriptEngineManager::instance();
}
2016-02-17 10:11:00 +03:00
void clearReport();
bool printReport(QPrinter *printer=0);
2017-04-21 23:03:56 +03:00
bool printPages(ReportPages pages, QPrinter *printer);
2016-02-17 10:11:00 +03:00
void printToFile(const QString& fileName);
2016-02-17 10:19:50 +03:00
bool printToPDF(const QString& fileName);
void previewReport(PreviewHints hints = PreviewBarsUserSetting);
2017-11-27 23:14:05 +03:00
ReportDesignWindowInterface* getDesignerWindow();
2016-02-17 10:11:00 +03:00
void designReport();
void setSettings(QSettings* value);
void setShowProgressDialog(bool value){m_showProgressDialog = value;}
QSettings* settings();
bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange);
2016-02-17 10:39:17 +03:00
bool loadFromByteArray(QByteArray *data, const QString& name = "");
bool loadFromString(const QString& report, const QString& name = "");
2016-02-17 10:11:00 +03:00
QString reportFileName(){return m_fileName;}
void setReportFileName(const QString& reportFileName){ m_fileName = reportFileName;}
bool saveToFile(const QString& fileName = "");
2016-02-17 10:39:17 +03:00
QByteArray saveToByteArray();
QString saveToString();
2016-02-17 10:11:00 +03:00
bool isNeedToSave();
QString lastError();
ReportEngine * q_ptr;
2016-02-17 10:39:17 +03:00
void emitSaveReport();
bool emitLoadReport();
void emitSaveFinished();
void emitPrintedToPDF(QString fileName);
2016-02-17 10:39:17 +03:00
bool isSaved();
void setCurrentReportsDir(const QString& dirName);
QString currentReportsDir(){ return m_reportsDir;}
void setReportName(const QString& reportName){ m_reportName=reportName;}
QString reportName(){ return m_reportName;}
bool hasActivePreview(){return m_activePreview;}
PageDesignIntf *createPreviewScene(QObject *parent);
PreviewReportWidget *createPreviewWidget(QWidget *parent);
QIcon previewWindowIcon() const;
void setPreviewWindowIcon(const QIcon &previewWindowIcon);
QString previewWindowTitle() const;
void setPreviewWindowTitle(const QString &previewWindowTitle);
bool suppressFieldAndVarError() const;
void setSuppressFieldAndVarError(bool suppressFieldAndVarError);
bool isBusy();
bool resultIsEditable() const;
void setResultEditable(bool value);
void setPassPhrase(const QString &passPhrase);
bool addTranslationLanguage(QLocale::Language language);
2017-08-16 01:18:56 +03:00
bool removeTranslationLanguage(QLocale::Language language);
bool setReportLanguage(QLocale::Language language);
QList<QLocale::Language> aviableLanguages();
ReportTranslation* reportTranslation(QLocale::Language language);
2017-08-19 00:16:55 +03:00
void reorderPages(const QList<PageDesignIntf *> &reorderedPages);
2017-09-21 22:02:13 +03:00
void clearSelection();
Qt::LayoutDirection previewLayoutDirection();
void setPreviewLayoutDirection(const Qt::LayoutDirection& previewLayoutDirection);
2017-12-11 16:48:00 +03:00
QString styleSheet() const;
void setStyleSheet(const QString &styleSheet);
QList<QLocale::Language> designerLanguages();
2018-04-10 16:28:48 +03:00
QLocale::Language currentDesignerLanguage();
void setCurrentDesignerLanguage(QLocale::Language language);
2016-02-17 10:11:00 +03:00
signals:
void pagesLoadFinished();
void datasourceCollectionLoadFinished(const QString& collectionName);
void cleared();
void renderStarted();
void renderFinished();
void renderPageFinished(int renderedPageCount);
2016-02-17 10:39:17 +03:00
void onLoad(bool& loaded);
void onSave();
void saveFinished();
2018-05-08 10:58:43 +03:00
void loaded();
void printedToPDF(QString fileName);
void getAviableLanguages(QList<QLocale::Language>* languages);
void currentDefaulLanguageChanged(QLocale::Language);
QLocale::Language getCurrentDefaultLanguage();
2016-02-17 10:11:00 +03:00
public slots:
bool slotLoadFromFile(const QString& fileName);
2016-02-17 10:11:00 +03:00
void cancelRender();
protected:
PageDesignIntf* createPage(const QString& pageName="");
protected slots:
void slotDataSourceCollectionLoaded(const QString& collectionName);
private slots:
2018-02-28 23:19:04 +03:00
void slotPreviewWindowDestroyed(QObject* window);
void slotDesignerWindowDestroyed(QObject* window);
2016-02-17 10:11:00 +03:00
private:
//ICollectionContainer
virtual QObject* createElement(const QString&,const QString&);
virtual int elementsCount(const QString&);
virtual QObject* elementAt(const QString&, int index);
virtual void collectionLoadFinished(const QString&);
void saveError(QString message);
void showError(QString message);
//ICollectionContainer
//ITranslationContainer
Translations* translations(){ return &m_translations;}
2017-08-05 01:38:19 +03:00
void updateTranslations();
//ITranslationContainer
2016-02-17 10:11:00 +03:00
ReportPages renderToPages();
QString renderToString();
PageItemDesignIntf *getPageByName(const QString& pageName);
ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();}
PageItemDesignIntf *createRenderingPage(PageItemDesignIntf *page);
2016-02-17 10:11:00 +03:00
private:
QList<PageDesignIntf*> m_pages;
QList<PageItemDesignIntf*> m_renderingPages;
2016-02-17 10:11:00 +03:00
DataSourceManager* m_datasources;
2016-06-10 18:05:18 +03:00
ScriptEngineContext* m_scriptEngineContext;
2016-02-17 10:11:00 +03:00
ReportRender::Ptr m_reportRender;
QString m_fileName;
QString m_lastError;
QSettings* m_settings;
bool m_ownedSettings;
QScopedPointer<QPrinter> m_printer;
bool m_printerSelected;
bool m_showProgressDialog;
2016-02-17 10:39:17 +03:00
QString m_reportsDir;
QString m_reportName;
QMainWindow* m_activePreview;
QIcon m_previewWindowIcon;
QString m_previewWindowTitle;
2017-11-27 23:14:05 +03:00
QPointer<ReportDesignWindowInterface> m_designerWindow;
ReportSettings m_reportSettings;
bool m_reportRendering;
bool m_resultIsEditable;
QString m_passPhrase;
QFileSystemWatcher *m_fileWatcher;
Translations m_translations;
2017-08-16 01:18:56 +03:00
QLocale::Language m_reportLanguage;
void activateLanguage(QLocale::Language language);
Qt::LayoutDirection m_previewLayoutDirection;
2017-11-24 00:13:47 +03:00
LimeReportPluginInterface* m_designerFactory;
2017-12-11 16:48:00 +03:00
QString m_styleSheet;
2018-04-10 16:28:48 +03:00
QLocale::Language m_currentDesignerLanguage;
2016-02-17 10:11:00 +03:00
};
}
#endif // LRREPORTDESIGNINTF_P_H