Always determine icons for the visible items first

When entering a folder, KFileItemModelRolesUpdater has not yet been
informed about the visible index range by the view when it tries to
determine icons synchronously. This resulted in the problem that it
tried to determine icons for all items in random order, and some visible
icons were somtimes still unknown after the "synchronous icon loading"
timeout of 200 ms.

This commit tries to improve the situation by loading icons starting
with the first item in increasing order. This should make it less likely
that some visible items still have unknown icons after 200 ms.

BUG: 316129
FIXED-IN: 4.10.3
REVIEW: 109843
This commit is contained in:
Frank Reininghaus 2013-04-22 21:21:31 +02:00
parent ee2d453f1f
commit 151c8d8c42
5 changed files with 27 additions and 1 deletions

View file

@ -323,6 +323,7 @@ void KFileItemListView::updateVisibleIndexRange()
const int index = firstVisibleIndex();
const int count = lastVisibleIndex() - index + 1;
m_modelRolesUpdater->setMaximumVisibleItems(maximumVisibleItems());
m_modelRolesUpdater->setVisibleIndexRange(index, count);
if (m_updateIconSizeTimer->isActive()) {

View file

@ -79,6 +79,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
m_iconSize(),
m_firstVisibleIndex(0),
m_lastVisibleIndex(-1),
m_maximumVisibleItems(100),
m_roles(),
m_enabledPlugins(),
m_pendingVisibleItems(),
@ -178,6 +179,11 @@ void KFileItemModelRolesUpdater::setVisibleIndexRange(int index, int count)
}
}
void KFileItemModelRolesUpdater::setMaximumVisibleItems(int count)
{
m_maximumVisibleItems = count;
}
void KFileItemModelRolesUpdater::setPreviewsShown(bool show)
{
if (show == m_previewShown) {
@ -670,7 +676,16 @@ void KFileItemModelRolesUpdater::startUpdating(const KItemRangeList& itemRanges)
const int lastIndex = range.index + range.count - 1;
for (int i = range.index; i <= lastIndex; ++i) {
const KFileItem item = m_model->fileItem(i);
if (!hasValidIndexRange || (i >= m_firstVisibleIndex && i <= m_lastVisibleIndex)) {
bool visible;
if (hasValidIndexRange) {
visible = (i >= m_firstVisibleIndex && i <= m_lastVisibleIndex);
} else {
// If the view has not informed us about the visible range yet,
// just assume that the first items are visible.
visible = (i < m_maximumVisibleItems);
}
if (visible) {
m_pendingVisibleItems.insert(item);
} else {
m_pendingInvisibleItems.insert(item);

View file

@ -77,6 +77,8 @@ public:
*/
void setVisibleIndexRange(int index, int count);
void setMaximumVisibleItems(int count);
/**
* If \a show is set to true, the "iconPixmap" role will be filled with a preview
* of the file. If \a show is false the MIME type icon will be used for the "iconPixmap"
@ -254,6 +256,7 @@ private:
QSize m_iconSize;
int m_firstVisibleIndex;
int m_lastVisibleIndex;
int m_maximumVisibleItems;
QSet<QByteArray> m_roles;
QSet<QByteArray> m_resolvableRoles;
QStringList m_enabledPlugins;

View file

@ -208,6 +208,11 @@ qreal KItemListView::maximumItemOffset() const
return m_layouter->maximumItemOffset();
}
int KItemListView::maximumVisibleItems() const
{
return m_layouter->maximumVisibleItems();
}
void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
{
const QList<QByteArray> previousRoles = m_visibleRoles;

View file

@ -92,6 +92,8 @@ public:
qreal maximumItemOffset() const;
int maximumVisibleItems() const;
void setVisibleRoles(const QList<QByteArray>& roles);
QList<QByteArray> visibleRoles() const;