From 3e0bcbff98346385ec32bc951cd958d1c1bfb371 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 26 Mar 2013 20:29:10 -0500 Subject: [PATCH] Update EtcProvider example to support configurable base url. Change-Id: Idb047bc7bf2c9f1c62c4749cb416bdf267e66e17 Reviewed-by: Gunnar Sletta --- examples/quick/textureprovider/etcprovider.cpp | 16 +++++++++++++--- examples/quick/textureprovider/etcprovider.h | 6 ++++++ examples/quick/textureprovider/main.cpp | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/quick/textureprovider/etcprovider.cpp b/examples/quick/textureprovider/etcprovider.cpp index 507965c..52c2c17 100644 --- a/examples/quick/textureprovider/etcprovider.cpp +++ b/examples/quick/textureprovider/etcprovider.cpp @@ -44,6 +44,7 @@ #include #include #include +#include //#define ETC_DEBUG @@ -168,10 +169,14 @@ QQuickTextureFactory *EtcProvider::requestTexture(const QString &id, QSize *size size->setHeight(0); size->setWidth(0); - // resolve paths relative to qrc file - QFile file(QLatin1String(":/textureprovider/") + id); + QUrl url = QUrl(id); + if (url.isRelative() && !m_baseUrl.isEmpty()) + url = m_baseUrl.resolved(url); + QString path = QQmlFile::urlToLocalFileOrQrc(url); + + QFile file(path); #ifdef ETC_DEBUG - qDebug() << "requestTexture opening file: " << id; + qDebug() << "requestTexture opening file: " << path; #endif if (file.open(QIODevice::ReadOnly)) { ret = new QEtcTextureFactory; @@ -200,3 +205,8 @@ QQuickTextureFactory *EtcProvider::requestTexture(const QString &id, QSize *size return ret; } + +void EtcProvider::setBaseUrl(const QUrl &base) +{ + m_baseUrl = base; +} diff --git a/examples/quick/textureprovider/etcprovider.h b/examples/quick/textureprovider/etcprovider.h index 24570e9..b7f2f3d 100644 --- a/examples/quick/textureprovider/etcprovider.h +++ b/examples/quick/textureprovider/etcprovider.h @@ -45,6 +45,7 @@ #include #include #include +#include class EtcProvider : public QQuickImageProvider { @@ -54,6 +55,11 @@ public: {} QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize); + + void setBaseUrl(const QUrl &base); + +private: + QUrl m_baseUrl; }; class EtcTexture : public QSGTexture diff --git a/examples/quick/textureprovider/main.cpp b/examples/quick/textureprovider/main.cpp index d9d4fb0..6397de8 100644 --- a/examples/quick/textureprovider/main.cpp +++ b/examples/quick/textureprovider/main.cpp @@ -48,7 +48,9 @@ int main(int argc, char* argv[]) QGuiApplication app(argc,argv); QQuickView view; - view.engine()->addImageProvider("etc", new EtcProvider()); + EtcProvider *provider = new EtcProvider(); + provider->setBaseUrl(QUrl("qrc:///textureprovider/")); + view.engine()->addImageProvider("etc", provider); view.setSource(QUrl("qrc:///textureprovider/textureprovider.qml")); view.show(); -- 1.7.2.5