diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-06-11 01:46:28 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-06-11 01:46:28 (GMT) |
commit | aa30b0002573b5377b17f26f9fd72ca7d098a36c (patch) | |
tree | 6b76dfd51004e307f883ef6fc3ca9349c920ebd3 | |
parent | 947358481f27ae44423d218aaece36375a2f7a2d (diff) | |
parent | f79b9634df97b55c1060d6ecc854df231d850cea (diff) | |
download | Qt-aa30b0002573b5377b17f26f9fd72ca7d098a36c.zip Qt-aa30b0002573b5377b17f26f9fd72ca7d098a36c.tar.gz Qt-aa30b0002573b5377b17f26f9fd72ca7d098a36c.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
-rw-r--r-- | doc/src/snippets/declarative/listmodel-modify.qml | 97 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativegridview.cpp | 16 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 16 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 29 |
4 files changed, 127 insertions, 31 deletions
diff --git a/doc/src/snippets/declarative/listmodel-modify.qml b/doc/src/snippets/declarative/listmodel-modify.qml new file mode 100644 index 0000000..03fb314 --- /dev/null +++ b/doc/src/snippets/declarative/listmodel-modify.qml @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import Qt 4.7 + +Rectangle { + width: 200; height: 200 + +ListModel { + id: fruitModel + + ListElement { + name: "Apple" + cost: 2.45 + attributes: [ + ListElement { description: "Core" }, + ListElement { description: "Deciduous" } + ] + } + ListElement { + name: "Orange" + cost: 3.25 + attributes: [ + ListElement { description: "Citrus" } + ] + } + ListElement { + name: "Banana" + cost: 1.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Seedless" } + ] + } +} + +//![delegate] + Component { + id: fruitDelegate + Item { + width: 200; height: 50 + Text { text: name } + Text { text: '$' + cost; anchors.right: parent.right } + + // Double the price when clicked. + MouseArea { + anchors.fill: parent + onClicked: fruitModel.setProperty(index, "cost", cost * 2) + } + } + } +//![delegate] + +ListView { + width: 200; height: 200 + model: fruitModel + delegate: fruitDelegate +} + +} diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index ed1d271..da01eb5 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -897,12 +897,10 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m timeline.reset(data.move); if (viewPos != position()) { - if (fixupDuration) { + if (fixupDuration) timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(-viewPos); - q->viewportMoved(); - } + else + timeline.set(data.move, -viewPos); } vTime = timeline.time(); } @@ -911,12 +909,10 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m qreal dist = qAbs(data.move.value() - pos); if (dist > 0) { timeline.reset(data.move); - if (fixupDuration) { + if (fixupDuration) timeline.move(data.move, pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(pos); - q->viewportMoved(); - } + else + timeline.set(data.move, pos); vTime = timeline.time(); } } else { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 3f2b4ce..4848008 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1144,12 +1144,10 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m timeline.reset(data.move); if (viewPos != position()) { - if (fixupDuration) { + if (fixupDuration) timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(-viewPos); - q->viewportMoved(); - } + else + timeline.set(data.move, -viewPos); } vTime = timeline.time(); } @@ -1159,12 +1157,10 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m qreal dist = qAbs(data.move + pos); if (dist > 0) { timeline.reset(data.move); - if (fixupDuration) { + if (fixupDuration) timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(-pos); - q->viewportMoved(); - } + else + timeline.set(data.move, -pos); vTime = timeline.time(); } } diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 7a6a73f..ca21a0c 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -196,9 +196,10 @@ public: static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key); QList< QPair<QString,QPixmap> > allPixmaps() const; - void flushDetachedPixmaps(bool nt); + bool flushDetachedPixmaps(bool nt); private: + enum { soon_time = 10000, flush_time = 30000 }; int *keyArray; int theid; int ps; @@ -236,38 +237,44 @@ QPMCache::~QPMCache() cleaning-up, and to not cut down the size of the cache while the cache is in active use. - When the last pixmap has been deleted from the cache, kill the - timer so Qt won't keep the CPU from going into sleep mode. + When the last detached pixmap has been deleted from the cache, kill the + timer so Qt won't keep the CPU from going into sleep mode. Currently + the timer is not restarted when the pixmap becomes unused, but it does + restart once something else is added (i.e. the cache space is actually needed). + + Returns true if any were removed. */ -void QPMCache::flushDetachedPixmaps(bool nt) +bool QPMCache::flushDetachedPixmaps(bool nt) { int mc = maxCost(); setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1); setMaxCost(mc); ps = totalCost(); + bool any = false; QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin(); while (it != cacheKeys.end()) { if (!contains(it.value())) { releaseKey(it.value()); it = cacheKeys.erase(it); + any = true; } else { ++it; } } + + return any; } void QPMCache::timerEvent(QTimerEvent *) { bool nt = totalCost() == ps; - flushDetachedPixmaps(nt); - - if (!size()) { + if (!flushDetachedPixmaps(nt)) { killTimer(theid); theid = 0; } else if (nt != t) { killTimer(theid); - theid = startTimer(nt ? 10000 : 30000); + theid = startTimer(nt ? soon_time : flush_time); t = nt; } } @@ -315,7 +322,7 @@ bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) if (success) { cacheKeys.insert(key, cacheKey); if (!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } } else { @@ -331,7 +338,7 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); if (success) { if (!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } } else { @@ -352,7 +359,7 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); if (success) { if(!theid) { - theid = startTimer(30000); + theid = startTimer(flush_time); t = false; } const_cast<QPixmapCache::Key&>(key) = cacheKey; |