mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Ensure that KItemListViewLayouter always has a size hint resolver
KItemListViewLayouter uses a KItemListSizeHintResolver to find out how much space the items will need in the view. Before this commit, the size hint resolver object could be changed at runtime, and it could also be null. However, we never made use of these possibilities, so all the code that checks if m_sizeHintResolver is null is actually not needed at all.
This commit is contained in:
parent
edca99745d
commit
cba1533b74
3 changed files with 11 additions and 39 deletions
|
@ -111,8 +111,7 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
|
|||
|
||||
m_sizeHintResolver = new KItemListSizeHintResolver(this);
|
||||
|
||||
m_layouter = new KItemListViewLayouter(this);
|
||||
m_layouter->setSizeHintResolver(m_sizeHintResolver);
|
||||
m_layouter = new KItemListViewLayouter(m_sizeHintResolver, this);
|
||||
|
||||
m_animation = new KItemListViewAnimation(this);
|
||||
connect(m_animation, SIGNAL(finished(QGraphicsWidget*,KItemListViewAnimation::AnimationType)),
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
// #define KITEMLISTVIEWLAYOUTER_DEBUG
|
||||
|
||||
KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
|
||||
KItemListViewLayouter::KItemListViewLayouter(KItemListSizeHintResolver* sizeHintResolver, QObject* parent) :
|
||||
QObject(parent),
|
||||
m_dirty(true),
|
||||
m_visibleIndexesDirty(true),
|
||||
|
@ -36,7 +36,7 @@ KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
|
|||
m_itemMargin(),
|
||||
m_headerHeight(0),
|
||||
m_model(0),
|
||||
m_sizeHintResolver(0),
|
||||
m_sizeHintResolver(sizeHintResolver),
|
||||
m_scrollOffset(0),
|
||||
m_maximumScrollOffset(0),
|
||||
m_itemOffset(0),
|
||||
|
@ -53,6 +53,7 @@ KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
|
|||
m_groupHeaderMargin(0),
|
||||
m_itemInfos()
|
||||
{
|
||||
Q_ASSERT(m_sizeHintResolver);
|
||||
}
|
||||
|
||||
KItemListViewLayouter::~KItemListViewLayouter()
|
||||
|
@ -209,19 +210,6 @@ const KItemModelBase* KItemListViewLayouter::model() const
|
|||
return m_model;
|
||||
}
|
||||
|
||||
void KItemListViewLayouter::setSizeHintResolver(KItemListSizeHintResolver* sizeHintResolver)
|
||||
{
|
||||
if (m_sizeHintResolver != sizeHintResolver) {
|
||||
m_sizeHintResolver = sizeHintResolver;
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
const KItemListSizeHintResolver* KItemListViewLayouter::sizeHintResolver() const
|
||||
{
|
||||
return m_sizeHintResolver;
|
||||
}
|
||||
|
||||
int KItemListViewLayouter::firstVisibleIndex() const
|
||||
{
|
||||
const_cast<KItemListViewLayouter*>(this)->doLayout();
|
||||
|
@ -241,12 +229,7 @@ QRectF KItemListViewLayouter::itemRect(int index) const
|
|||
return QRectF();
|
||||
}
|
||||
|
||||
QSizeF sizeHint;
|
||||
if (m_sizeHintResolver) {
|
||||
sizeHint = m_sizeHintResolver->sizeHint(index);
|
||||
} else {
|
||||
sizeHint = m_itemSize;
|
||||
}
|
||||
QSizeF sizeHint = m_sizeHintResolver->sizeHint(index);
|
||||
|
||||
const qreal x = m_columnOffsets.at(m_itemInfos.at(index).column);
|
||||
const qreal y = m_rowOffsets.at(m_itemInfos.at(index).row);
|
||||
|
@ -299,12 +282,7 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
|
|||
break;
|
||||
}
|
||||
|
||||
qreal itemWidth;
|
||||
if (m_sizeHintResolver) {
|
||||
itemWidth = m_sizeHintResolver->sizeHint(index).width();
|
||||
} else {
|
||||
itemWidth = m_itemSize.width();
|
||||
}
|
||||
const qreal itemWidth = m_sizeHintResolver->sizeHint(index).width();
|
||||
|
||||
if (itemWidth > headerWidth) {
|
||||
headerWidth = itemWidth;
|
||||
|
@ -482,12 +460,10 @@ void KItemListViewLayouter::doLayout()
|
|||
int column = 0;
|
||||
while (index < itemCount && column < m_columnCount) {
|
||||
qreal requiredItemHeight = itemSize.height();
|
||||
if (m_sizeHintResolver) {
|
||||
const QSizeF sizeHint = m_sizeHintResolver->sizeHint(index);
|
||||
const qreal sizeHintHeight = horizontalScrolling ? sizeHint.width() : sizeHint.height();
|
||||
if (sizeHintHeight > requiredItemHeight) {
|
||||
requiredItemHeight = sizeHintHeight;
|
||||
}
|
||||
const QSizeF sizeHint = m_sizeHintResolver->sizeHint(index);
|
||||
const qreal sizeHintHeight = horizontalScrolling ? sizeHint.width() : sizeHint.height();
|
||||
if (sizeHintHeight > requiredItemHeight) {
|
||||
requiredItemHeight = sizeHintHeight;
|
||||
}
|
||||
|
||||
ItemInfo& itemInfo = m_itemInfos[index];
|
||||
|
|
|
@ -50,7 +50,7 @@ class LIBDOLPHINPRIVATE_EXPORT KItemListViewLayouter : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KItemListViewLayouter(QObject* parent = 0);
|
||||
KItemListViewLayouter(KItemListSizeHintResolver* sizeHintResolver, QObject* parent = 0);
|
||||
virtual ~KItemListViewLayouter();
|
||||
|
||||
void setScrollOrientation(Qt::Orientation orientation);
|
||||
|
@ -103,9 +103,6 @@ public:
|
|||
void setModel(const KItemModelBase* model);
|
||||
const KItemModelBase* model() const;
|
||||
|
||||
void setSizeHintResolver(KItemListSizeHintResolver* sizeHintResolver);
|
||||
const KItemListSizeHintResolver* sizeHintResolver() const;
|
||||
|
||||
/**
|
||||
* @return The first (at least partly) visible index. -1 is returned
|
||||
* if the item count is 0.
|
||||
|
|
Loading…
Reference in a new issue