LimeReport Forum

General Category | Основное => Discussion | Обсуждение => Topic started by: LCoetzer on June 11, 2017, 10:23:27 AM

Title: Problems when using groups with callback data source
Post by: LCoetzer on June 11, 2017, 10:23:27 AM
Hi

Thank you for a great library.

I am using a callback data source and could not get the groups to display correctly.
Only the first group displayed correctly.
For the incorrect groups: (In my test data I actually only had two)
Depending what I did in my code it either didn't display the last line or it used the second line's data for the first line as well or it added the group heading a second time after the group.
I experienced problems using both the changePos slot mechanism as well as using the recordCount method.

In the end, unless I'm doing things wrong, I found some bugs in the library. When I made some small changes in the library, everything worked correctly. (Both methods)

May I please recommend the following changes on v 1.4.12:

void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* dataSource, bool firstTime)
{
    foreach(BandDesignIntf* band,parentBand->childrenByType(BandDesignIntf::GroupHeader)){
        IGroupBand* gb = dynamic_cast<IGroupBand*>(band);
        if (gb&&gb->isNeedToClose(m_datasources)){
            if (band->childBands().count()>0){
//I changed this line
                bool didGoBack = dataSource->prior();
                foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) {
                    foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){
                        renderBand(footer, 0);
                        closeDataGroup(subBand);
                    }
                }

                foreach (BandDesignIntf* footer, band->childrenByType(BandDesignIntf::GroupFooter)) {
                    renderBand(footer, 0, StartNewPageAsNeeded);
                }

//I changed this part
                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
                }
            }
.....


In IDataSource I added this method:
    virtual bool undoPrior() = 0;

In ModelToDataSource I added this method:
    bool undoPrior() {m_curRow++;}

In CallbackDatasource I added this method:
    bool undoPrior() {m_currentRow++;}


and to prevent my datasource to be read beyond it's limits, I made this change:

QVariant CallbackDatasource::data(const QString& columnName)
{
    QVariant result;
    if (!eof())
    {
        CallbackInfo info;
        info.dataType = CallbackInfo::ColumnData;
        info.columnName = columnName;
        info.index = m_currentRow;
        emit getCallbackData(info,result);
    }
    return result;
}


I also noticed that in the implementation of "bool ModelToDataSource::prior()" the variable m_curRow would be decremented twice if eof. That seems wrong but I didn't change it because I'm not using a ModelToDataSource and would not be able to test it properly.

I also attached the source files for diffing.

Thanks and Regards
    Louis Coetzer




Title: Re: Problems when using groups with callback data source
Post by: LCoetzer on June 11, 2017, 11:33:01 AM
Apologies. The undoPrior() function should return void.
Title: Re: Problems when using groups with callback data source
Post by: Arin Alex on June 12, 2017, 01:43:20 PM
Hi!
Thanks for your patch!
I have applied it (ver 1.4.14)
Title: Re: Problems when using groups with callback data source
Post by: LCoetzer on June 13, 2017, 11:32:32 AM
Thanks  :)