Callback datasource has been fixed

This commit is contained in:
Arin Alexander 2017-06-20 06:00:52 +03:00
commit b44077b443
4 changed files with 59 additions and 23 deletions

View File

@ -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 {

View File

@ -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<m_rowCount){
if (m_rowCount > 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<m_rowCount){
return true;
if (bof()) checkIfEmpty();
if (m_rowCount > 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();

View File

@ -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<QString, QVariant> m_valuesCache;
bool m_getDataFromCache;
};
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{

View File

@ -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);