From 9d9f1f4d98631ae56ed57e4a8eebda261c0d5f9e Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sun, 27 Mar 2016 10:40:13 +0300 Subject: [PATCH] Callback interface has been simplified From now on if slot getCallbackData(const LimeReport::CallbackInfo& info, QVariant& data) returns row count then there is no more need to implement second slot changePos(const LimeReport::CallbackInfo::ChangePosType& type, bool& result); --- demo_r1/mainwindow.cpp | 7 ++ include/lrcallbackdatasourceintf.h | 2 +- limereport/lrcallbackdatasourceintf.h | 2 +- limereport/lrdatadesignintf.cpp | 95 ++++++++++++++++++++++----- limereport/lrdatadesignintf.h | 22 ++----- 5 files changed, 92 insertions(+), 36 deletions(-) diff --git a/demo_r1/mainwindow.cpp b/demo_r1/mainwindow.cpp index 2903089..a6a33fb 100644 --- a/demo_r1/mainwindow.cpp +++ b/demo_r1/mainwindow.cpp @@ -91,6 +91,10 @@ MainWindow::MainWindow(QWidget *parent) : stringListModel->setStringList(simpleData); report->dataManager()->addModel("string_list",stringListModel,true); + QStringList strList; + strList<<"value1"<<"value2"; + QScriptValue value = qScriptValueFromSequence(report->scriptManager()->scriptEngine(),strList); + report->scriptManager()->scriptEngine()->globalObject().setProperty("test_list",value); } @@ -152,6 +156,9 @@ void MainWindow::renderFinished() void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data) { switch (info.dataType) { + case LimeReport::CallbackInfo::ColumnCount: + data = ds->record().count(); + break; case LimeReport::CallbackInfo::IsEmpty: data = !ds->first(); break; diff --git a/include/lrcallbackdatasourceintf.h b/include/lrcallbackdatasourceintf.h index 3259f4b..e59c71c 100644 --- a/include/lrcallbackdatasourceintf.h +++ b/include/lrcallbackdatasourceintf.h @@ -4,7 +4,7 @@ namespace LimeReport { struct CallbackInfo{ - enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData}; + enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData, ColumnCount, RowCount}; enum ChangePosType{First, Next}; DataType dataType; int index; diff --git a/limereport/lrcallbackdatasourceintf.h b/limereport/lrcallbackdatasourceintf.h index 3259f4b..e59c71c 100644 --- a/limereport/lrcallbackdatasourceintf.h +++ b/limereport/lrcallbackdatasourceintf.h @@ -4,7 +4,7 @@ namespace LimeReport { struct CallbackInfo{ - enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData}; + enum DataType{IsEmpty, HasNext, ColumnHeaderData, ColumnData, ColumnCount, RowCount}; enum ChangePosType{First, Next}; DataType dataType; int index; diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index e630fd4..332da20 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -594,8 +594,17 @@ bool CallbackDatasource::next(){ m_currentRow++; bool result = false; emit changePos(CallbackInfo::Next,result); - m_eof = !result; // !checkNextRecord(m_currentRow); - return result; + if (m_rowCount != -1){ + if (m_rowCount>0 && m_currentRow0) m_eof = false; + else m_eof = !result; } QVariant CallbackDatasource::data(const QString& columnName) @@ -619,21 +636,40 @@ QVariant CallbackDatasource::data(const QString& columnName) } int CallbackDatasource::columnCount(){ - if (m_headers.size()==0){ - int currIndex = 0; - do { - QVariant columnName; - CallbackInfo info; - info.dataType = CallbackInfo::ColumnHeaderData; - info.index = currIndex; - emit getCallbackData(info,columnName); - if (columnName.isValid()){ - m_headers.append(columnName.toString()); - currIndex++; - } else break; - } while (true); + CallbackInfo info; + if (m_columnCount == -1){ + QVariant columnCount; + info.dataType = CallbackInfo::ColumnCount; + emit getCallbackData(info,columnCount); + if (columnCount.isValid()){ + m_columnCount = columnCount.toInt(); + } + if (m_columnCount != -1){ + for(int i=0;i0) m_columnCount = m_headers.size(); + return m_columnCount; } QString CallbackDatasource::columnNameByIndex(int columnIndex) @@ -658,4 +694,29 @@ int CallbackDatasource::columnIndexByName(QString name) return -1; } +bool CallbackDatasource::checkNextRecord(int recordNum){ + if (m_rowCount>0 && m_currentRow m_headers; int m_currentRow; bool m_eof; + int m_columnCount; + int m_rowCount; }; class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{