From 491f7b49d704cf175a94df873ad2d81bd27c3e61 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Fri, 7 Apr 2017 23:02:58 -0400 Subject: [PATCH 01/12] Fix "hidden overloaded virtual function" warning I'm presuming that TearOffBand::isUnique() is supposed to override the base class's isUnique(), but it was missing a const... --- limereport/bands/lrtearoffband.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/limereport/bands/lrtearoffband.h b/limereport/bands/lrtearoffband.h index d1ee19b..e373a90 100644 --- a/limereport/bands/lrtearoffband.h +++ b/limereport/bands/lrtearoffband.h @@ -12,7 +12,7 @@ public: virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0); protected: QColor bandColor() const; - bool isUnique(){ return true;} + virtual bool isUnique() const {return true;} }; } // namespace LimeReport From 3ae754e3dddecc28b37461f6d0abe873f34f7477 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 09:31:02 -0400 Subject: [PATCH 02/12] Fix a memory leak in PageDesignIntf::copy() --- limereport/lrpagedesignintf.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 2178d43..49d513c 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -1226,6 +1226,8 @@ void PageDesignIntf::copy() if (shouldWrite) { clipboard->setText(writer->saveToString()); } + + delete writer; } } From 7ebc42c5142ba7313ea4966660b3eee3637e801d Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 09:35:09 -0400 Subject: [PATCH 03/12] Fixes a few instances where nullptrs might be dereferenced --- limereport/lrpagedesignintf.cpp | 2 +- limereport/lrreportdesignwidget.cpp | 2 +- limereport/lrreportrender.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 2178d43..679f583 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -2169,7 +2169,7 @@ void PropertyItemAlignChangedCommand::undoIt() if (reportItem && (reportItem->property(m_propertyName.toLatin1()) != m_oldValue)) { reportItem->setProperty(m_propertyName.toLatin1(), m_oldValue); } - if (m_oldValue == BaseDesignIntf::DesignedItemAlign){ + if (reportItem && (m_oldValue == BaseDesignIntf::DesignedItemAlign)){ reportItem->setPos(m_savedPos); } } diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 6a6ff0c..4852b97 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -74,7 +74,7 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int))); //m_instance=this; - m_scriptEditor->setPlainText(report->scriptContext()->initScript()); + m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); m_zoomer = new GraphicsViewZoomer(activeView()); #ifdef Q_OS_WIN m_defaultFont = QFont("Arial",10); diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 8d2ccb6..f1a40bd 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -481,9 +481,12 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign void ReportRender::renderDataBand(BandDesignIntf *dataBand) { + if (dataBand == NULL ) + return; + IDataSource* bandDatasource = 0; m_lastRenderedFooter = 0; - if (dataBand && !dataBand->datasourceName().isEmpty()) + if (!dataBand->datasourceName().isEmpty()) bandDatasource = datasources()->dataSource(dataBand->datasourceName()); BandDesignIntf* header = dataBand->bandHeader(); @@ -691,7 +694,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da // } } - if (!gb->isStarted()){ + if (gb && !gb->isStarted()){ if (band->reprintOnEachPage()) m_reprintableBands.append(band); gb->startGroup(m_datasources); From 942da982ca249b6b9e93f638fc88bda87b22f833 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 09:42:08 -0400 Subject: [PATCH 04/12] Ensure we aren't returning data that has been deleted by setting the pointer to NULL. --- limereport/lrreportrender.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 8d2ccb6..1b31b4f 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -442,6 +442,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign BandDesignIntf* upperPart = dynamic_cast(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn])); registerBand(upperPart); delete bandClone; + bandClone = NULL; } } else { @@ -459,6 +460,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign BandDesignIntf* upperPart = dynamic_cast(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn])); registerBand(upperPart); delete bandClone; + bandClone = NULL; }; } else { bandClone->setHeight(m_maxHeightByColumn[m_currentColumn]); From 64331fbaeb274f377330ef10dbae559558f3a016 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 12:53:05 -0400 Subject: [PATCH 05/12] Corrects spelling of method name --- include/lrdatasourcemanagerintf.h | 2 +- limereport/lrdatasourcemanager.cpp | 2 +- limereport/lrdatasourcemanager.h | 2 +- limereport/lrdatasourcemanagerintf.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/lrdatasourcemanagerintf.h b/include/lrdatasourcemanagerintf.h index 57bd0c1..e3a6ce7 100644 --- a/include/lrdatasourcemanagerintf.h +++ b/include/lrdatasourcemanagerintf.h @@ -54,7 +54,7 @@ public: virtual void removeModel(const QString& name) = 0; virtual bool containsDatasource(const QString& dataSourceName) = 0; virtual void clearUserVariables()=0; - virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0; + virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; //virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0; }; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index dc2c32e..d35f670 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -314,7 +314,7 @@ void DataSourceManager::removeModel(const QString &name) removeDatasource(name.toLower()); } -ICallbackDatasource *DataSourceManager::createCallbackDatasouce(const QString& name) +ICallbackDatasource *DataSourceManager::createCallbackDatasource(const QString& name) { ICallbackDatasource* ds = new CallbackDatasource(); IDataSourceHolder* holder = new CallbackDatasourceHolder(dynamic_cast(ds),true); diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 77967c5..b6bdad1 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -114,7 +114,7 @@ public: void addProxy(const QString& name, QString master, QString detail, QList fields); bool addModel(const QString& name, QAbstractItemModel *model, bool owned); void removeModel(const QString& name); - ICallbackDatasource* createCallbackDatasouce(const QString &name); + ICallbackDatasource* createCallbackDatasource(const QString &name); void registerDbCredentialsProvider(IDbCredentialsProvider *provider); void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name); void setReportVariable(const QString& name, const QVariant& value); diff --git a/limereport/lrdatasourcemanagerintf.h b/limereport/lrdatasourcemanagerintf.h index 57bd0c1..e3a6ce7 100644 --- a/limereport/lrdatasourcemanagerintf.h +++ b/limereport/lrdatasourcemanagerintf.h @@ -54,7 +54,7 @@ public: virtual void removeModel(const QString& name) = 0; virtual bool containsDatasource(const QString& dataSourceName) = 0; virtual void clearUserVariables()=0; - virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0; + virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; //virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0; }; From 6789b01e7913f56f315f69f6bf6c5204c96f2a9f Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 18:41:42 -0400 Subject: [PATCH 06/12] Fixes some shadowed vars & avoids string copies using const refs --- limereport/items/lrhorizontallayout.cpp | 8 ++++---- limereport/items/lrsimpletagparser.cpp | 2 +- limereport/items/lrtextitemeditor.cpp | 4 ++-- limereport/lrdatadesignintf.cpp | 3 +-- limereport/lrpagedesignintf.cpp | 8 ++++---- limereport/lrreportrender.cpp | 10 +++++----- limereport/serializators/lrxmlreader.cpp | 5 ++--- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/limereport/items/lrhorizontallayout.cpp b/limereport/items/lrhorizontallayout.cpp index 3269844..9ca4b0a 100644 --- a/limereport/items/lrhorizontallayout.cpp +++ b/limereport/items/lrhorizontallayout.cpp @@ -390,8 +390,8 @@ void HorizontalLayout::slotOnChildDestroy(QObject* child) BaseDesignIntf* HorizontalLayout::findNext(BaseDesignIntf* item){ if (m_children.count() &storage, QString text, int &curPos tagName.remove('>'); while (buff.contains(rx)){ - int pos=rx.indexIn(buff); + pos=rx.indexIn(buff); buff=buff.right(buff.length()-pos); curPos+=pos; if (extractWord(rx.cap(0),1).compare(extractWord(tagName,1),Qt::CaseInsensitive)==0){ diff --git a/limereport/items/lrtextitemeditor.cpp b/limereport/items/lrtextitemeditor.cpp index e2b6778..09a0e3a 100644 --- a/limereport/items/lrtextitemeditor.cpp +++ b/limereport/items/lrtextitemeditor.cpp @@ -124,8 +124,8 @@ void TextItemEditor::initUI() ui->twData->setModel(dm->datasourcesModel()); ui->twScriptEngine->setModel(se.model()); - foreach(QString dsName,dm->dataSourceNames()){ - foreach(QString field, dm->fieldNames(dsName)){ + foreach(const QString &dsName,dm->dataSourceNames()){ + foreach(const QString &field, dm->fieldNames(dsName)){ dataWords<headerData(columnIndex,Qt::Horizontal, Qt::UserRole).isValid()? m_model->headerData(columnIndex,Qt::Horizontal, Qt::UserRole).toString(): m_model->headerData(columnIndex,Qt::Horizontal).toString(); @@ -704,7 +704,6 @@ int CallbackDatasource::columnCount(){ int currIndex = 0; do { QVariant columnName; - CallbackInfo info; info.dataType = CallbackInfo::ColumnHeaderData; info.index = currIndex; emit getCallbackData(info,columnName); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 2178d43..201403e 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -1304,7 +1304,7 @@ void PageDesignIntf::deleteSelected() } void PageDesignIntf::cut() -{ +{ CommandIf::Ptr command = CutCommand::create(this); saveCommand(command); } @@ -1727,8 +1727,8 @@ CommandIf::Ptr DeleteLayoutCommand::create(PageDesignIntf *page, LayoutDesignInt DeleteLayoutCommand* command = new DeleteLayoutCommand(); command->setPage(page); command->setItem(item); - foreach (BaseDesignIntf* item, item->childBaseItems()){ - command->m_childItems.append(item->objectName()); + foreach (BaseDesignIntf* childItem, item->childBaseItems()){ + command->m_childItems.append(childItem->objectName()); } return CommandIf::Ptr(command); } @@ -1845,7 +1845,7 @@ CommandIf::Ptr CutCommand::create(PageDesignIntf *page) foreach(QGraphicsItem * item, page->selectedItems()) { if (!dynamic_cast(item)){ BaseDesignIntf *reportItem = dynamic_cast(item); - + if (reportItem) { command->m_itemNames.push_back(reportItem->objectName()); writer->putItem(reportItem); diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 8d2ccb6..ba678c9 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -254,7 +254,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) BandDesignIntf* lastRenderedBand = 0; for (int i=0;idataBandCount() && !m_renderCanceled;i++){ lastRenderedBand = m_patternPageItem->dataBandAt(i); - initDatasource(lastRenderedBand->datasourceName()); + initDatasource(lastRenderedBand->datasourceName()); renderDataBand(lastRenderedBand); if (idataBandCount()-1) closeFooterGroup(lastRenderedBand); } @@ -263,7 +263,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) renderBand(reportFooter, 0, StartNewPageAsNeeded); if (lastRenderedBand && lastRenderedBand->keepFooterTogether()) closeFooterGroup(lastRenderedBand); - + BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand); if (tearOffBand) renderBand(tearOffBand, 0, StartNewPageAsNeeded); @@ -335,7 +335,7 @@ void ReportRender::extractGroupsFunction(BandDesignIntf *band) foreach(BaseDesignIntf* item,band->childBaseItems()){ ContentItemDesignIntf* contentItem = dynamic_cast(item); if (contentItem&&(contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}")))){ - foreach(QString functionName, m_datasources->groupFunctionNames()){ + foreach(const QString &functionName, m_datasources->groupFunctionNames()){ QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName)); if (rx.indexIn(contentItem->content())>=0){ @@ -373,7 +373,7 @@ void ReportRender::replaceGroupsFunction(BandDesignIntf *band) ContentItemDesignIntf* contentItem = dynamic_cast(item); if (contentItem){ QString content = contentItem->content(); - foreach(QString functionName, m_datasources->groupFunctionNames()){ + foreach(const QString &functionName, m_datasources->groupFunctionNames()){ QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); if (rx.indexIn(content)>=0){ int pos = 0; @@ -1229,7 +1229,7 @@ void ReportRender::savePage(bool isLast) m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem)); m_pageCount++; emit pageRendered(m_pageCount); - + if (isLast){ BandDesignIntf* ph = m_renderPageItem->bandByType(BandDesignIntf::PageHeader); if (ph && !ph->property("printOnLastPage").toBool()){ diff --git a/limereport/serializators/lrxmlreader.cpp b/limereport/serializators/lrxmlreader.cpp index bee2ff8..2e791cd 100644 --- a/limereport/serializators/lrxmlreader.cpp +++ b/limereport/serializators/lrxmlreader.cpp @@ -106,7 +106,6 @@ bool XMLReader::readItem(QObject *item) void XMLReader::readItemFromNode(QObject* item,QDomElement *node) { - ObjectLoadingStateIntf* lf = dynamic_cast(item); if(lf) lf->objectLoadStarted(); for (int i=0;ichildNodes().count();i++){ @@ -123,8 +122,8 @@ void XMLReader::readItemFromNode(QObject* item,QDomElement *node) BaseDesignIntf* baseObj = dynamic_cast(item); if(baseObj) { - foreach(QGraphicsItem* item,baseObj->childItems()){ - BaseDesignIntf* baseItem = dynamic_cast(item); + foreach(QGraphicsItem* childItem,baseObj->childItems()){ + BaseDesignIntf* baseItem = dynamic_cast(childItem); if (baseItem) baseItem->parentObjectLoadFinished(); } } From aa5b4c6a66e3072e78d73b52c4571e13b1a2264a Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 21:38:23 -0400 Subject: [PATCH 07/12] Add missing initializers --- limereport/items/lralignpropitem.h | 2 +- limereport/lrbasedesignintf.h | 4 ++-- limereport/lrdatasourcemanager.h | 2 +- limereport/lrpreviewreportwidget_p.h | 1 + limereport/objectinspector/lrpropertydelegate.cpp | 2 +- limereport/objectinspector/propertyItems/lrenumpropitem.h | 2 +- limereport/objectinspector/propertyItems/lrfontpropitem.h | 2 +- limereport/objectsbrowser/lrobjectbrowser.cpp | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/limereport/items/lralignpropitem.h b/limereport/items/lralignpropitem.h index 36a0bd7..61e4b7f 100644 --- a/limereport/items/lralignpropitem.h +++ b/limereport/items/lralignpropitem.h @@ -43,7 +43,7 @@ class AlignmentPropItem : public ObjectPropItem { Q_OBJECT public: - AlignmentPropItem():ObjectPropItem(){} + AlignmentPropItem():ObjectPropItem(),m_horizEditor(NULL),m_vertEditor(NULL){} AlignmentPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true); QString displayValue() const; void setPropertyValue(QVariant value); diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index c925579..e722598 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -51,7 +51,7 @@ class BaseDesignIntf; class Marker : public QGraphicsItem{ public: - Marker(QGraphicsItem* parent=0):QGraphicsItem(parent){} + Marker(QGraphicsItem* parent=0):QGraphicsItem(parent),m_object(NULL){} QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); void setRect(QRectF rect){prepareGeometryChange();m_rect=rect;} @@ -266,7 +266,7 @@ public: QColor borderColor() const; void setBorderColor(const QColor &borderColor); void setItemVisible(const bool& value); - virtual bool canContainChildren(){ return false;} + virtual bool canContainChildren(){ return false;} ReportSettings* reportSettings() const; void setReportSettings(ReportSettings *reportSettings); void setZValueProperty(qreal value); diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 77967c5..b682ab9 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -71,7 +71,7 @@ class DataSourceModel : public QAbstractItemModel{ Q_OBJECT friend class DataSourceManager; public: - DataSourceModel():m_rootNode(new DataNode()){} + DataSourceModel():m_dataManager(NULL),m_rootNode(new DataNode()){} DataSourceModel(DataSourceManager* dataManager); ~DataSourceModel(); QModelIndex index(int row, int column, const QModelIndex &parent) const; diff --git a/limereport/lrpreviewreportwidget_p.h b/limereport/lrpreviewreportwidget_p.h index 695b605..9557a5d 100644 --- a/limereport/lrpreviewreportwidget_p.h +++ b/limereport/lrpreviewreportwidget_p.h @@ -13,6 +13,7 @@ class PreviewReportWidgetPrivate { public: PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget): + m_previewPage(NULL), m_report(NULL), m_zoomer(NULL), m_currentPage(1), m_changingPage(false), m_priorScrolValue(0), m_scalePercent(50), q_ptr(previewReportWidget) {} bool pageIsVisible(); diff --git a/limereport/objectinspector/lrpropertydelegate.cpp b/limereport/objectinspector/lrpropertydelegate.cpp index 4856efc..3abfb32 100644 --- a/limereport/objectinspector/lrpropertydelegate.cpp +++ b/limereport/objectinspector/lrpropertydelegate.cpp @@ -36,7 +36,7 @@ #include "lrglobal.h" LimeReport::PropertyDelegate::PropertyDelegate(QObject *parent) - :QItemDelegate(parent), m_editingItem(0), m_isEditing(false) + :QItemDelegate(parent), m_objectInspector(NULL), m_editingItem(0), m_isEditing(false) {} void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const diff --git a/limereport/objectinspector/propertyItems/lrenumpropitem.h b/limereport/objectinspector/propertyItems/lrenumpropitem.h index 7cd23c1..268cc3d 100644 --- a/limereport/objectinspector/propertyItems/lrenumpropitem.h +++ b/limereport/objectinspector/propertyItems/lrenumpropitem.h @@ -37,7 +37,7 @@ class EnumPropItem : public ObjectPropItem { Q_OBJECT public: - EnumPropItem():ObjectPropItem(){} + EnumPropItem():ObjectPropItem(), m_settingValue(false){} EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly) :ObjectPropItem(object, objects, name, displayName, value, parent, readonly),m_settingValue(false){} EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly, QVector acceptableValues) diff --git a/limereport/objectinspector/propertyItems/lrfontpropitem.h b/limereport/objectinspector/propertyItems/lrfontpropitem.h index fe0219a..a5a3cfd 100644 --- a/limereport/objectinspector/propertyItems/lrfontpropitem.h +++ b/limereport/objectinspector/propertyItems/lrfontpropitem.h @@ -87,7 +87,7 @@ class FontPropItem : public ObjectPropItem { Q_OBJECT public: - FontPropItem():ObjectPropItem(){} + FontPropItem():ObjectPropItem(), m_pointSize(NULL), m_bold(NULL), m_italic(NULL), m_underline(NULL), m_family(NULL) {} FontPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly); QWidget* createProperyEditor(QWidget *parent) const; QString displayValue() const; diff --git a/limereport/objectsbrowser/lrobjectbrowser.cpp b/limereport/objectsbrowser/lrobjectbrowser.cpp index 07192f7..5eff56d 100644 --- a/limereport/objectsbrowser/lrobjectbrowser.cpp +++ b/limereport/objectsbrowser/lrobjectbrowser.cpp @@ -35,7 +35,7 @@ namespace LimeReport{ ObjectBrowser::ObjectBrowser(QWidget *parent) - :QWidget(parent), m_changingItemSelection(false) + :QWidget(parent), m_report(NULL), m_mainWindow(NULL), m_changingItemSelection(false) { QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); From 42e0e3b70b3f6ce80e07947d8622f35e772dc0f7 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sat, 8 Apr 2017 21:44:52 -0400 Subject: [PATCH 08/12] Fix missed uses in the demo --- demo_r1/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo_r1/mainwindow.cpp b/demo_r1/mainwindow.cpp index d695a4e..6deb868 100644 --- a/demo_r1/mainwindow.cpp +++ b/demo_r1/mainwindow.cpp @@ -71,19 +71,19 @@ MainWindow::MainWindow(QWidget *parent) : }; } - LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasouce("master"); + LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasource("master"); connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), this, SLOT(slotGetCallbackData(LimeReport::CallbackInfo,QVariant&))); connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)), this, SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType&,bool&))); - callbackDatasource = report->dataManager()->createCallbackDatasouce("detail"); + callbackDatasource = report->dataManager()->createCallbackDatasource("detail"); connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), this, SLOT(slotGetCallbackChildData(LimeReport::CallbackInfo,QVariant&))); connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)), this, SLOT(slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType&,bool&))); - callbackDatasource = report->dataManager()->createCallbackDatasouce("oneSlotDS"); + callbackDatasource = report->dataManager()->createCallbackDatasource("oneSlotDS"); connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&))); From 8ee7fc01e5d7f2ed00661d7b06ec953941b295df Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Sun, 9 Apr 2017 11:40:56 -0400 Subject: [PATCH 09/12] Fix crash when cutting an item using the context menu page->cut() is deleting the object, which means that "this" is no longer valid, and then we're trying to call `processPopUpAction()` on it. --- limereport/lrbasedesignintf.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index a80fd33..bdba630 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -1180,7 +1180,10 @@ void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) QAction* a = menu.exec(event->screenPos()); if (a){ if (a == cutAction) + { page->cut(); + return; + } if (a == copyAction) page->copy(); if (a == pasteAction) From e786a9a6e6b6371a300c33adf6cd693b6184b351 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Wed, 19 Apr 2017 21:48:37 -0400 Subject: [PATCH 10/12] Fix spelling: slotPreviewWindowDestroed -> slotPreviewWindowDestroyed --- limereport/lrreportengine.cpp | 4 ++-- limereport/lrreportengine_p.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index fb7ee7c..d41c194 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -155,7 +155,7 @@ void ReportEnginePrivate::slotDataSourceCollectionLoaded(const QString &collecti emit datasourceCollectionLoadFinished(collectionName); } -void ReportEnginePrivate::slotPreviewWindowDestroed(QObject* window) +void ReportEnginePrivate::slotPreviewWindowDestroyed(QObject* window) { if (m_activePreview == window){ m_activePreview = 0; @@ -387,7 +387,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints) w->setHideResultEditButton(resultIsEditable()); m_activePreview = w; - connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroed(QObject*))); + connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); qDebug()<<"render time ="<exec(); } diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 4ec3508..ca080f2 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -144,7 +144,7 @@ protected: protected slots: void slotDataSourceCollectionLoaded(const QString& collectionName); private slots: - void slotPreviewWindowDestroed(QObject *window); + void slotPreviewWindowDestroyed(QObject *window); private: //ICollectionContainer virtual QObject* createElement(const QString&,const QString&); From 94db98d5966045dc0eb084fc361ff09810fa7b66 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Wed, 19 Apr 2017 22:43:48 -0400 Subject: [PATCH 11/12] Optionally monitor changes to files loaded with ReportEngine::loadFromFile() When using the designer as a stand alone application and the renderer/preview in the user application, the preview window would have to be closed and opened again every time a change was made to the report. This change adds an optional QFileSystemWatcher to monitor changes to the report file and automatically refreshes the preview in the application when it is saved. It may be turned on using the new parameter to ReportEngine::loadFromFile(). If the preview window is open in the application and the file name changes or the file is removed, inform the user and close the preview window. --- include/lrreportengine.h | 2 +- limereport/lrpreviewreportwindow.cpp | 5 ++ limereport/lrpreviewreportwindow.h | 1 + limereport/lrreportdesignwidget.cpp | 2 +- limereport/lrreportengine.cpp | 107 ++++++++++++++++++--------- limereport/lrreportengine.h | 2 +- limereport/lrreportengine_p.h | 7 +- 7 files changed, 89 insertions(+), 37 deletions(-) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index dbbb2a8..99728e1 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -82,7 +82,7 @@ public: void setShowProgressDialog(bool value); IDataSourceManager* dataManager(); IScriptEngineManager* scriptManager(); - bool loadFromFile(const QString& fileName); + bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false); bool loadFromByteArray(QByteArray *data); bool loadFromString(const QString& data); QString reportFileName(); diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index b000547..47c4ec0 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -136,6 +136,11 @@ void PreviewReportWindow::initPreview(int pagesCount) m_pagesNavigator->setValue(1); } +void PreviewReportWindow::reloadPreview() +{ + m_previewReportWidget->refreshPages(); +} + void PreviewReportWindow::setSettings(QSettings* value) { if (m_ownedSettings) diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index 92b2829..78e4c07 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -60,6 +60,7 @@ public: void setPages(ReportPages pages); void exec(); void initPreview(int pagesCount); + void reloadPreview(); void setSettings(QSettings* value); void setErrorMessages(const QStringList& value); void setToolBarVisible(bool value); diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 4852b97..9e22238 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -288,7 +288,7 @@ bool ReportDesignWidget::save() bool ReportDesignWidget::loadFromFile(const QString &fileName) { - if (m_report->loadFromFile(fileName)){ + if (m_report->loadFromFile(fileName,false)){ createTabs(); //connectPage(m_report->pageAt(0)); m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index d41c194..dbd1882 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "time.h" @@ -59,13 +60,15 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false), m_showProgressDialog(true), m_reportName(""), m_activePreview(0), m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")), - m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy") + m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"), + m_fileWatcher( new QFileSystemWatcher( this ) ) { m_datasources = new DataSourceManager(this); m_datasources->setReportSettings(&m_reportSettings); m_scriptEngineContext = new ScriptEngineContext(this); m_datasources->setObjectName("datasources"); connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString))); + connect(m_fileWatcher,SIGNAL(fileChanged(const QString &)),this,SLOT(slotLoadFromFile(const QString &))); } ReportEnginePrivate::~ReportEnginePrivate() @@ -457,6 +460,63 @@ void ReportEnginePrivate::setCurrentReportsDir(const QString &dirName) m_reportsDir = dirName; } +bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName) +{ + PreviewReportWindow *currentPreview = qobject_cast(m_activePreview); + + if (!QFile::exists(fileName)) + { + if ( hasActivePreview() ) + { + QMessageBox::information( NULL, + tr( "Report File Change" ), + tr( "The report file \"%1\" has changed names or been deleted.\n\nThis preview is no longer valid." ).arg( fileName ) + ); + + clearReport(); + + currentPreview->close(); + } + + return false; + } + + clearReport(); + + ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); + reader->setPassPhrase(m_passPhrase); + if (reader->first()){ + if (reader->readItem(this)){ + m_fileName=fileName; + QFileInfo fi(fileName); + m_reportName = fi.fileName(); + + QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db"; + if (QFile::exists(dbSettingFileName)){ + QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat); + foreach (ConnectionDesc* connection, dataManager()->conections()) { + if (!connection->keepDBCredentials()){ + dbcredentals.beginGroup(connection->name()); + connection->setUserName(dbcredentals.value("user").toString()); + connection->setPassword(dbcredentals.value("password").toString()); + dbcredentals.endGroup(); + } + } + } + + dataManager()->connectAutoConnections(); + + if ( hasActivePreview() ) + { + currentPreview->reloadPreview(); + } + return true; + }; + } + m_lastError = reader->lastError(); + return false; +} + void ReportEnginePrivate::cancelRender() { if (m_reportRender) @@ -509,39 +569,20 @@ QSettings*ReportEnginePrivate::settings() } } -bool ReportEnginePrivate::loadFromFile(const QString &fileName) +bool ReportEnginePrivate::loadFromFile(const QString &fileName, bool autoLoadPreviewOnChange) { - if (!QFile::exists(fileName)) return false; + // only watch one file at a time + if ( !m_fileWatcher->files().isEmpty() ) + { + m_fileWatcher->removePaths( m_fileWatcher->files() ); + } - clearReport(); + if ( autoLoadPreviewOnChange ) + { + m_fileWatcher->addPath( fileName ); + } - ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); - reader->setPassPhrase(m_passPhrase); - if (reader->first()){ - if (reader->readItem(this)){ - m_fileName=fileName; - QFileInfo fi(fileName); - m_reportName = fi.fileName(); - - QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db"; - if (QFile::exists(dbSettingFileName)){ - QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat); - foreach (ConnectionDesc* connection, dataManager()->conections()) { - if (!connection->keepDBCredentials()){ - dbcredentals.beginGroup(connection->name()); - connection->setUserName(dbcredentals.value("user").toString()); - connection->setPassword(dbcredentals.value("password").toString()); - dbcredentals.endGroup(); - } - } - } - - dataManager()->connectAutoConnections(); - return true; - }; - } - m_lastError = reader->lastError(); - return false; + return slotLoadFromFile( fileName ); } bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &name){ @@ -880,10 +921,10 @@ IScriptEngineManager* ReportEngine::scriptManager() return d->scriptManagerIntf(); } -bool ReportEngine::loadFromFile(const QString &fileName) +bool ReportEngine::loadFromFile(const QString &fileName, bool autoLoadPreviewOnChange) { Q_D(ReportEngine); - return d->loadFromFile(fileName); + return d->loadFromFile(fileName, autoLoadPreviewOnChange); } bool ReportEngine::loadFromByteArray(QByteArray* data){ diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index dbbb2a8..99728e1 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -82,7 +82,7 @@ public: void setShowProgressDialog(bool value); IDataSourceManager* dataManager(); IScriptEngineManager* scriptManager(); - bool loadFromFile(const QString& fileName); + bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false); bool loadFromByteArray(QByteArray *data); bool loadFromString(const QString& data); QString reportFileName(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index ca080f2..f900217 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -42,6 +42,8 @@ #include "serializators/lrstorageintf.h" #include "lrscriptenginemanager.h" +class QFileSystemWatcher; + namespace LimeReport{ class PageDesignIntf; @@ -91,7 +93,7 @@ public: void setSettings(QSettings* value); void setShowProgressDialog(bool value){m_showProgressDialog = value;} QSettings* settings(); - bool loadFromFile(const QString& fileName); + bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange); bool loadFromByteArray(QByteArray *data, const QString& name = ""); bool loadFromString(const QString& report, const QString& name = ""); QString reportFileName(){return m_fileName;} @@ -138,6 +140,7 @@ signals: void onSave(); void saveFinished(); public slots: + bool slotLoadFromFile(const QString& fileName); void cancelRender(); protected: PageDesignIntf* createPage(const QString& pageName=""); @@ -178,6 +181,8 @@ private: bool m_reportRendering; bool m_resultIsEditable; QString m_passPhrase; + + QFileSystemWatcher *m_fileWatcher; }; } From b3529ffd0c7537e04a05b83288349ab2c898cf85 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 20 Apr 2017 21:09:52 +0300 Subject: [PATCH 12/12] TextItem render has been fixed --- limereport/items/lrtextitem.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index 1224bc9..608f0ed 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -491,18 +491,20 @@ TextItem::TextPtr TextItem::textDocument() const setTextFont(text,_font); } - text->documentLayout(); + //text->documentLayout(); + if (m_lineSpacing != 1 || m_textIndent !=0 ){ - for ( QTextBlock block = text->begin(); block.isValid(); block = block.next()) - { - QTextCursor tc = QTextCursor(block); - QTextBlockFormat fmt = block.blockFormat(); - fmt.setTextIndent(m_textIndent); - - if(fmt.lineHeight() != m_lineSpacing) { - fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight); + for ( QTextBlock block = text->begin(); block.isValid(); block = block.next()) + { + QTextCursor tc = QTextCursor(block); + QTextBlockFormat fmt = block.blockFormat(); + fmt.setTextIndent(m_textIndent); + if (fmt.lineHeight() != m_lineSpacing) { + fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight); + } tc.setBlockFormat( fmt ); } + } return text;