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 KItemListHeaderWidget
;
40 class KItemListSizeHintResolver
;
41 class KItemListRubberBand
;
42 class KItemListViewAnimation
;
43 class KItemListViewLayouter
;
44 class KItemListWidget
;
45 class KItemListWidgetCreatorBase
;
46 class KItemListViewCreatorBase
;
50 * @brief Represents the view of an item-list.
52 * The view is responsible for showing the items of the model within
53 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
55 * The created view must be applied to the KItemListController with
56 * KItemListController::setView(). For showing a custom model it is not
57 * mandatory to derive from KItemListView, all that is necessary is
58 * to set a widget-creator that is capable to create KItemListWidgets
59 * showing the model items. A widget-creator can be set with
60 * KItemListView::setWidgetCreator().
62 * @see KItemListWidget
65 class LIBDOLPHINPRIVATE_EXPORT KItemListView
: public QGraphicsWidget
69 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
70 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
73 KItemListView(QGraphicsWidget
* parent
= 0);
74 virtual ~KItemListView();
77 * If the scroll-orientation is vertical, the items are ordered
78 * from top to bottom (= default setting). If the scroll-orientation
79 * is horizontal, the items are ordered from left to right.
81 void setScrollOrientation(Qt::Orientation orientation
);
82 Qt::Orientation
scrollOrientation() const;
84 void setItemSize(const QSizeF
& size
);
85 QSizeF
itemSize() const;
88 * Offset of the scrollbar that represents the scroll-orientation
89 * (see setScrollOrientation()).
91 void setScrollOffset(qreal offset
);
92 qreal
scrollOffset() const;
94 qreal
maximumScrollOffset() const;
97 * Offset related to an item, that does not fit into the available
98 * size of the listview. If the scroll-orientation is vertical
99 * the item-offset describes the offset of the horizontal axe, if
100 * the scroll-orientation is horizontal the item-offset describes
101 * the offset of the vertical axe.
103 void setItemOffset(qreal scrollOffset
);
104 qreal
itemOffset() const;
106 qreal
maximumItemOffset() const;
108 void setVisibleRoles(const QList
<QByteArray
>& roles
);
109 QList
<QByteArray
> visibleRoles() const;
112 * If set to true an automatic scrolling is done as soon as the
113 * mouse is moved near the borders of the view. Per default
114 * the automatic scrolling is turned off.
116 void setAutoScroll(bool enabled
);
117 bool autoScroll() const;
120 * If set to true selection-toggles will be shown when hovering
121 * an item. Per default the selection-toggles are disabled.
123 void setEnabledSelectionToggles(bool enabled
);
124 bool enabledSelectionToggles() const;
127 * @return Controller of the item-list. The controller gets
128 * initialized by KItemListController::setView() and will
129 * result in calling KItemListController::onControllerChanged().
131 KItemListController
* controller() const;
134 * @return Model of the item-list. The model gets
135 * initialized by KItemListController::setModel() and will
136 * result in calling KItemListController::onModelChanged().
138 KItemModelBase
* model() const;
141 * Sets the creator that creates a widget showing the
142 * content of one model-item. Usually it is sufficient
143 * to implement a custom widget X derived from KItemListWidget and
144 * set the creator by:
146 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
148 * Note that the ownership of the widget creator is not transferred to
149 * the item-list view: One instance of a widget creator might get shared
150 * by several item-list view instances.
152 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
153 KItemListWidgetCreatorBase
* widgetCreator() const;
155 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
156 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
158 void setStyleOption(const KItemListStyleOption
& option
);
159 const KItemListStyleOption
& styleOption() const;
162 virtual void setGeometry(const QRectF
& rect
);
165 * @return Index of the item that is below the point \a pos.
166 * The position is relative to the upper right of
167 * the visible area. Only (at least partly) visible
168 * items are considered. -1 is returned if no item is
169 * below the position.
171 int itemAt(const QPointF
& pos
) const;
172 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
173 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
176 * @return Index of the first item that is at least partly visible.
177 * -1 is returned if the model contains no items.
179 int firstVisibleIndex() const;
182 * @return Index of the last item that is at least partly visible.
183 * -1 is returned if the model contains no items.
185 int lastVisibleIndex() const;
188 * @return Required size for the item with the index \p index.
189 * Per default KItemListView::itemSize() is returned.
190 * When reimplementing this method it is recommended to
191 * also reimplement KItemListView::itemSizeHintUpdateRequired().
193 virtual QSizeF
itemSizeHint(int index
) const;
196 * @param itemRanges Items that must be checked for getting the widths of columns.
197 * @return The width of the column of each visible role. The width will
198 * be respected if the width of the item size is <= 0 (see
199 * KItemListView::setItemSize()). Per default an empty hash
202 virtual QHash
<QByteArray
, qreal
> columnWidths(const KItemRangeList
& itemRanges
) const;
205 * If set to true, items having child-items can be expanded to show the child-items as
206 * part of the view. Per default the expanding of items is is disabled. If expanding of
207 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
208 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
209 * must be reimplemented. The view-implementation
210 * has to take care itself how to visually represent the expanded items provided
213 void setSupportsItemExpanding(bool supportsExpanding
);
214 bool supportsItemExpanding() const;
217 * @return The rectangle of the item relative to the top/left of
218 * the currently visible area (see KItemListView::offset()).
220 QRectF
itemRect(int index
) const;
223 * @return The context rectangle of the item relative to the top/left of
224 * the currently visible area (see KItemListView::offset()). The
225 * context rectangle is defined by by the united rectangle of
226 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
227 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
228 * a tooltip or a context-menu for an item. Note that a context rectangle will
229 * only be returned for (at least partly) visible items. An empty rectangle will
230 * be returned for fully invisible items.
232 QRectF
itemContextRect(int index
) const;
235 * Scrolls to the item with the index \a index so that the item
236 * will be fully visible.
238 void scrollToItem(int index
);
241 * If several properties of KItemListView are changed synchronously, it is
242 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
243 * This prevents unnecessary and expensive layout-calculations.
245 void beginTransaction();
248 * Counterpart to beginTransaction(). The layout changes will only be animated if
249 * all property changes between beginTransaction() and endTransaction() support
252 void endTransaction();
254 bool isTransactionActive() const;
257 * Turns on the header if \p visible is true. Per default the
258 * header is not visible. Usually the header is turned on when
259 * showing a classic "table-view" to describe the shown columns.
261 void setHeaderVisible(bool visible
);
262 bool isHeaderVisible() const;
265 * @return Header of the list. The header is also available if it is not shown
266 * (see KItemListView::setHeaderShown()).
268 KItemListHeader
* header() const;
271 * @return Pixmap that is used for a drag operation based on the
272 * items given by \a indexes. The default implementation returns
275 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
280 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
283 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
284 void scrollOffsetChanged(qreal current
, qreal previous
);
285 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
286 void itemOffsetChanged(qreal current
, qreal previous
);
287 void maximumItemOffsetChanged(qreal current
, qreal previous
);
288 void scrollTo(qreal newOffset
);
291 * Is emitted if the user has changed the sort order by clicking on a
292 * header item (see KItemListView::setHeaderShown()). The sort order
293 * of the model has already been adjusted to
294 * the current sort order. Note that no signal will be emitted if the
295 * sort order of the model has been changed without user interaction.
297 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
300 * Is emitted if the user has changed the sort role by clicking on a
301 * header item (see KItemListView::setHeaderShown()). The sort role
302 * of the model has already been adjusted to
303 * the current sort role. Note that no signal will be emitted if the
304 * sort role of the model has been changed without user interaction.
306 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
309 * Is emitted if the user has changed the visible roles by moving a header
310 * item (see KItemListView::setHeaderShown()). Note that no signal will be
311 * emitted if the roles have been changed without user interaction by
312 * KItemListView::setVisibleRoles().
314 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
317 virtual void initializeItemListWidget(KItemListWidget
* item
);
320 * @return True if at least one of the changed roles \p changedRoles might result
321 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
322 * Per default true is returned which means on each role-change of existing items
323 * the item-size hints are recalculated. For performance reasons it is recommended
324 * to return false in case if a role-change will not result in a changed
327 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
329 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
330 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
332 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
333 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
334 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
335 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
336 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
337 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
339 virtual void onTransactionBegin();
340 virtual void onTransactionEnd();
342 virtual bool event(QEvent
* event
);
343 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
344 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
345 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
);
346 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
);
347 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
);
348 virtual void dropEvent(QGraphicsSceneDragDropEvent
* event
);
350 QList
<KItemListWidget
*> visibleItemListWidgets() const;
353 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
354 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
355 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
356 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
357 const QSet
<QByteArray
>& roles
);
359 virtual void slotGroupedSortingChanged(bool current
);
360 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
361 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
362 virtual void slotCurrentChanged(int current
, int previous
);
363 virtual void slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
366 void slotAnimationFinished(QGraphicsWidget
* widget
,
367 KItemListViewAnimation::AnimationType type
);
368 void slotLayoutTimerFinished();
370 void slotRubberBandPosChanged();
371 void slotRubberBandActivationChanged(bool active
);
374 * Is invoked if the column-width of one role in the header has
375 * been changed by the user. It is remembered that the user has modified
376 * the role-width, so that it won't be changed anymore automatically to
377 * calculate an optimized width.
379 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
381 qreal previousWidth
);
384 * Is invoked if a column has been moved by the user. Applies
385 * the moved role to the view.
387 void slotHeaderColumnMoved(const QByteArray
& role
,
392 * Triggers the autoscrolling if autoScroll() is enabled by checking the
393 * current mouse position. If the mouse position is within the autoscroll
394 * margins a timer will be started that periodically triggers the autoscrolling.
396 void triggerAutoScrolling();
399 * Is invoked if the geometry of the parent-widget from a group-header has been
400 * changed. The x-position and width of the group-header gets adjusted to assure
401 * that it always spans the whole width even during temporary transitions of the
404 void slotGeometryOfGroupHeaderParentChanged();
407 enum LayoutAnimationHint
419 void setController(KItemListController
* controller
);
420 void setModel(KItemModelBase
* model
);
422 KItemListRubberBand
* rubberBand() const;
424 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
427 * Helper method for doLayout: Returns a list of items that can be reused for the visible
428 * area. Invisible group headers get recycled. The reusable items are items that are
429 * invisible. If the animation hint is 'Animation' then items that are currently animated
430 * won't be reused. Reusing items is faster in comparison to deleting invisible
431 * items and creating a new instance for visible items.
433 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
434 int lastVisibleIndex
,
435 LayoutAnimationHint hint
);
438 * Helper method for doLayout: Starts a moving-animation for the widget to the given
439 * new position. The moving-animation is only started if the new position is within
440 * the same row or column, otherwise the create-animation is used instead.
441 * @return True if the moving-animation has been applied.
443 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
445 void emitOffsetChanges();
447 KItemListWidget
* createWidget(int index
);
448 void recycleWidget(KItemListWidget
* widget
);
451 * Changes the index of the widget to \a index and assures a consistent
452 * update for m_visibleItems and m_visibleCells. The cell-information
453 * for the new index will not be updated and be initialized as empty cell.
455 void setWidgetIndex(KItemListWidget
* widget
, int index
);
458 * Changes the index of the widget to \a index. In opposite to
459 * setWidgetIndex() the cell-information for the widget gets updated.
460 * This update gives doLayout() the chance to animate the moving
461 * of the item visually (see moveWidget()).
463 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
466 * Helper method for prepareLayoutForIncreasedItemCount().
468 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
471 * Helper method for createWidget() and setWidgetIndex() to update the properties
472 * of the itemlist widget.
474 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
477 * Helper method for updateWidgetPropertes() to create or update
478 * the itemlist group-header.
480 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
483 * Updates the position and size of the group-header that belongs
484 * to the itemlist widget \a widget. The given widget must represent
485 * the first item of a group.
487 void updateGroupHeaderLayout(KItemListWidget
* widget
);
490 * Recycles the group-header from the widget.
492 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
495 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
496 * and slotSortRoleChanged(): Iterates through all visible items and updates
497 * the group-header widgets.
499 void updateVisibleGroupHeaders();
502 * @return Index for the item in the list returned by KItemModelBase::groups()
503 * that represents the group where the item with the index \a index
504 * belongs to. -1 is returned if no groups are available.
506 int groupIndexForItem(int index
) const;
509 * Updates the alternate background for all visible items.
510 * @see updateAlternateBackgroundForWidget()
512 void updateAlternateBackgrounds();
515 * Updates the alternateBackground-property of the widget dependent
516 * on the state of useAlternateBackgrounds() and the grouping state.
518 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
521 * @return True if alternate backgrounds should be used for the items.
522 * This is the case if an empty item-size is given and if there
523 * is more than one visible role.
525 bool useAlternateBackgrounds() const;
527 void applyColumnWidthsFromHeader();
530 * Applies the roles-sizes from m_stretchedVisibleRolesSizes
533 void updateWidgetColumnWidths(KItemListWidget
* widget
);
536 * Updates m_visibleRolesSizes by calling KItemListView::visibleRolesSizes().
537 * Nothing will be done if m_itemRect is not empty or custom header-widths
538 * are used (see m_useHeaderWidths). Also m_strechedVisibleRolesSizes will be adjusted
539 * to respect the available view-size.
541 void updateColumnWidthsCache(const KItemRangeList
& itemRanges
);
544 * Convenience method for updateVisibleRoleSizes(KItemRangeList() << KItemRange(0, m_model->count()).
546 void updateColumnWidthsCache();
549 * Updates the column widhts of the header based on m_columnWidthsCache and the available
552 void updateColumnWidthsForHeader();
555 * @return Sum of the widths of all columns.
557 qreal
columnWidthsSum() const;
560 * @return Boundaries of the header. An empty rectangle is returned
561 * if no header is shown.
563 QRectF
headerBoundaries() const;
566 * @return True if the number of columns or rows will be changed when applying
567 * the new grid- and item-size. Used to determine whether an animation
568 * should be done when applying the new layout.
570 bool changesItemGridLayout(const QSizeF
& newGridSize
,
571 const QSizeF
& newItemSize
,
572 const QSizeF
& newItemMargin
) const;
575 * @param changedItemCount Number of inserted or removed items.
576 * @return True if the inserting or removing of items should be animated.
577 * No animation should be done if the number of items is too large
578 * to provide a pleasant animation.
580 bool animateChangedItemCount(int changedItemCount
) const;
583 * @return True if a scrollbar for the given scroll-orientation is required
584 * when using a size of \p size for the view. Calling the method is rather
585 * expansive as a temporary relayout needs to be done.
587 bool scrollBarRequired(const QSizeF
& size
) const;
590 * Applies the height of the group header to the layouter. The height
591 * depends on the used scroll orientation.
593 void updateGroupHeaderHeight();
596 * Updates the siblings-information for all visible items that are inside
597 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
598 * is smaller than 0, the siblings-information for all visible items gets
600 * @see KItemListWidget::setSiblingsInformation()
602 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
605 * Helper method for updateExpansionIndicators().
606 * @return True if the item with the index \a index has a sibling successor
607 * (= the item is not the last item of the current hierarchy).
609 bool hasSiblingSuccessor(int index
) const;
612 * Helper function for triggerAutoScrolling().
613 * @param pos Logical position of the mouse relative to the range.
614 * @param range Range of the visible area.
615 * @param oldInc Previous increment. Is used to assure that the increment
616 * increases only gradually.
617 * @return Scroll increment that should be added to the offset().
618 * As soon as \a pos is inside the autoscroll-margin a
619 * value != 0 will be returned.
621 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
624 * Helper functions for changesItemCount().
625 * @return The number of items that fit into the available size by
626 * respecting the size of the item and the margin between the items.
628 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
631 bool m_enabledSelectionToggles
;
633 bool m_supportsItemExpanding
;
634 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
635 LayoutAnimationHint m_endTransactionAnimationHint
;
638 KItemListController
* m_controller
;
639 KItemModelBase
* m_model
;
640 QList
<QByteArray
> m_visibleRoles
;
641 KItemListWidgetCreatorBase
* m_widgetCreator
;
642 KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
643 KItemListStyleOption m_styleOption
;
645 QHash
<int, KItemListWidget
*> m_visibleItems
;
646 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
648 QHash
<QByteArray
, qreal
> m_columnWidthsCache
; // Cache for columnWidths() result
652 Cell() : column(-1), row(-1) {}
653 Cell(int c
, int r
) : column(c
), row(r
) {}
657 QHash
<int, Cell
> m_visibleCells
;
659 int m_scrollBarExtent
;
660 KItemListSizeHintResolver
* m_sizeHintResolver
;
661 KItemListViewLayouter
* m_layouter
;
662 KItemListViewAnimation
* m_animation
;
664 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
665 qreal m_oldScrollOffset
;
666 qreal m_oldMaximumScrollOffset
;
667 qreal m_oldItemOffset
;
668 qreal m_oldMaximumItemOffset
;
670 bool m_skipAutoScrollForRubberBand
;
671 KItemListRubberBand
* m_rubberBand
;
674 int m_autoScrollIncrement
;
675 QTimer
* m_autoScrollTimer
;
677 KItemListHeader
* m_header
;
678 KItemListHeaderWidget
* m_headerWidget
;
680 friend class KItemListContainer
; // Accesses scrollBarRequired()
681 friend class KItemListHeader
; // Accesses m_headerWidget
682 friend class KItemListController
;
683 friend class KItemListControllerTest
;
687 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
688 * by recycling existing QGraphicsWidgets instances. Is used by
689 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
692 class LIBDOLPHINPRIVATE_EXPORT KItemListCreatorBase
695 virtual ~KItemListCreatorBase();
698 void addCreatedWidget(QGraphicsWidget
* widget
);
699 void pushRecycleableWidget(QGraphicsWidget
* widget
);
700 QGraphicsWidget
* popRecycleableWidget();
703 QSet
<QGraphicsWidget
*> m_createdWidgets
;
704 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
708 * @brief Base class for creating KItemListWidgets.
710 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
711 * For a custom implementation the methods create() and recyle() must be reimplemented.
712 * The intention of the widget creator is to prevent repetitive and expensive instantiations and
713 * deletions of KItemListWidgets by recycling existing widget instances.
715 class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
718 virtual ~KItemListWidgetCreatorBase();
719 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
720 virtual void recycle(KItemListWidget
* widget
);
724 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
727 virtual ~KItemListWidgetCreator();
728 virtual KItemListWidget
* create(KItemListView
* view
);
732 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
737 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
739 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
741 widget
= new T(view
);
742 addCreatedWidget(widget
);
748 * @brief Base class for creating KItemListGroupHeaders.
750 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
751 * For a custom implementation the methods create() and recyle() must be reimplemented.
752 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
753 * deletions of KItemListGroupHeaders by recycling existing header instances.
755 class LIBDOLPHINPRIVATE_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
758 virtual ~KItemListGroupHeaderCreatorBase();
759 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
760 virtual void recycle(KItemListGroupHeader
* header
);
764 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
767 virtual ~KItemListGroupHeaderCreator();
768 virtual KItemListGroupHeader
* create(KItemListView
* view
);
772 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
777 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
779 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
781 widget
= new T(view
);
782 addCreatedWidget(widget
);