diff --git a/include/lrdatasourcemanagerintf.h b/include/lrdatasourcemanagerintf.h index c0b345e..f86e51e 100644 --- a/include/lrdatasourcemanagerintf.h +++ b/include/lrdatasourcemanagerintf.h @@ -31,6 +31,7 @@ #define LRDATASOURCEMANAGERINTF_H #include "lrcallbackdatasourceintf.h" +#include "lrglobal.h" class QVariant; class QString; @@ -56,6 +57,11 @@ public: virtual void clearUserVariables()=0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; + + virtual QStringList variableNames() = 0; + virtual bool variableIsMandatory(const QString& name) = 0; + virtual VariableDataType variableDataType(const QString& name) = 0; + virtual bool variableIsSystem(const QString& name) = 0; }; } diff --git a/include/lrglobal.h b/include/lrglobal.h index a8ed17d..77156d3 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -157,6 +157,17 @@ namespace Const{ typedef QScriptValue ScriptValueType; #endif + class Enums + { + public: + enum VariableDataType {Undefined, String, Bool, Int, Real, Date, Time, DateTime}; + Q_ENUM(VariableDataType) + private: + Enums(){} + Q_GADGET + }; + typedef Enums::VariableDataType VariableDataType; + } // namespace LimeReport Q_DECLARE_OPERATORS_FOR_FLAGS(LimeReport::PreviewHints) diff --git a/limereport/databrowser/lrdatabrowser.cpp b/limereport/databrowser/lrdatabrowser.cpp index 0b4ac5a..79baae0 100644 --- a/limereport/databrowser/lrdatabrowser.cpp +++ b/limereport/databrowser/lrdatabrowser.cpp @@ -237,7 +237,7 @@ void DataBrowser::updateVariablesTree() } } - foreach(QString variableName,m_report->dataManager()->namesOfUserVariables()){ + foreach(QString variableName,m_report->dataManager()->userVariableNames()){ if (!m_report->dataManager()->variableNames().contains(variableName)){ QStringList values; values<dataManager()->variable(variableName).toString()+"]" diff --git a/limereport/databrowser/lrvariabledialog.cpp b/limereport/databrowser/lrvariabledialog.cpp index 4cebd55..d5c34d9 100644 --- a/limereport/databrowser/lrvariabledialog.cpp +++ b/limereport/databrowser/lrvariabledialog.cpp @@ -30,8 +30,10 @@ #include "lrvariabledialog.h" #include "ui_lrvariabledialog.h" #include "lrglobal.h" +#include "lrvariablesholder.h" #include #include +#include LRVariableDialog::LRVariableDialog(QWidget *parent) : QDialog(parent), @@ -42,8 +44,14 @@ LRVariableDialog::LRVariableDialog(QWidget *parent) : m_oldVariableName("") { ui->setupUi(this); - ui->cbbType->setVisible(false); - ui->lblType->setVisible(false); + + static int enumIndex = LimeReport::Enums::staticMetaObject.indexOfEnumerator("VariableDataType"); + QMetaEnum enumerator = LimeReport::Enums::staticMetaObject.enumerator(enumIndex); + for (int i = 0; icbbType->addItem(enumerator.key(i)); + } + //ui->cbbType->setVisible(false); + //ui->lblType->setVisible(false); } LRVariableDialog::~LRVariableDialog() @@ -66,28 +74,40 @@ void LRVariableDialog::setVariableName(const QString &value) void LRVariableDialog::showEvent(QShowEvent *) { ui->leName->setText(m_variableName); - if (!m_variableName.isEmpty()&&m_variablesContainer&&m_variablesContainer->containsVariable(m_variableName)){ + static int enumIndex = LimeReport::Enums::staticMetaObject.indexOfEnumerator("VariableDataType"); + QMetaEnum enumerator = LimeReport::Enums::staticMetaObject.enumerator(enumIndex); + if (!m_variableName.isEmpty()&&m_variablesContainer&&m_variablesContainer->containsVariable(m_variableName)){ ui->leValue->setText(m_variablesContainer->variable(m_variableName).toString()); + ui->cbbType->setCurrentText(enumerator.valueToKey(m_variablesContainer->variableDataType(m_variableName))); + ui->cbbMandatory->setChecked(m_variablesContainer->variableIsMandatory(m_variableName)); } } void LRVariableDialog::accept() { try{ - if (m_variablesContainer&&!ui->leName->text().isEmpty()){ - if (m_changeMode){ - if (m_oldVariableName==ui->leName->text()){ - m_variablesContainer->changeVariable(m_oldVariableName,value()); + static int enumIndex = LimeReport::Enums::staticMetaObject.indexOfEnumerator("VariableDataType"); + QMetaEnum enumerator = LimeReport::Enums::staticMetaObject.enumerator(enumIndex); + + if (m_variablesContainer&&!ui->leName->text().isEmpty()){ + if (m_changeMode){ + if (m_oldVariableName==ui->leName->text()){ + m_variablesContainer->changeVariable(m_oldVariableName,value()); + } else { + m_variablesContainer->deleteVariable(m_oldVariableName); + m_variablesContainer->addVariable(ui->leName->text(),value(), LimeReport::VarDesc::Report); + } } else { - m_variablesContainer->deleteVariable(m_oldVariableName); m_variablesContainer->addVariable(ui->leName->text(),value(), LimeReport::VarDesc::Report); } - } else { - m_variablesContainer->addVariable(ui->leName->text(),value(), LimeReport::VarDesc::Report); + m_variablesContainer->setVarableMandatory(ui->leName->text(),ui->cbbMandatory->isChecked()); + m_variablesContainer->setVariableDataType( + ui->leName->text(), + LimeReport::VariableDataType(enumerator.keysToValue(ui->cbbType->currentText().toLatin1())) + ); + emit signalVariableAccepted(ui->leName->text()); + QDialog::accept(); } - emit signalVariableAccepted(ui->leName->text()); - QDialog::accept(); - } } catch (LimeReport::ReportError &exception){ QMessageBox::critical(this,tr("Attention"),exception.what()); } diff --git a/limereport/databrowser/lrvariabledialog.ui b/limereport/databrowser/lrvariabledialog.ui index df97830..f372c73 100644 --- a/limereport/databrowser/lrvariabledialog.ui +++ b/limereport/databrowser/lrvariabledialog.ui @@ -6,8 +6,8 @@ 0 0 - 218 - 126 + 328 + 173 @@ -18,35 +18,8 @@ :/databrowser/images/value:/databrowser/images/value - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - 7 - - - 5 - - - 4 - - - 8 - + @@ -67,9 +40,6 @@ - - - @@ -77,8 +47,31 @@ + + + + + + + Mandatory + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index f7ba818..0e03986 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -211,7 +211,7 @@ void DataSourceModel::updateModel() } vars = m_rootNode->addChild(tr("External variables"),DataNode::Variables,QIcon(":/report/images/folder")); - foreach (QString name, m_dataManager->namesOfUserVariables()){ + foreach (QString name, m_dataManager->userVariableNames()){ vars->addChild(name,DataNode::Variable,QIcon(":/report/images/value")); } } @@ -1072,7 +1072,7 @@ int DataSourceManager::elementsCount(const QString &collectionName) return m_proxies.count(); } if (collectionName=="variables"){ - return m_reportVariables.userVariablesCount(); + return m_reportVariables.variablesCount(); } return 0; } @@ -1092,7 +1092,7 @@ QObject* DataSourceManager::elementAt(const QString &collectionName, int index) return m_proxies.at(index); } if (collectionName=="variables"){ - return m_reportVariables.userVariableAt(index); + return m_reportVariables.variableAt(index); } return 0; } @@ -1160,6 +1160,8 @@ void DataSourceManager::collectionLoadFinished(const QString &collectionName) foreach (VarDesc* item, m_tempVars) { if (!m_reportVariables.containsVariable(item->name())){ m_reportVariables.addVariable(item->name(),item->value(),VarDesc::Report,FirstPass); + VarDesc* currentVar = m_reportVariables.variableByName(item->name()); + currentVar->initFrom(item); } delete item; } @@ -1454,6 +1456,19 @@ bool DataSourceManager::variableIsSystem(const QString &name) return false; } +bool DataSourceManager::variableIsMandatory(const QString& name) +{ + if (m_reportVariables.containsVariable(name)) + return m_reportVariables.variableByName(name)->isMandatory(); + return false; +} + +void DataSourceManager::setVarableMandatory(const QString& name, bool value) +{ + if (m_reportVariables.containsVariable(name)) + m_reportVariables.variableByName(name)->setMandatory(value); +} + QStringList DataSourceManager::variableNames() { return m_reportVariables.variableNames(); @@ -1470,7 +1485,7 @@ QStringList DataSourceManager::variableNamesByRenderPass(RenderPass pass) return result; } -QStringList DataSourceManager::namesOfUserVariables(){ +QStringList DataSourceManager::userVariableNames(){ return m_userVariables.variableNames(); } @@ -1481,6 +1496,19 @@ VarDesc::VarType DataSourceManager::variableType(const QString &name) return VarDesc::User; } +VariableDataType DataSourceManager::variableDataType(const QString& name) +{ + if (m_reportVariables.containsVariable(name)) + return m_reportVariables.variableByName(name)->dataType(); + return VariableDataType::Undefined; +} + +void DataSourceManager::setVariableDataType(const QString& name, VariableDataType value) +{ + if (m_reportVariables.containsVariable(name)) + m_reportVariables.variableByName(name)->setDataType(value); +} + void DataSourceManager::setAllDatasourcesToFirst() { foreach(IDataSourceHolder* ds,m_datasources.values()) { diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 285a258..628a5f5 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -123,13 +123,17 @@ public: void clearUserVariables(); void addVariable(const QString& name, const QVariant& value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass); void changeVariable(const QString& name,const QVariant& value); - QVariant variable(const QString& variableName); - RenderPass variablePass(const QString& name); + QVariant variable(const QString& variableName); + RenderPass variablePass(const QString& name); QStringList variableNames(); QStringList variableNamesByRenderPass(RenderPass pass); - QStringList namesOfUserVariables(); - VarDesc::VarType variableType(const QString& name); + QStringList userVariableNames(); + VarDesc::VarType variableType(const QString& name); + VariableDataType variableDataType(const QString& name); + void setVariableDataType(const QString &name, VariableDataType value); bool variableIsSystem(const QString& name); + bool variableIsMandatory(const QString& name); + void setVarableMandatory(const QString &name, bool value); QString queryText(const QString& dataSourceName); QString connectionName(const QString& dataSourceName); void removeDatasource(const QString& name); diff --git a/limereport/lrdatasourcemanagerintf.h b/limereport/lrdatasourcemanagerintf.h index c0b345e..f86e51e 100644 --- a/limereport/lrdatasourcemanagerintf.h +++ b/limereport/lrdatasourcemanagerintf.h @@ -31,6 +31,7 @@ #define LRDATASOURCEMANAGERINTF_H #include "lrcallbackdatasourceintf.h" +#include "lrglobal.h" class QVariant; class QString; @@ -56,6 +57,11 @@ public: virtual void clearUserVariables()=0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; + + virtual QStringList variableNames() = 0; + virtual bool variableIsMandatory(const QString& name) = 0; + virtual VariableDataType variableDataType(const QString& name) = 0; + virtual bool variableIsSystem(const QString& name) = 0; }; } diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index a8ed17d..77156d3 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -157,6 +157,17 @@ namespace Const{ typedef QScriptValue ScriptValueType; #endif + class Enums + { + public: + enum VariableDataType {Undefined, String, Bool, Int, Real, Date, Time, DateTime}; + Q_ENUM(VariableDataType) + private: + Enums(){} + Q_GADGET + }; + typedef Enums::VariableDataType VariableDataType; + } // namespace LimeReport Q_DECLARE_OPERATORS_FOR_FLAGS(LimeReport::PreviewHints) diff --git a/limereport/lrvariablesholder.cpp b/limereport/lrvariablesholder.cpp index 9cdf630..c34dc4c 100644 --- a/limereport/lrvariablesholder.cpp +++ b/limereport/lrvariablesholder.cpp @@ -122,16 +122,50 @@ bool VariablesHolder::containsVariable(const QString &name) return m_varNames.contains(name); } -int VariablesHolder::userVariablesCount() +int VariablesHolder::variablesCount() { return m_userVariables.count(); } -VarDesc *VariablesHolder::userVariableAt(int index) +VarDesc* VariablesHolder::variableByName(const QString& name) +{ + if (m_varNames.contains(name)) + return m_varNames.value(name); + else return 0; +} + +VarDesc *VariablesHolder::variableAt(int index) { return m_userVariables.at(index); } +bool VariablesHolder::variableIsMandatory(const QString& name) +{ + if (m_varNames.contains(name)) + return m_varNames.value(name)->isMandatory(); + else return false; +} + +void VariablesHolder::setVarableMandatory(const QString& name, bool value) +{ + if (m_varNames.contains(name)) + m_varNames.value(name)->setMandatory(value); + +} + +VariableDataType VariablesHolder::variableDataType(const QString& name) +{ + if (m_varNames.contains(name)) + return m_varNames.value(name)->dataType(); + else return Enums::Undefined; +} + +void VariablesHolder::setVariableDataType(const QString& name, VariableDataType value) +{ + if (m_varNames.contains(name)) + m_varNames.value(name)->setDataType(value); +} + QStringList VariablesHolder::variableNames() { QStringList result; @@ -148,4 +182,40 @@ RenderPass VariablesHolder::variablePass(const QString &name) else throw ReportError(tr("variable with name ")+name+tr(" does not exists!")); } +bool VarDesc::isMandatory() const +{ + return m_mandatory; +} + +void VarDesc::setMandatory(bool mandatory) +{ + m_mandatory = mandatory; +} + +void VarDesc::initFrom(VarDesc* value) +{ + m_mandatory = value->isMandatory(); + m_dataType = value->dataType(); +} + +VariableDataType VarDesc::dataType() const +{ + return m_dataType; +} + +void VarDesc::setDataType(const VariableDataType& dataType) +{ + m_dataType = dataType; +} + +int VarDesc::readDataTypeProperty() const +{ + return static_cast(m_dataType); +} + +void VarDesc::setDataTypeProperty(int value) +{ + m_dataType = static_cast(value); +} + }// namespace LimeReport diff --git a/limereport/lrvariablesholder.h b/limereport/lrvariablesholder.h index e375ea8..2c3f961 100644 --- a/limereport/lrvariablesholder.h +++ b/limereport/lrvariablesholder.h @@ -42,7 +42,10 @@ class VarDesc : public QObject{ Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QVariant value READ value WRITE setValue) + Q_PROPERTY(bool isMandatory READ isMandatory WRITE setMandatory) + Q_PROPERTY(int dataType READ readDataTypeProperty WRITE setDataTypeProperty) public: + VarDesc() : m_dataType(VariableDataType::Undefined), m_mandatory(false){} enum VarType {System, User, Report}; void setVarType(VarType value){m_varType=value;} VarType varType(){return m_varType;} @@ -52,26 +55,39 @@ public: QString name(){return m_name;} void setValue(QVariant value){m_value=value;} QVariant value(){return m_value;} + VariableDataType dataType() const; + void setDataType(const VariableDataType& dataType); + int readDataTypeProperty() const; + void setDataTypeProperty(int value); + bool isMandatory() const; + void setMandatory(bool isMandatory); + void initFrom(VarDesc* value); private: VarType m_varType; RenderPass m_varPass; QString m_name; QVariant m_value; + VariableDataType m_dataType; + bool m_mandatory; }; class IVariablesContainer { public: virtual ~IVariablesContainer(){} - virtual void addVariable(const QString &name, const QVariant &value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass)=0; - virtual void deleteVariable(const QString &name)=0; - virtual void changeVariable(const QString &name, const QVariant &value)=0; - virtual void clearUserVariables()=0; - virtual QVariant variable(const QString &name)=0; - virtual VarDesc::VarType variableType(const QString &name)=0; - virtual RenderPass variablePass(const QString &name)=0; - virtual bool containsVariable(const QString &name)=0; - virtual QStringList variableNames()=0; + virtual void addVariable(const QString& name, const QVariant &value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass) = 0; + virtual void deleteVariable(const QString& name) = 0; + virtual void changeVariable(const QString& name, const QVariant &value) = 0; + virtual void clearUserVariables() = 0; + virtual QVariant variable(const QString& name) = 0; + virtual VarDesc::VarType variableType(const QString& name) = 0; + virtual RenderPass variablePass(const QString& name) = 0; + virtual bool containsVariable(const QString& name) = 0; + virtual QStringList variableNames() = 0; + virtual bool variableIsMandatory(const QString& name) = 0; + virtual void setVarableMandatory(const QString& name, bool value) = 0; + virtual VariableDataType variableDataType(const QString& name) = 0; + virtual void setVariableDataType(const QString& name, VariableDataType value) = 0; }; class VariablesHolder : public QObject, public IVariablesContainer @@ -85,12 +101,17 @@ public: void changeVariable(const QString &name, const QVariant &value); void clearUserVariables(); QVariant variable(const QString &name); - VarDesc::VarType variableType(const QString &name); - RenderPass variablePass(const QString &name); - bool containsVariable(const QString &name); - QStringList variableNames(); - int userVariablesCount(); - VarDesc* userVariableAt(int index); + VarDesc::VarType variableType(const QString& name); + RenderPass variablePass(const QString &name); + bool containsVariable(const QString &name); + QStringList variableNames(); + int variablesCount(); + VarDesc* variableByName(const QString& name); + VarDesc* variableAt(int index); + bool variableIsMandatory(const QString& name); + void setVarableMandatory(const QString &name, bool value); + VariableDataType variableDataType(const QString& name); + void setVariableDataType(const QString &name, VariableDataType value); signals: void variableHasBeenAdded(const QString& variableName); void variableHasBeenChanged(const QString& variableName);