Permalink
Browse files

Added *.xml files to the filter for TMX and TSX formats

The plugins already supported reading and writing to files with .xml
extension, but these files were not shown in the Open/Save dialogs nor
in the Maps dock.
  • Loading branch information...
bjorn committed Jul 17, 2017
1 parent 1955237 commit bfc29692de3da4ef1361c9e929b0281126847afd
Showing with 23 additions and 27 deletions.
  1. +2 −7 src/tiled/mapsdock.cpp
  2. +2 −2 src/tiled/tmxmapformat.h
  3. +18 −18 src/tiled/utils.cpp
  4. +1 −0 src/tiled/utils.h
View
@@ -161,19 +161,14 @@ MapsView::MapsView(QWidget *parent)
mFileSystemModel = new FileSystemModel(this);
mFileSystemModel->setRootPath(mapsDir.absolutePath());
QStringList nameFilters(QLatin1String("*.tmx"));
// The file system model name filters are plain, whereas the plugins expose
// a filter as part of the file description
QRegExp filterFinder(QLatin1String("\\((\\*\\.[^\\)\\s]*)"));
QStringList nameFilters;
for (MapFormat *format : PluginManager::objects<MapFormat>()) {
if (!(format->capabilities() & MapFormat::Read))
continue;
const QString filter = format->nameFilter();
if (filterFinder.indexIn(filter) != -1)
nameFilters.append(filterFinder.cap(1));
nameFilters.append(Utils::cleanFilterList(filter));
}
mFileSystemModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDot);
View
@@ -61,7 +61,7 @@ class TmxMapFormat : public MapFormat
*/
Map *fromByteArray(const QByteArray &data);
QString nameFilter() const override { return tr("Tiled map files (*.tmx)"); }
QString nameFilter() const override { return tr("Tiled map files (*.tmx *.xml)"); }
QString shortName() const override { return QLatin1String("tmx"); }
@@ -89,7 +89,7 @@ class TsxTilesetFormat : public TilesetFormat
bool write(const Tileset &tileset, const QString &fileName) override;
QString nameFilter() const override { return tr("Tiled tileset files (*.tsx)"); }
QString nameFilter() const override { return tr("Tiled tileset files (*.tsx *.xml)"); }
QString shortName() const override { return QLatin1String("tsx"); }
View
@@ -51,24 +51,6 @@ static QString toImageFileFilter(const QList<QByteArray> &formats)
return filter;
}
// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
//
// Copied from qplatformdialoghelper.cpp in Qt, used under the terms of the GPL
// version 2.0.
static QStringList cleanFilterList(const QString &filter)
{
const char filterRegExp[] =
"^(.*)\\(([a-zA-Z0-9_.,*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
QRegExp regexp(QString::fromLatin1(filterRegExp));
Q_ASSERT(regexp.isValid());
QString f = filter;
int i = regexp.indexIn(f);
if (i >= 0)
f = regexp.cap(2);
return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
}
namespace Tiled {
namespace Utils {
@@ -88,6 +70,24 @@ QString writableImageFormatsFilter()
return toImageFileFilter(QImageWriter::supportedImageFormats());
}
// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
//
// Copied from qplatformdialoghelper.cpp in Qt, used under the terms of the GPL
// version 2.0.
QStringList cleanFilterList(const QString &filter)
{
const char filterRegExp[] =
"^(.*)\\(([a-zA-Z0-9_.,*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
QRegExp regexp(QString::fromLatin1(filterRegExp));
Q_ASSERT(regexp.isValid());
QString f = filter;
int i = regexp.indexIn(f);
if (i >= 0)
f = regexp.cap(2);
return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
}
/**
* Returns whether the \a fileName has an extension that is matched by
* the \a nameFilter.
View
@@ -33,6 +33,7 @@ namespace Utils {
QString readableImageFormatsFilter();
QString writableImageFormatsFilter();
QStringList cleanFilterList(const QString &filter);
bool fileNameMatchesNameFilter(const QString &fileName,
const QString &nameFilter);

0 comments on commit bfc2969

Please sign in to comment.