ItemView: use categorized logging for delegate lifecycle
authorShawn Rutledge <shawn.rutledge@digia.com>
Tue, 12 Aug 2014 11:42:19 +0000 (13:42 +0200)
committerShawn Rutledge <shawn.rutledge@digia.com>
Wed, 13 Aug 2014 08:09:10 +0000 (10:09 +0200)
It becomes configurable at runtime instead of having to uncomment
and recompile.

Change-Id: I2c6f24c89f7e6fe1a9a77b948cdac6f2994680bf
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
src/quick/items/qquickgridview.cpp
src/quick/items/qquickitemview.cpp
src/quick/items/qquickitemview_p.h
src/quick/items/qquicklistview.cpp

index 5b92831..64458c8 100644 (file)
@@ -58,8 +58,6 @@ QT_BEGIN_NAMESPACE
 #define QML_FLICK_SNAPONETHRESHOLD 30
 #endif
 
-//#define DEBUG_DELEGATE_LIFECYCLE
-
 //----------------------------------------------------------------------------
 
 class FxGridItemSG : public FxViewItem
@@ -512,9 +510,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
     bool changed = false;
 
     while (modelIndex < model->count() && rowPos <= fillTo + rowSize()*(columns - colNum)/(columns+1)) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: append item" << modelIndex << colPos << rowPos;
-#endif
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: append item" << modelIndex << colPos << rowPos;
         if (!(item = static_cast<FxGridItemSG*>(createItem(modelIndex, doBuffer))))
             break;
         if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
@@ -549,9 +545,7 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
     // Prepend
     colPos = colNum * colSize();
     while (visibleIndex > 0 && rowPos + rowSize() - 1 >= fillFrom - rowSize()*(colNum+1)/(columns+1)){
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos;
-#endif
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos;
         if (!(item = static_cast<FxGridItemSG*>(createItem(visibleIndex-1, doBuffer))))
             break;
         --visibleIndex;
@@ -580,16 +574,12 @@ bool QQuickGridViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer
                 && item->rowPos()+rowSize()-1 < bufferFrom - rowSize()*(item->colPos()/colSize()+1)/(columns+1)) {
         if (item->attached->delayRemove())
             break;
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos();
-#endif
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos();
         if (item->index != -1)
             visibleIndex++;
         visibleItems.removeFirst();
         if (item->transitionScheduledOrRunning()) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-            qDebug() << "\tnot releasing animating item:" << item->index << item->item->objectName();
-#endif
+            qCDebug(lcItemViewDelegateLifecycle) << "\tnot releasing animating item:" << item->index << item->item->objectName();
             item->releaseAfterTransition = true;
             releasePendingTransition.append(item);
         } else {
@@ -602,14 +592,10 @@ bool QQuickGridViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer
                 && item->rowPos() > bufferTo + rowSize()*(columns - item->colPos()/colSize())/(columns+1)) {
         if (item->attached->delayRemove())
             break;
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1;
-#endif
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: remove last" << visibleIndex+visibleItems.count()-1;
         visibleItems.removeLast();
         if (item->transitionScheduledOrRunning()) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-            qDebug() << "\tnot releasing animating item:" << item->index << item->item->objectName();
-#endif
+            qCDebug(lcItemViewDelegateLifecycle) << "\tnot releasing animating item:" << item->index << item->item->objectName();
             item->releaseAfterTransition = true;
             releasePendingTransition.append(item);
         } else {
index 2a686b4..c53ae9c 100644 (file)
@@ -46,6 +46,8 @@
 
 QT_BEGIN_NAMESPACE
 
+Q_LOGGING_CATEGORY(lcItemViewDelegateLifecycle, "qt.quick.itemview.lifecycle")
+
 // Default cacheBuffer for all views.
 #ifndef QML_VIEW_DEFAULTCACHEBUFFER
 #define QML_VIEW_DEFAULTCACHEBUFFER 320
index 57635d7..cb27e55 100644 (file)
 
 #include "qquickflickable_p.h"
 #include <qpointer.h>
+#include <QtCore/QLoggingCategory>
 
 QT_BEGIN_NAMESPACE
 
+Q_DECLARE_LOGGING_CATEGORY(lcItemViewDelegateLifecycle)
+
 class QQmlChangeSet;
 
 class QQuickItemViewPrivate;
index 1b268ec..b58f440 100644 (file)
@@ -59,8 +59,6 @@ QT_BEGIN_NAMESPACE
 #define QML_FLICK_SNAPONETHRESHOLD 30
 #endif
 
-//#define DEBUG_DELEGATE_LIFECYCLE
-
 class FxListItemSG;
 
 class QQuickListViewPrivate : public QQuickItemViewPrivate
@@ -665,11 +663,9 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
     FxListItemSG *item = 0;
     qreal pos = itemEnd;
     while (modelIndex < model->count() && pos <= fillTo) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: append item" << modelIndex << "pos" << pos << "buffer" << doBuffer;
-#endif
         if (!(item = static_cast<FxListItemSG*>(createItem(modelIndex, doBuffer))))
             break;
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: append item" << modelIndex << "pos" << pos << "buffer" << doBuffer << "item" << item->item->objectName();
         if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
             item->setPosition(pos, true);
         QQuickItemPrivate::get(item->item)->setCulled(doBuffer);
@@ -683,11 +679,9 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
         return changed;
 
     while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > fillFrom) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos << "buffer" << doBuffer;
-#endif
         if (!(item = static_cast<FxListItemSG*>(createItem(visibleIndex-1, doBuffer))))
             break;
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos << "buffer" << doBuffer << "item" << item->item->objectName();
         --visibleIndex;
         visiblePos -= item->size() + spacing;
         if (!transitioner || !transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) // pos will be set by layoutVisibleItems()
@@ -716,18 +710,14 @@ bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer
             break;
 
         if (item->size() > 0) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-            qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition();
-#endif
+            qCDebug(lcItemViewDelegateLifecycle) << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition();
             // remove this item and all zero-sized items before it
             while (item) {
                 if (item->index != -1)
                     visibleIndex++;
                 visibleItems.removeAt(index);
                 if (item->transitionScheduledOrRunning()) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-                    qDebug() << "refill not releasing animating item" << item->index << item->item->objectName();
-#endif
+                    qCDebug(lcItemViewDelegateLifecycle) << "\tnot releasing animating item" << item->index << item->item->objectName();
                     item->releaseAfterTransition = true;
                     releasePendingTransition.append(item);
                 } else {
@@ -746,14 +736,10 @@ bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal buffer
     while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > bufferTo) {
         if (item->attached->delayRemove())
             break;
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-        qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1 << item->position();
-#endif
+        qCDebug(lcItemViewDelegateLifecycle) << "refill: remove last" << visibleIndex+visibleItems.count()-1 << item->position() << item->item->objectName();
         visibleItems.removeLast();
         if (item->transitionScheduledOrRunning()) {
-#ifdef DEBUG_DELEGATE_LIFECYCLE
-            qDebug() << "refill not releasing animating item" << item->index << item->item->objectName();
-#endif
+            qCDebug(lcItemViewDelegateLifecycle) << "\tnot releasing animating item" << item->index << item->item->objectName();
             item->releaseAfterTransition = true;
             releasePendingTransition.append(item);
         } else {