From 7e8d529d1542b3c581cff27641ba7b37b40ca161 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 16 Dec 2009 17:34:38 +1000 Subject: Allow a ListView.section.delegate to avoid creating sections in delegate. --- examples/declarative/listview/sections.qml | 25 +++---- .../graphicsitems/qmlgraphicslistview.cpp | 84 ++++++++++++++++++---- .../graphicsitems/qmlgraphicslistview_p.h | 8 ++- 3 files changed, 88 insertions(+), 29 deletions(-) diff --git a/examples/declarative/listview/sections.qml b/examples/declarative/listview/sections.qml index b51cf58..6e72ce7 100644 --- a/examples/declarative/listview/sections.qml +++ b/examples/declarative/listview/sections.qml @@ -17,25 +17,11 @@ Rectangle { id: wrapper width: 200 // My height is the combined height of the description and the section separator - height: separator.height + desc.height - Rectangle { - id: separator - color: "lightsteelblue" - width: parent.width - // Only show the section separator when we are the beginning of a new section - // Note that for this to work nicely, the list must be ordered by section. - height: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 - opacity: wrapper.ListView.prevSection != wrapper.ListView.section ? 1 : 0 - Text { - text: wrapper.ListView.section; font.bold: true - x: 2; height: parent.height; verticalAlignment: 'AlignVCenter' - } - } + height: desc.height Item { id: desc x: 5 height: layout.height + 4 - anchors.top: separator.bottom Column { id: layout y: 2 @@ -66,6 +52,15 @@ Rectangle { // We use this to determine which section we are in above. section.property: "size" section.criteria: ViewSection.FullString + section.delegate: Rectangle { + color: "lightsteelblue" + width: 200 + height: 20 + Text { + text: section; font.bold: true + x: 2; height: parent.height; verticalAlignment: 'AlignVCenter' + } + } focus: true } } diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index bf734b8..77761ac 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -68,6 +68,14 @@ void QmlGraphicsViewSection::setCriteria(QmlGraphicsViewSection::SectionCriteria } } +void QmlGraphicsViewSection::setDelegate(QmlComponent *delegate) +{ + if (delegate != m_delegate) { + m_delegate = delegate; + emit delegateChanged(); + } +} + QString QmlGraphicsViewSection::sectionString(const QString &value) { if (m_criteria == FirstCharacter) @@ -162,14 +170,23 @@ QHash QmlGraphicsListViewAttached::attac class FxListItem { public: - FxListItem(QmlGraphicsItem *i, QmlGraphicsListView *v) : item(i), view(v) { + FxListItem(QmlGraphicsItem *i, QmlGraphicsListView *v) : item(i), section(0), view(v) { attached = QmlGraphicsListViewAttached::properties(item); attached->m_view = view; } ~FxListItem() {} - - qreal position() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() : item->x()); } - int size() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->height() : item->width()); } + qreal position() const { + if (section) + return (view->orientation() == QmlGraphicsListView::Vertical ? section->y() : section->x()); + else + return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() : item->x()); + } + int size() const { + if (section) + return (view->orientation() == QmlGraphicsListView::Vertical ? item->height()+section->height() : item->width()+section->height()); + else + return (view->orientation() == QmlGraphicsListView::Vertical ? item->height() : item->width()); + } qreal endPosition() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() + (item->height() > 0 ? item->height() : 1) @@ -177,13 +194,22 @@ public: } void setPosition(qreal pos) { if (view->orientation() == QmlGraphicsListView::Vertical) { + if (section) { + section->setY(pos); + pos += section->height(); + } item->setY(pos); } else { + if (section) { + section->setX(pos); + pos += section->width(); + } item->setX(pos); } } QmlGraphicsItem *item; + QmlGraphicsItem *section; QmlGraphicsListView *view; QmlGraphicsListViewAttached *attached; int index; @@ -467,6 +493,7 @@ public: void updateTrackedItem(); void createHighlight(); void updateHighlight(); + void createSection(FxListItem *); void updateSections(); void updateCurrentSection(); void updateCurrent(int); @@ -573,6 +600,11 @@ FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) listItem->item->setParent(q->viewport()); QmlGraphicsItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addGeometryListener(this); + if (sectionCriteria && sectionCriteria->delegate()) { + qDebug() << "have delegate"; + if (listItem->attached->m_prevSection != listItem->attached->m_section) + createSection(listItem); + } } requestedIndex = -1; @@ -597,6 +629,8 @@ void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); } + if (item->section) + delete item->section; delete item; } @@ -693,6 +727,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to, bool doBuffer) void QmlGraphicsListViewPrivate::layout() { Q_Q(QmlGraphicsListView); + updateSections(); if (!visibleItems.isEmpty()) { int oldEnd = visibleItems.last()->endPosition(); int pos = visibleItems.first()->endPosition() + spacing + 1; @@ -842,6 +877,36 @@ void QmlGraphicsListViewPrivate::updateHighlight() updateTrackedItem(); } +void QmlGraphicsListViewPrivate::createSection(FxListItem *listItem) +{ + Q_Q(QmlGraphicsListView); + if (!sectionCriteria || !sectionCriteria->delegate()) + return; + if (listItem->attached->m_prevSection != listItem->attached->m_section) { + if (!listItem->section) { + qDebug() << "create Section"; + QmlContext *context = new QmlContext(qmlContext(q)); + QObject *nobj = sectionCriteria->delegate()->create(context); + if (nobj) { + context->setParent(nobj); + listItem->section = qobject_cast(nobj); + if (!listItem->section) { + delete nobj; + } else { + context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); + listItem->section->setZValue(1); + listItem->section->setParent(q->viewport()); + } + } else { + delete context; + } + } + } else { + delete listItem->section; + listItem->section = 0; + } +} + void QmlGraphicsListViewPrivate::updateSections() { if (sectionCriteria) { @@ -852,6 +917,7 @@ void QmlGraphicsListViewPrivate::updateSections() if (visibleItems.at(i)->index != -1) { QmlGraphicsListViewAttached *attached = visibleItems.at(i)->attached; attached->setPrevSection(prevSection); + createSection(visibleItems.at(i)); prevSection = attached->section(); } } @@ -2240,7 +2306,6 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) d->updateUnrequestedIndexes(); if (!d->visibleItems.count() || d->model->count() <= 1) { d->layout(); - d->updateSections(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; @@ -2351,11 +2416,7 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) // everything is in order now - emit add() signal for (int j = 0; j < added.count(); ++j) added.at(j)->attached->emitAdd(); - d->updateUnrequestedPositions(); - d->updateViewport(); - d->updateSections(); - d->updateHeader(); - d->updateFooter(); + d->layout(); emit countChanged(); } @@ -2386,7 +2447,6 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) d->updateCurrent(qMin(modelIndex, d->model->count()-1)); } d->layout(); - d->updateSections(); emit countChanged(); return; } @@ -2459,7 +2519,6 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) } else { // Correct the positioning of the items d->layout(); - d->updateSections(); } emit countChanged(); @@ -2557,7 +2616,6 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) d->visibleItems.first()->setPosition(d->visibleItems.first()->position() + moveBy); d->layout(); - d->updateSections(); } void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 18b2ab5..2a2ef8a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -55,9 +55,10 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsViewSection : public QObject Q_OBJECT Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY changed) Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY changed) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_ENUMS(SectionCriteria) public: - QmlGraphicsViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString) {} + QmlGraphicsViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString), m_delegate(0) {} QString property() const { return m_property; } void setProperty(const QString &); @@ -66,14 +67,19 @@ public: SectionCriteria criteria() const { return m_criteria; } void setCriteria(SectionCriteria); + QmlComponent *delegate() const { return m_delegate; } + void setDelegate(QmlComponent *delegate); + QString sectionString(const QString &value); Q_SIGNALS: void changed(); + void delegateChanged(); private: QString m_property; SectionCriteria m_criteria; + QmlComponent *m_delegate; }; -- cgit v0.12 From 6ac1fa11ecc929ed9be1ff5a353cf7d776c5835b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 16 Dec 2009 17:56:35 +1000 Subject: Set section delegate "section" property before creation. --- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 77761ac..28ce781 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -601,7 +601,6 @@ FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) QmlGraphicsItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addGeometryListener(this); if (sectionCriteria && sectionCriteria->delegate()) { - qDebug() << "have delegate"; if (listItem->attached->m_prevSection != listItem->attached->m_section) createSection(listItem); } @@ -884,8 +883,8 @@ void QmlGraphicsListViewPrivate::createSection(FxListItem *listItem) return; if (listItem->attached->m_prevSection != listItem->attached->m_section) { if (!listItem->section) { - qDebug() << "create Section"; QmlContext *context = new QmlContext(qmlContext(q)); + context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); QObject *nobj = sectionCriteria->delegate()->create(context); if (nobj) { context->setParent(nobj); @@ -893,7 +892,6 @@ void QmlGraphicsListViewPrivate::createSection(FxListItem *listItem) if (!listItem->section) { delete nobj; } else { - context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); listItem->section->setZValue(1); listItem->section->setParent(q->viewport()); } -- cgit v0.12 From 87a939fa289a0d96c1f0eb10fa74b1cb89fc05f1 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 16 Dec 2009 19:01:19 +1000 Subject: Set a more reasonable default maximumFlickVelocity. --- src/declarative/graphicsitems/qmlgraphicsflickable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index f3f138b..79c7659 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -155,7 +155,7 @@ QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate() : viewport(new QmlGraphicsItem), _moveX(viewport, &QmlGraphicsItem::setX), _moveY(viewport, &QmlGraphicsItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) - , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) + , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) , flickDirection(QmlGraphicsFlickable::AutoFlickDirection) @@ -1166,7 +1166,7 @@ bool QmlGraphicsFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) \qmlproperty real Flickable::maximumFlickVelocity This property holds the maximum velocity that the user can flick the view in pixels/second. - The default is 5000 pixels/s + The default is 2000 pixels/s */ qreal QmlGraphicsFlickable::maximumFlickVelocity() const { -- cgit v0.12 From bb7a6e90375f4f546d1d5dc899e972d9389c2936 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 16 Dec 2009 14:51:33 +0100 Subject: Fix bug in positioners where changes were not being watched Task-number: QT-2638 --- .../graphicsitems/qmlgraphicspositioners.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index b96b8b8..9f6baae 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -173,8 +173,20 @@ void QmlGraphicsBasePositioner::componentComplete() QVariant QmlGraphicsBasePositioner::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == ItemChildAddedChange || - change == ItemChildRemovedChange) { + Q_D(QmlGraphicsBasePositioner); + if (change == ItemChildAddedChange){ + QmlGraphicsItem* child = value.value(); + if(!child) + return QVariant(); + if(!d->watched.contains(child)) + d->watchChanges(child); + prePositioning(); + }else if (change == ItemChildRemovedChange) { + QmlGraphicsItem* child = value.value(); + if(!child) + return QVariant(); + if(d->watched.contains(child)) + d->unwatchChanges(child); prePositioning(); } @@ -212,10 +224,8 @@ void QmlGraphicsBasePositioner::prePositioning() //Assumed that (aside from init) every add/remove triggers this check //thus the above check will be triggered every time an item is removed QSet deletedItems = d->items - positionedItems.toSet(); - foreach(QmlGraphicsItem *child, deletedItems){ - d->unwatchChanges(child); + foreach(QmlGraphicsItem *child, deletedItems) d->items -= child; - } } doPositioning(); if(d->addTransition || d->moveTransition) -- cgit v0.12 From 7f9bfd5dae0aa55a9425908995ba9249b7921ad4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 16 Dec 2009 15:41:27 +0100 Subject: Set score text color (so that it will be visible) --- demos/declarative/samegame/content/samegame.js | 2 +- demos/declarative/samegame/samegame.qml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 8651c84..0a42e88 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -56,7 +56,7 @@ function initBoard() } timer = new Date(); - print(timer.valueOf() - a.valueOf()); + //print(timer.valueOf() - a.valueOf()); } var fillFound;//Set after a floodFill call to the number of tiles found diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 19b929f..72ea564 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -72,6 +72,7 @@ Rectangle { text: "Score: " + gameCanvas.score; font.bold: true anchors.right: parent.right; anchors.rightMargin: 3 anchors.verticalCenter: parent.verticalCenter + color: activePalette.text } } } -- cgit v0.12 From 3dbe316e92204963765d74665d4f33f56d3c1730 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Wed, 16 Dec 2009 15:48:49 +0100 Subject: Add a quit button to the toolbar Allows to run SameGame full-screen on the N900, and being able to quit without having to use xkill :) --- demos/declarative/samegame/samegame.qml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 72ea564..d40d644 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -67,6 +67,12 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter } + Button { + id: btnB; text: "Quit"; onClicked: {Qt.quit();} + anchors.left: btnA.right; anchors.leftMargin: 3 + anchors.verticalCenter: parent.verticalCenter + } + Text { id: score text: "Score: " + gameCanvas.score; font.bold: true -- cgit v0.12 From 0cfb48518250e988c4ef0d9717e69fa1b73561b6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 17 Dec 2009 08:33:41 +1000 Subject: Use faster listmodelinterface data accessor. --- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 6b4a773..d4d07cc 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -496,19 +496,13 @@ QVariant QmlGraphicsVisualDataModelDataMetaObject::initialValue(int propId) QHash::const_iterator it = model->m_roleNames.find(propName); if (it != model->m_roleNames.end()) { roleToProp.insert(*it, propId); - QHash values = model->m_listModelInterface->data(data->m_index, QList() << *it); - if (values.isEmpty()) - return QVariant(); - else - return values.value(*it); + QVariant value = model->m_listModelInterface->data(data->m_index, *it); + return value; } else if (model->m_roles.count() == 1 && propName == "modelData") { //for compatability with other lists, assign modelData if there is only a single role roleToProp.insert(model->m_roles.first(), propId); - QHash values = model->m_listModelInterface->data(data->m_index, QList() << model->m_roles.first()); - if (values.isEmpty()) - return QVariant(); - else - return *values.begin(); + QVariant value = model->m_listModelInterface->data(data->m_index, model->m_roles.first()); + return value; } } else if (model->m_abstractItemModel) { model->ensureRoles(); -- cgit v0.12 From 152b06c18bf0ca5ae8607efabcb0db29eb81c78b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 17 Dec 2009 11:09:46 +1000 Subject: Reuse section headers. --- .../graphicsitems/qmlgraphicslistview.cpp | 68 +++++++++++++++++----- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 28ce781..d4d201a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -529,6 +530,8 @@ public: QmlEaseFollow *highlightSizeAnimator; QmlGraphicsViewSection *sectionCriteria; QString currentSection; + static const int sectionCacheSize = 3; + QmlGraphicsItem *sectionCache[sectionCacheSize]; qreal spacing; qreal highlightMoveSpeed; qreal highlightResizeSpeed; @@ -559,6 +562,7 @@ void QmlGraphicsListViewPrivate::init() QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); q->setFlickDirection(QmlGraphicsFlickable::VerticalFlick); + ::memset(sectionCache, 0, sizeof(QmlGraphicsItem*) * sectionCacheSize); } void QmlGraphicsListViewPrivate::clear() @@ -566,6 +570,10 @@ void QmlGraphicsListViewPrivate::clear() for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); + for (int i = 0; i < sectionCacheSize; ++i) { + delete sectionCache[i]; + sectionCache[i] = 0; + } visiblePos = header ? header->size() : 0; visibleIndex = 0; releaseItem(currentItem); @@ -628,8 +636,19 @@ void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); } - if (item->section) + if (item->section) { + int i = 0; + do { + if (!sectionCache[i]) { + sectionCache[i] = item->section; + sectionCache[i]->setVisible(false); + item->section = 0; + break; + } + ++i; + } while (i < sectionCacheSize); delete item->section; + } delete item; } @@ -883,23 +902,44 @@ void QmlGraphicsListViewPrivate::createSection(FxListItem *listItem) return; if (listItem->attached->m_prevSection != listItem->attached->m_section) { if (!listItem->section) { - QmlContext *context = new QmlContext(qmlContext(q)); - context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); - QObject *nobj = sectionCriteria->delegate()->create(context); - if (nobj) { - context->setParent(nobj); - listItem->section = qobject_cast(nobj); - if (!listItem->section) { - delete nobj; + int i = sectionCacheSize-1; + while (i >= 0 && !sectionCache[i]) + --i; + if (i >= 0) { + listItem->section = sectionCache[i]; + sectionCache[i] = 0; + listItem->section->setVisible(true); + QmlContext *context = QmlEngine::contextForObject(listItem->section); + context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); + } else { + QmlContext *context = new QmlContext(qmlContext(q)); + context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); + QObject *nobj = sectionCriteria->delegate()->create(context); + if (nobj) { + context->setParent(nobj); + listItem->section = qobject_cast(nobj); + if (!listItem->section) { + delete nobj; + } else { + listItem->section->setZValue(1); + listItem->section->setParent(q->viewport()); + } } else { - listItem->section->setZValue(1); - listItem->section->setParent(q->viewport()); + delete context; } - } else { - delete context; } } - } else { + } else if (listItem->section) { + int i = 0; + do { + if (!sectionCache[i]) { + sectionCache[i] = listItem->section; + sectionCache[i]->setVisible(false); + listItem->section = 0; + return; + } + ++i; + } while (i < sectionCacheSize); delete listItem->section; listItem->section = 0; } -- cgit v0.12 From e1111688bba1abbc24762b2a96d79fcd86599fa7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 17 Dec 2009 11:10:07 +1000 Subject: Avoid calling qgi::update() until after component complete --- src/declarative/graphicsitems/qmlgraphicstext.cpp | 25 ++++++++-------------- .../graphicsitems/qmlgraphicstext_p_p.h | 6 ++++++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 6ec72ef..52d68fd 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -144,9 +144,8 @@ void QmlGraphicsText::setFont(const QFont &font) Q_D(QmlGraphicsText); d->font = font; - d->imgDirty = true; d->updateSize(); - update(); + d->markImgDirty(); } void QmlGraphicsText::setText(const QString &n) @@ -171,10 +170,9 @@ void QmlGraphicsText::setText(const QString &n) } d->text = n; - d->imgDirty = true; d->updateSize(); + d->markImgDirty(); emit textChanged(d->text); - update(); } /*! @@ -197,9 +195,8 @@ void QmlGraphicsText::setColor(const QColor &color) if (d->color == color) return; - d->imgDirty = true; d->color = color; - update(); + d->markImgDirty(); } /*! @@ -252,9 +249,8 @@ void QmlGraphicsText::setStyle(QmlGraphicsText::TextStyle style) if (d->style == style) return; - d->imgDirty = true; d->style = style; - update(); + d->markImgDirty(); } void QmlGraphicsText::setStyleColor(const QColor &color) @@ -263,9 +259,8 @@ void QmlGraphicsText::setStyleColor(const QColor &color) if (d->styleColor == color) return; - d->imgDirty = true; d->styleColor = color; - update(); + d->markImgDirty(); } /*! @@ -345,8 +340,8 @@ void QmlGraphicsText::setWrap(bool w) d->wrap = w; - d->imgDirty = true; d->updateSize(); + d->markImgDirty(); } /*! @@ -401,9 +396,8 @@ void QmlGraphicsText::setTextFormat(TextFormat format) if (wasRich && !d->richText) { //### delete control? (and vice-versa below) - d->imgDirty = true; d->updateSize(); - update(); + d->markImgDirty(); } else if (!wasRich && d->richText) { if (!d->doc) { @@ -413,9 +407,8 @@ void QmlGraphicsText::setTextFormat(TextFormat format) d->doc->setDocumentMargin(0); } d->doc->setHtml(d->text); - d->imgDirty = true; d->updateSize(); - update(); + d->markImgDirty(); } d->format = format; } @@ -450,8 +443,8 @@ void QmlGraphicsText::setElideMode(QmlGraphicsText::TextElideMode mode) d->elideMode = mode; - d->imgDirty = true; d->updateSize(); + d->markImgDirty(); } void QmlGraphicsText::geometryChanged(const QRectF &newGeometry, diff --git a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h index 6fbee50..7e77c69 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h @@ -81,6 +81,12 @@ public: ~QmlGraphicsTextPrivate(); void updateSize(); + void markImgDirty() { + Q_Q(QmlGraphicsText); + imgDirty = true; + if (q->isComponentComplete()) + q->update(); + } void checkImgCache(); void drawOutline(); -- cgit v0.12