diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-10-26 04:23:33 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-10-26 04:23:33 (GMT) |
commit | ab235f522d22f4940e40aa3114fface354fbb611 (patch) | |
tree | 6db076d1456e5f8962195447fbdb3b471cda4a34 /tools/qmlviewer/qmlviewer.cpp | |
parent | 9159ddc77750ce46a36995b8818cd5edcf7e1877 (diff) | |
download | Qt-ab235f522d22f4940e40aa3114fface354fbb611.zip Qt-ab235f522d22f4940e40aa3114fface354fbb611.tar.gz Qt-ab235f522d22f4940e40aa3114fface354fbb611.tar.bz2 |
Work again for URLs.
Diffstat (limited to 'tools/qmlviewer/qmlviewer.cpp')
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 60fa13a..73aae44 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -600,14 +600,17 @@ void QmlViewer::addLibraryPath(const QString& lib) void QmlViewer::reload() { - openQml(currentFileName); + openQml(canvas->url()); } void QmlViewer::open() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), currentFileName, tr("QML Files (*.qml)")); - if (!fileName.isEmpty()) - openQml(fileName); + QString cur = canvas->url().toLocalFile(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + openQml(QUrl::fromLocalFile(fi.absoluteFilePath())); + } } void QmlViewer::executeErrors() @@ -615,55 +618,55 @@ void QmlViewer::executeErrors() if (tester) tester->executefailure(); } -void QmlViewer::openQml(const QString& fileName) +void QmlViewer::openQml(const QUrl& url) { - setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); + QString fileName = url.toLocalFile(); + setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName.isEmpty() ? url.toString() : fileName)); if (!m_script.isEmpty()) tester = new QFxTester(m_script, m_scriptOptions, canvas); canvas->reset(); - currentFileName = fileName; - QUrl url(fileName); - QFileInfo fi(fileName); - if (fi.exists()) { - if (fi.suffix().toLower() != QLatin1String("qml")) { - qWarning() << "qmlviewer cannot open non-QML file" << fileName; - return; - } + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + if (fi.exists()) { + if (fi.suffix().toLower() != QLatin1String("qml")) { + qWarning() << "qmlviewer cannot open non-QML file" << fileName; + return; + } - url = QUrl::fromLocalFile(fi.absoluteFilePath()); - QmlContext *ctxt = canvas->rootContext(); - QDir dir(fi.path()+"/dummydata", "*.qml"); - QStringList list = dir.entryList(); - for (int i = 0; i < list.size(); ++i) { - QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QmlComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - - if(comp.isError()) { - QList<QmlError> errors = comp.errors(); - foreach (const QmlError &error, errors) { - qWarning() << error; + QmlContext *ctxt = canvas->rootContext(); + QDir dir(fi.path()+"/dummydata", "*.qml"); + QStringList list = dir.entryList(); + for (int i = 0; i < list.size(); ++i) { + QString qml = list.at(i); + QFile f(dir.filePath(qml)); + f.open(QIODevice::ReadOnly); + QByteArray data = f.readAll(); + QmlComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList<QmlError> errors = comp.errors(); + foreach (const QmlError &error, errors) { + qWarning() << error; + } + if (tester) tester->executefailure(); } - if (tester) tester->executefailure(); - } - if (dummyData) { - qWarning() << "Loaded dummy data:" << dir.filePath(qml); - qml.truncate(qml.length()-4); - ctxt->setContextProperty(qml, dummyData); - dummyData->setParent(this); + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + ctxt->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } } + } else { + qWarning() << "qmlviewer cannot find file:" << fileName; + return; } - } else { - qWarning() << "qmlviewer cannot find file:" << fileName; - return; } canvas->setUrl(url); |