mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-26 13:28:09 +03:00
Callback datasource has been fixed
This commit is contained in:
commit
b44077b443
@ -151,6 +151,7 @@ bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager)
|
|||||||
IDataSource* ds = dataManager->dataSource(datasourceName);
|
IDataSource* ds = dataManager->dataSource(datasourceName);
|
||||||
if (ds){
|
if (ds){
|
||||||
if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false;
|
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;
|
return ds->data(m_groupFiledName)!=m_groupFieldValue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,11 +638,22 @@ QVariant MasterDetailProxyModel::masterData(QString fieldName) const
|
|||||||
|
|
||||||
bool CallbackDatasource::next(){
|
bool CallbackDatasource::next(){
|
||||||
if (!m_eof){
|
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++;
|
m_currentRow++;
|
||||||
bool result = false;
|
bool result = true;
|
||||||
|
if (!m_getDataFromCache)
|
||||||
emit changePos(CallbackInfo::Next,result);
|
emit changePos(CallbackInfo::Next,result);
|
||||||
|
m_getDataFromCache = false;
|
||||||
if (m_rowCount != -1){
|
if (m_rowCount != -1){
|
||||||
if (m_rowCount>0 && m_currentRow<m_rowCount){
|
if (m_rowCount > 0 && m_currentRow < m_rowCount){
|
||||||
m_eof = false;
|
m_eof = false;
|
||||||
} else {
|
} else {
|
||||||
m_eof = true;
|
m_eof = true;
|
||||||
@ -655,6 +666,22 @@ bool CallbackDatasource::next(){
|
|||||||
} else return false;
|
} 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(){
|
void CallbackDatasource::first(){
|
||||||
m_currentRow = 0;
|
m_currentRow = 0;
|
||||||
m_eof=checkIfEmpty();
|
m_eof=checkIfEmpty();
|
||||||
@ -674,13 +701,17 @@ void CallbackDatasource::first(){
|
|||||||
QVariant CallbackDatasource::data(const QString& columnName)
|
QVariant CallbackDatasource::data(const QString& columnName)
|
||||||
{
|
{
|
||||||
QVariant result;
|
QVariant result;
|
||||||
if (!eof()) //Don't read past the end
|
if (!eof() && !bof())
|
||||||
{
|
{
|
||||||
|
if (!m_getDataFromCache){
|
||||||
CallbackInfo info;
|
CallbackInfo info;
|
||||||
info.dataType = CallbackInfo::ColumnData;
|
info.dataType = CallbackInfo::ColumnData;
|
||||||
info.columnName = columnName;
|
info.columnName = columnName;
|
||||||
info.index = m_currentRow;
|
info.index = m_currentRow;
|
||||||
emit getCallbackData(info,result);
|
emit getCallbackData(info,result);
|
||||||
|
} else {
|
||||||
|
result = m_valuesCache[columnName];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -744,8 +775,9 @@ int CallbackDatasource::columnIndexByName(QString name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CallbackDatasource::checkNextRecord(int recordNum){
|
bool CallbackDatasource::checkNextRecord(int recordNum){
|
||||||
if (m_rowCount>0 && m_currentRow<m_rowCount){
|
if (bof()) checkIfEmpty();
|
||||||
return true;
|
if (m_rowCount > 0) {
|
||||||
|
return (m_currentRow < (m_rowCount-1));
|
||||||
} else {
|
} else {
|
||||||
QVariant result = false;
|
QVariant result = false;
|
||||||
CallbackInfo info;
|
CallbackInfo info;
|
||||||
@ -765,7 +797,10 @@ bool CallbackDatasource::checkIfEmpty(){
|
|||||||
CallbackInfo info;
|
CallbackInfo info;
|
||||||
info.dataType = CallbackInfo::RowCount;
|
info.dataType = CallbackInfo::RowCount;
|
||||||
emit getCallbackData(info, recordCount);
|
emit getCallbackData(info, recordCount);
|
||||||
if (recordCount.toInt()>0) return false;
|
if (recordCount.toInt()>0) {
|
||||||
|
m_rowCount = recordCount.toInt();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
info.dataType = CallbackInfo::IsEmpty;
|
info.dataType = CallbackInfo::IsEmpty;
|
||||||
emit getCallbackData(info,isEmpty);
|
emit getCallbackData(info,isEmpty);
|
||||||
return isEmpty.toBool();
|
return isEmpty.toBool();
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
virtual bool next() = 0;
|
virtual bool next() = 0;
|
||||||
virtual bool hasNext() = 0;
|
virtual bool hasNext() = 0;
|
||||||
virtual bool prior() = 0;
|
virtual bool prior() = 0;
|
||||||
virtual void undoPrior() = 0;
|
|
||||||
virtual void first() = 0;
|
virtual void first() = 0;
|
||||||
virtual void last() = 0;
|
virtual void last() = 0;
|
||||||
virtual bool bof() = 0;
|
virtual bool bof() = 0;
|
||||||
@ -355,7 +354,6 @@ public:
|
|||||||
bool next();
|
bool next();
|
||||||
bool hasNext();
|
bool hasNext();
|
||||||
bool prior();
|
bool prior();
|
||||||
void undoPrior() {m_curRow++;}
|
|
||||||
void first();
|
void first();
|
||||||
void last();
|
void last();
|
||||||
bool eof();
|
bool eof();
|
||||||
@ -382,11 +380,11 @@ private:
|
|||||||
class CallbackDatasource :public ICallbackDatasource, public IDataSource {
|
class CallbackDatasource :public ICallbackDatasource, public IDataSource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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 next();
|
||||||
bool hasNext(){ if (!m_eof) return checkNextRecord(m_currentRow); else return false;}
|
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;}
|
bool prior();
|
||||||
void undoPrior() {m_currentRow++;}
|
|
||||||
void first();
|
void first();
|
||||||
void last(){}
|
void last(){}
|
||||||
bool bof(){return m_currentRow == -1;}
|
bool bof(){return m_currentRow == -1;}
|
||||||
@ -407,6 +405,8 @@ private:
|
|||||||
bool m_eof;
|
bool m_eof;
|
||||||
int m_columnCount;
|
int m_columnCount;
|
||||||
int m_rowCount;
|
int m_rowCount;
|
||||||
|
QHash<QString, QVariant> m_valuesCache;
|
||||||
|
bool m_getDataFromCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
||||||
|
@ -576,7 +576,10 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
|
|||||||
|
|
||||||
m_reprintableBands.removeOne(dataBand->bandHeader());
|
m_reprintableBands.removeOne(dataBand->bandHeader());
|
||||||
|
|
||||||
|
if (bandDatasource->prior()){
|
||||||
renderGroupFooter(dataBand);
|
renderGroupFooter(dataBand);
|
||||||
|
bandDatasource->next();
|
||||||
|
}
|
||||||
|
|
||||||
if (footer && !footer->printAlways())
|
if (footer && !footer->printAlways())
|
||||||
renderBand(footer, 0, StartNewPageAsNeeded);
|
renderBand(footer, 0, StartNewPageAsNeeded);
|
||||||
@ -706,11 +709,8 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
|
|||||||
renderBand(footer, 0, StartNewPageAsNeeded);
|
renderBand(footer, 0, StartNewPageAsNeeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didGoBack)
|
if (didGoBack){
|
||||||
{
|
dataSource->next();
|
||||||
//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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closeDataGroup(band);
|
closeDataGroup(band);
|
||||||
|
Loading…
Reference in New Issue
Block a user