Commit 269506c9 authored by Kai Koehne's avatar Kai Koehne
Browse files

Add new JavaScriptFiles & ImageFiles element to .qmlproject file format

parent f3cf0c36
#include "filefilteritems.h"
#include <qdebug.h>
#include <QtGui/QImageReader>
namespace QmlProjectManager {
......@@ -167,6 +168,27 @@ QmlFileFilterItem::QmlFileFilterItem(QObject *parent)
setFilter(QLatin1String("*.qml"));
}
JsFileFilterItem::JsFileFilterItem(QObject *parent)
: FileFilterBaseItem(parent)
{
setFilter(QLatin1String("*.js"));
}
ImageFileFilterItem::ImageFileFilterItem(QObject *parent)
: FileFilterBaseItem(parent)
{
QString filter;
// supported image formats according to
QList<QByteArray> extensions = QImageReader::supportedImageFormats();
foreach (const QByteArray &extension, extensions) {
filter.append(QString("*.%1;").arg(QString::fromAscii(extension)));
}
setFilter(filter);
}
} // namespace QmlProjectManager
QML_DEFINE_TYPE(QmlProject,1,0,QmlFiles,QmlProjectManager::QmlFileFilterItem)
QML_DEFINE_TYPE(QmlProject,1,0,JavaScriptFiles,QmlProjectManager::JsFileFilterItem)
QML_DEFINE_TYPE(QmlProject,1,0,ImageFiles,QmlProjectManager::ImageFileFilterItem)
......@@ -76,8 +76,26 @@ public:
QmlFileFilterItem(QObject *parent = 0);
};
class JsFileFilterItem : public FileFilterBaseItem {
Q_OBJECT
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged())
public:
JsFileFilterItem(QObject *parent = 0);
};
class ImageFileFilterItem : public FileFilterBaseItem {
Q_OBJECT
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged())
public:
ImageFileFilterItem(QObject *parent = 0);
};
} // namespace QmlProjectManager
QML_DECLARE_TYPE(QmlProjectManager::QmlFileFilterItem)
QML_DECLARE_TYPE(QmlProjectManager::JsFileFilterItem)
QML_DECLARE_TYPE(QmlProjectManager::ImageFileFilterItem)
#endif // FILEFILTERITEMS_HPROJECTITEM_H
......@@ -79,22 +79,22 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
}
/* Returns list of absolute paths */
QStringList QmlProjectItem::qmlFiles() const
QStringList QmlProjectItem::files() const
{
const Q_D(QmlProjectItem);
QStringList qmlFiles;
QStringList files;
for (int i = 0; i < d->content.size(); ++i) {
QmlProjectContentItem *contentElement = d->content.at(i);
QmlFileFilterItem *qmlFileFilter = qobject_cast<QmlFileFilterItem*>(contentElement);
if (qmlFileFilter) {
foreach (const QString &file, qmlFileFilter->files()) {
if (!qmlFiles.contains(file))
qmlFiles << file;
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
foreach (const QString &file, fileFilter->files()) {
if (!files.contains(file))
files << file;
}
}
}
return qmlFiles;
return files;
}
} // namespace QmlProjectManager
......
......@@ -35,7 +35,7 @@ public:
QString sourceDirectory() const;
void setSourceDirectory(const QString &directoryPath);
QStringList qmlFiles() const;
QStringList files() const;
signals:
void qmlFilesChanged();
......
......@@ -155,7 +155,7 @@ void QmlProject::parseProject(RefreshOptions options)
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
m_modelManager->updateSourceFiles(m_projectItem.data()->qmlFiles());
m_modelManager->updateSourceFiles(m_projectItem.data()->files());
}
m_rootNode->refresh();
}
......@@ -196,7 +196,7 @@ QStringList QmlProject::files() const
{
QStringList files;
if (m_projectItem) {
files = m_projectItem.data()->qmlFiles();
files = m_projectItem.data()->files();
} else {
files = m_files;
}
......
......@@ -51,7 +51,7 @@ void TestProject::testQmlFileFilter()
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml");
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
......@@ -81,7 +81,7 @@ void TestProject::testQmlFileFilter()
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml"
<< testDataDir + "/subdir/file3.qml");
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
......@@ -107,7 +107,7 @@ void TestProject::testQmlFileFilter()
project->setSourceDirectory(testDataDir);
QStringList expectedFiles(QStringList() << testDataDir + "/subdir/file3.qml");
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
......@@ -140,8 +140,8 @@ void TestProject::testQmlFileFilter()
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml"
<< testDataDir + "/subdir/file3.qml");
QCOMPARE(project->qmlFiles().size(), 3);
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
QCOMPARE(project->files().size(), 3);
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
......@@ -171,9 +171,37 @@ void TestProject::testQmlFileFilter()
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml");
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
// include specific list
//
projectFile = QLatin1String(
"import QmlProject 1.0\n"
"Project {\n"
" ImageFiles {\n"
" directory: \".\"\n"
" }\n"
"}\n");
{
QmlEngine engine;
QmlComponent component(&engine);
component.setData(projectFile.toUtf8(), QUrl());
if (!component.isReady())
qDebug() << component.errorsString();
QVERIFY(component.isReady());
QmlProjectItem *project = qobject_cast<QmlProjectItem*>(component.create());
QVERIFY(project);
project->setSourceDirectory(testDataDir);
QStringList expectedFiles(QStringList() << testDataDir + "/image.gif");
qDebug() << project->files().toSet() << expectedFiles.toSet();
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment