summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:49:35 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:49:35 (GMT)
commit5783d51bcaed2a769c222ae7f6123f7638d6388a (patch)
treec672130f70e84bf788667c9389d1a2c7bc3d2b21
parentb0830166fb28ad26257602b55e3158bb61a9d5cd (diff)
downloadQt-5783d51bcaed2a769c222ae7f6123f7638d6388a.zip
Qt-5783d51bcaed2a769c222ae7f6123f7638d6388a.tar.gz
Qt-5783d51bcaed2a769c222ae7f6123f7638d6388a.tar.bz2
Simplify dynamic resource loading to avoid cluttering Text API.
Task-number: QTBUG-9900 QT-3287
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp13
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h4
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp6
3 files changed, 10 insertions, 13 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 9fcfd92..a95c930 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -77,7 +77,7 @@ protected:
if (type == QTextDocument::ImageResource) {
QPixmap pm;
QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(url, &pm, &errorString, 0, true, 0, 0);
+ QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(url, &pm, &errorString, 0, false, 0, 0);
if (status == QDeclarativePixmapReply::Ready)
return pm;
if (status == QDeclarativePixmapReply::Error) {
@@ -89,7 +89,6 @@ protected:
QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(parent()), url);
connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
outstanding++;
- static_cast<QDeclarativeText*>(parent())->reloadWithResources();
}
}
@@ -100,7 +99,8 @@ private slots:
void requestFinished()
{
outstanding--;
- static_cast<QDeclarativeText*>(parent())->reloadWithResources();
+ if (outstanding == 0)
+ static_cast<QDeclarativeText*>(parent())->reloadWithResources();
}
private:
@@ -968,17 +968,13 @@ void QDeclarativeText::reloadWithResources()
Q_D(QDeclarativeText);
if (!d->richText)
return;
- if (resourcesLoading()!=0)
- return;
- emit resourcesLoadingChanged();
d->doc->setHtml(d->text);
d->updateLayout();
d->markImgDirty();
}
/*!
- \qmlproperty int Text::resourcesLoading
- This property is the number of resources (images) that are being loaded asynchronously.
+ Returns the number of resources (images) that are being loaded asynchronously.
*/
int QDeclarativeText::resourcesLoading() const
{
@@ -986,7 +982,6 @@ int QDeclarativeText::resourcesLoading() const
return d->doc ? d->doc->resourcesLoading() : 0;
}
-
void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeText);
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index fcad898..4fd5e3a 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -72,7 +72,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapModeChanged)
Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
- Q_PROPERTY(int resourcesLoading READ resourcesLoading NOTIFY resourcesLoadingChanged)
public:
QDeclarativeText(QDeclarativeItem *parent=0);
@@ -139,7 +138,7 @@ public:
virtual void componentComplete();
- int resourcesLoading() const;
+ int resourcesLoading() const; // mainly for testing
Q_SIGNALS:
void textChanged(const QString &text);
@@ -153,7 +152,6 @@ Q_SIGNALS:
void wrapModeChanged();
void textFormatChanged(TextFormat textFormat);
void elideModeChanged(TextElideMode mode);
- void resourcesLoadingChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
index ca7dfe7..edb4a32 100644
--- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
+++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
@@ -897,10 +897,14 @@ void tst_qdeclarativetext::embeddedImages()
QTRY_COMPARE(textObject->resourcesLoading(), 0);
+ QPixmap pm(SRCDIR "/data/http/exists.png");
if (error.isEmpty()) {
- QPixmap pm(SRCDIR "/data/http/exists.png");
QCOMPARE(textObject->width(), double(pm.width()));
QCOMPARE(textObject->height(), double(pm.height()));
+ } else {
+ QVERIFY(16 != pm.width()); // check test is effective
+ QCOMPARE(textObject->width(), 16.0); // default size of QTextDocument broken image icon
+ QCOMPARE(textObject->height(), 16.0);
}
}