2016-03-30 23:04:59 +03:00
|
|
|
#include "lrpreviewreportwidget.h"
|
|
|
|
#include "ui_lrpreviewreportwidget.h"
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrexportersfactory.h"
|
2016-03-30 23:04:59 +03:00
|
|
|
#include "lrpagedesignintf.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrpreparedpages.h"
|
2016-03-30 23:04:59 +03:00
|
|
|
#include "lrpreviewreportwidget_p.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrreportengine_p.h"
|
|
|
|
#include "lrreportrender.h"
|
2016-03-30 23:04:59 +03:00
|
|
|
#include "serializators/lrxmlwriter.h"
|
2018-06-23 00:04:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QPrintDialog>
|
|
|
|
#include <QPrinter>
|
|
|
|
#include <QPrinterInfo>
|
|
|
|
#include <QScrollBar>
|
2018-06-23 00:04:28 +03:00
|
|
|
|
2016-03-30 23:04:59 +03:00
|
|
|
namespace LimeReport {
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool PreviewReportWidgetPrivate::pageIsVisible()
|
|
|
|
{
|
2016-03-30 23:04:59 +03:00
|
|
|
QGraphicsView* view = q_ptr->ui->graphicsView;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_currentPage - 1 >= m_reportPages.size() || m_currentPage <= 0)
|
2016-12-06 18:28:28 +03:00
|
|
|
return false;
|
2024-09-04 17:31:16 +03:00
|
|
|
PageItemDesignIntf::Ptr page = m_reportPages.at(m_currentPage - 1);
|
|
|
|
return page->mapToScene(page->rect())
|
|
|
|
.boundingRect()
|
|
|
|
.intersects(view->mapToScene(view->viewport()->geometry()).boundingRect());
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QRectF PreviewReportWidgetPrivate::calcPageShift()
|
|
|
|
{
|
|
|
|
QGraphicsView* view = q_ptr->ui->graphicsView;
|
|
|
|
PageItemDesignIntf::Ptr page = m_reportPages.at(m_currentPage - 1);
|
2016-03-30 23:04:59 +03:00
|
|
|
qreal pageHeight = page->mapToScene(page->boundingRect()).boundingRect().height();
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal viewHeight
|
|
|
|
= view->mapToScene(0, view->viewport()->height()).y() - view->mapToScene(0, 0).y();
|
|
|
|
viewHeight = (pageHeight < viewHeight) ? pageHeight : viewHeight;
|
|
|
|
QRectF pageStartPos = m_reportPages.at(m_currentPage - 1)
|
|
|
|
->mapRectToScene(m_reportPages.at(m_currentPage - 1)->rect());
|
|
|
|
return QRectF(0, pageStartPos.y(), 0, viewHeight);
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewReportWidgetPrivate::setPages(ReportPages pages)
|
|
|
|
{
|
|
|
|
m_reportPages = pages;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_reportPages.isEmpty()) {
|
2016-03-30 23:04:59 +03:00
|
|
|
m_previewPage->setPageItems(m_reportPages);
|
|
|
|
m_changingPage = true;
|
|
|
|
m_currentPage = 1;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.at(0))
|
|
|
|
pages.at(0)->setSelected(true);
|
2016-03-30 23:04:59 +03:00
|
|
|
m_changingPage = false;
|
|
|
|
q_ptr->initPreview();
|
2016-04-02 03:38:23 +03:00
|
|
|
q_ptr->emitPageSet();
|
2019-03-01 23:48:28 +03:00
|
|
|
q_ptr->activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
PageItemDesignIntf::Ptr PreviewReportWidgetPrivate::currentPage()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_reportPages.count() > 0 && m_reportPages.count() >= m_currentPage && m_currentPage > 0)
|
|
|
|
return m_reportPages.at(m_currentPage - 1);
|
|
|
|
else
|
|
|
|
return PageItemDesignIntf::Ptr(0);
|
2016-04-02 03:38:23 +03:00
|
|
|
}
|
|
|
|
|
2018-06-23 00:04:28 +03:00
|
|
|
QList<QString> PreviewReportWidgetPrivate::aviableExporters()
|
|
|
|
{
|
|
|
|
return ExportersFactory::instance().map().keys();
|
|
|
|
}
|
|
|
|
|
2019-02-21 03:20:26 +03:00
|
|
|
void PreviewReportWidgetPrivate::startInsertTextItem()
|
|
|
|
{
|
|
|
|
m_previewPage->startInsertMode("TextItem");
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidgetPrivate::activateItemSelectionMode() { m_previewPage->startEditMode(); }
|
2019-03-01 23:48:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidgetPrivate::deleteSelectedItems() { m_previewPage->deleteSelected(); }
|
2019-03-01 23:48:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PreviewReportWidget::PreviewReportWidget(ReportEngine* report, QWidget* parent):
|
2016-03-30 23:04:59 +03:00
|
|
|
QWidget(parent),
|
2024-09-04 17:31:16 +03:00
|
|
|
ui(new Ui::PreviewReportWidget),
|
|
|
|
d_ptr(new PreviewReportWidgetPrivate(this)),
|
|
|
|
m_scaleType(FitWidth),
|
|
|
|
m_scalePercent(0),
|
|
|
|
m_previewPageBackgroundColor(Qt::white),
|
|
|
|
m_defaultPrinter(0),
|
|
|
|
m_scaleChanging(false)
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-03-22 14:42:09 +03:00
|
|
|
d_ptr->m_report = report->d_ptr;
|
|
|
|
d_ptr->m_previewPage = d_ptr->m_report->createPreviewPage();
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_previewPage->setItemMode(LimeReport::PreviewMode);
|
2018-07-11 02:42:43 +03:00
|
|
|
m_resizeTimer.setSingleShot(true);
|
2016-03-30 23:04:59 +03:00
|
|
|
|
|
|
|
ui->errorsView->setVisible(false);
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(ui->graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this,
|
|
|
|
SLOT(slotSliderMoved(int)));
|
|
|
|
connect(d_ptr->m_report, SIGNAL(destroyed(QObject*)), this,
|
|
|
|
SLOT(reportEngineDestroyed(QObject*)));
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_zoomer = new GraphicsViewZoomer(ui->graphicsView);
|
2016-04-05 23:06:11 +03:00
|
|
|
connect(d_ptr->m_zoomer, SIGNAL(zoomed(double)), this, SLOT(slotZoomed(double)));
|
2018-07-11 02:42:43 +03:00
|
|
|
connect(&m_resizeTimer, SIGNAL(timeout()), this, SLOT(resizeDone()));
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewReportWidget::~PreviewReportWidget()
|
|
|
|
{
|
|
|
|
delete d_ptr->m_previewPage;
|
|
|
|
d_ptr->m_previewPage = 0;
|
|
|
|
delete d_ptr->m_zoomer;
|
|
|
|
delete d_ptr;
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QList<QString> PreviewReportWidget::aviableExporters() { return d_ptr->aviableExporters(); }
|
2018-06-23 00:04:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool PreviewReportWidget::exportReport(QString exporterName, const QMap<QString, QVariant>& params)
|
2018-06-23 00:04:28 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ExportersFactory::instance().map().contains(exporterName)) {
|
2018-06-23 00:04:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportExporterInterface* e
|
|
|
|
= ExportersFactory::instance().objectCreator(exporterName)(d_ptr->m_report);
|
|
|
|
QString defaultFileName
|
|
|
|
= d_ptr->m_report->defaultExportDir() + d_ptr->m_report->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
|
|
|
QString fileName = QFileDialog::getSaveFileName(
|
|
|
|
this, tr("%1 file name").arg(e->exporterName()), defaultFileName, filter);
|
|
|
|
if (!fileName.isEmpty()) {
|
2018-06-23 00:04:28 +03:00
|
|
|
QFileInfo fi(fileName);
|
|
|
|
if (fi.suffix().isEmpty())
|
|
|
|
fileName += QString(".%1").arg(e->exporterFileExt());
|
|
|
|
bool result = e->exportPages(d_ptr->m_reportPages, fileName, params);
|
|
|
|
delete e;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-30 23:04:59 +03:00
|
|
|
void PreviewReportWidget::initPreview()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ui->graphicsView->scene() != d_ptr->m_previewPage)
|
2016-04-02 03:38:23 +03:00
|
|
|
ui->graphicsView->setScene(d_ptr->m_previewPage);
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2016-04-01 23:39:07 +03:00
|
|
|
ui->graphicsView->resetMatrix();
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
|
|
|
ui->graphicsView->resetTransform();
|
|
|
|
#endif
|
2016-03-30 23:04:59 +03:00
|
|
|
ui->graphicsView->centerOn(0, 0);
|
2019-02-18 15:16:55 +03:00
|
|
|
ui->graphicsView->scene()->setBackgroundBrush(QColor(m_previewPageBackgroundColor));
|
2016-04-02 03:38:23 +03:00
|
|
|
setScalePercent(d_ptr->m_scalePercent);
|
2019-03-01 23:48:28 +03:00
|
|
|
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(ui->graphicsView->scene());
|
|
|
|
if (page)
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(page, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)), this,
|
|
|
|
SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)));
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
|
|
|
|
{
|
|
|
|
ui->errorsView->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::zoomIn()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_scalePercent = (d_ptr->m_scalePercent / 10) * 10 + 10;
|
2016-04-02 03:38:23 +03:00
|
|
|
setScalePercent(d_ptr->m_scalePercent);
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::zoomOut()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (d_ptr->m_scalePercent > 0)
|
2016-04-05 23:06:11 +03:00
|
|
|
d_ptr->m_scalePercent = (d_ptr->m_scalePercent / 10) * 10 - 10;
|
2016-04-02 03:38:23 +03:00
|
|
|
setScalePercent(d_ptr->m_scalePercent);
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::firstPage()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
|
|
|
if ((!d_ptr->m_reportPages.isEmpty()) && (d_ptr->m_currentPage > 1)) {
|
|
|
|
d_ptr->m_currentPage = 1;
|
2016-03-30 23:04:59 +03:00
|
|
|
ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0);
|
|
|
|
emit pageChanged(d_ptr->m_currentPage);
|
2019-03-01 23:54:41 +03:00
|
|
|
activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = false;
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::priorPage()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
|
|
|
if ((!d_ptr->m_reportPages.isEmpty()) && (d_ptr->m_currentPage > 1)) {
|
|
|
|
d_ptr->m_currentPage--;
|
|
|
|
ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0);
|
|
|
|
emit pageChanged(d_ptr->m_currentPage);
|
|
|
|
activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = false;
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::nextPage()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
|
|
|
if ((!d_ptr->m_reportPages.isEmpty())
|
|
|
|
&& (d_ptr->m_reportPages.count() > (d_ptr->m_currentPage))) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_currentPage++;
|
|
|
|
ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0);
|
|
|
|
emit pageChanged(d_ptr->m_currentPage);
|
2019-03-01 23:54:41 +03:00
|
|
|
activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = false;
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::lastPage()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
|
|
|
if ((!d_ptr->m_reportPages.isEmpty())
|
|
|
|
&& (d_ptr->m_reportPages.count() > (d_ptr->m_currentPage))) {
|
|
|
|
d_ptr->m_currentPage = d_ptr->m_reportPages.count();
|
2016-03-30 23:04:59 +03:00
|
|
|
ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0);
|
|
|
|
emit pageChanged(d_ptr->m_currentPage);
|
2019-03-01 23:54:41 +03:00
|
|
|
activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = false;
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 13:54:26 +03:00
|
|
|
void PreviewReportWidget::printPages(QPrinter* printer)
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2019-02-20 13:54:26 +03:00
|
|
|
if (!d_ptr->m_reportPages.isEmpty())
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_report->printPages(d_ptr->m_reportPages, printer);
|
|
|
|
foreach (PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages) {
|
2019-02-20 13:54:26 +03:00
|
|
|
d_ptr->m_previewPage->reactivatePageItem(pageItem);
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:39:50 +03:00
|
|
|
|
2019-02-20 13:54:26 +03:00
|
|
|
void PreviewReportWidget::print()
|
2022-04-30 14:46:49 +03:00
|
|
|
{
|
2019-02-21 19:15:31 +03:00
|
|
|
QPrinterInfo pi;
|
|
|
|
QPrinter lp(QPrinter::HighResolution);
|
2019-02-20 13:54:26 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!pi.defaultPrinter().isNull()) {
|
2021-08-24 10:22:30 +03:00
|
|
|
#if QT_VERSION >= 0x050300
|
2024-09-04 17:31:16 +03:00
|
|
|
lp.setPrinterName(pi.defaultPrinterName());
|
2019-01-26 23:30:13 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
lp.setPrinterName(pi.defaultPrinter().printerName());
|
2017-04-19 01:04:14 +03:00
|
|
|
#endif
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2019-02-21 19:15:31 +03:00
|
|
|
|
|
|
|
QPrinter* printer = m_defaultPrinter ? m_defaultPrinter : &lp;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QPrintDialog dialog(printer, QApplication::activeWindow());
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2019-02-21 19:15:31 +03:00
|
|
|
printPages(printer);
|
|
|
|
}
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::printToPDF()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!d_ptr->m_reportPages.isEmpty()) {
|
2018-06-23 00:04:28 +03:00
|
|
|
exportReport("PDF");
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_previewPage->reactivatePageItem(pageItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::pageNavigatorChanged(int value)
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (d_ptr->m_changingPage)
|
|
|
|
return;
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
2024-09-04 17:31:16 +03:00
|
|
|
if ((!d_ptr->m_reportPages.isEmpty()) && (d_ptr->m_reportPages.count() >= value) && value > 0) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_currentPage = value;
|
2019-03-01 23:54:41 +03:00
|
|
|
activateCurrentPage();
|
2016-03-30 23:04:59 +03:00
|
|
|
ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0);
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_changingPage = false;
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::saveToFile()
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2019-05-29 16:32:58 +03:00
|
|
|
bool saved = false;
|
|
|
|
PreparedPages pagesManager = PreparedPages(&d_ptr->m_reportPages);
|
|
|
|
emit onSave(saved, &pagesManager);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!saved) {
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Report file name"),
|
|
|
|
d_ptr->m_report->defaultExportDir());
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
|
|
|
foreach (PageItemDesignIntf::Ptr page, d_ptr->m_reportPages) {
|
2019-05-29 16:32:58 +03:00
|
|
|
writer->putItem(page.data());
|
|
|
|
}
|
|
|
|
writer->saveToFile(fileName);
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:38:23 +03:00
|
|
|
void PreviewReportWidget::setScalePercent(int percent)
|
|
|
|
{
|
2021-06-01 23:33:38 +03:00
|
|
|
m_scaleChanging = true;
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2016-04-02 03:38:23 +03:00
|
|
|
ui->graphicsView->resetMatrix();
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
|
|
|
ui->graphicsView->resetTransform();
|
|
|
|
#endif
|
2016-04-02 16:07:01 +03:00
|
|
|
d_ptr->m_scalePercent = percent;
|
2024-09-04 17:31:16 +03:00
|
|
|
qreal scaleSize = percent / 100.0;
|
2016-04-02 03:38:23 +03:00
|
|
|
ui->graphicsView->scale(scaleSize, scaleSize);
|
|
|
|
emit scalePercentChanged(percent);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (percent == 100) {
|
2018-07-11 02:42:43 +03:00
|
|
|
m_scaleType = OneToOne;
|
|
|
|
} else {
|
|
|
|
m_scaleType = Percents;
|
2018-07-11 12:35:41 +03:00
|
|
|
m_scalePercent = percent;
|
2018-07-11 02:42:43 +03:00
|
|
|
}
|
2021-06-01 23:33:38 +03:00
|
|
|
m_scaleChanging = false;
|
2016-04-02 03:38:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewReportWidget::fitWidth()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (d_ptr->currentPage()) {
|
2021-10-05 17:42:37 +03:00
|
|
|
resize(m_scaleType = FitWidth);
|
2016-04-02 03:38:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewReportWidget::fitPage()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (d_ptr->currentPage()) {
|
2021-10-05 17:42:37 +03:00
|
|
|
resize(m_scaleType = FitPage);
|
2016-04-02 03:38:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::resizeEvent(QResizeEvent*) { m_resizeTimer.start(100); }
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::setErrorMessages(const QStringList& value)
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
|
|
|
foreach (QString line, value) {
|
|
|
|
ui->errorsView->append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::emitPageSet() { emit pagesSet(d_ptr->m_reportPages.count()); }
|
2016-04-02 03:38:23 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QPrinter* PreviewReportWidget::defaultPrinter() const { return m_defaultPrinter; }
|
2019-02-20 13:54:26 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::setDefaultPrinter(QPrinter* defaultPrinter)
|
2019-02-20 13:54:26 +03:00
|
|
|
{
|
|
|
|
m_defaultPrinter = defaultPrinter;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScaleType PreviewReportWidget::scaleType() const { return m_scaleType; }
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::startInsertTextItem() { d_ptr->startInsertTextItem(); }
|
2019-02-21 03:20:26 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::activateItemSelectionMode() { d_ptr->activateItemSelectionMode(); }
|
2019-03-01 23:48:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::deleteSelectedItems() { d_ptr->deleteSelectedItems(); }
|
2019-03-01 23:48:28 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int PreviewReportWidget::scalePercent() const { return m_scalePercent; }
|
2018-07-11 02:42:43 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::setScaleType(const ScaleType& scaleType, int percent)
|
2018-07-11 02:42:43 +03:00
|
|
|
{
|
|
|
|
m_scaleType = scaleType;
|
|
|
|
m_scalePercent = percent;
|
|
|
|
}
|
|
|
|
|
2019-02-18 15:16:55 +03:00
|
|
|
void PreviewReportWidget::setPreviewPageBackgroundColor(QColor color)
|
|
|
|
{
|
|
|
|
m_previewPageBackgroundColor = color;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QColor PreviewReportWidget::previewPageBackgroundColor() { return m_previewPageBackgroundColor; }
|
2019-02-18 15:16:55 +03:00
|
|
|
|
2016-03-30 23:04:59 +03:00
|
|
|
void PreviewReportWidget::refreshPages()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (d_ptr->m_report) {
|
|
|
|
try {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_report->dataManager()->setDesignTime(false);
|
|
|
|
ReportPages pages = d_ptr->m_report->renderToPages();
|
|
|
|
d_ptr->m_report->dataManager()->setDesignTime(true);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (pages.count() > 0) {
|
2016-04-01 23:39:07 +03:00
|
|
|
d_ptr->setPages(pages);
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& exception) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_report->saveError(exception.what());
|
|
|
|
d_ptr->m_report->showError(exception.what());
|
2024-09-04 17:31:16 +03:00
|
|
|
}
|
2016-03-30 23:04:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 23:48:28 +03:00
|
|
|
void PreviewReportWidget::activateCurrentPage()
|
|
|
|
{
|
|
|
|
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(ui->graphicsView->scene());
|
|
|
|
if (page)
|
|
|
|
page->setCurrentPage(d_ptr->currentPage().data());
|
|
|
|
}
|
|
|
|
|
2021-10-05 17:42:37 +03:00
|
|
|
void PreviewReportWidget::resize(ScaleType scaleType, int percent)
|
|
|
|
{
|
|
|
|
switch (scaleType) {
|
|
|
|
case FitWidth:
|
2024-09-04 17:31:16 +03:00
|
|
|
setScalePercent(ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width()
|
|
|
|
* 100);
|
2021-10-05 17:42:37 +03:00
|
|
|
break;
|
|
|
|
case FitPage:
|
2024-09-04 17:31:16 +03:00
|
|
|
setScalePercent(
|
|
|
|
qMin(ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width(),
|
|
|
|
ui->graphicsView->viewport()->height() / d_ptr->currentPage()->height())
|
|
|
|
* 100);
|
2021-10-05 17:42:37 +03:00
|
|
|
break;
|
|
|
|
case OneToOne:
|
|
|
|
setScalePercent(100);
|
|
|
|
break;
|
|
|
|
case Percents:
|
|
|
|
setScalePercent(percent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 23:04:59 +03:00
|
|
|
void PreviewReportWidget::slotSliderMoved(int value)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_scaleChanging)
|
|
|
|
return;
|
2019-03-01 23:48:28 +03:00
|
|
|
int curPage = d_ptr->m_currentPage;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ui->graphicsView->verticalScrollBar()->minimum() == value) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_currentPage = 1;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else if (ui->graphicsView->verticalScrollBar()->maximum() == value) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_currentPage = d_ptr->m_reportPages.count();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!d_ptr->pageIsVisible()) {
|
|
|
|
if (value > d_ptr->m_priorScrolValue) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_currentPage++;
|
|
|
|
} else {
|
|
|
|
d_ptr->m_currentPage--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (curPage != d_ptr->m_currentPage) {
|
2019-03-01 23:48:28 +03:00
|
|
|
d_ptr->m_changingPage = true;
|
|
|
|
emit pageChanged(d_ptr->m_currentPage);
|
|
|
|
activateCurrentPage();
|
|
|
|
d_ptr->m_changingPage = false;
|
|
|
|
}
|
2019-02-21 03:20:26 +03:00
|
|
|
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_priorScrolValue = value;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::reportEngineDestroyed(QObject* object)
|
2016-03-30 23:04:59 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (object == d_ptr->m_report) {
|
2016-03-30 23:04:59 +03:00
|
|
|
d_ptr->m_report = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreviewReportWidget::slotZoomed(double)
|
2016-04-05 23:06:11 +03:00
|
|
|
{
|
2022-05-07 21:07:43 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_scalePercent = ui->graphicsView->matrix().m11() * 100;
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
d_ptr->m_scalePercent = ui->graphicsView->transform().m11() * 100;
|
2021-08-23 08:07:08 +03:00
|
|
|
#endif
|
2016-04-05 23:06:11 +03:00
|
|
|
emit scalePercentChanged(d_ptr->m_scalePercent);
|
|
|
|
}
|
|
|
|
|
2018-07-11 02:42:43 +03:00
|
|
|
void PreviewReportWidget::resizeDone()
|
|
|
|
{
|
|
|
|
switch (m_scaleType) {
|
|
|
|
case FitPage:
|
|
|
|
fitPage();
|
|
|
|
break;
|
|
|
|
case FitWidth:
|
|
|
|
fitWidth();
|
|
|
|
break;
|
|
|
|
case OneToOne:
|
|
|
|
setScalePercent(100);
|
|
|
|
break;
|
|
|
|
case Percents:
|
|
|
|
setScalePercent(m_scalePercent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 23:04:59 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} // namespace LimeReport
|