Skip to content

Commit

Permalink
Moved the layer format setting to the 'New Map' dialog
Browse files Browse the repository at this point in the history
This should avoid confusion about the setting in the preferences not
taking effect and make it clear that it is a map setting now.

This change is jumping through some hoops to avoid breaking string
freeze, hence the use of QCoreApplication::translate.

Closes mapeditor#447
  • Loading branch information
bjorn committed Jul 27, 2013
1 parent 3db213d commit bc52942
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/libtiled/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Map::Map(Orientation orientation,
mHeight(height),
mTileWidth(tileWidth),
mTileHeight(tileHeight),
mLayerDataFormat(Default)
mLayerDataFormat(Base64Zlib)
{
}

Expand Down
1 change: 0 additions & 1 deletion src/libtiled/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class TILEDSHARED_EXPORT Map : public Object
* The different formats in which the tile layer data can be stored.
*/
enum LayerDataFormat {
Default = -1,
XML = 0,
Base64 = 1,
Base64Gzip = 2,
Expand Down
19 changes: 9 additions & 10 deletions src/tiled/mappropertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ MapPropertiesDialog::MapPropertiesDialog(MapDocument *mapDocument,
grid->addWidget(mColorButton, 0, 1);

grid->addWidget(new QLabel(tr("Layer format:")), 1, 0);
// fixme: is it possible to reuse the one from the main preferences?
mLayerDataCombo->addItem(QLatin1String("Default"));
mLayerDataCombo->addItem(QLatin1String("XML"));
mLayerDataCombo->addItem(QLatin1String("Base64 (uncompressed)"));
mLayerDataCombo->addItem(QLatin1String("Base64 (gzip compressed)"));
mLayerDataCombo->addItem(QLatin1String("Base64 (zlib compressed)"));
mLayerDataCombo->addItem(QLatin1String("CSV"));
mLayerDataCombo->setCurrentIndex(mMapDocument->map()->layerDataFormat() + 1);

mLayerDataCombo->addItem(QCoreApplication::translate("PreferencesDialog", "XML"));
mLayerDataCombo->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (uncompressed)"));
mLayerDataCombo->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (gzip compressed)"));
mLayerDataCombo->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (zlib compressed)"));
mLayerDataCombo->addItem(QCoreApplication::translate("PreferencesDialog", "CSV"));
mLayerDataCombo->setCurrentIndex(mMapDocument->map()->layerDataFormat());
grid->addWidget(mLayerDataCombo);

QColor bgColor = mapDocument->map()->backgroundColor();
Expand All @@ -71,10 +70,10 @@ void MapPropertiesDialog::accept()
int format = mLayerDataCombo->currentIndex();
if (format == -1) {
// this shouldn't happen!
format = 0;
format = 3;
}

Map::LayerDataFormat newLayerDataFormat = static_cast<Map::LayerDataFormat>(format - 1);
Map::LayerDataFormat newLayerDataFormat = static_cast<Map::LayerDataFormat>(format);

QUndoStack *undoStack = mMapDocument->undoStack();

Expand Down
17 changes: 16 additions & 1 deletion src/tiled/newmapdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ NewMapDialog::NewMapDialog(QWidget *parent) :
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

// Restore previously used settings
QSettings *s = Preferences::instance()->settings();
Preferences *prefs = Preferences::instance();
QSettings *s = prefs->settings();
const int orientation = s->value(QLatin1String(ORIENTATION_KEY)).toInt();
const int mapWidth = s->value(QLatin1String(MAP_WIDTH_KEY), 100).toInt();
const int mapHeight = s->value(QLatin1String(MAP_HEIGHT_KEY), 100).toInt();
const int tileWidth = s->value(QLatin1String(TILE_WIDTH_KEY), 32).toInt();
const int tileHeight = s->value(QLatin1String(TILE_HEIGHT_KEY),
32).toInt();

mUi->layerFormatLabel->setText(QCoreApplication::translate("Tiled::Internal::MapPropertiesDialog", "Layer format:"));
mUi->layerFormat->addItem(QCoreApplication::translate("PreferencesDialog", "XML"));
mUi->layerFormat->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (uncompressed)"));
mUi->layerFormat->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (gzip compressed)"));
mUi->layerFormat->addItem(QCoreApplication::translate("PreferencesDialog", "Base64 (zlib compressed)"));
mUi->layerFormat->addItem(QCoreApplication::translate("PreferencesDialog", "CSV"));

mUi->orientation->addItem(tr("Orthogonal"), Map::Orthogonal);
mUi->orientation->addItem(tr("Isometric"), Map::Isometric);
mUi->orientation->addItem(tr("Isometric (Staggered)"), Map::Staggered);

mUi->orientation->setCurrentIndex(orientation);
mUi->layerFormat->setCurrentIndex(prefs->layerDataFormat());
mUi->mapWidth->setValue(mapWidth);
mUi->mapHeight->setValue(mapHeight);
mUi->tileWidth->setValue(tileWidth);
Expand Down Expand Up @@ -98,15 +107,21 @@ MapDocument *NewMapDialog::createMap()
QVariant orientationData = mUi->orientation->itemData(orientationIndex);
const Map::Orientation orientation =
static_cast<Map::Orientation>(orientationData.toInt());
const Map::LayerDataFormat layerFormat =
static_cast<Map::LayerDataFormat>(mUi->layerFormat->currentIndex());

Map *map = new Map(orientation,
mapWidth, mapHeight,
tileWidth, tileHeight);

map->setLayerDataFormat(layerFormat);

// Add one filling tile layer to new maps
map->addLayer(new TileLayer(tr("Tile Layer 1"), 0, 0, mapWidth, mapHeight));

// Store settings for next time
Preferences *prefs = Preferences::instance();
prefs->setLayerDataFormat(layerFormat);
QSettings *s = Preferences::instance()->settings();
s->setValue(QLatin1String(ORIENTATION_KEY), orientationIndex);
s->setValue(QLatin1String(MAP_WIDTH_KEY), mapWidth);
Expand Down
23 changes: 18 additions & 5 deletions src/tiled/newmapdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>349</width>
<height>241</height>
<width>365</width>
<height>268</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -187,8 +187,8 @@
<property name="title">
<string>Map</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Orientation:</string>
Expand All @@ -198,7 +198,7 @@
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QComboBox" name="orientation">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand All @@ -208,6 +208,19 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="layerFormatLabel">
<property name="text">
<string>Layer format:</string>
</property>
<property name="buddy">
<cstring>layerFormat</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="layerFormat"/>
</item>
</layout>
</widget>
</item>
Expand Down
41 changes: 0 additions & 41 deletions src/tiled/preferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ void PreferencesDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange: {
const int formatIndex = mUi->layerDataCombo->currentIndex();
mUi->retranslateUi(this);
mUi->layerDataCombo->setCurrentIndex(formatIndex);
mUi->languageCombo->setItemText(0, tr("System default"));
}
break;
Expand Down Expand Up @@ -299,27 +297,6 @@ void PreferencesDialog::fromPreferences()
if (mUi->openGL->isEnabled())
mUi->openGL->setChecked(prefs->useOpenGL());

int formatIndex = 0;
switch (prefs->layerDataFormat()) {
case Map::XML:
formatIndex = 0;
break;
case Map::Base64:
formatIndex = 1;
break;
case Map::Base64Gzip:
formatIndex = 2;
break;
default:
case Map::Base64Zlib:
formatIndex = 3;
break;
case Map::CSV:
formatIndex = 4;
break;
}
mUi->layerDataCombo->setCurrentIndex(formatIndex);

// Not found (-1) ends up at index 0, system default
int languageIndex = mUi->languageCombo->findData(prefs->language());
if (languageIndex == -1)
Expand All @@ -336,27 +313,9 @@ void PreferencesDialog::toPreferences()

prefs->setReloadTilesetsOnChanged(mUi->reloadTilesetImages->isChecked());
prefs->setDtdEnabled(mUi->enableDtd->isChecked());
prefs->setLayerDataFormat(layerDataFormat());
prefs->setAutomappingDrawing(mUi->autoMapWhileDrawing->isChecked());
}

Map::LayerDataFormat PreferencesDialog::layerDataFormat() const
{
switch (mUi->layerDataCombo->currentIndex()) {
case 0:
return Map::XML;
case 1:
return Map::Base64;
case 2:
return Map::Base64Gzip;
case 3:
default:
return Map::Base64Zlib;
case 4:
return Map::CSV;
}
}

void PreferencesDialog::useAutomappingDrawingToggled(bool enabled)
{
Preferences::instance()->setAutomappingDrawing(enabled);
Expand Down
4 changes: 0 additions & 4 deletions src/tiled/preferencesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#ifndef PREFERENCESDIALOG_H
#define PREFERENCESDIALOG_H

#include "map.h"

#include <QDialog>

class QModelIndex;
Expand Down Expand Up @@ -68,8 +66,6 @@ private slots:
void fromPreferences();
void toPreferences();

Map::LayerDataFormat layerDataFormat() const;

Ui::PreferencesDialog *mUi;
QStringList mLanguages;
ObjectTypesModel *mObjectTypesModel;
Expand Down
58 changes: 9 additions & 49 deletions src/tiled/preferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>392</height>
<width>421</width>
<height>369</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -33,59 +33,20 @@
<string>Saving and Loading</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Store tile layer data as:</string>
</property>
<property name="buddy">
<cstring>layerDataCombo</cstring>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="enableDtd">
<property name="toolTip">
<string>Not enabled by default since a reference to an external DTD is known to cause problems with some XML parsers.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="layerDataCombo">
<item>
<property name="text">
<string>XML</string>
</property>
</item>
<item>
<property name="text">
<string>Base64 (uncompressed)</string>
</property>
</item>
<item>
<property name="text">
<string>Base64 (gzip compressed)</string>
</property>
</item>
<item>
<property name="text">
<string>Base64 (zlib compressed)</string>
</property>
</item>
<item>
<property name="text">
<string>CSV</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="reloadTilesetImages">
<property name="text">
<string>&amp;Reload tileset images when they change</string>
<string>Include &amp;DTD reference in saved maps</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="enableDtd">
<property name="toolTip">
<string>Not enabled by default since a reference to an external DTD is known to cause problems with some XML parsers.</string>
</property>
<widget class="QCheckBox" name="reloadTilesetImages">
<property name="text">
<string>Include &amp;DTD reference in saved maps</string>
<string>&amp;Reload tileset images when they change</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -318,7 +279,6 @@
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>layerDataCombo</tabstop>
<tabstop>enableDtd</tabstop>
<tabstop>reloadTilesetImages</tabstop>
<tabstop>languageCombo</tabstop>
Expand Down
6 changes: 1 addition & 5 deletions src/tiled/tmxmapwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ bool TmxMapWriter::write(const Map *map, const QString &fileName)
{
Preferences *prefs = Preferences::instance();

Map::LayerDataFormat format = map->layerDataFormat();
if (format == Map::Default)
format = prefs->layerDataFormat();

MapWriter writer;
writer.setLayerDataFormat(format);
writer.setLayerDataFormat(map->layerDataFormat());
writer.setDtdEnabled(prefs->dtdEnabled());

bool result = writer.writeMap(map, fileName);
Expand Down
2 changes: 1 addition & 1 deletion translations/tiled_nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2165,7 +2165,7 @@ Kies een specifiek bestandsformaat.</translation>
<message>
<location line="+3"/>
<source>Layer format:</source>
<translation>&amp;Tilelagen opslaan als:</translation>
<translation>Tilelagen opslaan als:</translation>
</message>
</context>
<context>
Expand Down

0 comments on commit bc52942

Please sign in to comment.