[PATCH] Speed up iconView's setIcons 2x...

Koos Vriezen koos.vriezen at xs4all.nl
Wed Aug 28 20:35:14 BST 2002


On Wed, 28 Aug 2002, David Faure wrote:

> Oh, ok, cool. No objections to this patch begin applied then.

Hmmm ... is it mine or your english :)

> > <icons are painted unsorted two times>
>
> > Next timer event for updating (slotUpdate) and sorting occurs
> >   #0  0x40b12695 in QIconView::arrangeItemsInGrid ()
> >   #1  0x40b1a2f0 in QIconView::sort ()
> >   #2  0x40b10b24 in QIconView::slotUpdate ()
> >   #8  0x40c20b29 in QTimer::timeout ()
> >   #9  0x409d4bbf in QTimer::event ()
>
> Well, if the sorting happens after a QTimer, then obviously that's the problem
> (it paints immediately, but sorts after the timer, and repaints then). Sounds like
> a QIconView bug/misbehaving to me... Either it should sort immediately,
> or maybe it could prevent repaints before the sorting has been done.

This is from qt-copy/src/iconview/qiconview.cpp:

/*!
    This slot is used for a slightly-delayed update.

    The icon view is not redrawn immediately after inserting a new item
    but after a very small delay using a QTimer. This means that when
    many items are inserted in a loop the icon view is probably redrawn
    only once at the end of the loop. This makes the insertions both
    flicker-free and faster.
*/

void QIconView::slotUpdate()
{
    d->updateTimer->stop();
    d->fullRedrawTimer->stop();

    if ( !d->firstItem || !d->lastItem )
        return;

    // #### remove that ASA insertInGrid uses cached values and is efficient
    if ( d->resortItemsWhenInsert )
        sort( d->sortDirection );
    .......

/*!
    \overload

    Arranges all the items in the grid given by gridX() and gridY().

    Even if sorting() is enabled, the items are not sorted by this
    function. If you want to sort or rearrange the items, use
    iconview->sort(iconview->sortDirection()).

    If \a update is TRUE (the default), the viewport is repainted as
    well.

    \sa QIconView::setGridX(), QIconView::setGridY(), QIconView::sort()
*/

void QIconView::arrangeItemsInGrid( bool update )

This timer appears to be started in 'QIconView::insertItem'.
So, as Lars said before in this thread, always call arrangeItemsInGrid
with 'false' and do an 'update()'. Maybe a call to 'sort' before 'update'
or call the protected 'slotUpdate' directly?
Anyways, the traces showed the repaints didn't come from the QIconView.
Probably from some parent widget or layout manager. This is really hard to
debug :(.
The problem with 'only repaint when calling from a timer events' is that
in some case you do want to repaint (eg. selectAll). Maybe Qt should sort
icons in drawContents when new icons are added after the last paint, but
... Or we have to live with it.

Koos







More information about the kfm-devel mailing list