From 3bd49b6ffd82224dea060cefc7e9ccaa543c98da Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Tue, 19 Feb 2019 02:43:16 +0300 Subject: [PATCH] getFieldByRowIndex() has been added --- include/lrdatasourceintf.h | 1 + limereport/lrdatadesignintf.cpp | 22 ++++++++++++++++++++++ limereport/lrdatadesignintf.h | 2 ++ limereport/lrdatasourceintf.h | 1 + limereport/lrdatasourcemanager.cpp | 11 +++++++++++ limereport/lrdatasourcemanager.h | 1 + 6 files changed, 38 insertions(+) diff --git a/include/lrdatasourceintf.h b/include/lrdatasourceintf.h index c2a6c90..26f7a65 100644 --- a/include/lrdatasourceintf.h +++ b/include/lrdatasourceintf.h @@ -17,6 +17,7 @@ public: virtual bool bof() = 0; virtual bool eof() = 0; virtual QVariant data(const QString& columnName) = 0; + virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0; virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; virtual int columnCount() = 0; virtual QString columnNameByIndex(int columnIndex) = 0; diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index 23b1e76..9fae29e 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -258,6 +258,13 @@ QVariant ModelToDataSource::data(const QString &columnName) return m_model->data(m_model->index(currentRow(),columnIndexByName(columnName))); } +QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex) +{ + if (m_model->rowCount() > rowIndex) + return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName))); + return QVariant(); +} + QVariant ModelToDataSource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) { for( int i=0; i < m_model->rowCount(); ++i ){ @@ -693,6 +700,21 @@ QVariant CallbackDatasource::data(const QString& columnName) return result; } +QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex) +{ + int backupCurrentRow = m_currentRow; + QVariant result = QVariant(); + first(); + for (int i = 0; i < rowIndex && !eof(); ++i, next()){} + if (!eof()) result = callbackData(columnName, rowIndex); + first(); + if (backupCurrentRow != -1){ + for (int i = 0; i < backupCurrentRow; ++i) + next(); + } + return result; +} + QVariant CallbackDatasource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) { int backupCurrentRow = m_currentRow; diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 06edc3d..a05c81e 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -328,6 +328,7 @@ public: bool eof(); bool bof(); QVariant data(const QString& columnName); + QVariant dataByRowIndex(const QString &columnName, int rowIndex); QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData); int columnCount(); QString columnNameByIndex(int columnIndex); @@ -360,6 +361,7 @@ public: bool bof(){return m_currentRow == -1;} bool eof(){return m_eof;} QVariant data(const QString &columnName); + QVariant dataByRowIndex(const QString& columnName, int rowIndex); QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData); int columnCount(); QString columnNameByIndex(int columnIndex); diff --git a/limereport/lrdatasourceintf.h b/limereport/lrdatasourceintf.h index c2a6c90..26f7a65 100644 --- a/limereport/lrdatasourceintf.h +++ b/limereport/lrdatasourceintf.h @@ -17,6 +17,7 @@ public: virtual bool bof() = 0; virtual bool eof() = 0; virtual QVariant data(const QString& columnName) = 0; + virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0; virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; virtual int columnCount() = 0; virtual QString columnNameByIndex(int columnIndex) = 0; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 6e2babc..4f9b147 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -1469,6 +1469,17 @@ QVariant DataSourceManager::fieldData(const QString &fieldName) return QVariant(); } +QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex) +{ + if (containsField(fieldName)){ + IDataSource* ds = dataSource(extractDataSource(fieldName)); + if (ds){ + return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex); + } + } + return QVariant(); +} + QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue) { IDataSource* ds = dataSource(datasourceName); diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 6dd6518..001e09e 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -167,6 +167,7 @@ public: QStringList fieldNames(const QString& datasourceName); bool containsField(const QString& fieldName); QVariant fieldData(const QString& fieldName); + QVariant fieldDataByRowIndex(const QString& fieldName, int rowIndex); QVariant fieldDataByKey( const QString& datasourceName, const QString& valueFieldName,