From 83a57b5cbe3b770d51a361b624c5bb2a19c45331 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 21 Feb 2019 03:20:26 +0300 Subject: [PATCH 1/8] Added the ability to add text elements in preview (in edit mode) --- include/lrpreviewreportwidget.h | 1 + limereport/lrpagedesignintf.cpp | 32 +++++++++++++------ limereport/lrpagedesignintf.h | 4 +++ limereport/lrpreviewreportwidget.cpp | 14 ++++++++ limereport/lrpreviewreportwidget.h | 1 + limereport/lrpreviewreportwidget_p.h | 1 + limereport/lrpreviewreportwindow.cpp | 11 ++++++- limereport/lrpreviewreportwindow.h | 1 + limereport/lrpreviewreportwindow.ui | 48 +++++++++++++++++++++++++++- 9 files changed, 101 insertions(+), 12 deletions(-) diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 9c50adb..faa26c7 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -34,6 +34,7 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); public slots: void refreshPages(); void zoomIn(); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 1bb5558..b379c3a 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -91,7 +91,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent): m_movedItem(0), m_joinItem(0), m_magneticMovement(false), - m_reportSettings(0) + m_reportSettings(0), + m_currentPage(0) { m_reportEditor = dynamic_cast(parent); updatePageRect(); @@ -240,7 +241,9 @@ void PageDesignIntf::startInsertMode(const QString &ItemType) m_insertItemType = ItemType; m_itemInsertRect = this->addRect(0, 0, 200, 50); m_itemInsertRect->setVisible(false); - m_itemInsertRect->setParentItem(pageItem()); + PageItemDesignIntf* page = pageItem() ? pageItem() : getCurrentPage(); + if (page) + m_itemInsertRect->setParentItem(page); } void PageDesignIntf::startEditMode() @@ -258,6 +261,7 @@ PageItemDesignIntf *PageDesignIntf::pageItem() void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem) { + if (pageItem.isNull()) return; if (!m_pageItem.isNull()) { removeItem(m_pageItem.data()); m_pageItem->setParent(0); @@ -334,13 +338,15 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) m_selectionRect->setRect(selectionRect); } - if ((m_insertMode) && (pageItem()->rect().contains(pageItem()->mapFromScene(event->scenePos())))) { + PageItemDesignIntf* page = pageItem() ? pageItem() : getCurrentPage(); + if ((m_insertMode) && (page && page->rect().contains(page->mapFromScene(event->scenePos())))) { if (!m_itemInsertRect->isVisible()) m_itemInsertRect->setVisible(true); - qreal posY = div(pageItem()->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); - qreal posX = div(pageItem()->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); + qreal posY = div(page->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep(); + qreal posX = div(page->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep(); m_itemInsertRect->setPos(posX,posY); + } else { + if (m_insertMode) m_itemInsertRect->setVisible(false); } - else { if (m_insertMode) m_itemInsertRect->setVisible(false); } QGraphicsScene::mouseMoveEvent(event); } @@ -481,10 +487,6 @@ BaseDesignIntf *PageDesignIntf::addReportItem(const QString &itemType, QPointF p BandDesignIntf *band = bandAt(pos); if (band) { BaseDesignIntf *reportItem = addReportItem(itemType, band, band); -// QPointF insertPos = band->mapFromScene(pos); -// insertPos = QPointF(div(insertPos.x(), horizontalGridStep()).quot * horizontalGridStep(), -// div(insertPos.y(), verticalGridStep()).quot * verticalGridStep()); - reportItem->setPos(placePosOnGrid(band->mapFromScene(pos))); reportItem->setSize(placeSizeOnGrid(size)); return reportItem; @@ -1057,6 +1059,16 @@ void PageDesignIntf::changeSelectedGroupProperty(const QString &name, const QVar } } +PageItemDesignIntf* PageDesignIntf::getCurrentPage() const +{ + return m_currentPage; +} + +void PageDesignIntf::setCurrentPage(PageItemDesignIntf* currentPage) +{ + m_currentPage = currentPage; +} + ReportSettings *PageDesignIntf::getReportSettings() const { return m_reportSettings; diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 901ddbc..c9c4aab 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -175,6 +175,9 @@ namespace LimeReport { void setPropertyToSelectedItems(const char *name, const QVariant &value); + PageItemDesignIntf* getCurrentPage() const; + void setCurrentPage(PageItemDesignIntf* currentPage); + protected: virtual void keyPressEvent(QKeyEvent *event); @@ -312,6 +315,7 @@ namespace LimeReport { JoinType m_joinType; bool m_magneticMovement; ReportSettings* m_reportSettings; + PageItemDesignIntf* m_currentPage; }; class AbstractPageCommand : public CommandIf{ diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 7b3290d..24420fe 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -68,6 +68,11 @@ QList PreviewReportWidgetPrivate::aviableExporters() return ExportersFactory::instance().map().keys(); } +void PreviewReportWidgetPrivate::startInsertTextItem() +{ + m_previewPage->startInsertMode("TextItem"); +} + PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), @@ -332,6 +337,11 @@ ScaleType PreviewReportWidget::scaleType() const return m_scaleType; } +void PreviewReportWidget::startInsertTextItem() +{ + d_ptr->startInsertTextItem(); +} + int PreviewReportWidget::scalePercent() const { return m_scalePercent; @@ -389,6 +399,10 @@ void PreviewReportWidget::slotSliderMoved(int value) d_ptr->m_changingPage = true; emit pageChanged(d_ptr->m_currentPage); + PageDesignIntf* page = dynamic_cast(ui->graphicsView->scene()); + if (page) + page->setCurrentPage(d_ptr->currentPage().data()); + d_ptr->m_changingPage = false; d_ptr->m_priorScrolValue = value; } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 9c50adb..faa26c7 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -34,6 +34,7 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); public slots: void refreshPages(); void zoomIn(); diff --git a/limereport/lrpreviewreportwidget_p.h b/limereport/lrpreviewreportwidget_p.h index 078ce5e..dba8bd8 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -21,6 +21,7 @@ public: void setPages( ReportPages pages); PageItemDesignIntf::Ptr currentPage(); QList aviableExporters(); + void startInsertTextItem(); public: PageDesignIntf* m_previewPage; ReportPages m_reportPages; diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 035a5e0..df61773 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -57,6 +57,7 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, m_pagesNavigator->setPrefix(tr("Page: ")); m_pagesNavigator->setMinimumWidth(120); ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator); + ui->editModeTools->hide(); ui->actionShowMessages->setVisible(false); connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int))); @@ -326,7 +327,9 @@ void PreviewReportWindow::on_actionEdit_Mode_triggered(bool checked) m_previewReportWidget->d_ptr->m_previewPage->setItemMode((checked)?ItemModes(DesignMode):PreviewMode); m_textAlignmentEditor->setVisible(checked); m_fontEditor->setVisible(checked); - //m_reportPages.at(m_currentPage)->setItemMode((checked)?DesignMode:PreviewMode); + if (checked) + ui->editModeTools->show(); + else ui->editModeTools->hide(); } void PreviewReportWindow::slotSelectionChanged() @@ -403,6 +406,11 @@ void PreviewReportWindow::slotPageChanged(int pageIndex) m_pagesNavigator->setValue(pageIndex); } +void PreviewReportWindow::slotInsertNewTextItem() +{ + m_previewReportWidget->startInsertTextItem(); +} + void PreviewReportWindow::on_actionFit_page_width_triggered() { m_previewReportWidget->fitWidth(); @@ -439,6 +447,7 @@ void PreviewReportWindow::slotScalePercentChanged(int percent) void PreviewReportWindow::on_actionShowMessages_toggled(bool value) { m_previewReportWidget->setErrorsMesagesVisible(value); + m_previewReportWidget->startInsertTextItem(); } void PreviewReportWindow::on_actionShow_Toolbar_triggered() diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index eb5b2e6..2104669 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -100,6 +100,7 @@ public slots: void slotLastPage(); void slotPrintToPDF(); void slotPageChanged(int pageIndex); + void slotInsertNewTextItem(); private slots: void on_actionFit_page_width_triggered(); void on_actionFit_page_triggered(); diff --git a/limereport/lrpreviewreportwindow.ui b/limereport/lrpreviewreportwindow.ui index 5c6cc24..23550ec 100644 --- a/limereport/lrpreviewreportwindow.ui +++ b/limereport/lrpreviewreportwindow.ui @@ -35,7 +35,7 @@ 0 0 800 - 20 + 22 @@ -93,6 +93,21 @@ + + + true + + + toolBar_2 + + + LeftToolBarArea + + + false + + + @@ -279,11 +294,25 @@ Show toolbar + + + + :/items/TextItem:/items/TextItem + + + InsertTextItem + + + Add new TextItem + + + + @@ -431,6 +460,22 @@ + + actionInsertTextItem + triggered() + LimeReport::PreviewReportWindow + slotInsertNewTextItem() + + + -1 + -1 + + + 399 + 299 + + + slotNextPage() @@ -441,5 +486,6 @@ slotFirstPage() slotLastPage() slotPrintToPDF() + slotInsertNewTextItem() From b74a72531cb20aa4f5e2d387483b3e027a114992 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 21 Feb 2019 19:15:31 +0300 Subject: [PATCH 2/8] Preview printer initialization changed --- limereport/lrpreviewreportwidget.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 24420fe..0ba6426 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -213,29 +213,29 @@ void PreviewReportWidget::printPages(QPrinter* printer) void PreviewReportWidget::print() { - if (m_defaultPrinter){ - printPages(m_defaultPrinter); - } else { + QPrinterInfo pi; + QPrinter lp(QPrinter::HighResolution); - QPrinterInfo pi; - QPrinter printer(QPrinter::HighResolution); - - if (!pi.defaultPrinter().isNull()) + if (!pi.defaultPrinter().isNull()){ #ifdef HAVE_QT4 - printer.setPrinterName(pi.defaultPrinter().printerName()); + lp.setPrinterName(pi.defaultPrinter().printerName()); #endif #ifdef HAVE_QT5 #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - printer.setPrinterName(pi.defaultPrinterName()); + lp.setPrinterName(pi.defaultPrinterName()); #else - printer.setPrinterName(pi.defaultPrinter().printerName()); + lp.setPrinterName(pi.defaultPrinter().printerName()); #endif #endif - QPrintDialog dialog(&printer,QApplication::activeWindow()); - if (dialog.exec()==QDialog::Accepted){ - printPages(&printer); - } } + + QPrinter* printer = m_defaultPrinter ? m_defaultPrinter : &lp; + + QPrintDialog dialog(printer,QApplication::activeWindow()); + if (dialog.exec()==QDialog::Accepted){ + printPages(printer); + } + } void PreviewReportWidget::printToPDF() From 78cac1126cf9d066eef1ede2e16f81eea021ca49 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 21 Feb 2019 22:44:43 +0300 Subject: [PATCH 3/8] TextItem placement on a page has been fixed --- limereport/lritemdesignintf.cpp | 12 +++++++----- limereport/lrpagedesignintf.cpp | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/limereport/lritemdesignintf.cpp b/limereport/lritemdesignintf.cpp index a2b51f2..f90a90d 100644 --- a/limereport/lritemdesignintf.cpp +++ b/limereport/lritemdesignintf.cpp @@ -66,11 +66,13 @@ void ItemDesignIntf::setItemLocation(LocationType location) } else { if (scene()){ PageItemDesignIntf* page = dynamic_cast(scene())->pageItem(); - QPointF parentPos = page->mapFromItem(parentItem(),x(),y()); - setParentItem(page); - setParent(page); - setPos(parentPos); - emit itemLocationChanged(this, page); + if (page){ + QPointF parentPos = page->mapFromItem(parentItem(),x(),y()); + setParentItem(page); + setParent(page); + setPos(parentPos); + emit itemLocationChanged(this, page); + } } } notify("locationType",oldValue,location); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index b379c3a..85ba475 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -491,13 +491,16 @@ BaseDesignIntf *PageDesignIntf::addReportItem(const QString &itemType, QPointF p reportItem->setSize(placeSizeOnGrid(size)); return reportItem; } else { - BaseDesignIntf *reportItem = addReportItem(itemType, pageItem(), pageItem()); - reportItem->setPos(placePosOnGrid(pageItem()->mapFromScene(pos))); - reportItem->setSize(placeSizeOnGrid(size)); - ItemDesignIntf* ii = dynamic_cast(reportItem); - if (ii) - ii->setItemLocation(ItemDesignIntf::Page); - return reportItem; + PageItemDesignIntf* page = pageItem() ? pageItem() : m_currentPage; + if (page){ + BaseDesignIntf *reportItem = addReportItem(itemType, page, page); + reportItem->setPos(placePosOnGrid(page->mapFromScene(pos))); + reportItem->setSize(placeSizeOnGrid(size)); + ItemDesignIntf* ii = dynamic_cast(reportItem); + if (ii) + ii->setItemLocation(ItemDesignIntf::Page); + return reportItem; + } } return 0; @@ -1066,7 +1069,9 @@ PageItemDesignIntf* PageDesignIntf::getCurrentPage() const void PageDesignIntf::setCurrentPage(PageItemDesignIntf* currentPage) { - m_currentPage = currentPage; + if (m_currentPage != currentPage ){ + m_currentPage = currentPage; + } } ReportSettings *PageDesignIntf::getReportSettings() const From c7045ec1d6375c4ee82d8796829c7ab6b7e4f2a1 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 1 Mar 2019 19:41:27 +0300 Subject: [PATCH 4/8] Edit mode changed --- limereport/lrbanddesignintf.cpp | 3 ++- limereport/lrbanddesignintf.h | 1 + limereport/lrpagedesignintf.cpp | 22 ++++++++++++++-------- limereport/lrpreviewreportwindow.cpp | 3 +-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index 9e3323a..37f14d4 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -105,6 +105,7 @@ void BandMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) if (!(event->modifiers() & Qt::ControlModifier)) m_band->scene()->clearSelection(); m_band->setSelected(true); + m_oldBandPos = m_band->pos(); update(0,0,boundingRect().width(),boundingRect().width()); } } @@ -136,7 +137,7 @@ void BandMarker::mouseMoveEvent(QGraphicsSceneMouseEvent* event) void BandMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { - m_band->posChanged(m_band, m_band->pos(), m_band->pos()); + m_band->posChanged(m_band, m_band->pos(), m_oldBandPos); } BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, QObject* owner, QGraphicsItem *parent) : diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index 33bca63..8faf9c8 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -72,6 +72,7 @@ private: QRectF m_rect; QColor m_color; BandDesignIntf* m_band; + QPointF m_oldBandPos; }; class BandNameLabel : public QGraphicsItem{ diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 08ac13b..260584d 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -256,7 +256,7 @@ void PageDesignIntf::startEditMode() PageItemDesignIntf *PageDesignIntf::pageItem() { - return m_pageItem.data(); + return m_currentPage ? m_currentPage : m_pageItem.data(); } void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem) @@ -1079,7 +1079,11 @@ PageItemDesignIntf* PageDesignIntf::getCurrentPage() const void PageDesignIntf::setCurrentPage(PageItemDesignIntf* currentPage) { if (m_currentPage != currentPage ){ + if (m_currentPage) m_currentPage->setItemMode(PreviewMode); m_currentPage = currentPage; + if (m_itemMode == DesignMode){ + m_currentPage->setItemMode(DesignMode); + } } } @@ -1766,13 +1770,14 @@ void PageDesignIntf::removeAllItems() void PageDesignIntf::setItemMode(BaseDesignIntf::ItemMode state) { m_itemMode = state; - foreach(QGraphicsItem * item, items()) { - BaseDesignIntf *reportItem = dynamic_cast(item); +// foreach(QGraphicsItem * item, items()) { +// BaseDesignIntf *reportItem = dynamic_cast(item); - if (reportItem) { - reportItem->setItemMode(itemMode()); - } - } +// if (reportItem) { +// reportItem->setItemMode(itemMode()); +// } +// } + if (m_currentPage) m_currentPage->setItemMode(state); } BaseDesignIntf* PageDesignIntf::reportItemByName(const QString &name) @@ -2507,7 +2512,8 @@ bool BandMoveFromToCommand::doIt() void BandMoveFromToCommand::undoIt() { - if (page()) page()->pageItem()->moveBandFromTo(to, from); + if (page() && page()->pageItem()) + page()->pageItem()->moveBandFromTo(to, from); } } diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index df61773..0e6c4cc 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -261,6 +261,7 @@ void PreviewReportWindow::moveEvent(QMoveEvent* e) void PreviewReportWindow::showEvent(QShowEvent *) { m_fontEditor->setVisible(ui->actionEdit_Mode->isChecked()); + ui->editModeTools->setVisible(false); m_textAlignmentEditor->setVisible(ui->actionEdit_Mode->isChecked()); switch (m_previewScaleType) { case FitWidth: @@ -458,5 +459,3 @@ void PreviewReportWindow::on_actionShow_Toolbar_triggered() }// namespace LimeReport - - From c6c5e2b2067c1c49401600d3f9d9d635462dc927 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 1 Mar 2019 23:48:28 +0300 Subject: [PATCH 5/8] Finished add new text item in preview mode --- include/lrpreviewreportwidget.h | 6 +++ limereport/lrpreviewreportwidget.cpp | 46 ++++++++++++++++--- limereport/lrpreviewreportwidget.h | 6 +++ limereport/lrpreviewreportwidget_p.h | 2 + limereport/lrpreviewreportwindow.cpp | 37 +++++++++++++-- limereport/lrpreviewreportwindow.h | 4 ++ limereport/lrpreviewreportwindow.ui | 69 +++++++++++++++++++++++++++- 7 files changed, 158 insertions(+), 12 deletions(-) diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index faa26c7..e7ff76e 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -15,6 +15,7 @@ class PreviewReportWidget; class PreviewReportWidgetPrivate; class ReportEnginePrivate; class ReportEngine; +class PageDesignIntf; class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget { @@ -35,6 +36,10 @@ public: QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); void startInsertTextItem(); + void activateItemSelectionMode(); + void deleteSelectedItems(); + void activateCurrentPage(); + public slots: void refreshPages(); void zoomIn(); @@ -58,6 +63,7 @@ signals: void pageChanged(int page); void scalePercentChanged(int percent); void pagesSet(int pageCount); + void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 0ba6426..328eb1f 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -53,6 +53,7 @@ void PreviewReportWidgetPrivate::setPages(ReportPages pages) m_changingPage = false; q_ptr->initPreview(); q_ptr->emitPageSet(); + q_ptr->activateCurrentPage(); } } @@ -73,6 +74,16 @@ void PreviewReportWidgetPrivate::startInsertTextItem() m_previewPage->startInsertMode("TextItem"); } +void PreviewReportWidgetPrivate::activateItemSelectionMode() +{ + m_previewPage->startEditMode(); +} + +void PreviewReportWidgetPrivate::deleteSelectedItems() +{ + m_previewPage->deleteSelected(); +} + PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), @@ -135,6 +146,10 @@ void PreviewReportWidget::initPreview() ui->graphicsView->centerOn(0, 0); ui->graphicsView->scene()->setBackgroundBrush(QColor(m_previewPageBackgroundColor)); setScalePercent(d_ptr->m_scalePercent); + PageDesignIntf* page = dynamic_cast(ui->graphicsView->scene()); + if (page) + connect(page, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)), + this, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString))); } void PreviewReportWidget::setErrorsMesagesVisible(bool visible) @@ -342,6 +357,16 @@ void PreviewReportWidget::startInsertTextItem() d_ptr->startInsertTextItem(); } +void PreviewReportWidget::activateItemSelectionMode() +{ + d_ptr->activateItemSelectionMode(); +} + +void PreviewReportWidget::deleteSelectedItems() +{ + d_ptr->deleteSelectedItems(); +} + int PreviewReportWidget::scalePercent() const { return m_scalePercent; @@ -380,8 +405,16 @@ void PreviewReportWidget::refreshPages() } } +void PreviewReportWidget::activateCurrentPage() +{ + PageDesignIntf* page = dynamic_cast(ui->graphicsView->scene()); + if (page) + page->setCurrentPage(d_ptr->currentPage().data()); +} + void PreviewReportWidget::slotSliderMoved(int value) { + int curPage = d_ptr->m_currentPage; if (ui->graphicsView->verticalScrollBar()->minimum()==value){ d_ptr->m_currentPage = 1; } else if (ui->graphicsView->verticalScrollBar()->maximum()==value){ @@ -396,14 +429,13 @@ void PreviewReportWidget::slotSliderMoved(int value) } } - d_ptr->m_changingPage = true; - emit pageChanged(d_ptr->m_currentPage); + if (curPage != d_ptr->m_currentPage){ + d_ptr->m_changingPage = true; + emit pageChanged(d_ptr->m_currentPage); + activateCurrentPage(); + d_ptr->m_changingPage = false; + } - PageDesignIntf* page = dynamic_cast(ui->graphicsView->scene()); - if (page) - page->setCurrentPage(d_ptr->currentPage().data()); - - d_ptr->m_changingPage = false; d_ptr->m_priorScrolValue = value; } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index faa26c7..e7ff76e 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -15,6 +15,7 @@ class PreviewReportWidget; class PreviewReportWidgetPrivate; class ReportEnginePrivate; class ReportEngine; +class PageDesignIntf; class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget { @@ -35,6 +36,10 @@ public: QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); void startInsertTextItem(); + void activateItemSelectionMode(); + void deleteSelectedItems(); + void activateCurrentPage(); + public slots: void refreshPages(); void zoomIn(); @@ -58,6 +63,7 @@ signals: void pageChanged(int page); void scalePercentChanged(int percent); void pagesSet(int pageCount); + void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); diff --git a/limereport/lrpreviewreportwidget_p.h b/limereport/lrpreviewreportwidget_p.h index dba8bd8..d7dc719 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -22,6 +22,8 @@ public: PageItemDesignIntf::Ptr currentPage(); QList aviableExporters(); void startInsertTextItem(); + void activateItemSelectionMode(); + void deleteSelectedItems(); public: PageDesignIntf* m_previewPage; ReportPages m_reportPages; diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 0e6c4cc..7d01c0c 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -82,10 +82,13 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent); initPercentCombobox(); -// connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int))); connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors())); connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int))); connect(m_scalePercent, SIGNAL(currentIndexChanged(QString)), this, SLOT(scaleComboboxChanged(QString))); + connect(m_previewReportWidget, SIGNAL(pageChanged(int)), this, SLOT(slotCurrentPageChanged(int))); + connect(m_previewReportWidget, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)), + this, SLOT(slotItemInserted(LimeReport::PageDesignIntf*, QPointF, QString))); + restoreSetting(); selectStateIcon(); } @@ -110,10 +113,13 @@ void PreviewReportWindow::restoreSetting() int screenWidth = desktop->screenGeometry().width(); int screenHeight = desktop->screenGeometry().height(); - int x = screenWidth*0.1; - int y = screenHeight*0.1; + int x = static_cast(screenWidth*0.1); + int y = static_cast(screenHeight*0.1); - resize(screenWidth*0.8, screenHeight*0.8); + resize( + static_cast(screenWidth*0.8), + static_cast(screenHeight*0.8) + ); move(x, y); } v = settings()->value("State"); @@ -410,6 +416,19 @@ void PreviewReportWindow::slotPageChanged(int pageIndex) void PreviewReportWindow::slotInsertNewTextItem() { m_previewReportWidget->startInsertTextItem(); + ui->actionSelection_Mode->setChecked(false); +} + +void PreviewReportWindow::slotActivateItemSelectionMode() +{ + m_previewReportWidget->activateItemSelectionMode(); + ui->actionSelection_Mode->setChecked(true); + ui->actionInsertTextItem->setChecked(false); +} + +void PreviewReportWindow::slotDeleteSelectedItems() +{ + m_previewReportWidget->deleteSelectedItems(); } void PreviewReportWindow::on_actionFit_page_width_triggered() @@ -457,5 +476,15 @@ void PreviewReportWindow::on_actionShow_Toolbar_triggered() writeSetting(); } +void PreviewReportWindow::slotCurrentPageChanged(int page) +{ + slotActivateItemSelectionMode(); +} + +void PreviewReportWindow::slotItemInserted(PageDesignIntf *, QPointF, const QString&) +{ + slotActivateItemSelectionMode(); +} + }// namespace LimeReport diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index 2104669..992a34d 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -101,6 +101,8 @@ public slots: void slotPrintToPDF(); void slotPageChanged(int pageIndex); void slotInsertNewTextItem(); + void slotActivateItemSelectionMode(); + void slotDeleteSelectedItems(); private slots: void on_actionFit_page_width_triggered(); void on_actionFit_page_triggered(); @@ -109,6 +111,8 @@ private slots: void slotScalePercentChanged(int percent); void on_actionShowMessages_toggled(bool value); void on_actionShow_Toolbar_triggered(); + void slotCurrentPageChanged(int page); + void slotItemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); private: ItemsReaderIntf* reader(); void initPercentCombobox(); diff --git a/limereport/lrpreviewreportwindow.ui b/limereport/lrpreviewreportwindow.ui index 23550ec..8ce8873 100644 --- a/limereport/lrpreviewreportwindow.ui +++ b/limereport/lrpreviewreportwindow.ui @@ -35,7 +35,7 @@ 0 0 800 - 22 + 20 @@ -106,7 +106,10 @@ false + + + @@ -295,6 +298,9 @@ + + true + :/items/TextItem:/items/TextItem @@ -306,6 +312,33 @@ Add new TextItem + + + true + + + true + + + + :/report/images/editMode:/report/images/editMode + + + Selection Mode + + + + + + :/report/images/delete:/report/images/delete + + + Delete Item + + + Del + + @@ -476,6 +509,38 @@ + + actionSelection_Mode + triggered() + LimeReport::PreviewReportWindow + slotActivateItemSelectionMode() + + + -1 + -1 + + + 399 + 299 + + + + + actionDelete_Item + triggered() + LimeReport::PreviewReportWindow + slotDeleteSelectedItems() + + + -1 + -1 + + + 399 + 299 + + + slotNextPage() @@ -487,5 +552,7 @@ slotLastPage() slotPrintToPDF() slotInsertNewTextItem() + slotActivateItemSelectionMode() + slotDeleteSelectedItems() From bf3e34677a6b180e23ec36f4485f5c1f657882fe Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 1 Mar 2019 23:54:41 +0300 Subject: [PATCH 6/8] Current page activation has been fixed --- limereport/lrpreviewreportwidget.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 328eb1f..4109dbd 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -177,6 +177,7 @@ void PreviewReportWidget::firstPage() d_ptr->m_currentPage=1; ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0); emit pageChanged(d_ptr->m_currentPage); + activateCurrentPage(); } d_ptr->m_changingPage=false; } @@ -188,6 +189,7 @@ void PreviewReportWidget::priorPage() d_ptr->m_currentPage--; ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0); emit pageChanged(d_ptr->m_currentPage); + activateCurrentPage(); } d_ptr->m_changingPage=false; } @@ -199,6 +201,7 @@ void PreviewReportWidget::nextPage() d_ptr->m_currentPage++; ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0); emit pageChanged(d_ptr->m_currentPage); + activateCurrentPage(); } d_ptr->m_changingPage=false; } @@ -210,6 +213,7 @@ void PreviewReportWidget::lastPage() d_ptr->m_currentPage=d_ptr->m_reportPages.count(); ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0); emit pageChanged(d_ptr->m_currentPage); + activateCurrentPage(); } d_ptr->m_changingPage=false; } @@ -269,6 +273,7 @@ void PreviewReportWidget::pageNavigatorChanged(int value) d_ptr->m_changingPage = true; if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_reportPages.count() >= value) && value>0){ d_ptr->m_currentPage = value; + activateCurrentPage(); ui->graphicsView->ensureVisible(d_ptr->calcPageShift(), 0, 0); } d_ptr->m_changingPage=false; From 424665d03834bf9e4044efec713c97b70ebb1879 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sat, 2 Mar 2019 00:29:18 +0300 Subject: [PATCH 7/8] Band marker has been fixed --- limereport/lrbanddesignintf.cpp | 3 +-- limereport/lrpageitemdesignintf.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index 37f14d4..61f6b0a 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -775,8 +775,7 @@ BandDesignIntf* BandDesignIntf::findParentBand() void BandDesignIntf::updateBandMarkerGeometry() { if (parentItem() && m_bandMarker){ - QPointF sp = parentItem()->mapToScene(pos()); - m_bandMarker->setPos((sp.x()-m_bandMarker->boundingRect().width()),sp.y()); + m_bandMarker->setPos(pos().x()-m_bandMarker->width(),pos().y()); m_bandMarker->setHeight(rect().height()); } } diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index d0f949e..b0cdff8 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -479,7 +479,7 @@ void PageItemDesignIntf::relocateBands() { if (isLoading()) return; - int bandSpace = (itemMode() & DesignMode)?0:0; + int bandSpace = 0; QVector posByColumn; From ed902b4ef13e5346501668e7ecf20d2255b7406f Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sat, 2 Mar 2019 01:08:20 +0300 Subject: [PATCH 8/8] Script editor has been changed for preview mode --- limereport/lrreportengine.cpp | 7 ++++--- limereport/lrreportengine_p.h | 2 +- limereport/lrscriptenginemanager.cpp | 2 +- limereport/scripteditor/lrscripteditor.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index e83aadf..b07c607 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -155,12 +155,13 @@ QObject *ReportEnginePrivate::elementAt(const QString &, int index) return pageAt(index); } -PageDesignIntf *ReportEnginePrivate::createPage(const QString &pageName) +PageDesignIntf *ReportEnginePrivate::createPage(const QString &pageName, bool preview) { PageDesignIntf* page =new PageDesignIntf(); page->setObjectName(pageName); page->pageItem()->setObjectName("Report"+pageName); - page->setReportEditor(this); + if (!preview) + page->setReportEditor(this); page->setReportSettings(&m_reportSettings); return page; } @@ -185,7 +186,7 @@ bool ReportEnginePrivate::deletePage(PageDesignIntf *page){ PageDesignIntf *ReportEnginePrivate::createPreviewPage() { - return createPage(); + return createPage("preview",true); } int ReportEnginePrivate::elementsCount(const QString &) diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 69831b7..3210e64 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -240,7 +240,7 @@ public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); protected: - PageDesignIntf* createPage(const QString& pageName=""); + PageDesignIntf* createPage(const QString& pageName="", bool preview = false); protected slots: void slotDataSourceCollectionLoaded(const QString& collectionName); private slots: diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index f6197e9..0f3aa1a 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -336,7 +336,7 @@ QStringList ScriptEngineManager::functionsNames() } void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){ - if (m_dataManager != dataManager){ + if (dataManager && m_dataManager != dataManager){ m_dataManager = dataManager; if (m_dataManager){ foreach(QString func, m_dataManager->groupFunctionNames()){ diff --git a/limereport/scripteditor/lrscripteditor.cpp b/limereport/scripteditor/lrscripteditor.cpp index c1a7141..7c9656d 100644 --- a/limereport/scripteditor/lrscripteditor.cpp +++ b/limereport/scripteditor/lrscripteditor.cpp @@ -54,14 +54,16 @@ void ScriptEditor::setReportEngine(ReportEnginePrivateInterface* reportEngine) { m_reportEngine = reportEngine; DataSourceManager* dm = m_reportEngine->dataManager(); - initEditor(dm); + if (dm) initEditor(dm); + else ui->tabWidget->setVisible(false); } void ScriptEditor::setReportPage(PageDesignIntf* page) { m_page = page; DataSourceManager* dm = page->datasourceManager(); - initEditor(dm); + if (dm) initEditor(dm); + else ui->tabWidget->setVisible(false); } void ScriptEditor::setPageBand(BandDesignIntf* band)