diff --git a/limereport/bands/lrgroupbands.cpp b/limereport/bands/lrgroupbands.cpp index 74b55eb..575760f 100644 --- a/limereport/bands/lrgroupbands.cpp +++ b/limereport/bands/lrgroupbands.cpp @@ -151,6 +151,7 @@ bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager) IDataSource* ds = dataManager->dataSource(datasourceName); if (ds){ if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false; + if (!ds->data(m_groupFiledName).isValid()) return false; return ds->data(m_groupFiledName)!=m_groupFieldValue; } } else { diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index c3e9344..806d12c 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -638,11 +638,22 @@ QVariant MasterDetailProxyModel::masterData(QString fieldName) const bool CallbackDatasource::next(){ if (!m_eof){ + + if (m_currentRow>-1){ + if (!m_getDataFromCache && checkNextRecord(m_currentRow)){ + for (int i = 0; i < m_columnCount; ++i ){ + m_valuesCache[columnNameByIndex(i)] = data(columnNameByIndex(i)); + } + } + + } m_currentRow++; - bool result = false; - emit changePos(CallbackInfo::Next,result); + bool result = true; + if (!m_getDataFromCache) + emit changePos(CallbackInfo::Next,result); + m_getDataFromCache = false; if (m_rowCount != -1){ - if (m_rowCount>0 && m_currentRow 0 && m_currentRow < m_rowCount){ m_eof = false; } else { m_eof = true; @@ -655,6 +666,22 @@ bool CallbackDatasource::next(){ } else return false; } +bool CallbackDatasource::prior(){ + if (m_currentRow !=-1) { + if (!m_getDataFromCache && !m_valuesCache.isEmpty()){ + m_getDataFromCache = true; + if (eof()) m_currentRow--; + m_currentRow--; + m_eof = false; + return true; + } else { + return false; + } + } else { + return false; + } +} + void CallbackDatasource::first(){ m_currentRow = 0; m_eof=checkIfEmpty(); @@ -674,13 +701,17 @@ void CallbackDatasource::first(){ QVariant CallbackDatasource::data(const QString& columnName) { QVariant result; - if (!eof()) //Don't read past the end + if (!eof() && !bof()) { - CallbackInfo info; - info.dataType = CallbackInfo::ColumnData; - info.columnName = columnName; - info.index = m_currentRow; - emit getCallbackData(info,result); + if (!m_getDataFromCache){ + CallbackInfo info; + info.dataType = CallbackInfo::ColumnData; + info.columnName = columnName; + info.index = m_currentRow; + emit getCallbackData(info,result); + } else { + result = m_valuesCache[columnName]; + } } return result; } @@ -744,8 +775,9 @@ int CallbackDatasource::columnIndexByName(QString name) } bool CallbackDatasource::checkNextRecord(int recordNum){ - if (m_rowCount>0 && m_currentRow 0) { + return (m_currentRow < (m_rowCount-1)); } else { QVariant result = false; CallbackInfo info; @@ -765,7 +797,10 @@ bool CallbackDatasource::checkIfEmpty(){ CallbackInfo info; info.dataType = CallbackInfo::RowCount; emit getCallbackData(info, recordCount); - if (recordCount.toInt()>0) return false; + if (recordCount.toInt()>0) { + m_rowCount = recordCount.toInt(); + return false; + } info.dataType = CallbackInfo::IsEmpty; emit getCallbackData(info,isEmpty); return isEmpty.toBool(); diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 8737bb2..e51a3af 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -53,7 +53,6 @@ public: virtual bool next() = 0; virtual bool hasNext() = 0; virtual bool prior() = 0; - virtual void undoPrior() = 0; virtual void first() = 0; virtual void last() = 0; virtual bool bof() = 0; @@ -355,7 +354,6 @@ public: bool next(); bool hasNext(); bool prior(); - void undoPrior() {m_curRow++;} void first(); void last(); bool eof(); @@ -382,11 +380,11 @@ private: class CallbackDatasource :public ICallbackDatasource, public IDataSource { Q_OBJECT public: - CallbackDatasource(): m_currentRow(-1), m_eof(false), m_columnCount(-1), m_rowCount(-1){} + CallbackDatasource(): m_currentRow(-1), m_eof(false), m_columnCount(-1), + m_rowCount(-1), m_getDataFromCache(false){} bool next(); bool hasNext(){ if (!m_eof) return checkNextRecord(m_currentRow); else return false;} - bool prior(){ if (m_currentRow !=-1) {m_currentRow--; return true;} else return false;} - void undoPrior() {m_currentRow++;} + bool prior(); void first(); void last(){} bool bof(){return m_currentRow == -1;} @@ -407,6 +405,8 @@ private: bool m_eof; int m_columnCount; int m_rowCount; + QHash m_valuesCache; + bool m_getDataFromCache; }; class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{ diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 77ebdbd..eb20072 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -576,7 +576,10 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand) m_reprintableBands.removeOne(dataBand->bandHeader()); - renderGroupFooter(dataBand); + if (bandDatasource->prior()){ + renderGroupFooter(dataBand); + bandDatasource->next(); + } if (footer && !footer->printAlways()) renderBand(footer, 0, StartNewPageAsNeeded); @@ -706,11 +709,8 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da renderBand(footer, 0, StartNewPageAsNeeded); } - if (didGoBack) - { - //New Method to undo prior... Alternatively pass in bool isUndoPrior into next() - dataSource->undoPrior(); - //dataSource->next(); //Also emit changePos, which it should not at this point + if (didGoBack){ + dataSource->next(); } } closeDataGroup(band);