on xenial help sign in
Move the code to a function
e08f5caAlbert Astals
plugins/DashViews/verticaljournal.cpp+22−17
@@ -444,6 +444,27 @@ void VerticalJournal::releaseItem(const ViewItem &item)
444 }
444 }
445}
445}
446
446
447+void VerticalJournal::calculateImplicitHeight()
448+{
449+ m_implicitHeightDirty = false;
450+
451+ int lastModelIndex = -1;
452+ qreal bottomMostY = 0;
453+ Q_FOREACH(const auto &column, m_columnVisibleItems) {
454+ if (!column.isEmpty()) {
455+ const ViewItem &item = column.last();
456+ lastModelIndex = qMax(lastModelIndex, item.m_modelIndex);
457+ bottomMostY = qMax(bottomMostY, item.y() + item.height() + m_verticalSpacing);
458+ }
459+ }
460+ if (lastModelIndex >= 0) {
461+ const double averageHeight = bottomMostY / (lastModelIndex + 1);
462+ setImplicitHeight(bottomMostY + averageHeight * (model()->rowCount() - lastModelIndex - 1));
463+ } else {
464+ setImplicitHeight(0);
465+ }
466+}
467+
447#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
468#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
448void VerticalJournal::itemCreated(int modelIndex, QQuickItem *item)
469void VerticalJournal::itemCreated(int modelIndex, QQuickItem *item)
449{
470{
@@ -521,23 +542,7 @@ void VerticalJournal::updatePolish()
521 }
542 }
522
543
523 if (m_implicitHeightDirty) {
544 if (m_implicitHeightDirty) {
524− m_implicitHeightDirty = false;
545+ calculateImplicitHeight();
525−
526− int lastModelIndex = -1;
527− qreal bottomMostY = 0;
528− Q_FOREACH(const auto &column, m_columnVisibleItems) {
529− if (!column.isEmpty()) {
530− const ViewItem &item = column.last();
531− lastModelIndex = qMax(lastModelIndex, item.m_modelIndex);
532− bottomMostY = qMax(bottomMostY, item.y() + item.height() + m_verticalSpacing);
533− }
534− }
535− if (lastModelIndex >= 0) {
536− const double averageHeight = bottomMostY / (lastModelIndex + 1);
537− setImplicitHeight(bottomMostY + averageHeight * (model()->rowCount() - lastModelIndex - 1));
538− } else {
539− setImplicitHeight(0);
540− }
541 }
546 }
542}
547}
543
548
plugins/DashViews/verticaljournal.h+1
@@ -154,6 +154,7 @@ private:
154 void positionItem(int modelIndex, QQuickItem *item);
154 void positionItem(int modelIndex, QQuickItem *item);
155 void cleanupExistingItems();
155 void cleanupExistingItems();
156 void releaseItem(const ViewItem &item);
156 void releaseItem(const ViewItem &item);
157+ void calculateImplicitHeight();
157
158
158#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
159#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
159 QQuickVisualDataModel *m_delegateModel;
160 QQuickVisualDataModel *m_delegateModel;