Bug 303228

Summary: KCategorizedView is calling visualRect recursively
Product: [Frameworks and Libraries] kdelibs Reporter: Percy Camilo Triveño Aucahuasi <percy.camilo.ta>
Component: kdeuiAssignee: Rafael Fernández López <ereslibre>
Status: CONFIRMED ---    
Severity: critical CC: faure, kdelibs-bugs, sebastian.gottfried, thomas.luebking
Priority: NOR    
Version: 4.8.4   
Target Milestone: ---   
Platform: Debian unstable   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: sample code of the test case
crash backtrace of the test case

Description Percy Camilo Triveño Aucahuasi 2012-07-09 09:33:56 UTC
Hi there,
I modified the test of kcategorizedview to categorized the items in 2 groups: even/odd number, but kcategorizedview seem calling visualRect recursively ... ¿is this ok? or I'm doing something wrong?


it seems the problem is arround line 25, this is the backtrace:



Reproducible: Always

Steps to Reproduce:
1.copy the paste 
2.build debug mode 

Actual Results:  
visualRect() is calling itself recursively 

Expected Results:  
The view should show the items in two categories: odd and even
Comment 1 Percy Camilo Triveño Aucahuasi 2012-07-12 07:46:31 UTC
Created attachment 72470 [details]
sample code of the test case
Comment 2 Percy Camilo Triveño Aucahuasi 2012-07-12 07:47:03 UTC
Created attachment 72471 [details]
crash backtrace of the test case
Comment 3 Percy Camilo Triveño Aucahuasi 2012-07-12 07:49:40 UTC
Also you can use this use case: Is the same of the kdelibs/kdeui/test but this time we add more items after the view has been setup, please also note the comments about setCategorizedModel; so here is *another use case*:


    #include <QMainWindow>
    #include <QStringListModel>
    #include <kapplication.h>
    #include <kaboutdata.h>
    #include <kcmdlineargs.h>
    #include <kiconloader.h>
    #include <kcategorizedview.h>
    #include <kcategorydrawer.h>
    #include <kcategorizedsortfilterproxymodel.h>
    QStringList icons;
    class MyModel
        : public QStringListModel
        virtual QVariant data(const QModelIndex &index, int role) const
            switch (role) {
                case KCategorizedSortFilterProxyModel::CategoryDisplayRole: {
                        return QString::number(index.row() / 10);
                case KCategorizedSortFilterProxyModel::CategorySortRole: {
                        return index.row() / 10;
                case Qt::DecorationRole:
                    return DesktopIcon(icons[index.row() % 4], KIconLoader::Desktop);
            return QStringListModel::data(index, role);
    int main(int argc, char **argv)
        icons << "konqueror";
        icons << "okular";
        icons << "plasma";
        icons << "system-file-manager";
        KAboutData aboutData("KCategorizedViewTest",
                             ki18n("(c) 2009 Rafael Fernández López"),
        KCmdLineArgs::init(argc, argv, &aboutData);
        KApplication app;
        QMainWindow *mainWindow = new QMainWindow();
        mainWindow->setMinimumSize(640, 480);
        KCategorizedView *listView = new KCategorizedView();
        listView->setCategoryDrawer(new KCategoryDrawer());
        MyModel *model = new MyModel();
        model->insertRows(0, 100);
        for (int i = 0; i < 100; ++i)
            model->setData(model->index(i, 0), QString::number(i), Qt::DisplayRole);
        KCategorizedSortFilterProxyModel *proxyModel = new KCategorizedSortFilterProxyModel();
        //NOTE if you disable temporally the CategorizedModel flag work ok but the scroll bar fails
        //BEGIN HERE
        model->insertRows(0, 100);
        for (int i = 0; i < 100; ++i)
            QModelIndex mi = model->index(0,0);
            model->setData(model->index(i, 0, mi), QString::number(i), Qt::DisplayRole);
        //END HERE
        //NOTE if you reenabled the flag works fien but the scroll bar fails
        return app.exec();

--- UNTIL HERE ---
Comment 4 Thomas Lübking 2012-07-12 19:58:09 UTC
Gave it a short test:
case KCategorizedSortFilterProxyModel::CategorySortRole seems never be queried and the proxymodel most likely runs into a race on the items (ie. with i<2 everything is fine since there're only two non equal items and so is if you pass QString::number(index.role()) as display role.

Don't ask me why, i got the nature of the bug wrong and then looked out of curiosity. I've never touched or seen the kcat'model code. Sorry.