┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kitemlistview.h
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-03-27 00:44:39 +0200
committerPeter Penz <[email protected]>2012-03-27 00:48:34 +0200
commit793311dac163592a8b63fc4859fdc054d7a22022 (patch)
tree9645cd870530072b23d422d51fd0515f74de6c1f /src/kitemviews/kitemlistview.h
parent8c986e22fd8fa34ea6c29ad2e88e08c2f9b34bf2 (diff)
KItemListView interface and implementation simplification
- Remove KItemListView::preferredRoleColumnWidth() and allow implementing this as part of derived classes from KItemListWidget. Those derived classes are aware about the layout and hence also can provide the preferred role width. - Make KItemListView::itemSizeHint() non-virtual and also allow implementing the size hint as part of derived classes from KItemListWidget.
Diffstat (limited to 'src/kitemviews/kitemlistview.h')
-rw-r--r--src/kitemviews/kitemlistview.h60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index 9c42a6f3e..d65ece8e2 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -186,17 +186,11 @@ public:
/**
* @return Required size for the item with the index \p index.
- * Per default KItemListView::itemSize() is returned.
- * When reimplementing this method it is recommended to
- * also reimplement KItemListView::itemSizeHintUpdateRequired().
+ * The returned value might be larger than KItemListView::itemSize().
+ * In this case the layout grid will be stretched to assure an
+ * unclipped item.
*/
- virtual QSizeF itemSizeHint(int index) const;
-
- /**
- * @return The preferred column-width of the given \a role for the item
- * with the index \a index.
- */
- virtual qreal preferredRoleColumnWidth(const QByteArray& role, int index) const;
+ QSizeF itemSizeHint(int index) const;
/**
* If set to true, items having child-items can be expanded to show the child-items as
@@ -714,24 +708,50 @@ private:
* @brief Base class for creating KItemListWidgets.
*
* It is recommended that applications simply use the KItemListWidgetCreator-template class.
- * For a custom implementation the methods create() and recyle() must be reimplemented.
- * The intention of the widget creator is to prevent repetitive and expensive instantiations and
- * deletions of KItemListWidgets by recycling existing widget instances.
+ * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
+ * must be reimplemented. The intention of the widget creator is to prevent repetitive and
+ * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
+ * instances.
*/
class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase : public KItemListCreatorBase
{
public:
virtual ~KItemListWidgetCreatorBase();
+
virtual KItemListWidget* create(KItemListView* view) = 0;
+
virtual void recycle(KItemListWidget* widget);
+
+ virtual QSizeF itemSizeHint(int index, const KItemListView* view) const = 0;
+
+ virtual qreal preferredRoleColumnWidth(const QByteArray& role,
+ int index,
+ const KItemListView* view) const = 0;
};
+/**
+ * @brief Template class for creating KItemListWidgets.
+ *
+ * The template class must provide the following two static methods:
+ * - QSizeF itemSizeHint(int index, const KItemListView* view)
+ * - preferredRoleColumnWidth(const QByteArray& role, int index, const KItemListView* view)
+ * Those static methods are used as implementation for
+ * KItemListWidgetCreatorBase::itemSizeHint() and
+ * KItemListWidgetCreatorBase::preferedRoleColumnWidth().
+ */
template <class T>
class KItemListWidgetCreator : public KItemListWidgetCreatorBase
{
public:
virtual ~KItemListWidgetCreator();
+
virtual KItemListWidget* create(KItemListView* view);
+
+ virtual QSizeF itemSizeHint(int index, const KItemListView* view) const;
+
+ virtual qreal preferredRoleColumnWidth(const QByteArray& role,
+ int index,
+ const KItemListView* view) const;
};
template <class T>
@@ -750,6 +770,20 @@ KItemListWidget* KItemListWidgetCreator<T>::create(KItemListView* view)
return widget;
}
+template<class T>
+QSizeF KItemListWidgetCreator<T>::itemSizeHint(int index, const KItemListView* view) const
+{
+ return T::itemSizeHint(index, view);
+}
+
+template<class T>
+qreal KItemListWidgetCreator<T>::preferredRoleColumnWidth(const QByteArray& role,
+ int index,
+ const KItemListView* view) const
+{
+ return T::preferredRoleColumnWidth(role, index, view);
+}
+
/**
* @brief Base class for creating KItemListGroupHeaders.
*