1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #ifndef KITEMLISTVIEW_H
24 #define KITEMLISTVIEW_H
26 #include <libdolphin_export.h>
28 #include <kitemviews/kitemlistgroupheader.h>
29 #include <kitemviews/kitemliststyleoption.h>
30 #include <kitemviews/kitemlistviewanimation_p.h>
31 #include <kitemviews/kitemlistwidget.h>
32 #include <kitemviews/kitemmodelbase.h>
33 #include <QGraphicsWidget>
36 class KItemListController
;
37 class KItemListGroupHeaderCreatorBase
;
38 class KItemListHeader
;
39 class KItemListSizeHintResolver
;
40 class KItemListRubberBand
;
41 class KItemListViewAnimation
;
42 class KItemListViewLayouter
;
43 class KItemListWidget
;
44 class KItemListWidgetCreatorBase
;
45 class KItemListViewCreatorBase
;
49 * @brief Represents the view of an item-list.
51 * The view is responsible for showing the items of the model within
52 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
54 * The created view must be applied to the KItemListController with
55 * KItemListController::setView(). For showing a custom model it is not
56 * mandatory to derive from KItemListView, all that is necessary is
57 * to set a widget-creator that is capable to create KItemListWidgets
58 * showing the model items. A widget-creator can be set with
59 * KItemListView::setWidgetCreator().
61 * @see KItemListWidget
64 class LIBDOLPHINPRIVATE_EXPORT KItemListView
: public QGraphicsWidget
68 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
69 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
72 KItemListView(QGraphicsWidget
* parent
= 0);
73 virtual ~KItemListView();
76 * If the scroll-orientation is vertical, the items are ordered
77 * from top to bottom (= default setting). If the scroll-orientation
78 * is horizontal, the items are ordered from left to right.
80 void setScrollOrientation(Qt::Orientation orientation
);
81 Qt::Orientation
scrollOrientation() const;
83 void setItemSize(const QSizeF
& size
);
84 QSizeF
itemSize() const;
87 * Offset of the scrollbar that represents the scroll-orientation
88 * (see setScrollOrientation()).
90 void setScrollOffset(qreal offset
);
91 qreal
scrollOffset() const;
93 qreal
maximumScrollOffset() const;
96 * Offset related to an item, that does not fit into the available
97 * size of the listview. If the scroll-orientation is vertical
98 * the item-offset describes the offset of the horizontal axe, if
99 * the scroll-orientation is horizontal the item-offset describes
100 * the offset of the vertical axe.
102 void setItemOffset(qreal scrollOffset
);
103 qreal
itemOffset() const;
105 qreal
maximumItemOffset() const;
107 void setVisibleRoles(const QList
<QByteArray
>& roles
);
108 QList
<QByteArray
> visibleRoles() const;
111 * If set to true an automatic scrolling is done as soon as the
112 * mouse is moved near the borders of the view. Per default
113 * the automatic scrolling is turned off.
115 void setAutoScroll(bool enabled
);
116 bool autoScroll() const;
119 * If set to true selection-toggles will be shown when hovering
120 * an item. Per default the selection-toggles are disabled.
122 void setEnabledSelectionToggles(bool enabled
);
123 bool enabledSelectionToggles() const;
126 * @return Controller of the item-list. The controller gets
127 * initialized by KItemListController::setView() and will
128 * result in calling KItemListController::onControllerChanged().
130 KItemListController
* controller() const;
133 * @return Model of the item-list. The model gets
134 * initialized by KItemListController::setModel() and will
135 * result in calling KItemListController::onModelChanged().
137 KItemModelBase
* model() const;
140 * Sets the creator that creates a widget showing the
141 * content of one model-item. Usually it is sufficient
142 * to implement a custom widget X derived from KItemListWidget and
143 * set the creator by:
145 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
147 * Note that the ownership of the widget creator is not transferred to
148 * the item-list view: One instance of a widget creator might get shared
149 * by several item-list view instances.
151 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
152 KItemListWidgetCreatorBase
* widgetCreator() const;
154 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
155 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
157 void setStyleOption(const KItemListStyleOption
& option
);
158 const KItemListStyleOption
& styleOption() const;
161 virtual void setGeometry(const QRectF
& rect
);
164 * @return Index of the item that is below the point \a pos.
165 * The position is relative to the upper right of
166 * the visible area. Only (at least partly) visible
167 * items are considered. -1 is returned if no item is
168 * below the position.
170 int itemAt(const QPointF
& pos
) const;
171 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
172 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
175 * @return Index of the first item that is at least partly visible.
176 * -1 is returned if the model contains no items.
178 int firstVisibleIndex() const;
181 * @return Index of the last item that is at least partly visible.
182 * -1 is returned if the model contains no items.
184 int lastVisibleIndex() const;
187 * @return Required size for the item with the index \p index.
188 * Per default KItemListView::itemSize() is returned.
189 * When reimplementing this method it is recommended to
190 * also reimplement KItemListView::itemSizeHintUpdateRequired().
192 virtual QSizeF
itemSizeHint(int index
) const;
195 * @param itemRanges Items that must be checked for getting the visible roles sizes.
196 * @return The size of each visible role in case if KItemListView::itemSize()
197 * is empty. This allows to have dynamic but equal role sizes between
198 * all items, like used in the classic "table-views". Per default an
199 * empty hash is returned.
201 virtual QHash
<QByteArray
, QSizeF
> visibleRolesSizes(const KItemRangeList
& itemRanges
) const;
204 * If set to true, items having child-items can be expanded to show the child-items as
205 * part of the view. Per default the expanding of items is is disabled. If expanding of
206 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
207 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
208 * must be reimplemented. The view-implementation
209 * has to take care itself how to visually represent the expanded items provided
212 void setSupportsItemExpanding(bool supportsExpanding
);
213 bool supportsItemExpanding() const;
216 * @return The rectangle of the item relative to the top/left of
217 * the currently visible area (see KItemListView::offset()).
219 QRectF
itemRect(int index
) const;
222 * @return The context rectangle of the item relative to the top/left of
223 * the currently visible area (see KItemListView::offset()). The
224 * context rectangle is defined by by the united rectangle of
225 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
226 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
227 * a tooltip or a context-menu for an item. Note that a context rectangle will
228 * only be returned for (at least partly) visible items. An empty rectangle will
229 * be returned for fully invisible items.
231 QRectF
itemContextRect(int index
) const;
234 * Scrolls to the item with the index \a index so that the item
235 * will be fully visible.
237 void scrollToItem(int index
);
240 * If several properties of KItemListView are changed synchronously, it is
241 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
242 * This prevents unnecessary and expensive layout-calculations.
244 void beginTransaction();
247 * Counterpart to beginTransaction(). The layout changes will only be animated if
248 * all property changes between beginTransaction() and endTransaction() support
251 void endTransaction();
253 bool isTransactionActive() const;
256 * Turns on the header if \p show is true. Per default the
257 * header is not shown. Usually the header is turned on when
258 * showing a classic "table-view" to describe the shown columns.
260 void setHeaderShown(bool show
);
261 bool isHeaderShown() const;
264 * @return Pixmap that is used for a drag operation based on the
265 * items given by \a indexes. The default implementation returns
268 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
273 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
276 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
277 void scrollOffsetChanged(qreal current
, qreal previous
);
278 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
279 void itemOffsetChanged(qreal current
, qreal previous
);
280 void maximumItemOffsetChanged(qreal current
, qreal previous
);
281 void scrollTo(qreal newOffset
);
284 * Is emitted if the user has changed the sort order by clicking on a
285 * header item (see KItemListView::setHeaderShown()). The sort order
286 * of the model has already been adjusted to
287 * the current sort order. Note that no signal will be emitted if the
288 * sort order of the model has been changed without user interaction.
290 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
293 * Is emitted if the user has changed the sort role by clicking on a
294 * header item (see KItemListView::setHeaderShown()). The sort role
295 * of the model has already been adjusted to
296 * the current sort role. Note that no signal will be emitted if the
297 * sort role of the model has been changed without user interaction.
299 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
302 * Is emitted if the user has changed the visible roles by moving a header
303 * item (see KItemListView::setHeaderShown()). Note that no signal will be
304 * emitted if the roles have been changed without user interaction by
305 * KItemListView::setVisibleRoles().
307 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
310 virtual void initializeItemListWidget(KItemListWidget
* item
);
313 * @return True if at least one of the changed roles \p changedRoles might result
314 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
315 * Per default true is returned which means on each role-change of existing items
316 * the item-size hints are recalculated. For performance reasons it is recommended
317 * to return false in case if a role-change will not result in a changed
320 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
322 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
323 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
325 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
326 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
327 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
328 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
329 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
330 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
332 virtual void onTransactionBegin();
333 virtual void onTransactionEnd();
335 virtual bool event(QEvent
* event
);
336 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
337 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
338 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
);
339 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
);
340 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
);
341 virtual void dropEvent(QGraphicsSceneDragDropEvent
* event
);
343 QList
<KItemListWidget
*> visibleItemListWidgets() const;
346 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
347 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
348 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
349 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
350 const QSet
<QByteArray
>& roles
);
352 virtual void slotGroupedSortingChanged(bool current
);
353 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
354 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
355 virtual void slotCurrentChanged(int current
, int previous
);
356 virtual void slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
359 void slotAnimationFinished(QGraphicsWidget
* widget
,
360 KItemListViewAnimation::AnimationType type
);
361 void slotLayoutTimerFinished();
363 void slotRubberBandPosChanged();
364 void slotRubberBandActivationChanged(bool active
);
367 * Is invoked if the visible role-width of one role in the header has
368 * been changed by the user. It is remembered that the user has modified
369 * the role-width, so that it won't be changed anymore automatically to
370 * calculate an optimized width.
372 void slotVisibleRoleWidthChanged(const QByteArray
& role
,
374 qreal previousWidth
);
377 * Is invoked if a visible role has been moved by the user. Applies
378 * the moved role to the view.
380 void slotVisibleRoleMoved(const QByteArray
& role
,
385 * Triggers the autoscrolling if autoScroll() is enabled by checking the
386 * current mouse position. If the mouse position is within the autoscroll
387 * margins a timer will be started that periodically triggers the autoscrolling.
389 void triggerAutoScrolling();
392 * Is invoked if the geometry of the parent-widget from a group-header has been
393 * changed. The x-position and width of the group-header gets adjusted to assure
394 * that it always spans the whole width even during temporary transitions of the
397 void slotGeometryOfGroupHeaderParentChanged();
400 enum LayoutAnimationHint
412 void setController(KItemListController
* controller
);
413 void setModel(KItemModelBase
* model
);
415 KItemListRubberBand
* rubberBand() const;
417 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
420 * Helper method for doLayout: Returns a list of items that can be reused for the visible
421 * area. Invisible group headers get recycled. The reusable items are items that are
422 * invisible. If the animation hint is 'Animation' then items that are currently animated
423 * won't be reused. Reusing items is faster in comparison to deleting invisible
424 * items and creating a new instance for visible items.
426 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
427 int lastVisibleIndex
,
428 LayoutAnimationHint hint
);
431 * Helper method for doLayout: Starts a moving-animation for the widget to the given
432 * new position. The moving-animation is only started if the new position is within
433 * the same row or column, otherwise the create-animation is used instead.
434 * @return True if the moving-animation has been applied.
436 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
438 void emitOffsetChanges();
440 KItemListWidget
* createWidget(int index
);
441 void recycleWidget(KItemListWidget
* widget
);
444 * Changes the index of the widget to \a index and assures a consistent
445 * update for m_visibleItems and m_visibleCells. The cell-information
446 * for the new index will not be updated and be initialized as empty cell.
448 void setWidgetIndex(KItemListWidget
* widget
, int index
);
451 * Changes the index of the widget to \a index. In opposite to
452 * setWidgetIndex() the cell-information for the widget gets updated.
453 * This update gives doLayout() the chance to animate the moving
454 * of the item visually (see moveWidget()).
456 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
459 * Helper method for prepareLayoutForIncreasedItemCount().
461 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
464 * Helper method for createWidget() and setWidgetIndex() to update the properties
465 * of the itemlist widget.
467 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
470 * Helper method for updateWidgetPropertes() to create or update
471 * the itemlist group-header.
473 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
476 * Updates the position and size of the group-header that belongs
477 * to the itemlist widget \a widget. The given widget must represent
478 * the first item of a group.
480 void updateGroupHeaderLayout(KItemListWidget
* widget
);
483 * Recycles the group-header from the widget.
485 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
488 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
489 * and slotSortRoleChanged(): Iterates through all visible items and updates
490 * the group-header widgets.
492 void updateVisibleGroupHeaders();
495 * @return Index for the item in the list returned by KItemModelBase::groups()
496 * that represents the group where the item with the index \a index
497 * belongs to. -1 is returned if no groups are available.
499 int groupIndexForItem(int index
) const;
502 * Updates the alternate background for all visible items.
503 * @see updateAlternateBackgroundForWidget()
505 void updateAlternateBackgrounds();
508 * Updates the alternateBackground-property of the widget dependent
509 * on the state of useAlternateBackgrounds() and the grouping state.
511 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
514 * @return True if alternate backgrounds should be used for the items.
515 * This is the case if an empty item-size is given and if there
516 * is more than one visible role.
518 bool useAlternateBackgrounds() const;
521 * @return The widths of each visible role that is shown in the KItemListHeader.
523 QHash
<QByteArray
, qreal
> headerRolesWidths() const;
526 * Updates m_visibleRolesSizes by calling KItemListView::visibleRolesSizes().
527 * Nothing will be done if m_itemRect is not empty or custom header-widths
528 * are used (see m_useHeaderWidths). Also m_strechedVisibleRolesSizes will be adjusted
529 * to respect the available view-size.
531 void updateVisibleRolesSizes(const KItemRangeList
& itemRanges
);
534 * Convenience method for updateVisibleRoleSizes(KItemRangeList() << KItemRange(0, m_model->count()).
536 void updateVisibleRolesSizes();
539 * Updates m_stretchedVisibleRolesSizes based on m_visibleRolesSizes and the available
540 * view-size. Nothing will be done if m_itemRect is not empty or custom header-widths
541 * are used (see m_useHeaderWidths).
543 void updateStretchedVisibleRolesSizes();
546 * @return Sum of the widths of all visible roles.
548 qreal
visibleRolesSizesWidthSum() const;
551 * @return Sum of the heights of all visible roles.
553 qreal
visibleRolesSizesHeightSum() const;
556 * @return Boundaries of the header. An empty rectangle is returned
557 * if no header is shown.
559 QRectF
headerBoundaries() const;
562 * @return True if the number of columns or rows will be changed when applying
563 * the new grid- and item-size. Used to determine whether an animation
564 * should be done when applying the new layout.
566 bool changesItemGridLayout(const QSizeF
& newGridSize
,
567 const QSizeF
& newItemSize
,
568 const QSizeF
& newItemMargin
) const;
571 * @param changedItemCount Number of inserted or removed items.
572 * @return True if the inserting or removing of items should be animated.
573 * No animation should be done if the number of items is too large
574 * to provide a pleasant animation.
576 bool animateChangedItemCount(int changedItemCount
) const;
579 * @return True if a scrollbar for the given scroll-orientation is required
580 * when using a size of \p size for the view. Calling the method is rather
581 * expansive as a temporary relayout needs to be done.
583 bool scrollBarRequired(const QSizeF
& size
) const;
586 * Applies the height of the group header to the layouter. The height
587 * depends on the used scroll orientation.
589 void updateGroupHeaderHeight();
592 * Updates the siblings-information for all visible items that are inside
593 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
594 * is smaller than 0, the siblings-information for all visible items gets
596 * @see KItemListWidget::setSiblingsInformation()
598 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
601 * Helper method for updateExpansionIndicators().
602 * @return True if the item with the index \a index has a sibling successor
603 * (= the item is not the last item of the current hierarchy).
605 bool hasSiblingSuccessor(int index
) const;
608 * Helper function for triggerAutoScrolling().
609 * @param pos Logical position of the mouse relative to the range.
610 * @param range Range of the visible area.
611 * @param oldInc Previous increment. Is used to assure that the increment
612 * increases only gradually.
613 * @return Scroll increment that should be added to the offset().
614 * As soon as \a pos is inside the autoscroll-margin a
615 * value != 0 will be returned.
617 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
620 * Helper functions for changesItemCount().
621 * @return The number of items that fit into the available size by
622 * respecting the size of the item and the margin between the items.
624 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
627 bool m_enabledSelectionToggles
;
629 bool m_supportsItemExpanding
;
630 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
631 LayoutAnimationHint m_endTransactionAnimationHint
;
634 KItemListController
* m_controller
;
635 KItemModelBase
* m_model
;
636 QList
<QByteArray
> m_visibleRoles
;
637 QHash
<QByteArray
, QSizeF
> m_visibleRolesSizes
;
638 QHash
<QByteArray
, QSizeF
> m_stretchedVisibleRolesSizes
;
639 KItemListWidgetCreatorBase
* m_widgetCreator
;
640 KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
641 KItemListStyleOption m_styleOption
;
643 QHash
<int, KItemListWidget
*> m_visibleItems
;
644 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
648 Cell() : column(-1), row(-1) {}
649 Cell(int c
, int r
) : column(c
), row(r
) {}
653 QHash
<int, Cell
> m_visibleCells
;
655 int m_scrollBarExtent
;
656 KItemListSizeHintResolver
* m_sizeHintResolver
;
657 KItemListViewLayouter
* m_layouter
;
658 KItemListViewAnimation
* m_animation
;
660 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
661 qreal m_oldScrollOffset
;
662 qreal m_oldMaximumScrollOffset
;
663 qreal m_oldItemOffset
;
664 qreal m_oldMaximumItemOffset
;
666 bool m_skipAutoScrollForRubberBand
;
667 KItemListRubberBand
* m_rubberBand
;
670 int m_autoScrollIncrement
;
671 QTimer
* m_autoScrollTimer
;
673 KItemListHeader
* m_header
;
674 bool m_useHeaderWidths
;
676 friend class KItemListContainer
; // Accesses scrollBarRequired()
677 friend class KItemListController
;
678 friend class KItemListControllerTest
;
682 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
683 * by recycling existing QGraphicsWidgets instances. Is used by
684 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
687 class LIBDOLPHINPRIVATE_EXPORT KItemListCreatorBase
690 virtual ~KItemListCreatorBase();
693 void addCreatedWidget(QGraphicsWidget
* widget
);
694 void pushRecycleableWidget(QGraphicsWidget
* widget
);
695 QGraphicsWidget
* popRecycleableWidget();
698 QSet
<QGraphicsWidget
*> m_createdWidgets
;
699 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
703 * @brief Base class for creating KItemListWidgets.
705 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
706 * For a custom implementation the methods create() and recyle() must be reimplemented.
707 * The intention of the widget creator is to prevent repetitive and expensive instantiations and
708 * deletions of KItemListWidgets by recycling existing widget instances.
710 class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
713 virtual ~KItemListWidgetCreatorBase();
714 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
715 virtual void recycle(KItemListWidget
* widget
);
719 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
722 virtual ~KItemListWidgetCreator();
723 virtual KItemListWidget
* create(KItemListView
* view
);
727 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
732 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
734 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
736 widget
= new T(view
);
737 addCreatedWidget(widget
);
743 * @brief Base class for creating KItemListGroupHeaders.
745 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
746 * For a custom implementation the methods create() and recyle() must be reimplemented.
747 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
748 * deletions of KItemListGroupHeaders by recycling existing header instances.
750 class LIBDOLPHINPRIVATE_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
753 virtual ~KItemListGroupHeaderCreatorBase();
754 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
755 virtual void recycle(KItemListGroupHeader
* header
);
759 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
762 virtual ~KItemListGroupHeaderCreator();
763 virtual KItemListGroupHeader
* create(KItemListView
* view
);
767 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
772 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
774 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
776 widget
= new T(view
);
777 addCreatedWidget(widget
);