diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 9c50adb..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 { @@ -34,6 +35,11 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); + void activateItemSelectionMode(); + void deleteSelectedItems(); + void activateCurrentPage(); + public slots: void refreshPages(); void zoomIn(); @@ -57,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/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/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 0e039d8..260584d 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() @@ -253,11 +256,12 @@ void PageDesignIntf::startEditMode() PageItemDesignIntf *PageDesignIntf::pageItem() { - return m_pageItem.data(); + return m_currentPage ? m_currentPage : m_pageItem.data(); } void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem) { + if (pageItem.isNull()) return; if (!m_pageItem.isNull()) { removeItem(m_pageItem.data()); m_pageItem->setParent(0); @@ -334,10 +338,11 @@ 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); if (magneticMovement()){ rectMoved( @@ -348,8 +353,9 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event) ) ); } + } else { + if (m_insertMode) m_itemInsertRect->setVisible(false); } - else { if (m_insertMode) m_itemInsertRect->setVisible(false); } QGraphicsScene::mouseMoveEvent(event); } @@ -490,21 +496,20 @@ 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; } 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,6 +1071,22 @@ void PageDesignIntf::changeSelectedGroupProperty(const QString &name, const QVar } } +PageItemDesignIntf* PageDesignIntf::getCurrentPage() const +{ + return m_currentPage; +} + +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); + } + } +} + ReportSettings *PageDesignIntf::getReportSettings() const { return m_reportSettings; @@ -1749,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) @@ -2490,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/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 49f8031..6475373 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -176,6 +176,8 @@ namespace LimeReport { void setPropertyToSelectedItems(const char *name, const QVariant &value); + PageItemDesignIntf* getCurrentPage() const; + void setCurrentPage(PageItemDesignIntf* currentPage); protected: @@ -314,7 +316,7 @@ namespace LimeReport { JoinType m_joinType; bool m_magneticMovement; ReportSettings* m_reportSettings; - + PageItemDesignIntf* m_currentPage; }; class AbstractPageCommand : public CommandIf{ 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; diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 3f2a984..4109dbd 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(); } } @@ -68,6 +69,21 @@ QList PreviewReportWidgetPrivate::aviableExporters() return ExportersFactory::instance().map().keys(); } +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)), @@ -130,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) @@ -157,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; } @@ -168,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; } @@ -179,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; } @@ -190,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; } @@ -249,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; @@ -332,6 +357,21 @@ ScaleType PreviewReportWidget::scaleType() const return m_scaleType; } +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; @@ -370,8 +410,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){ @@ -386,10 +434,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; + } - d_ptr->m_changingPage = false; d_ptr->m_priorScrolValue = value; } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 9c50adb..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 { @@ -34,6 +35,11 @@ public: QColor previewPageBackgroundColor(); QPrinter *defaultPrinter() const; void setDefaultPrinter(QPrinter *defaultPrinter); + void startInsertTextItem(); + void activateItemSelectionMode(); + void deleteSelectedItems(); + void activateCurrentPage(); + public slots: void refreshPages(); void zoomIn(); @@ -57,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 078ce5e..d7dc719 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -21,6 +21,9 @@ public: void setPages( ReportPages pages); 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 035a5e0..7d01c0c 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))); @@ -81,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(); } @@ -109,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"); @@ -260,6 +267,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: @@ -326,7 +334,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 +413,24 @@ void PreviewReportWindow::slotPageChanged(int pageIndex) m_pagesNavigator->setValue(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() { m_previewReportWidget->fitWidth(); @@ -439,6 +467,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() @@ -447,7 +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 eb5b2e6..992a34d 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -100,6 +100,9 @@ public slots: void slotLastPage(); 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(); @@ -108,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 5c6cc24..8ce8873 100644 --- a/limereport/lrpreviewreportwindow.ui +++ b/limereport/lrpreviewreportwindow.ui @@ -93,6 +93,24 @@ + + + true + + + toolBar_2 + + + LeftToolBarArea + + + false + + + + + + @@ -279,11 +297,55 @@ Show toolbar + + + true + + + + :/items/TextItem:/items/TextItem + + + InsertTextItem + + + Add new TextItem + + + + + true + + + true + + + + :/report/images/editMode:/report/images/editMode + + + Selection Mode + + + + + + :/report/images/delete:/report/images/delete + + + Delete Item + + + Del + + + + @@ -431,6 +493,54 @@ + + actionInsertTextItem + triggered() + LimeReport::PreviewReportWindow + slotInsertNewTextItem() + + + -1 + -1 + + + 399 + 299 + + + + + actionSelection_Mode + triggered() + LimeReport::PreviewReportWindow + slotActivateItemSelectionMode() + + + -1 + -1 + + + 399 + 299 + + + + + actionDelete_Item + triggered() + LimeReport::PreviewReportWindow + slotDeleteSelectedItems() + + + -1 + -1 + + + 399 + 299 + + + slotNextPage() @@ -441,5 +551,8 @@ slotFirstPage() slotLastPage() slotPrintToPDF() + slotInsertNewTextItem() + slotActivateItemSelectionMode() + slotDeleteSelectedItems() 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)