~ubuntu-branches/ubuntu/raring/tiled-qt/raring

« back to all changes in this revision

Viewing changes to src/tmxmapwriter.h

  • Committer: Bazaar Package Importer
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2010-05-20 20:33:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100520203327-juwesr442s3dwbbu
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Tiled Map Editor (Qt)
 
3
 * Copyright 2008 Tiled (Qt) developers (see AUTHORS file)
 
4
 *
 
5
 * This file is part of Tiled (Qt).
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the Free
 
9
 * Software Foundation; either version 2 of the License, or (at your option)
 
10
 * any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
15
 * more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along with
 
18
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
19
 * Place, Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifndef TMXMAPWRITER_H
 
23
#define TMXMAPWRITER_H
 
24
 
 
25
#include "mapwriterinterface.h"
 
26
 
 
27
#include <QCoreApplication>
 
28
#include <QDir>
 
29
#include <QMap>
 
30
#include <QString>
 
31
#include <QXmlStreamWriter>
 
32
 
 
33
namespace Tiled {
 
34
 
 
35
class Layer;
 
36
class MapObject;
 
37
class ObjectGroup;
 
38
class Tile;
 
39
class TileLayer;
 
40
class Tileset;
 
41
 
 
42
namespace Internal {
 
43
 
 
44
/**
 
45
 * A writer for Tiled's .tmx map format.
 
46
 */
 
47
class TmxMapWriter : public MapWriterInterface
 
48
{
 
49
    Q_DECLARE_TR_FUNCTIONS(TmxMapReader)
 
50
 
 
51
public:
 
52
    TmxMapWriter();
 
53
 
 
54
    bool write(const Map *map, const QString &fileName);
 
55
    
 
56
    /**
 
57
     * Converts the given map to a string (in .tmx format). This is for
 
58
     * storing a map in the clipboard. References to other files (like tileset
 
59
     * images) will be saved as absolute paths.
 
60
     *
 
61
     * @see TmxMapReader::fromString
 
62
     */
 
63
    QString toString(const Map *map);
 
64
 
 
65
    QString name() const { return tr("XML map writer (*.tmx)"); }
 
66
 
 
67
    QString errorString() const { return mError; }
 
68
 
 
69
    /**
 
70
     * The different formats in which the tile layer data can be stored.
 
71
     */
 
72
    enum LayerDataFormat {
 
73
        XML        = 0,
 
74
        Base64     = 1,
 
75
        Base64Gzip = 2,
 
76
        Base64Zlib = 3,
 
77
        CSV        = 4,
 
78
    };
 
79
 
 
80
    /**
 
81
     * Sets the format in which the tile layer data is stored.
 
82
     */
 
83
    void setLayerDataFormat(LayerDataFormat format)
 
84
    { mLayerDataFormat = format; }
 
85
 
 
86
    LayerDataFormat layerDataFormat() const
 
87
    { return mLayerDataFormat; }
 
88
 
 
89
    /**
 
90
     * Sets whether the DTD reference is written when saving the map.
 
91
     */
 
92
    void setDtdEnabled(bool enabled)
 
93
    { mDtdEnabled = enabled; }
 
94
 
 
95
    bool isDtdEnabled() const
 
96
    { return mDtdEnabled; }
 
97
 
 
98
private:
 
99
    void writeMap(QXmlStreamWriter &w, const Map *map);
 
100
    void writeTileset(QXmlStreamWriter &w, const Tileset *tileset,
 
101
                      int firstGid);
 
102
    void writeTileLayer(QXmlStreamWriter &w, const TileLayer *tileLayer);
 
103
    void writeLayerAttributes(QXmlStreamWriter &w, const Layer *layer);
 
104
    int gidForTile(const Tile *tile) const;
 
105
    void writeObjectGroup(QXmlStreamWriter &w, const ObjectGroup *objectGroup);
 
106
    void writeObject(QXmlStreamWriter &w, const MapObject *mapObject);
 
107
    void writeProperties(QXmlStreamWriter &w,
 
108
                         const QMap<QString, QString> &properties);
 
109
 
 
110
    QString mError;
 
111
    QDir mMapDir;     // The directory in which the map is being saved
 
112
    QMap<int, const Tileset*> mFirstGidToTileset;
 
113
    bool mUseAbsolutePaths;
 
114
    LayerDataFormat mLayerDataFormat;
 
115
    bool mDtdEnabled;
 
116
};
 
117
 
 
118
} // namespace Internal
 
119
} // namespace Tiled
 
120
 
 
121
#endif // TMXMAPWRITER_H