on xenial help sign in
Move the code to a function
commite08f5cadf40d29c46198c2e884b12087c942ad79 authorAlbert Astals <albert.astals@canonical.com> dateTue 17 Dec 2013, 10:09 (13 years ago) parentf110847
2 files changed+23−17
plugins/DashViews/verticaljournal.cpp+22−17 plugins/DashViews/verticaljournal.h+1
plugins/DashViews/verticaljournal.cpp+22−17
@@ -444,6 +444,27 @@ void VerticalJournal::releaseItem(const ViewItem &item)
444444 }
445445}
446446
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+
447468#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
448469void VerticalJournal::itemCreated(int modelIndex, QQuickItem *item)
449470{
@@ -521,23 +542,7 @@ void VerticalJournal::updatePolish()
521542 }
522543
523544 if (m_implicitHeightDirty) {
524− m_implicitHeightDirty = false;
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− }
545+ calculateImplicitHeight();
541546 }
542547}
543548
plugins/DashViews/verticaljournal.h+1
@@ -154,6 +154,7 @@ private:
154154 void positionItem(int modelIndex, QQuickItem *item);
155155 void cleanupExistingItems();
156156 void releaseItem(const ViewItem &item);
157+ void calculateImplicitHeight();
157158
158159#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
159160 QQuickVisualDataModel *m_delegateModel;