From be67e6309bf96a0a86a6e8bbe344d39edaa394b9 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Wed, 2 Nov 2016 00:21:45 +0300 Subject: [PATCH 1/2] pri file has been refactored pri file refactored --- limereport/limereport.pri | 99 ++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/limereport/limereport.pri b/limereport/limereport.pri index ae11f9e..37f2234 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -11,7 +11,6 @@ INCLUDEPATH += \ $$REPORT_PATH/databrowser SOURCES += \ - $$REPORT_PATH/items/lrtextitem.cpp \ $$REPORT_PATH/bands/lrpageheader.cpp \ $$REPORT_PATH/bands/lrpagefooter.cpp \ $$REPORT_PATH/bands/lrreportheader.cpp \ @@ -20,31 +19,31 @@ SOURCES += \ $$REPORT_PATH/bands/lrgroupbands.cpp \ $$REPORT_PATH/bands/lrsubdetailband.cpp \ $$REPORT_PATH/bands/lrtearoffband.cpp \ - $$REPORT_PATH/objectinspector/lrobjectinspectorwidget.cpp \ - $$REPORT_PATH/objectinspector/lrobjectitemmodel.cpp \ - $$REPORT_PATH/objectinspector/lrobjectpropitem.cpp \ - $$REPORT_PATH/objectinspector/lrpropertydelegate.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrstringpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrrectproptem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrintpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrenumpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrboolpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrflagspropitem.cpp \ - $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.cpp \ - $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.cpp \ - $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.cpp \ - $$REPORT_PATH/objectinspector/editors/lrbuttonlineeditor.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrfontpropitem.cpp \ - $$REPORT_PATH/objectinspector/editors/lrfonteditor.cpp \ - $$REPORT_PATH/objectinspector/editors/lrimageeditor.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrimagepropitem.cpp \ - $$REPORT_PATH/objectinspector/lrbasedesignobjectmodel.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrqrealpropitem.cpp \ - $$REPORT_PATH/objectinspector/editors/lrcoloreditor.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrcolorpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrdatasourcepropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrgroupfieldpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrcontentpropitem.cpp \ + $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrbuttonlineeditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrfonteditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrimageeditor.cpp \ + $$REPORT_PATH/objectinspector/editors/lrcoloreditor.cpp \ + $$REPORT_PATH/objectinspector/lrbasedesignobjectmodel.cpp \ + $$REPORT_PATH/objectinspector/lrobjectinspectorwidget.cpp \ + $$REPORT_PATH/objectinspector/lrobjectitemmodel.cpp \ + $$REPORT_PATH/objectinspector/lrobjectpropitem.cpp \ + $$REPORT_PATH/objectinspector/lrpropertydelegate.cpp \ $$REPORT_PATH/objectsbrowser/lrobjectbrowser.cpp \ $$REPORT_PATH/databrowser/lrdatabrowser.cpp \ $$REPORT_PATH/databrowser/lrsqleditdialog.cpp \ @@ -67,6 +66,7 @@ SOURCES += \ $$REPORT_PATH/items/lrimageitem.cpp \ $$REPORT_PATH/items/lrtextitemeditor.cpp \ $$REPORT_PATH/items/lrshapeitem.cpp \ + $$REPORT_PATH/items/lrtextitem.cpp \ $$REPORT_PATH/lrbanddesignintf.cpp \ $$REPORT_PATH/lrpageitemdesignintf.cpp \ $$REPORT_PATH/lrpagedesignintf.cpp \ @@ -97,30 +97,21 @@ contains(CONFIG, zint){ HEADERS += \ $$REPORT_PATH/base/lrsingleton.h \ + $$REPORT_PATH/base/lrsimpleabstractfactory.h \ + $$REPORT_PATH/base/lrattribsabstractfactory.h \ $$REPORT_PATH/bands/lrpageheader.h \ $$REPORT_PATH/bands/lrpagefooter.h \ $$REPORT_PATH/bands/lrreportheader.h \ $$REPORT_PATH/bands/lrreportfooter.h \ $$REPORT_PATH/bands/lrdataband.h \ $$REPORT_PATH/bands/lrtearoffband.h \ - $$REPORT_PATH/objectinspector/lrobjectinspectorwidget.h \ - $$REPORT_PATH/objectinspector/lrobjectitemmodel.h \ - $$REPORT_PATH/objectinspector/lrobjectpropitem.h \ - $$REPORT_PATH/objectinspector/lrpropertydelegate.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrstringpropitem.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrrectproptem.h \ + $$REPORT_PATH/bands/lrsubdetailband.h \ + $$REPORT_PATH/bands/lrgroupbands.h \ $$REPORT_PATH/databrowser/lrdatabrowser.h \ $$REPORT_PATH/databrowser/lrsqleditdialog.h \ $$REPORT_PATH/databrowser/lrconnectiondialog.h \ $$REPORT_PATH/databrowser/lrvariabledialog.h \ $$REPORT_PATH/databrowser/lrdatabrowsertree.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrdatasourcepropitem.h \ - $$REPORT_PATH/lrbanddesignintf.h \ - $$REPORT_PATH/lrpageitemdesignintf.h \ - $$REPORT_PATH/lrbandsmanager.h \ - $$REPORT_PATH/lrglobal.h \ - $$REPORT_PATH/base/lrsimpleabstractfactory.h \ - $$REPORT_PATH/base/lrattribsabstractfactory.h \ $$REPORT_PATH/serializators/lrserializatorintf.h \ $$REPORT_PATH/serializators/lrstorageintf.h \ $$REPORT_PATH/serializators/lrxmlqrectserializator.h \ @@ -128,29 +119,49 @@ HEADERS += \ $$REPORT_PATH/serializators/lrxmlbasetypesserializators.h \ $$REPORT_PATH/serializators/lrxmlreader.h \ $$REPORT_PATH/serializators/lrxmlwriter.h \ - $$REPORT_PATH/lrbasedesignintf.h \ - $$REPORT_PATH/lritemdesignintf.h \ - $$REPORT_PATH/lrdesignelementsfactory.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrstringpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrrectproptem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrdatasourcepropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrfontpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrimagepropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrintpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrenumpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrboolpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrflagspropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrgroupfieldpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrcontentpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrqrealpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrcolorpropitem.h \ $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.h \ $$REPORT_PATH/objectinspector/editors/lrbuttonlineeditor.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrgroupfieldpropitem.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrcontentpropitem.h \ + $$REPORT_PATH/objectinspector/editors/lrimageeditor.h \ + $$REPORT_PATH/objectinspector/editors/lrcoloreditor.h \ + $$REPORT_PATH/objectinspector/editors/lrfonteditor.h \ + $$REPORT_PATH/objectinspector/lrbasedesignobjectmodel.h \ + $$REPORT_PATH/objectinspector/lrobjectinspectorwidget.h \ + $$REPORT_PATH/objectinspector/lrobjectitemmodel.h \ + $$REPORT_PATH/objectinspector/lrobjectpropitem.h \ + $$REPORT_PATH/objectinspector/lrpropertydelegate.h \ $$REPORT_PATH/objectsbrowser/lrobjectbrowser.h \ - $$REPORT_PATH/items/lrtextitem.h \ - $$REPORT_PATH/items/lrsubitemparentpropitem.h \ - $$REPORT_PATH/items/lralignpropitem.h \ - $$REPORT_PATH/items/lrhorizontallayout.h \ $$REPORT_PATH/items/editors/lritemeditorwidget.h \ $$REPORT_PATH/items/editors/lrfonteditorwidget.h \ $$REPORT_PATH/items/editors/lrtextalignmenteditorwidget.h \ $$REPORT_PATH/items/editors/lritemsaligneditorwidget.h \ $$REPORT_PATH/items/editors/lritemsborderseditorwidget.h \ + $$REPORT_PATH/items/lrtextitem.h \ + $$REPORT_PATH/items/lrsubitemparentpropitem.h \ + $$REPORT_PATH/items/lralignpropitem.h \ + $$REPORT_PATH/items/lrhorizontallayout.h \ + $$REPORT_PATH/items/lrtextitemeditor.h \ + $$REPORT_PATH/items/lrshapeitem.h \ + $$REPORT_PATH/items/lrimageitem.h \ + $$REPORT_PATH/items/lrsimpletagparser.h \ + $$REPORT_PATH/lrbanddesignintf.h \ + $$REPORT_PATH/lrpageitemdesignintf.h \ + $$REPORT_PATH/lrbandsmanager.h \ + $$REPORT_PATH/lrglobal.h \ $$REPORT_PATH/lrdatadesignintf.h \ $$REPORT_PATH/lrcollection.h \ $$REPORT_PATH/lrpagedesignintf.h \ @@ -158,26 +169,15 @@ HEADERS += \ $$REPORT_PATH/lrreportengine_p.h \ $$REPORT_PATH/lrdatasourcemanager.h \ $$REPORT_PATH/lrreportdesignwindow.h \ - $$REPORT_PATH/items/lrsimpletagparser.h \ - $$REPORT_PATH/bands/lrsubdetailband.h \ $$REPORT_PATH/lrreportrender.h \ $$REPORT_PATH/lrpreviewreportwindow.h \ $$REPORT_PATH/lrpreviewreportwidget.h \ $$REPORT_PATH/lrpreviewreportwidget_p.h \ $$REPORT_PATH/lrgraphicsviewzoom.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrfontpropitem.h \ - $$REPORT_PATH/objectinspector/editors/lrfonteditor.h \ - $$REPORT_PATH/items/lrimageitem.h \ - $$REPORT_PATH/objectinspector/editors/lrimageeditor.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrimagepropitem.h \ - $$REPORT_PATH/items/lrtextitemeditor.h \ - $$REPORT_PATH/objectinspector/lrbasedesignobjectmodel.h \ + $$REPORT_PATH/lrbasedesignintf.h \ + $$REPORT_PATH/lritemdesignintf.h \ + $$REPORT_PATH/lrdesignelementsfactory.h \ $$REPORT_PATH/lrscriptenginemanager.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrqrealpropitem.h \ - $$REPORT_PATH/items/lrshapeitem.h \ - $$REPORT_PATH/objectinspector/editors/lrcoloreditor.h \ - $$REPORT_PATH/objectinspector/propertyItems/lrcolorpropitem.h \ - $$REPORT_PATH/bands/lrgroupbands.h \ $$REPORT_PATH/lrvariablesholder.h \ $$REPORT_PATH/lrgroupfunctions.h \ $$REPORT_PATH/lrreportengine.h \ @@ -204,6 +204,7 @@ FORMS += \ $$REPORT_PATH/lraboutdialog.ui \ $$REPORT_PATH/lrsettingdialog.ui + RESOURCES += \ $$REPORT_PATH/objectinspector/lobjectinspector.qrc \ $$REPORT_PATH/databrowser/lrdatabrowser.qrc \ From 0055790bcd0edffff30c2d096e8616703d2fb8b3 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Tue, 8 Nov 2016 01:09:35 +0300 Subject: [PATCH 2/2] setDefaultDatabasePath() has been added to DataSourceManager --- include/lrdatasourcemanagerintf.h | 1 + limereport/lrdatasourcemanager.cpp | 70 +++++++++++++++++++--------- limereport/lrdatasourcemanager.h | 5 +- limereport/lrdatasourcemanagerintf.h | 1 + 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/include/lrdatasourcemanagerintf.h b/include/lrdatasourcemanagerintf.h index 7ff5aee..85cf388 100644 --- a/include/lrdatasourcemanagerintf.h +++ b/include/lrdatasourcemanagerintf.h @@ -40,6 +40,7 @@ namespace LimeReport{ class IDataSourceManager{ public: virtual void setReportVariable(const QString& name, const QVariant& value)=0; + virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0; virtual void deleteVariable(const QString& name)=0; virtual bool containsVariable(const QString& variableName)=0; virtual QVariant variable(const QString& variableName)=0; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 1b228ea..b6c25d3 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace LimeReport{ @@ -227,6 +228,16 @@ DataSourceManager::DataSourceManager(QObject *parent) : setSystemVariable(QLatin1String("#PAGE_COUNT"),0,SecondPass); m_datasourcesModel.setDataSourceManager(this); } + +QString DataSourceManager::defaultDatabasePath() const +{ + return m_defaultDatabasePath; +} + +void DataSourceManager::setDefaultDatabasePath(const QString &defaultDatabasePath) +{ + m_defaultDatabasePath = defaultDatabasePath; +} bool DataSourceManager::designTime() const { return m_designTime; @@ -364,7 +375,8 @@ QString DataSourceManager::replaceVariables(QString value){ QString var=rx.cap(0); var.remove("$V{"); var.remove("}"); - if (variableNames().contains(var)){ + + if (variable(var).isValid()){ value.replace(pos,rx.cap(0).length(),variable(var).toString()); } else { value.replace(pos,rx.cap(0).length(),QString(tr("Variable \"%1\" not found!").arg(var))); @@ -670,28 +682,11 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) dataSourceHolder(datasourceName)->clearErrors(); } - if (!QSqlDatabase::contains(connectionDesc->name())){ - { - QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name()); - db.setHostName(replaceVariables(connectionDesc->host())); - db.setUserName(replaceVariables(connectionDesc->userName())); - db.setPassword(replaceVariables(connectionDesc->password())); - db.setDatabaseName(replaceVariables(connectionDesc->databaseName())); - connected=db.open(); - if (!connected) lastError=db.lastError().text(); - } - } else { - connected = QSqlDatabase::database(connectionDesc->name()).isOpen(); - } - if (!connected) { - QSqlDatabase::removeDatabase(connectionDesc->name()); - setLastError(lastError); - return false; - } else { + if (QSqlDatabase::contains(connectionDesc->name())){ foreach(QString datasourceName, dataSourceNames()){ if (isQuery(datasourceName)){ QueryHolder* qh = dynamic_cast(dataSourceHolder(datasourceName)); - if (qh){ + if (qh && qh->connectionName().compare(connectionDesc->name())==0){ qh->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE); invalidateChildren(datasourceName); } @@ -705,8 +700,41 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) } } } - if (designTime()) emit datasourcesChanged(); + + QSqlDatabase::removeDatabase(connectionDesc->name()); } + + QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name()); + db.setHostName(replaceVariables(connectionDesc->host())); + db.setUserName(replaceVariables(connectionDesc->userName())); + db.setPassword(replaceVariables(connectionDesc->password())); + QString dbName = replaceVariables(connectionDesc->databaseName()); + if (connectionDesc->driver().compare("QSQLITE")==0){ + if (!defaultDatabasePath().isEmpty()){ + dbName = !QFileInfo(dbName).exists() ? + defaultDatabasePath()+QFileInfo(dbName).fileName() : + dbName; + } + if (QFileInfo(dbName).exists()){ + db.setDatabaseName(dbName); + connected=db.open(); + } else { + lastError = tr("Database \"%1\" not found").arg(dbName); + } + } else { + db.setDatabaseName(dbName); + connected=db.open(); + if (!connected) lastError=db.lastError().text(); + } + + if (designTime()) emit datasourcesChanged(); + + if (!connected) { + QSqlDatabase::removeDatabase(connectionDesc->name()); + setLastError(lastError); + return false; + } + return true; } diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 3e44687..1567ae5 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -189,6 +189,9 @@ public: QSharedPointer previewSQL(const QString& connectionName, const QString& sqlText, QString masterDatasource=""); void updateDatasourceModel(); bool isNeedUpdateDatasourceModel(){ return m_needUpdate;} + QString defaultDatabasePath() const; + void setDefaultDatabasePath(const QString &defaultDatabasePath); + signals: void loadCollectionFinished(const QString& collectionName); void cleared(); @@ -208,7 +211,6 @@ protected: virtual QObject *elementAt(const QString& collectionName,int index); virtual void collectionLoadFinished(const QString& collectionName); - void setSystemVariable(const QString& name, const QVariant& value, RenderPass pass); void setLastError(const QString& value); void invalidateLinkedDatasources(QString datasourceName); @@ -236,6 +238,7 @@ private: QStringList m_errorsList; bool m_designTime; bool m_needUpdate; + QString m_defaultDatabasePath; }; } diff --git a/limereport/lrdatasourcemanagerintf.h b/limereport/lrdatasourcemanagerintf.h index 7ff5aee..85cf388 100644 --- a/limereport/lrdatasourcemanagerintf.h +++ b/limereport/lrdatasourcemanagerintf.h @@ -40,6 +40,7 @@ namespace LimeReport{ class IDataSourceManager{ public: virtual void setReportVariable(const QString& name, const QVariant& value)=0; + virtual void setDefaultDatabasePath(const QString &defaultDatabasePath)=0; virtual void deleteVariable(const QString& name)=0; virtual bool containsVariable(const QString& variableName)=0; virtual QVariant variable(const QString& variableName)=0;