Skip to content

Commit

Permalink
Flare plugin: Port to Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Oct 12, 2020
1 parent 9d7f3c1 commit 4b8d64c
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/plugins/flare/flareplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <QDir>
#include <QFileInfo>
#include <QStringList>
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
#include <QStringView>
#endif
#include <QTextStream>

#include <memory>
Expand Down Expand Up @@ -78,6 +81,11 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)

while (!stream.atEnd()) {
line = stream.readLine();
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
const QStringView lineView(line);
#else
const QStringRef lineView(&line);
#endif

if (!line.length())
continue;
Expand All @@ -94,8 +102,8 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)
//get map properties
int epos = line.indexOf(QChar('='));
if (epos != -1) {
const QStringRef key = line.leftRef(epos).trimmed();
const QStringRef value = line.midRef(epos + 1, -1).trimmed();
const auto key = lineView.left(epos).trimmed();
const auto value = lineView.mid(epos + 1, -1).trimmed();
if (key == QLatin1String("width"))
map->setWidth(value.toInt());
else if (key == QLatin1String("height"))
Expand All @@ -107,7 +115,7 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)
else if (key == QLatin1String("orientation"))
map->setOrientation(orientationFromString(value.toString()));
else if (key == QLatin1String("background_color")){
QVector<QStringRef> rgbaList = value.split(',');
auto rgbaList = value.split(',');

if (!rgbaList.isEmpty())
backgroundColor.setRed(rgbaList.takeFirst().toInt());
Expand All @@ -126,10 +134,10 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)
} else if (sectionName == QLatin1String("tilesets")) {
tilesetsSectionFound = true;
int epos = line.indexOf(QChar('='));
const QStringRef key = line.leftRef(epos).trimmed();
const QStringRef value = line.midRef(epos + 1, -1).trimmed();
const auto key = lineView.left(epos).trimmed();
const auto value = lineView.mid(epos + 1, -1).trimmed();
if (key == QLatin1String("tileset")) {
const QVector<QStringRef> list = value.split(QChar(','));
const auto list = value.split(QChar(','));

QString absoluteSource(list.first().toString());
if (QDir::isRelativePath(absoluteSource))
Expand Down Expand Up @@ -171,8 +179,8 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)
tilelayerSectionFound = true;
int epos = line.indexOf(QChar('='));
if (epos != -1) {
const QStringRef key = line.leftRef(epos).trimmed();
const QStringRef value = line.midRef(epos + 1, -1).trimmed();
const auto key = lineView.left(epos).trimmed();
const auto value = lineView.mid(epos + 1, -1).trimmed();

if (key == QLatin1String("type")) {
tilelayer = new TileLayer(value.toString(), 0, 0,
Expand Down Expand Up @@ -220,18 +228,18 @@ std::unique_ptr<Tiled::Map> FlarePlugin::read(const QString &fileName)
continue;

if (startsWith == QChar('#')) {
QString name = line.midRef(1).trimmed().toString();
QString name = lineView.mid(1).trimmed().toString();
mapobject->setName(name);
}

int epos = line.indexOf(QChar('='));
if (epos != -1) {
const QStringRef key = line.leftRef(epos).trimmed();
const QStringRef value = line.midRef(epos + 1, -1).trimmed();
const auto key = lineView.left(epos).trimmed();
const auto value = lineView.mid(epos + 1, -1).trimmed();
if (key == QLatin1String("type")) {
mapobject->setType(value.toString());
} else if (key == QLatin1String("location")) {
const QVector<QStringRef> loc = value.split(QChar(','));
const auto loc = value.split(QChar(','));
qreal x,y;
qreal w,h;
if (map->orientation() == Map::Orthogonal) {
Expand Down Expand Up @@ -305,11 +313,13 @@ bool FlarePlugin::write(const Tiled::Map *map, const QString &fileName, Options
}

QTextStream out(file.device());
QColor backgroundColor = map->backgroundColor();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
out.setCodec("UTF-8");
#endif

const int mapWidth = map->width();
const int mapHeight = map->height();
const QColor backgroundColor = map->backgroundColor();

// write [header]
out << "[header]\n";
Expand Down

0 comments on commit 4b8d64c

Please sign in to comment.