2 * This file is part of the KDE project
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "klistview.h"
22 #include "klistview_p.h"
24 #include <math.h> // trunc on C99 compliant systems
25 #include <kdefakes.h> // trunc for not C99 compliant systems
27 #include <QApplication>
30 #include <QPaintEvent>
35 #include "kitemcategorizer.h"
36 #include "ksortfilterproxymodel.h"
47 inline LessThan(const KSortFilterProxyModel
*proxyModel
,
49 : proxyModel(proxyModel
)
54 inline bool operator()(const QModelIndex
&left
,
55 const QModelIndex
&right
) const
57 if (purpose
== GeneralPurpose
)
59 return proxyModel
->sortOrder() == Qt::AscendingOrder
?
60 proxyModel
->lessThanGeneralPurpose(left
, right
) :
61 !proxyModel
->lessThanGeneralPurpose(left
, right
);
64 return proxyModel
->sortOrder() == Qt::AscendingOrder
?
65 proxyModel
->lessThanCategoryPurpose(left
, right
) :
66 !proxyModel
->lessThanCategoryPurpose(left
, right
);
70 const KSortFilterProxyModel
*proxyModel
;
71 const Purpose purpose
;
75 //==============================================================================
78 KListView::Private::Private(KListView
*listView
)
81 , mouseButtonPressed(false)
83 , lastIndex(QModelIndex())
87 KListView::Private::~Private()
91 const QModelIndexList
&KListView::Private::intersectionSet(const QRect
&rect
)
94 QRect indexVisualRect
;
96 intersectedIndexes
.clear();
98 // Lets find out where we should start
99 int top
= proxyModel
->rowCount() - 1;
101 int middle
= (top
+ bottom
) / 2;
102 while (bottom
<= top
)
104 middle
= (top
+ bottom
) / 2;
106 index
= elementDictionary
[proxyModel
->index(middle
, 0)];
107 indexVisualRect
= visualRect(index
);
109 if (qMax(indexVisualRect
.topLeft().y(),
110 indexVisualRect
.bottomRight().y()) < qMin(rect
.topLeft().y(),
111 rect
.bottomRight().y()))
122 for (int i
= middle
; i
< proxyModel
->rowCount(); i
++)
124 index
= elementDictionary
[proxyModel
->index(i
, 0)];
125 indexVisualRect
= visualRect(index
);
127 if (rect
.intersects(indexVisualRect
))
128 intersectedIndexes
.append(index
);
130 // If we passed next item, stop searching for hits
131 if (qMax(rect
.bottomRight().y(), rect
.topLeft().y()) <
132 indexVisualRect
.topLeft().y())
138 return intersectedIndexes
;
141 QRect
KListView::Private::visualRectInViewport(const QModelIndex
&index
) const
143 if (!index
.isValid())
146 QString curCategory
= elementsInfo
[index
].category
;
148 QRect
retRect(listView
->spacing(), listView
->spacing() * 2 +
149 30 /* categoryHeight */, 0, 0);
151 int viewportWidth
= listView
->viewport()->width() - listView
->spacing();
153 // We really need all items to be of same size. Otherwise we cannot do this
156 // listView->sizeHintForIndex(proxyModel->mapFromSource(index));
157 // int itemHeight = itemSize.height();
158 // int itemWidth = itemSize.width();*/
159 int itemHeight
= 107;
161 int itemWidthPlusSeparation
= listView
->spacing() + itemWidth
;
162 int elementsPerRow
= viewportWidth
/ itemWidthPlusSeparation
;
166 int column
= elementsInfo
[index
].relativeOffsetToCategory
% elementsPerRow
;
167 int row
= elementsInfo
[index
].relativeOffsetToCategory
/ elementsPerRow
;
169 retRect
.setLeft(retRect
.left() + column
* listView
->spacing() +
174 foreach (const QString
&category
, categories
)
176 if (category
== curCategory
)
179 rows
= (float) ((float) categoriesIndexes
[category
].count() /
180 (float) elementsPerRow
);
181 rowsInt
= categoriesIndexes
[category
].count() / elementsPerRow
;
183 if (rows
- trunc(rows
)) rowsInt
++;
185 retRect
.setTop(retRect
.top() +
186 (rowsInt
* listView
->spacing()) +
187 (rowsInt
* itemHeight
) +
188 30 /* categoryHeight */ +
189 listView
->spacing() * 2);
192 retRect
.setTop(retRect
.top() + row
* listView
->spacing() +
195 retRect
.setWidth(itemWidth
);
196 retRect
.setHeight(itemHeight
);
201 QRect
KListView::Private::visualCategoryRectInViewport(const QString
&category
)
204 QRect
retRect(listView
->spacing(),
206 listView
->viewport()->width() - listView
->spacing() * 2,
209 if (!proxyModel
->rowCount() || !categories
.contains(category
))
212 QModelIndex index
= proxyModel
->index(0, 0, QModelIndex());
214 int viewportWidth
= listView
->viewport()->width() - listView
->spacing();
216 // We really need all items to be of same size. Otherwise we cannot do this
218 // QSize itemSize = listView->sizeHintForIndex(index);
219 // int itemHeight = itemSize.height();
220 // int itemWidth = itemSize.width();
221 int itemHeight
= 107;
223 int itemWidthPlusSeparation
= listView
->spacing() + itemWidth
;
224 int elementsPerRow
= viewportWidth
/ itemWidthPlusSeparation
;
231 foreach (const QString
&itCategory
, categories
)
233 if (itCategory
== category
)
236 rows
= (float) ((float) categoriesIndexes
[itCategory
].count() /
237 (float) elementsPerRow
);
238 rowsInt
= categoriesIndexes
[itCategory
].count() / elementsPerRow
;
240 if (rows
- trunc(rows
)) rowsInt
++;
242 retRect
.setTop(retRect
.top() +
243 (rowsInt
* listView
->spacing()) +
244 (rowsInt
* itemHeight
) +
245 30 /* categoryHeight */ +
246 listView
->spacing() * 2);
249 retRect
.setHeight(30 /* categoryHeight */);
254 // We're sure elementsPosition doesn't contain index
255 const QRect
&KListView::Private::cacheIndex(const QModelIndex
&index
)
257 QRect rect
= visualRectInViewport(index
);
258 elementsPosition
[index
] = rect
;
260 return elementsPosition
[index
];
263 // We're sure categoriesPosition doesn't contain category
264 const QRect
&KListView::Private::cacheCategory(const QString
&category
)
266 QRect rect
= visualCategoryRectInViewport(category
);
267 categoriesPosition
[category
] = rect
;
269 return categoriesPosition
[category
];
272 const QRect
&KListView::Private::cachedRectIndex(const QModelIndex
&index
)
274 if (elementsPosition
.contains(index
)) // If we have it cached
276 return elementsPosition
[index
];
278 else // Otherwise, cache it
280 return cacheIndex(index
);
284 const QRect
&KListView::Private::cachedRectCategory(const QString
&category
)
286 if (categoriesPosition
.contains(category
)) // If we have it cached
288 return categoriesPosition
[category
];
290 else // Otherwise, cache it and
292 return cacheCategory(category
);
296 QRect
KListView::Private::visualRect(const QModelIndex
&index
)
298 QModelIndex mappedIndex
= proxyModel
->mapToSource(index
);
300 QRect retRect
= cachedRectIndex(mappedIndex
);
301 int dx
= -listView
->horizontalOffset();
302 int dy
= -listView
->verticalOffset();
303 retRect
.adjust(dx
, dy
, dx
, dy
);
308 QRect
KListView::Private::categoryVisualRect(const QString
&category
)
310 QRect retRect
= cachedRectCategory(category
);
311 int dx
= -listView
->horizontalOffset();
312 int dy
= -listView
->verticalOffset();
313 retRect
.adjust(dx
, dy
, dx
, dy
);
318 void KListView::Private::drawNewCategory(const QString
&category
,
319 const QStyleOption
&option
,
322 QColor color
= option
.palette
.color(QPalette::Text
);
325 painter
->setRenderHint(QPainter::Antialiasing
);
327 QStyleOptionButton opt
;
329 opt
.rect
= option
.rect
;
330 opt
.palette
= option
.palette
;
331 opt
.direction
= option
.direction
;
334 if (option
.rect
.contains(listView
->viewport()->mapFromGlobal(QCursor::pos())) &&
337 const QPalette::ColorGroup group
=
338 option
.state
& QStyle::State_Enabled
?
339 QPalette::Normal
: QPalette::Disabled
;
341 QLinearGradient
gradient(option
.rect
.topLeft(),
342 option
.rect
.bottomRight());
343 gradient
.setColorAt(0,
344 option
.palette
.color(group
,
345 QPalette::Highlight
).light());
346 gradient
.setColorAt(1, Qt::transparent
);
348 painter
->fillRect(option
.rect
, gradient
);
351 /*if (const KStyle *style = dynamic_cast<const KStyle*>(QApplication::style()))
353 style->drawControl(KStyle::CE_Category, &opt, painter, this);
357 QFont painterFont
= painter
->font();
358 painterFont
.setWeight(QFont::Bold
);
359 QFontMetrics
metrics(painterFont
);
360 painter
->setFont(painterFont
);
363 path
.addRect(option
.rect
.left(),
364 option
.rect
.bottom() - 2,
368 QLinearGradient
gradient(option
.rect
.topLeft(),
369 option
.rect
.bottomRight());
370 gradient
.setColorAt(0, color
);
371 gradient
.setColorAt(1, Qt::transparent
);
373 painter
->setBrush(gradient
);
374 painter
->fillPath(path
, gradient
);
376 painter
->setPen(color
);
378 painter
->drawText(option
.rect
, Qt::AlignVCenter
| Qt::AlignLeft
,
379 metrics
.elidedText(category
, Qt::ElideRight
, option
.rect
.width()));
385 void KListView::Private::updateScrollbars()
387 int lastItemBottom
= cachedRectIndex(lastIndex
).bottom() +
388 listView
->spacing() - listView
->viewport()->height();
390 listView
->verticalScrollBar()->setSingleStep(listView
->viewport()->height() / 10);
391 listView
->verticalScrollBar()->setPageStep(listView
->viewport()->height());
392 listView
->verticalScrollBar()->setRange(0, lastItemBottom
);
396 //==============================================================================
399 KListView::KListView(QWidget
*parent
)
401 , d(new Private(this))
405 KListView::~KListView()
410 void KListView::setModel(QAbstractItemModel
*model
)
414 QObject::disconnect(d
->proxyModel
,
415 SIGNAL(rowsRemoved(QModelIndex
,int,int)),
416 this, SLOT(rowsRemoved(QModelIndex
,int,int)));
418 QObject::disconnect(d
->proxyModel
,
419 SIGNAL(sortingRoleChanged()),
420 this, SLOT(slotSortingRoleChanged()));
423 QListView::setModel(model
);
425 d
->proxyModel
= dynamic_cast<KSortFilterProxyModel
*>(model
);
429 QObject::connect(d
->proxyModel
,
430 SIGNAL(rowsRemoved(QModelIndex
,int,int)),
431 this, SLOT(rowsRemoved(QModelIndex
,int,int)));
433 QObject::connect(d
->proxyModel
,
434 SIGNAL(sortingRoleChanged()),
435 this, SLOT(slotSortingRoleChanged()));
439 QRect
KListView::visualRect(const QModelIndex
&index
) const
441 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
444 return QListView::visualRect(index
);
447 if (!qobject_cast
<const QSortFilterProxyModel
*>(index
.model()))
449 return d
->visualRect(d
->proxyModel
->mapFromSource(index
));
452 return d
->visualRect(index
);
455 KItemCategorizer
*KListView::itemCategorizer() const
457 return d
->itemCategorizer
;
460 void KListView::setItemCategorizer(KItemCategorizer
*itemCategorizer
)
462 if (!itemCategorizer
&& d
->proxyModel
)
464 QObject::disconnect(d
->proxyModel
,
465 SIGNAL(rowsRemoved(QModelIndex
,int,int)),
466 this, SLOT(rowsRemoved(QModelIndex
,int,int)));
468 QObject::disconnect(d
->proxyModel
,
469 SIGNAL(sortingRoleChanged()),
470 this, SLOT(slotSortingRoleChanged()));
472 else if (itemCategorizer
&& d
->proxyModel
)
474 QObject::connect(d
->proxyModel
,
475 SIGNAL(rowsRemoved(QModelIndex
,int,int)),
476 this, SLOT(rowsRemoved(QModelIndex
,int,int)));
478 QObject::connect(d
->proxyModel
,
479 SIGNAL(sortingRoleChanged()),
480 this, SLOT(slotSortingRoleChanged()));
483 d
->itemCategorizer
= itemCategorizer
;
487 rowsInserted(QModelIndex(), 0, d
->proxyModel
->rowCount() - 1);
495 QModelIndex
KListView::indexAt(const QPoint
&point
) const
497 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
500 return QListView::indexAt(point
);
505 QModelIndexList item
= d
->intersectionSet(QRect(point
, point
));
507 if (item
.count() == 1)
517 void KListView::reset()
521 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
527 d
->elementsInfo
.clear();
528 d
->elementsPosition
.clear();
529 d
->elementDictionary
.clear();
530 d
->categoriesIndexes
.clear();
531 d
->categoriesPosition
.clear();
532 d
->categories
.clear();
533 d
->intersectedIndexes
.clear();
534 d
->sourceModelIndexList
.clear();
535 d
->hovered
= QModelIndex();
536 d
->mouseButtonPressed
= false;
539 void KListView::paintEvent(QPaintEvent
*event
)
541 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
544 QListView::paintEvent(event
);
548 QStyleOptionViewItemV3 option
= viewOptions();
549 QPainter
painter(viewport());
550 QRect area
= event
->rect();
551 const bool focus
= (hasFocus() || viewport()->hasFocus()) &&
552 currentIndex().isValid();
553 const QStyle::State state
= option
.state
;
554 const bool enabled
= (state
& QStyle::State_Enabled
) != 0;
558 QModelIndexList dirtyIndexes
= d
->intersectionSet(area
);
559 foreach (const QModelIndex
&index
, dirtyIndexes
)
561 option
.state
= state
;
562 option
.rect
= d
->visualRect(index
);
564 if (selectionModel() && selectionModel()->isSelected(index
))
566 option
.state
|= QStyle::State_Selected
;
571 QPalette::ColorGroup cg
;
572 if ((d
->proxyModel
->flags(index
) & Qt::ItemIsEnabled
) == 0)
574 option
.state
&= ~QStyle::State_Enabled
;
575 cg
= QPalette::Disabled
;
579 cg
= QPalette::Normal
;
581 option
.palette
.setCurrentColorGroup(cg
);
584 if (focus
&& currentIndex() == index
)
586 option
.state
|= QStyle::State_HasFocus
;
587 if (this->state() == EditingState
)
588 option
.state
|= QStyle::State_Editing
;
591 if ((index
== d
->hovered
) && !d
->mouseButtonPressed
)
592 option
.state
|= QStyle::State_MouseOver
;
594 option
.state
&= ~QStyle::State_MouseOver
;
596 itemDelegate(index
)->paint(&painter
, option
, index
);
600 QStyleOptionViewItem otherOption
;
601 foreach (const QString
&category
, d
->categories
)
603 otherOption
= option
;
604 otherOption
.rect
= d
->categoryVisualRect(category
);
606 if (otherOption
.rect
.intersects(area
))
608 d
->drawNewCategory(category
, otherOption
, &painter
);
612 if (d
->mouseButtonPressed
)
614 QPoint start
, end
, initialPressPosition
;
616 initialPressPosition
= d
->initialPressPosition
;
618 initialPressPosition
.setY(initialPressPosition
.y() - verticalOffset());
619 initialPressPosition
.setX(initialPressPosition
.x() - horizontalOffset());
621 if (d
->initialPressPosition
.x() > d
->mousePosition
.x() ||
622 d
->initialPressPosition
.y() > d
->mousePosition
.y())
624 start
= d
->mousePosition
;
625 end
= initialPressPosition
;
629 start
= initialPressPosition
;
630 end
= d
->mousePosition
;
633 QStyleOptionRubberBand yetAnotherOption
;
634 yetAnotherOption
.initFrom(this);
635 yetAnotherOption
.shape
= QRubberBand::Rectangle
;
636 yetAnotherOption
.opaque
= false;
637 yetAnotherOption
.rect
= QRect(start
, end
).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
639 style()->drawControl(QStyle::CE_RubberBand
, &yetAnotherOption
, &painter
);
646 void KListView::resizeEvent(QResizeEvent
*event
)
648 QListView::resizeEvent(event
);
650 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
656 // Clear the items positions cache
657 d
->elementsPosition
.clear();
658 d
->categoriesPosition
.clear();
660 d
->updateScrollbars();
663 void KListView::setSelection(const QRect
&rect
,
664 QItemSelectionModel::SelectionFlags flags
)
666 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
669 QListView::setSelection(rect
, flags
);
673 // FIXME: I have to rethink and rewrite this method (ereslibre)
675 QModelIndexList dirtyIndexes
= d
->intersectionSet(rect
);
676 foreach (const QModelIndex
&index
, dirtyIndexes
)
678 if (!d
->mouseButtonPressed
&& rect
.intersects(visualRect(index
)))
680 selectionModel()->select(index
, flags
);
684 selectionModel()->select(index
, QItemSelectionModel::Select
);
686 if (d
->mouseButtonPressed
)
687 d
->tempSelected
.append(index
);
691 if (d
->mouseButtonPressed
)
693 foreach (const QModelIndex
&index
, selectionModel()->selectedIndexes())
695 if (!rect
.intersects(visualRect(index
)))
697 selectionModel()->select(index
, QItemSelectionModel::Deselect
);
699 if (d
->mouseButtonPressed
)
701 d
->tempSelected
.removeAll(index
);
708 void KListView::mouseMoveEvent(QMouseEvent
*event
)
710 QListView::mouseMoveEvent(event
);
712 d
->mousePosition
= event
->pos();
714 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
722 viewport()->update();
725 void KListView::mousePressEvent(QMouseEvent
*event
)
727 QListView::mousePressEvent(event
);
729 d
->tempSelected
.clear();
731 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
739 if (event
->button() == Qt::LeftButton
)
741 d
->mouseButtonPressed
= true;
743 d
->initialPressPosition
= event
->pos();
744 d
->initialPressPosition
.setY(d
->initialPressPosition
.y() +
746 d
->initialPressPosition
.setX(d
->initialPressPosition
.x() +
750 viewport()->update();
753 void KListView::mouseReleaseEvent(QMouseEvent
*event
)
755 QListView::mouseReleaseEvent(event
);
757 d
->mouseButtonPressed
= false;
759 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
767 // FIXME: I have to rethink and rewrite this method (ereslibre)
769 QPoint initialPressPosition
= viewport()->mapFromGlobal(QCursor::pos());
770 initialPressPosition
.setY(initialPressPosition
.y() + verticalOffset());
771 initialPressPosition
.setX(initialPressPosition
.x() + horizontalOffset());
773 if (initialPressPosition
== d
->initialPressPosition
)
775 foreach(const QString
&category
, d
->categories
)
777 if (d
->categoryVisualRect(category
).contains(event
->pos()))
780 QItemSelectionModel::SelectionFlag flag
;
781 foreach (const QModelIndex
&mappedIndex
,
782 d
->categoriesIndexes
[category
])
784 index
= d
->proxyModel
->mapFromSource(mappedIndex
);
786 if (selectionModel()->selectedIndexes().contains(index
))
788 flag
= QItemSelectionModel::Deselect
;
792 flag
= QItemSelectionModel::Select
;
795 selectionModel()->select(index
, flag
);
801 viewport()->update();
804 void KListView::leaveEvent(QEvent
*event
)
806 QListView::leaveEvent(event
);
808 d
->hovered
= QModelIndex();
810 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
818 viewport()->update();
821 void KListView::startDrag(Qt::DropActions supportedActions
)
823 d
->mouseButtonPressed
= false;
825 QListView::startDrag(supportedActions
);
828 void KListView::rowsInserted(const QModelIndex
&parent
,
832 QListView::rowsInserted(parent
, start
, end
);
834 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
840 rowsInsertedArtifficial(parent
, start
, end
);
843 void KListView::rowsInsertedArtifficial(const QModelIndex
&parent
,
847 d
->elementsInfo
.clear();
848 d
->elementsPosition
.clear();
849 d
->elementDictionary
.clear();
850 d
->categoriesIndexes
.clear();
851 d
->categoriesPosition
.clear();
852 d
->categories
.clear();
853 d
->intersectedIndexes
.clear();
854 d
->sourceModelIndexList
.clear();
855 d
->hovered
= QModelIndex();
856 d
->mouseButtonPressed
= false;
858 if (start
> end
|| end
< 0 || start
< 0 || !d
->proxyModel
->rowCount())
863 // Add all elements mapped to the source model
864 for (int k
= 0; k
< d
->proxyModel
->rowCount(); k
++)
866 d
->sourceModelIndexList
<<
867 d
->proxyModel
->mapToSource(d
->proxyModel
->index(k
, 0));
870 // Sort them with the general purpose lessThan method
871 LessThan
generalLessThan(d
->proxyModel
,
872 LessThan::GeneralPurpose
);
874 qStableSort(d
->sourceModelIndexList
.begin(), d
->sourceModelIndexList
.end(),
877 // Explore categories
878 QString prevCategory
=
879 d
->itemCategorizer
->categoryForItem(d
->sourceModelIndexList
[0],
880 d
->proxyModel
->sortRole());
881 QString lastCategory
= prevCategory
;
882 QModelIndexList modelIndexList
;
883 struct Private::ElementInfo elementInfo
;
884 foreach (const QModelIndex
&index
, d
->sourceModelIndexList
)
886 lastCategory
= d
->itemCategorizer
->categoryForItem(index
,
887 d
->proxyModel
->sortRole());
889 elementInfo
.category
= lastCategory
;
891 if (prevCategory
!= lastCategory
)
893 d
->categoriesIndexes
.insert(prevCategory
, modelIndexList
);
894 d
->categories
<< prevCategory
;
895 modelIndexList
.clear();
898 modelIndexList
<< index
;
899 prevCategory
= lastCategory
;
901 d
->elementsInfo
.insert(index
, elementInfo
);
904 d
->categoriesIndexes
.insert(prevCategory
, modelIndexList
);
905 d
->categories
<< prevCategory
;
907 // Sort items locally in their respective categories with the category
909 LessThan
categoryLessThan(d
->proxyModel
,
910 LessThan::CategoryPurpose
);
912 foreach (const QString
&key
, d
->categories
)
914 QModelIndexList
&indexList
= d
->categoriesIndexes
[key
];
916 qStableSort(indexList
.begin(), indexList
.end(), categoryLessThan
);
919 d
->lastIndex
= d
->categoriesIndexes
[d
->categories
[d
->categories
.count() - 1]][d
->categoriesIndexes
[d
->categories
[d
->categories
.count() - 1]].count() - 1];
921 // Finally, fill data information of items situation. This will help when
922 // trying to compute an item place in the viewport
923 int i
= 0; // position relative to the category beginning
924 int j
= 0; // number of elements before current
925 foreach (const QString
&key
, d
->categories
)
927 foreach (const QModelIndex
&index
, d
->categoriesIndexes
[key
])
929 struct Private::ElementInfo
&elementInfo
= d
->elementsInfo
[index
];
931 elementInfo
.relativeOffsetToCategory
= i
;
933 d
->elementDictionary
.insert(d
->proxyModel
->index(j
, 0),
934 d
->proxyModel
->mapFromSource(index
));
943 d
->updateScrollbars();
946 void KListView::rowsRemoved(const QModelIndex
&parent
,
952 // Force the view to update all elements
953 rowsInsertedArtifficial(parent
, start
, end
);
957 void KListView::updateGeometries()
959 if ((viewMode() == KListView::ListMode
) || !d
->proxyModel
||
962 QListView::updateGeometries();
966 // Avoid QListView::updateGeometries(), since it will try to set another
967 // range to our scroll bars, what we don't want (ereslibre)
968 QAbstractItemView::updateGeometries();
971 void KListView::slotSortingRoleChanged()
973 if ((viewMode() == KListView::IconMode
) && d
->proxyModel
&&
976 // Force the view to update all elements
977 rowsInsertedArtifficial(QModelIndex(), 0, d
->proxyModel
->rowCount() - 1);
981 #include "klistview.moc"