::of(&QGeoPositionInfoSource::error), this, &GPSDisplay::error);
+ connect(source, &QGeoPositionInfoSource::updateTimeout, this, &GPSDisplay::updateTimeout);
#elif defined(MAPPER_DEVELOPMENT_BUILD)
// DEBUG
QTimer* debug_timer = new QTimer(this);
@@ -78,7 +76,7 @@ GPSDisplay::GPSDisplay(MapWidget* widget, const Georeferencing& georeferencing)
GPSDisplay::~GPSDisplay()
{
stopUpdates();
- widget->setGPSDisplay(NULL);
+ widget->setGPSDisplay(nullptr);
}
bool GPSDisplay::checkGPSEnabled()
@@ -172,12 +170,11 @@ void GPSDisplay::paint(QPainter* painter)
painter->setBrush(QBrush(tracking_lost ? Qt::gray : Qt::red));
if (heading_indicator_enabled)
{
- const qreal arrow_length = Util::mmToPixelLogical(1.5f);
- const qreal heading_indicator_length = Util::mmToPixelLogical(9999.0f); // very long
+ const qreal base_length_unit = Util::mmToPixelLogical(0.6);
// For heading indicator, get azimuth from compass and calculate
// the relative rotation to map view rotation, clockwise.
- float heading_rotation_deg = Compass::getInstance().getCurrentAzimuth() + 180.0f / M_PI * widget->getMapView()->getRotation();
+ qreal heading_rotation_deg = Compass::getInstance().getCurrentAzimuth() + qRadiansToDegrees(widget->getMapView()->getRotation());
painter->save();
painter->translate(gps_pos);
@@ -185,17 +182,17 @@ void GPSDisplay::paint(QPainter* painter)
// Draw arrow
static const QPointF arrow_points[4] = {
- QPointF(0, -arrow_length),
- QPointF(0.4f * arrow_length, 0.4f * arrow_length),
+ QPointF(0, -2.5 * base_length_unit),
+ QPointF(base_length_unit, base_length_unit),
QPointF(0, 0),
- QPointF(-0.4f * arrow_length, 0.4f * arrow_length)
+ QPointF(base_length_unit, base_length_unit)
};
painter->drawPolygon(arrow_points, 4);
// Draw heading line
- painter->setPen(QPen(Qt::gray, Util::mmToPixelLogical(0.1f)));
+ painter->setPen(QPen(Qt::gray, base_length_unit / 6));
painter->setBrush(Qt::NoBrush);
- painter->drawLine(QPointF(0, 0), QPointF(0, -1 * heading_indicator_length));
+ painter->drawLine(QPointF(0, 0), QPointF(0, -10000 * base_length_unit)); // very long
painter->restore();
}
@@ -205,27 +202,28 @@ void GPSDisplay::paint(QPainter* painter)
painter->drawEllipse(gps_pos, dot_radius, dot_radius);
}
+ auto meters_to_pixels = widget->getMapView()->lengthToPixel(qreal(1000000) / georeferencing.getScaleDenominator());
// Draw distance circles
if (distance_rings_enabled)
{
const int num_distance_rings = 2;
- const float distance_ring_radius_meters = 10;
+ const qreal distance_ring_radius_meters = 10;
- float distance_ring_radius_pixels = widget->getMapView()->lengthToPixel(100000.0 * distance_ring_radius_meters / georeferencing.getScaleDenominator());
- painter->setPen(QPen(Qt::gray, Util::mmToPixelLogical(0.1f)));
+ auto distance_ring_radius_pixels = distance_ring_radius_meters * meters_to_pixels;
+ painter->setPen(QPen(Qt::gray, Util::mmToPixelLogical(0.1)));
painter->setBrush(Qt::NoBrush);
- for (int i = 0; i < num_distance_rings; ++ i)
+ auto radius = distance_ring_radius_pixels;
+ for (int i = 0; i < num_distance_rings; ++i)
{
- float radius = (i + 1) * distance_ring_radius_pixels;
painter->drawEllipse(gps_pos, radius, radius);
+ radius += distance_ring_radius_pixels;
}
}
// Draw accuracy circle
if (latest_gps_coord_accuracy >= 0)
{
- float accuracy_meters = latest_gps_coord_accuracy;
- float accuracy_pixels = widget->getMapView()->lengthToPixel(1000000.0 * accuracy_meters / georeferencing.getScaleDenominator());
+ auto accuracy_pixels = latest_gps_coord_accuracy * meters_to_pixels;
painter->setPen(QPen(tracking_lost ? Qt::gray : Qt::red, Util::mmToPixelLogical(0.2f)));
painter->setBrush(Qt::NoBrush);
@@ -286,7 +284,7 @@ void GPSDisplay::updateTimeout()
void GPSDisplay::debugPositionUpdate()
{
#if MAPPER_DEVELOPMENT_BUILD
- if (! visible)
+ if (!visible)
return;
QTime now = QTime::currentTime();
@@ -344,17 +342,16 @@ MapCoordF GPSDisplay::calcLatestGPSCoord(bool& ok)
latest_gps_coord = georeferencing.toMapCoordF(latlon, &ok);
if (!ok)
{
- qDebug() << "GPSDisplay::calcLatestGPSCoord(): Cannot convert LatLon to MapCoordF!";
+ qDebug("GPSDisplay::calcLatestGPSCoord(): Cannot convert LatLon to MapCoordF!");
return latest_gps_coord;
}
gps_updated = false;
ok = true;
- return latest_gps_coord;
#else
ok = has_valid_position;
- return latest_gps_coord;
#endif
+ return latest_gps_coord;
}
void GPSDisplay::updateMapWidget()
diff --git a/src/gps_display.h b/src/gps_display.h
index 92d13200a..2101c4f96 100644
--- a/src/gps_display.h
+++ b/src/gps_display.h
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Thomas Schöps
+ * Copyright 2016 Kai Pastor
*
* This file is part of OpenOrienteering.
*
@@ -31,11 +32,12 @@
QT_BEGIN_NAMESPACE
class QPainter;
+class QGeoPositionInfo;
+class QGeoPositionInfoSource;
QT_END_NAMESPACE
+
class MapWidget;
class Georeferencing;
-class QGeoPositionInfo;
-class QGeoPositionInfoSource;
/**
@@ -46,9 +48,9 @@ class GPSDisplay : public QObject
Q_OBJECT
public:
/// Creates a GPS display for the given map widget and georeferencing.
- GPSDisplay(MapWidget* widget, const Georeferencing& georeferencing);
+ GPSDisplay(MapWidget* widget, const Georeferencing& georeferencing, QObject* parent = nullptr);
/// Destructor, removes the GPS display from the map widget.
- virtual ~GPSDisplay();
+ ~GPSDisplay() override;
/**
* @brief Checks if GPS is enabled and may guide the user to the device settings.
@@ -115,7 +117,9 @@ private slots:
MapCoordF calcLatestGPSCoord(bool& ok);
void updateMapWidget();
- bool gps_updated;
+ MapWidget* widget;
+ const Georeferencing& georeferencing;
+ QGeoPositionInfoSource* source;
#if defined(QT_POSITIONING_LIB)
QGeoPositionInfo latest_pos_info;
#endif
@@ -123,14 +127,10 @@ private slots:
float latest_gps_coord_accuracy;
bool tracking_lost;
bool has_valid_position;
-
+ bool gps_updated;
bool visible;
bool distance_rings_enabled;
bool heading_indicator_enabled;
-
- QGeoPositionInfoSource* source;
- MapWidget* widget;
- const Georeferencing& georeferencing;
};
#endif
diff --git a/src/gps_track.cpp b/src/gps_track.cpp
index 6f5db0f14..fc79eab71 100644
--- a/src/gps_track.cpp
+++ b/src/gps_track.cpp
@@ -39,7 +39,7 @@ namespace
{
// Shared definition of standard geographic CRS.
// TODO: Merge with Georeferencing.
- static const QString geographic_crs_spec = "+proj=latlong +datum=WGS84";
+ static const QString geographic_crs_spec = QString::fromLatin1("+proj=latlong +datum=WGS84");
}
@@ -62,17 +62,17 @@ TrackPoint::TrackPoint(LatLon coord, QDateTime datetime, float elevation, int nu
}
void TrackPoint::save(QXmlStreamWriter* stream) const
{
- stream->writeAttribute("lat", QString::number(gps_coord.latitude(), 'f', 12));
- stream->writeAttribute("lon", QString::number(gps_coord.longitude(), 'f', 12));
+ stream->writeAttribute(QStringLiteral("lat"), QString::number(gps_coord.latitude(), 'f', 12));
+ stream->writeAttribute(QStringLiteral("lon"), QString::number(gps_coord.longitude(), 'f', 12));
if (datetime.isValid())
- stream->writeTextElement("time", datetime.toString(Qt::ISODate) + 'Z');
+ stream->writeTextElement(QStringLiteral("time"), datetime.toString(Qt::ISODate) + QLatin1Char('Z'));
if (elevation > -9999)
- stream->writeTextElement("ele", QString::number(elevation, 'f', 3));
+ stream->writeTextElement(QStringLiteral("ele"), QString::number(elevation, 'f', 3));
if (num_satellites >= 0)
- stream->writeTextElement("sat", QString::number(num_satellites));
+ stream->writeTextElement(QStringLiteral("sat"), QString::number(num_satellites));
if (hDOP >= 0)
- stream->writeTextElement("hdop", QString::number(hDOP, 'f', 3));
+ stream->writeTextElement(QStringLiteral("hdop"), QString::number(hDOP, 'f', 3));
}
@@ -161,17 +161,17 @@ bool Track::loadFrom(const QString& path, bool project_points, QWidget* dialog_p
clear();
- if (path.endsWith(".gpx", Qt::CaseInsensitive))
+ if (path.endsWith(QLatin1String(".gpx"), Qt::CaseInsensitive))
{
if (!loadFromGPX(&file, project_points, dialog_parent))
return false;
}
- else if (path.endsWith(".dxf", Qt::CaseInsensitive))
+ else if (path.endsWith(QLatin1String(".dxf"), Qt::CaseInsensitive))
{
if (!loadFromDXF(&file, project_points, dialog_parent))
return false;
}
- else if (path.endsWith(".osm", Qt::CaseInsensitive))
+ else if (path.endsWith(QLatin1String(".osm"), Qt::CaseInsensitive))
{
if (!loadFromOSM(&file, project_points, dialog_parent))
return false;
@@ -190,28 +190,28 @@ bool Track::saveTo(const QString& path) const
QXmlStreamWriter stream(&file);
stream.writeStartDocument();
- stream.writeStartElement("gpx");
- stream.writeAttribute("version", "1.1");
- stream.writeAttribute("creator", APP_NAME);
+ stream.writeStartElement(QString::fromLatin1("gpx"));
+ stream.writeAttribute(QString::fromLatin1("version"), QString::fromLatin1("1.1"));
+ stream.writeAttribute(QString::fromLatin1("creator"), APP_NAME);
int size = getNumWaypoints();
for (int i = 0; i < size; ++i)
{
- stream.writeStartElement("wpt");
+ stream.writeStartElement(QStringLiteral("wpt"));
const TrackPoint& point = getWaypoint(i);
point.save(&stream);
- stream.writeTextElement("name", waypoint_names[i]);
+ stream.writeTextElement(QStringLiteral("name"), waypoint_names[i]);
stream.writeEndElement();
}
- stream.writeStartElement("trk");
+ stream.writeStartElement(QStringLiteral("trk"));
for (int i = 0; i < getNumSegments(); ++i)
{
- stream.writeStartElement("trkseg");
+ stream.writeStartElement(QStringLiteral("trkseg"));
size = getSegmentPointCount(i);
for (int k = 0; k < size; ++k)
{
- stream.writeStartElement("trkpt");
+ stream.writeStartElement(QStringLiteral("trkpt"));
const TrackPoint& point = getSegmentPoint(i, k);
point.save(&stream);
stream.writeEndElement();
@@ -347,7 +347,7 @@ bool Track::loadFromGPX(QFile* file, bool project_points, QWidget* dialog_parent
Q_UNUSED(dialog_parent);
track_crs = new Georeferencing();
- track_crs->setProjectedCRS("", geographic_crs_spec);
+ track_crs->setProjectedCRS({}, geographic_crs_spec);
track_crs->setTransformationDirectly(QTransform());
TrackPoint point;
@@ -359,18 +359,18 @@ bool Track::loadFromGPX(QFile* file, bool project_points, QWidget* dialog_parent
stream.readNext();
if (stream.tokenType() == QXmlStreamReader::StartElement)
{
- if (stream.name().compare("wpt", Qt::CaseInsensitive) == 0 ||
- stream.name().compare("trkpt", Qt::CaseInsensitive) == 0 ||
- stream.name().compare("rtept", Qt::CaseInsensitive) == 0)
+ if (stream.name().compare(QLatin1String("wpt"), Qt::CaseInsensitive) == 0
+ || stream.name().compare(QLatin1String("trkpt"), Qt::CaseInsensitive) == 0
+ || stream.name().compare(QLatin1String("rtept"), Qt::CaseInsensitive) == 0)
{
- point = TrackPoint(LatLon(stream.attributes().value("lat").toString().toDouble(),
- stream.attributes().value("lon").toString().toDouble()));
+ point = TrackPoint(LatLon(stream.attributes().value(QLatin1String("lat")).toDouble(),
+ stream.attributes().value(QLatin1String("lon")).toDouble()));
if (project_points)
point.map_coord = map_georef.toMapCoordF(point.gps_coord); // TODO: check for errors
- point_name = "";
+ point_name.clear();
}
- else if (stream.name().compare("trkseg", Qt::CaseInsensitive) == 0 ||
- stream.name().compare("rte", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("trkseg"), Qt::CaseInsensitive) == 0
+ || stream.name().compare(QLatin1String("rte"), Qt::CaseInsensitive) == 0)
{
if (segment_starts.size() == 0 ||
segment_starts.back() < (int)segment_points.size())
@@ -378,26 +378,26 @@ bool Track::loadFromGPX(QFile* file, bool project_points, QWidget* dialog_parent
segment_starts.push_back(segment_points.size());
}
}
- else if (stream.name().compare("ele", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("ele"), Qt::CaseInsensitive) == 0)
point.elevation = stream.readElementText().toFloat();
- else if (stream.name().compare("time", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("time"), Qt::CaseInsensitive) == 0)
point.datetime = QDateTime::fromString(stream.readElementText(), Qt::ISODate);
- else if (stream.name().compare("sat", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("sat"), Qt::CaseInsensitive) == 0)
point.num_satellites = stream.readElementText().toInt();
- else if (stream.name().compare("hdop", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("hdop"), Qt::CaseInsensitive) == 0)
point.hDOP = stream.readElementText().toFloat();
- else if (stream.name().compare("name", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("name"), Qt::CaseInsensitive) == 0)
point_name = stream.readElementText();
}
else if (stream.tokenType() == QXmlStreamReader::EndElement)
{
- if (stream.name().compare("wpt", Qt::CaseInsensitive) == 0)
+ if (stream.name().compare(QLatin1String("wpt"), Qt::CaseInsensitive) == 0)
{
waypoints.push_back(point);
waypoint_names.push_back(point_name);
}
- else if (stream.name().compare("trkpt", Qt::CaseInsensitive) == 0 ||
- stream.name().compare("rtept", Qt::CaseInsensitive) == 0)
+ else if (stream.name().compare(QLatin1String("trkpt"), Qt::CaseInsensitive) == 0
+ || stream.name().compare(QLatin1String("rtept"), Qt::CaseInsensitive) == 0)
{
segment_points.push_back(point);
}
@@ -483,7 +483,7 @@ bool Track::loadFromDXF(QFile* file, bool project_points, QWidget* dialog_parent
bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent)
{
track_crs = new Georeferencing();
- track_crs->setProjectedCRS("", geographic_crs_spec);
+ track_crs->setProjectedCRS({}, geographic_crs_spec);
track_crs->setTransformationDirectly(QTransform());
// Basic OSM file support
@@ -496,7 +496,7 @@ bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent
QXmlStreamReader xml(file);
if (xml.readNextStartElement())
{
- if (xml.name() != "osm")
+ if (xml.name() != QLatin1String("osm"))
{
QMessageBox::critical(dialog_parent, TemplateTrack::tr("Error"), TemplateTrack::tr("%1:\nNot an OSM file."));
return false;
@@ -504,15 +504,19 @@ bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent
else
{
QXmlStreamAttributes attributes(xml.attributes());
- const double osm_version = attributes.value("version").toString().toDouble();
+ const double osm_version = attributes.value(QLatin1String("version")).toDouble();
if (osm_version < min_supported_version)
{
- QMessageBox::critical(dialog_parent, TemplateTrack::tr("Error"), TemplateTrack::tr("The OSM file has version %1.\nThe minimum supported version is %2.").arg(attributes.value("version").toString(), QString::number(min_supported_version, 'g', 1)));
+ QMessageBox::critical(dialog_parent, TemplateTrack::tr("Error"),
+ TemplateTrack::tr("The OSM file has version %1.\nThe minimum supported version is %2.").arg(
+ attributes.value(QLatin1String("version")).toString(), QString::number(min_supported_version, 'g', 1)));
return false;
}
if (osm_version > max_supported_version)
{
- QMessageBox::critical(dialog_parent, TemplateTrack::tr("Error"), TemplateTrack::tr("The OSM file has version %1.\nThe maximum supported version is %2.").arg(attributes.value("version").toString(), QString::number(min_supported_version, 'g', 1)));
+ QMessageBox::critical(dialog_parent, TemplateTrack::tr("Error"),
+ TemplateTrack::tr("The OSM file has version %1.\nThe maximum supported version is %2.").arg(
+ attributes.value(QLatin1String("version")).toString(), QString::number(max_supported_version, 'g', 1)));
return false;
}
}
@@ -523,24 +527,24 @@ bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent
{
const QStringRef name(xml.name());
QXmlStreamAttributes attributes(xml.attributes());
- if (attributes.value("visible") == "false")
+ if (attributes.value(QLatin1String("visible")) == QLatin1String("false"))
{
xml.skipCurrentElement();
continue;
}
- QString id(attributes.value("id").toString());
+ QString id(attributes.value(QLatin1String("id")).toString());
if (id.isEmpty())
{
- id = "!" + QString::number(++internal_node_id);
+ id = QLatin1Char('!') + QString::number(++internal_node_id);
}
- if (name == "node")
+ if (name == QLatin1String("node"))
{
bool ok = true;
double lat = 0.0, lon = 0.0;
- if (ok) lat = attributes.value("lat").toString().toDouble(&ok);
- if (ok) lon = attributes.value("lon").toString().toDouble(&ok);
+ if (ok) lat = attributes.value(QLatin1String("lat")).toDouble(&ok);
+ if (ok) lon = attributes.value(QLatin1String("lon")).toDouble(&ok);
if (!ok)
{
node_problems++;
@@ -557,19 +561,19 @@ bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent
while (xml.readNextStartElement())
{
- if (xml.name() == "tag")
+ if (xml.name() == QLatin1String("tag"))
{
- const QString k(xml.attributes().value("k").toString());
- const QString v(xml.attributes().value("v").toString());
+ const QString k(xml.attributes().value(QLatin1String("k")).toString());
+ const QString v(xml.attributes().value(QLatin1String("v")).toString());
element_tags[id][k] = v;
- if (k == "ele")
+ if (k == QLatin1String("ele"))
{
bool ok;
double elevation = v.toDouble(&ok);
if (ok) nodes[id].elevation = elevation;
}
- else if (k == "name")
+ else if (k == QLatin1String("name"))
{
if (!v.isEmpty() && !nodes.contains(v))
{
@@ -581,24 +585,24 @@ bool Track::loadFromOSM(QFile* file, bool project_points, QWidget* dialog_parent
xml.skipCurrentElement();
}
}
- else if (name == "way")
+ else if (name == QLatin1String("way"))
{
segment_starts.push_back(segment_points.size());
segment_names.push_back(id);
while (xml.readNextStartElement())
{
- if (xml.name() == "nd")
+ if (xml.name() == QLatin1String("nd"))
{
- QString ref = xml.attributes().value("ref").toString();
+ QString ref = xml.attributes().value(QLatin1String("ref")).toString();
if (ref.isEmpty() || !nodes.contains(ref))
node_problems++;
else
segment_points.push_back(nodes[ref]);
}
- else if (xml.name() == "tag")
+ else if (xml.name() == QLatin1String("tag"))
{
- const QString k(xml.attributes().value("k").toString());
- const QString v(xml.attributes().value("v").toString());
+ const QString k(xml.attributes().value(QLatin1String("k")).toString());
+ const QString v(xml.attributes().value(QLatin1String("v")).toString());
element_tags[id][k] = v;
}
xml.skipCurrentElement();
diff --git a/src/gui/about_dialog.cpp b/src/gui/about_dialog.cpp
index bd7b06243..00786d19e 100644
--- a/src/gui/about_dialog.cpp
+++ b/src/gui/about_dialog.cpp
@@ -35,7 +35,7 @@
* But an empty URL will be ignored by QTextBrowser's history, leading to
* unexpected behaviour of backward navigation.
*/
-const QUrl about_page_url = QUrl(QStringLiteral("#ABOUT"));
+const QUrl about_page_url = QUrl(QString::fromLatin1("#ABOUT"));
/**
* Puts the items of a QStringList into an HTML block or a sequence of blocks.
@@ -43,38 +43,39 @@ const QUrl about_page_url = QUrl(QStringLiteral("#ABOUT"));
static QString formatBlock(const QStringList& items)
{
#if defined(Q_OS_ANDROID) // or any other small-screen device
- QString block = QStringLiteral("");
- block.append(items.join(QStringLiteral(", ")));
- block.append(QStringLiteral("
"));
- return block;
+ QString block = QLatin1String("")
+ + items.join(QString::fromLatin1(", "))
+ + QLatin1String("
");
#else
- const int columns = 3;
+ QString block;
+ block.reserve(100 + 30 * items.size());
+ block.append(QLatin1String(""));
+ constexpr int columns = 3;
const int rows = (int)ceil((double)items.size() / columns);
- QString table(QStringLiteral(""));
- for(int i = 0, row = 1; i < items.size(); ++i)
+ for (int i = 0, row = 1; i < items.size(); ++i)
{
- table.append(items[i]);
+ block.append(items[i]);
if (rows != row)
{
- table.append(QStringLiteral(" "));
+ block.append(QString::fromLatin1(" "));
++row;
}
else if (i < items.size())
{
- table.append(QStringLiteral(" | | "));
+ block.append(QString::fromLatin1(" | | "));
row = 1;
}
}
- table.append(QStringLiteral(" | "));
- return table;
+ block.append(QString::fromLatin1(" |
"));
#endif
+ return block;
}
AboutDialog::AboutDialog(QWidget* parent)
: TextBrowserDialog(about_page_url, parent)
{
- text_browser->setSearchPaths(text_browser->searchPaths() << QStringLiteral(":/doc/licensing/html/"));
+ text_browser->setSearchPaths(text_browser->searchPaths() << QString::fromLatin1(":/doc/licensing/html/"));
text_browser->setHtml(about());
text_browser->document()->adjustSize();
updateWindowTitle();
@@ -97,90 +98,79 @@ void AboutDialog::updateWindowTitle()
QString AboutDialog::about()
{
static QStringList developers_list( QStringList()
- << QStringLiteral("Peter Curtis (2012-2013)")
- << QStringLiteral("Kai Pastor")
- << QStringLiteral("Thomas Schöps (2012-2014, %1)")
+ << QString::fromLatin1("Peter Curtis (2012-2013)")
+ << QString::fromLatin1("Kai Pastor")
+ << QString::fromUtf8("Thomas Schöps (2012-2014, %1)")
);
static QStringList contributors_list( QStringList()
- << QStringLiteral("Javier Arufe")
- << QStringLiteral("Jon Cundill")
- << QStringLiteral("Sławomir Cygler")
- << QStringLiteral("Jan Dalheimer")
- << QStringLiteral("Davide De Nardis")
- << QStringLiteral("Eugeniy Fedirets")
- << QStringLiteral("Pavel Fric")
- << QStringLiteral("Anders Gressli")
- << QStringLiteral("Peter Hoban")
- << QStringLiteral("Henrik Johansson")
- << QStringLiteral("Panu Karhu")
- << QStringLiteral("Oskar Karlin")
- << QStringLiteral("Matthias Kühlewein")
- << QStringLiteral("Albin Larsson")
- << QStringLiteral("István Marczis")
- << QStringLiteral("Tojo Masaya")
- << QStringLiteral("Yevhen Mazur")
- << QStringLiteral("Fraser Mills")
- << QStringLiteral("Vincent Poinsignon")
- << QStringLiteral("Russell Porter")
- << QStringLiteral("Christopher Schive")
- << QStringLiteral("Semyon Yakimov")
- << QStringLiteral("Aivars Zogla")
+ << QString::fromLatin1("Javier Arufe")
+ << QString::fromLatin1("Eric Boulet")
+ << QString::fromLatin1("Jon Cundill")
+ << QString::fromUtf8("Sławomir Cygler")
+ << QString::fromLatin1("Jan Dalheimer")
+ << QString::fromLatin1("Davide De Nardis")
+ << QString::fromLatin1("Eugeniy Fedirets")
+ << QString::fromLatin1("Pavel Fric")
+ << QString::fromLatin1("Anders Gressli")
+ << QString::fromLatin1("Peter Hoban")
+ << QString::fromLatin1("Henrik Johansson")
+ << QString::fromLatin1("Panu Karhu")
+ << QString::fromLatin1("Oskar Karlin")
+ << QString::fromUtf8("Matthias Kühlewein")
+ << QString::fromLatin1("Albin Larsson")
+ << QString::fromUtf8("István Marczis")
+ << QString::fromLatin1("Tojo Masaya")
+ << QString::fromLatin1("Yevhen Mazur")
+ << QString::fromLatin1("Fraser Mills")
+ << QString::fromLatin1("Vincent Poinsignon")
+ << QString::fromLatin1("Russell Porter")
+ << QString::fromLatin1("Christopher Schive")
+ << QString::fromLatin1("Semyon Yakimov")
+ << QString::fromLatin1("Aivars Zogla")
);
- QString mapper_about(
- QString(""
- "%0"
- ""
- ""
- " | "
- " | "
- "
"
- "%1 %2
"
- ""
- "%3
"
- "%4
"
- "Copyright (C) 2015 The OpenOrienteering developers
"
- "%5
"
- "%6
"
- "%7
"
- "%8
%9"
- "
%10
%11"
- ""
- ).
- // %0
- arg(tr("About %1")).
- // %1 %2
- arg(APP_NAME).arg(APP_VERSION).
- // %3
- arg(tr("A free software for drawing orienteering maps")).
- // %4
- arg("http://openorienteering.org/apps/mapper/").
- // %5
- arg(tr("This program is free software: you can redistribute it "
- "and/or modify it under the terms of the "
- "GNU General Public License (GPL), version 3, "
- "as published by the Free Software Foundation.").
- arg("href=\"gpl-3-0.html\"")).
+ QString mapper_about = QString::fromLatin1(
+ ""
+ "%0"
+ ""
+ ""
+ " | "
+ " | "
+ "
"
+ "%1
"
+ ""
+ "%3
"
+ "%4
"
+ "Copyright (C) 2016 The OpenOrienteering developers
"
+ "%5
"
+ "%6
"
+ "%7
"
+ "%8
%9"
+ "
%10
%11"
+ ""
+ ).arg(
+ tr("About %1").arg(APP_NAME), // %0
+ qApp->applicationDisplayName(), // %1
+ tr("A free software for drawing orienteering maps"), // %3
+ QString::fromLatin1("http://openorienteering.org/apps/mapper/"), // %4
+ tr("This program is free software: you can redistribute it "
+ "and/or modify it under the terms of the "
+ "GNU General Public License (GPL), version 3, "
+ "as published by the Free Software Foundation.").arg(QString::fromLatin1("href=\"gpl-3-0.html\"")), // %5
// %6
- arg(tr("This program is distributed in the hope that it will be useful, "
- "but WITHOUT ANY WARRANTY; without even the implied warranty of "
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
- "GNU General Public License (GPL), version 3, for "
- "more details.").
- arg("href=\"gpl-3-0.html#15-disclaimer-of-warranty\"")).
- // %7
- arg(tr("All about licenses, copyright notices, conditions and "
- "disclaimers.").
- arg(QStringLiteral("href=\"licensing.html\""))).
- // %8
- arg(tr("The OpenOrienteering developers in alphabetical order:")).
- // %9
- arg(formatBlock(developers_list).arg(tr("(project initiator)").replace('(',QString::null).replace(')',QString::null))).
- // %10
- arg(tr("For contributions, thanks to:")).
- // %11
- arg(formatBlock(contributors_list)) );
+ tr("This program is distributed in the hope that it will be useful, "
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of "
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
+ "GNU General Public License (GPL), version 3, for "
+ "more details.").arg(QString::fromLatin1("href=\"gpl-3-0.html#15-disclaimer-of-warranty\"")), // %6
+ tr("All about licenses, copyright notices, conditions and disclaimers.").arg(QString::fromLatin1("href=\"licensing.html\"")) // %7
+ ).arg(
+ tr("The OpenOrienteering developers in alphabetical order:"), // %8
+ formatBlock(developers_list).arg(tr("(project initiator)").replace(QLatin1Char('('), QString{}).replace(QLatin1Char(')'), QString{})), // %9
+ tr("For contributions, thanks to:"), // %10
+ formatBlock(contributors_list) // %11
+ );
return mapper_about;
}
diff --git a/src/gui/autosave_dialog.cpp b/src/gui/autosave_dialog.cpp
index 1a01750fe..5cf824791 100644
--- a/src/gui/autosave_dialog.cpp
+++ b/src/gui/autosave_dialog.cpp
@@ -36,7 +36,7 @@ AutosaveDialog::AutosaveDialog(QString path, QString autosave_path, QString actu
, autosave_path(autosave_path)
, resolved(false)
{
- const QString text_template = QString("%1
%2
%3");
+ const QString text_template = QString::fromLatin1("%1
%2
%3");
QFileInfo autosaved_file_info(autosave_path);
autosaved_text.setHtml(text_template.
@@ -56,7 +56,7 @@ AutosaveDialog::AutosaveDialog(QString path, QString autosave_path, QString actu
setWindowTitle(tr("File recovery"));
QString intro_text = tr("File %1 was not properly closed. At the moment, there are two versions:");
- QLabel* label = new QLabel(intro_text.arg(QString("%1").arg(user_saved_file_info.fileName())));
+ QLabel* label = new QLabel(intro_text.arg(QString::fromLatin1("%1").arg(user_saved_file_info.fileName())));
label->setWordWrap(true);
layout->addWidget(label);
diff --git a/src/gui/color_dialog.cpp b/src/gui/color_dialog.cpp
index e76059653..95c73263c 100644
--- a/src/gui/color_dialog.cpp
+++ b/src/gui/color_dialog.cpp
@@ -149,7 +149,7 @@ ColorDialog::ColorDialog(const Map& map, const MapColor& source_color, QWidget*
QWidget* prof_color_widget = new QWidget();
prof_color_widget->setLayout(prof_color_layout);
- prof_color_widget->setObjectName("professional");
+ prof_color_widget->setObjectName(QString::fromLatin1("professional"));
QGridLayout* desktop_layout = new QGridLayout();
@@ -178,17 +178,17 @@ ColorDialog::ColorDialog(const Map& map, const MapColor& source_color, QWidget*
desktop_layout->addWidget(custom_rgb_option, row, col, 1, 2);
++row;
- r_edit = Util::SpinBox::create(1, 0.0, 255.0, "", 5);
+ r_edit = Util::SpinBox::create(1, 0.0, 255.0, {}, 5);
desktop_layout->addWidget(new QLabel(tr("Red")), row, col);
desktop_layout->addWidget(r_edit, row, col+1);
++row;
- g_edit = Util::SpinBox::create(1, 0.0, 255.0, "", 5);
+ g_edit = Util::SpinBox::create(1, 0.0, 255.0, {}, 5);
desktop_layout->addWidget(new QLabel(tr("Green")), row, col);
desktop_layout->addWidget(g_edit, row, col+1);
++row;
- b_edit = Util::SpinBox::create(1, 0.0, 255.0, "", 5);
+ b_edit = Util::SpinBox::create(1, 0.0, 255.0, {}, 5);
desktop_layout->addWidget(new QLabel(tr("Blue")), row, col);
desktop_layout->addWidget(b_edit, row, col+1);
@@ -208,7 +208,7 @@ ColorDialog::ColorDialog(const Map& map, const MapColor& source_color, QWidget*
QWidget* desktop_color_widget = new QWidget();
desktop_color_widget->setLayout(desktop_layout);
- desktop_color_widget->setObjectName("desktop");
+ desktop_color_widget->setObjectName(QString::fromLatin1("desktop"));
properties_widget = new QTabWidget();
@@ -257,8 +257,8 @@ ColorDialog::ColorDialog(const Map& map, const MapColor& source_color, QWidget*
connect(b_edit, SIGNAL(valueChanged(double)), this, SLOT(rgbValueChanged()));
QSettings settings;
- settings.beginGroup("ColorDialog");
- QString default_view = settings.value("view").toString();
+ settings.beginGroup(QString::fromLatin1("ColorDialog"));
+ QString default_view = settings.value(QString::fromLatin1("view")).toString();
settings.endGroup();
properties_widget->setCurrentWidget(properties_widget->findChild(default_view));
}
@@ -433,8 +433,8 @@ void ColorDialog::updateWidgets()
void ColorDialog::accept()
{
QSettings settings;
- settings.beginGroup("ColorDialog");
- settings.setValue("view", properties_widget->currentWidget()->objectName());
+ settings.beginGroup(QString::fromLatin1("ColorDialog"));
+ settings.setValue(QString::fromLatin1("view"), properties_widget->currentWidget()->objectName());
settings.endGroup();
QDialog::accept();
@@ -489,7 +489,7 @@ void ColorDialog::spotColorTypeChanged(int id)
case MapColor::SpotColor:
name = color.getName();
if (name.isEmpty())
- name = "?";
+ name = QLatin1Char('?');
color.setSpotColorName(name);
break;
case MapColor::CustomColor:
diff --git a/src/gui/configure_grid_dialog.cpp b/src/gui/configure_grid_dialog.cpp
index 14c225155..d19b8ae10 100644
--- a/src/gui/configure_grid_dialog.cpp
+++ b/src/gui/configure_grid_dialog.cpp
@@ -45,10 +45,10 @@
ConfigureGridDialog::ConfigureGridDialog(QWidget* parent, const Map& map, bool grid_visible)
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint)
, map(map)
-, grid{ map.getGrid() }
-, grid_visible{ grid_visible }
-, current_color{ grid.getColor() }
-, current_unit{ grid.getUnit() }
+, grid(map.getGrid())
+, grid_visible(grid_visible)
+, current_color(grid.getColor())
+, current_unit(grid.getUnit())
{
setWindowTitle(tr("Configure grid"));
@@ -240,7 +240,7 @@ void ConfigureGridDialog::updateStates()
unit_combo->setEnabled(show_grid_check->isChecked());
- QString unit_suffix = QString(" ") % ((current_unit == MapGrid::MetersInTerrain) ? tr("m", "meters") : tr("mm", "millimeters"));
+ QString unit_suffix = QLatin1Char(' ') + ((current_unit == MapGrid::MetersInTerrain) ? tr("m", "meters") : tr("mm", "millimeters"));
horz_spacing_edit->setEnabled(show_grid_check->isChecked() && display_mode != MapGrid::HorizontalLines);
horz_spacing_edit->setSuffix(unit_suffix);
vert_spacing_edit->setEnabled(show_grid_check->isChecked() && display_mode != MapGrid::VerticalLines);
diff --git a/src/gui/georeferencing_dialog.cpp b/src/gui/georeferencing_dialog.cpp
index 5eed6eaaa..9d8139db6 100644
--- a/src/gui/georeferencing_dialog.cpp
+++ b/src/gui/georeferencing_dialog.cpp
@@ -98,6 +98,12 @@ GeoreferencingDialog::GeoreferencingDialog(
status_label = new QLabel(tr("Status:"));
status_field = new QLabel();
+ /*: The grid scale factor is the ratio between a length in the grid plane
+ and the corresponding length on the curved earth model. It is applied
+ as a factor to ground distances to get grid plane distances. */
+ auto scale_factor_label = new QLabel(tr("Grid scale factor:"));
+ scale_factor_edit = Util::SpinBox::create(Georeferencing::scaleFactorPrecision(), 0.001, 1000.0);
+
QLabel* reference_point_label = Util::Headline::create(tr("Reference point"));
ref_point_button = new QPushButton(tr("&Pick on map"));
@@ -157,7 +163,7 @@ GeoreferencingDialog::GeoreferencingDialog(
QLabel* map_north_label = Util::Headline::create(tr("Map north"));
declination_edit = Util::SpinBox::create(Georeferencing::declinationPrecision(), -180.0, +180.0, trUtf8("°"));
- declination_button = new QPushButton("");
+ declination_button = new QPushButton(tr("Lookup..."));
QHBoxLayout* declination_layout = new QHBoxLayout();
declination_layout->addWidget(declination_edit, 1);
#if defined(QT_NETWORK_LIB)
@@ -181,6 +187,7 @@ GeoreferencingDialog::GeoreferencingDialog(
edit_layout->addRow(tr("&Coordinate reference system:"), crs_selector);
crs_selector->setDialogLayout(edit_layout);
edit_layout->addRow(status_label, status_field);
+ edit_layout->addRow(scale_factor_label, scale_factor_edit);
edit_layout->addItem(Util::SpacerItem::create(this));
edit_layout->addRow(reference_point_label);
@@ -190,7 +197,7 @@ GeoreferencingDialog::GeoreferencingDialog(
edit_layout->addRow(show_refpoint_label, link_label);
edit_layout->addRow(show_refpoint_label, link_label);
edit_layout->addRow(tr("On CRS changes, keep:"), keep_projected_radio);
- edit_layout->addRow("", keep_geographic_radio);
+ edit_layout->addRow({}, keep_geographic_radio);
edit_layout->addItem(Util::SpacerItem::create(this));
edit_layout->addRow(map_north_label);
@@ -208,6 +215,8 @@ GeoreferencingDialog::GeoreferencingDialog(
connect(crs_selector, &CRSSelector::crsChanged, this, &GeoreferencingDialog::crsEdited);
using TakingDoubleArgument = void (QDoubleSpinBox::*)(double);
+ connect(scale_factor_edit, (TakingDoubleArgument)&QDoubleSpinBox::valueChanged, this, &GeoreferencingDialog::scaleFactorEdited);
+
connect(map_x_edit, (TakingDoubleArgument)&QDoubleSpinBox::valueChanged, this, &GeoreferencingDialog::mapRefChanged);
connect(map_y_edit, (TakingDoubleArgument)&QDoubleSpinBox::valueChanged, this, &GeoreferencingDialog::mapRefChanged);
connect(ref_point_button, &QPushButton::clicked, this, &GeoreferencingDialog::selectMapRefPoint);
@@ -271,7 +280,8 @@ void GeoreferencingDialog::transformationChanged()
{
ScopedMultiSignalsBlocker block(
map_x_edit, map_y_edit,
- easting_edit, northing_edit
+ easting_edit, northing_edit,
+ scale_factor_edit
);
map_x_edit->setValue(georef->getMapRefPoint().x());
@@ -280,6 +290,8 @@ void GeoreferencingDialog::transformationChanged()
easting_edit->setValue(georef->getProjectedRefPoint().x());
northing_edit->setValue(georef->getProjectedRefPoint().y());
+ scale_factor_edit->setValue(georef->getGridScaleFactor());
+
updateGrivation();
}
@@ -299,7 +311,7 @@ void GeoreferencingDialog::projectionChanged()
{
// The CRS id is not there anymore or the number of parameters has changed.
// Enter as custom spec.
- crs_selector->setCurrentCRS(CRSTemplateRegistry().find("PROJ.4"), { georef->getProjectedCRSSpec() });
+ crs_selector->setCurrentCRS(CRSTemplateRegistry().find(QString::fromLatin1("PROJ.4")), { georef->getProjectedCRSSpec() });
}
else
{
@@ -313,10 +325,10 @@ void GeoreferencingDialog::projectionChanged()
lat_edit->setValue(latitude);
lon_edit->setValue(longitude);
QString osm_link =
- QString("http://www.openstreetmap.org/?lat=%1&lon=%2&zoom=18&layers=M").
+ QString::fromLatin1("http://www.openstreetmap.org/?lat=%1&lon=%2&zoom=18&layers=M").
arg(latitude).arg(longitude);
QString worldofo_link =
- QString("http://maps.worldofo.com/?zoom=15&lat=%1&lng=%2").
+ QString::fromLatin1("http://maps.worldofo.com/?zoom=15&lat=%1&lng=%2").
arg(latitude).arg(longitude);
link_label->setText(
tr("OpenStreetMap | World of O Maps").
@@ -328,7 +340,7 @@ void GeoreferencingDialog::projectionChanged()
if (error.length() == 0)
status_field->setText(tr("valid"));
else
- status_field->setText(QString("") % error % "");
+ status_field->setText(QLatin1String("") + error + QLatin1String(""));
}
// slot
@@ -345,8 +357,8 @@ void GeoreferencingDialog::requestDeclination(bool no_confirm)
return;
// TODO: Move to resources or preferences. Assess security risks of url distinction.
- QString user_url("http://www.ngdc.noaa.gov/geomag-web/");
- QUrl service_url("http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination");
+ QString user_url(QString::fromLatin1("http://www.ngdc.noaa.gov/geomag-web/"));
+ QUrl service_url(QString::fromLatin1("http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination"));
LatLon latlon(georef->getGeographicRefPoint());
if (!no_confirm)
@@ -368,12 +380,12 @@ void GeoreferencingDialog::requestDeclination(bool no_confirm)
QUrlQuery query;
QDate today = QDate::currentDate();
- query.addQueryItem("lat1", QString::number(latlon.latitude()));
- query.addQueryItem("lon1", QString::number(latlon.longitude()));
- query.addQueryItem("startYear", QString::number(today.year()));
- query.addQueryItem("startMonth", QString::number(today.month()));
- query.addQueryItem("startDay", QString::number(today.day()));
- query.addQueryItem("resultFormat", "xml");
+ query.addQueryItem(QString::fromLatin1("lat1"), QString::number(latlon.latitude()));
+ query.addQueryItem(QString::fromLatin1("lon1"), QString::number(latlon.longitude()));
+ query.addQueryItem(QString::fromLatin1("startYear"), QString::number(today.year()));
+ query.addQueryItem(QString::fromLatin1("startMonth"), QString::number(today.month()));
+ query.addQueryItem(QString::fromLatin1("startDay"), QString::number(today.day()));
+ query.addQueryItem(QString::fromLatin1("resultFormat"), QString::fromLatin1("xml"));
service_url.setQuery(query);
network->get(QNetworkRequest(service_url));
#else
@@ -453,7 +465,7 @@ void GeoreferencingDialog::updateWidgets()
ref_point_button->setEnabled(controller != nullptr);
if (crs_selector->currentCRSTemplate())
- projected_ref_label->setText(crs_selector->currentCRSTemplate()->coordinatesName(crs_selector->parameters()) + ":");
+ projected_ref_label->setText(crs_selector->currentCRSTemplate()->coordinatesName(crs_selector->parameters()) + QLatin1Char(':'));
else
projected_ref_label->setText(tr("Local coordinates:"));
@@ -489,7 +501,7 @@ void GeoreferencingDialog::updateGrivation()
{
QString text = trUtf8("%1 °", "degree value").arg(QLocale().toString(georef->getGrivation(), 'f', Georeferencing::declinationPrecision()));
if (grivation_locked)
- text.append(QString(" (%1)").arg(tr("locked")));
+ text.append(QString::fromLatin1(" (%1)").arg(tr("locked")));
grivation_label->setText(text);
}
@@ -527,6 +539,13 @@ void GeoreferencingDialog::crsEdited()
reset_button->setEnabled(true);
}
+void GeoreferencingDialog::scaleFactorEdited()
+{
+ const QSignalBlocker block{scale_factor_edit};
+ georef->setGridScaleFactor(scale_factor_edit->value());
+ reset_button->setEnabled(true);
+}
+
void GeoreferencingDialog::selectMapRefPoint()
{
if (controller)
@@ -602,15 +621,15 @@ void GeoreferencingDialog::declinationReplyFinished(QNetworkReply* reply)
QXmlStreamReader xml(reply);
while (xml.readNextStartElement())
{
- if (xml.name() == "maggridresult")
+ if (xml.name() == QLatin1String("maggridresult"))
{
while(xml.readNextStartElement())
{
- if (xml.name() == "result")
+ if (xml.name() == QLatin1String("result"))
{
while (xml.readNextStartElement())
{
- if (xml.name() == "declination")
+ if (xml.name() == QLatin1String("declination"))
{
QString text = xml.readElementText(QXmlStreamReader::IncludeChildElements);
bool ok;
@@ -622,7 +641,7 @@ void GeoreferencingDialog::declinationReplyFinished(QNetworkReply* reply)
}
else
{
- error_string = tr("Could not parse data.") % ' ';
+ error_string = tr("Could not parse data.") + QLatin1Char(' ');
}
}
@@ -633,9 +652,9 @@ void GeoreferencingDialog::declinationReplyFinished(QNetworkReply* reply)
xml.skipCurrentElement(); // child of mapgridresult
}
}
- else if (xml.name() == "errors")
+ else if (xml.name() == QLatin1String("errors"))
{
- error_string.append(xml.readElementText(QXmlStreamReader::IncludeChildElements) % ' ');
+ error_string.append(xml.readElementText(QXmlStreamReader::IncludeChildElements) + QLatin1Char(' '));
}
xml.skipCurrentElement(); // child of root
@@ -721,6 +740,6 @@ bool GeoreferencingTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coo
const QCursor& GeoreferencingTool::getCursor() const
{
- static auto const cursor = QCursor(QPixmap(":/images/cursor-crosshair.png"), 11, 11);
+ static auto const cursor = scaledToScreen(QCursor{ QPixmap{ QString::fromLatin1(":/images/cursor-crosshair.png") }, 11, 11 });
return cursor;
}
diff --git a/src/gui/georeferencing_dialog.h b/src/gui/georeferencing_dialog.h
index e36ddf6db..4992038ed 100644
--- a/src/gui/georeferencing_dialog.h
+++ b/src/gui/georeferencing_dialog.h
@@ -188,6 +188,11 @@ Q_OBJECT
*/
void crsEdited();
+ /**
+ * Notifies the dialog of a change in the grid scale factor.
+ */
+ void scaleFactorEdited();
+
/**
* Hides the dialog and activates a GeoreferencingTool for selecting
* the reference point on the map.
@@ -245,6 +250,7 @@ Q_OBJECT
CRSSelector* crs_selector;
QLabel* status_label;
QLabel* status_field;
+ QDoubleSpinBox* scale_factor_edit;
QDoubleSpinBox* map_x_edit;
QDoubleSpinBox* map_y_edit;
diff --git a/src/gui/home_screen_controller.cpp b/src/gui/home_screen_controller.cpp
index a2c84f554..954825fb1 100644
--- a/src/gui/home_screen_controller.cpp
+++ b/src/gui/home_screen_controller.cpp
@@ -44,7 +44,7 @@ void HomeScreenController::attach(MainWindow* window)
{
this->window = window;
- if (window->mobileMode())
+ if (MainWindow::mobileMode())
{
widget = new HomeScreenWidgetMobile(this);
}
@@ -52,7 +52,7 @@ void HomeScreenController::attach(MainWindow* window)
{
widget = new HomeScreenWidgetDesktop(this);
window->statusBar()->hide();
- window->setStatusBarText("");
+ window->setStatusBarText(QString{});
}
window->setCentralWidget(widget);
@@ -64,7 +64,7 @@ void HomeScreenController::attach(MainWindow* window)
void HomeScreenController::detach()
{
- if (!window->mobileMode())
+ if (!MainWindow::mobileMode())
{
window->statusBar()->show();
}
@@ -126,13 +126,13 @@ void HomeScreenController::goToTip(int index)
if (tips.isEmpty())
{
// Normally, this will be read only once.
- QFile file(":/help/tip-of-the-day/tips.txt");
+ QFile file(QString::fromLatin1(":/help/tip-of-the-day/tips.txt"));
if (file.open(QIODevice::ReadOnly))
{
while (!file.atEnd())
{
QString tip(QString::fromUtf8(file.readLine().constData()));
- if (tip.endsWith('\n'))
+ if (tip.endsWith(QLatin1Char('\n')))
tip.chop(1);
if (!tip.isEmpty())
tips.push_back(tip);
@@ -144,7 +144,7 @@ void HomeScreenController::goToTip(int index)
{
// Some error may have occured during reading the tips file.
// Display a welcome text.
- widget->setTipOfTheDay(QString("%1
").arg(tr("Welcome to OpenOrienteering Mapper!")));
+ widget->setTipOfTheDay(QString::fromLatin1("%1
").arg(tr("Welcome to OpenOrienteering Mapper!")));
}
else
{
diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp
index 3502d4b05..00f4bb4bf 100644
--- a/src/gui/main_window.cpp
+++ b/src/gui/main_window.cpp
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013, 2014 Thomas Schöps
- * Copyright 2012-2015 Kai Pastor
+ * Copyright 2012-2016 Kai Pastor
*
* This file is part of OpenOrienteering.
*
@@ -30,74 +30,62 @@
#include
#include
#include
-#include
#include
#include
#include
-#include
#include
#include
+#if defined(Q_OS_ANDROID)
+# include
+#endif
+
#include
#include "about_dialog.h"
#include "autosave_dialog.h"
+#include "home_screen_controller.h"
+#include "settings_dialog.h"
+#include "text_browser_dialog.h"
#include "../file_format_registry.h"
#include "../file_import_export.h"
-#include "home_screen_controller.h"
#include "../map.h"
#include "../map_dialog_new.h"
#include "../map_editor.h"
#include "../mapper_resource.h"
#include "../file_format.h"
#include "../settings.h"
-#include "settings_dialog.h"
-#include "text_browser_dialog.h"
+#include "../symbol.h"
+#include "../undo_manager.h"
#include "../util.h"
-
-#if defined(Q_OS_ANDROID)
-#include
-#endif
+#include "../util/backports.h"
+constexpr int MainWindow::max_recent_files;
int MainWindow::num_open_files = 0;
-MainWindow::MainWindow(bool as_main_window)
-: QMainWindow()
-, has_autosave_conflict(false)
-, homescreen_disabled(false)
+MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
+: MainWindow { true, parent, flags }
{
-#if (defined Q_OS_MAC)
- // Cf. qtbase/src/plugins/platforms/cocoa/qcocoamenuloader.mm.
- // These translations should come with Qt, but were missing
- // for some languages (at least for de in Qt 5.0.1).
- static const char *application_menu_strings[] = {
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Services"),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Hide %1"),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Hide Others"),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Show All"),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Preferences..."),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "Quit %1"),
- QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU", "About %1")
- };
- Q_UNUSED(application_menu_strings)
-#endif
-
- controller = NULL;
- has_unsaved_changes = false;
- has_opened_file = false;
+ // nothing else
+}
- create_menu = as_main_window;
- show_menu = create_menu && !mobileMode();
-
- disable_shortcuts = false;
- setCurrentPath(QString());
- maximized_before_fullscreen = false;
- general_toolbar = NULL;
- file_menu = NULL;
-
- setWindowIcon(QIcon(":/images/mapper.png"));
+MainWindow::MainWindow(bool as_main_window, QWidget* parent, Qt::WindowFlags flags)
+: QMainWindow { parent, flags }
+, controller { nullptr }
+, create_menu { as_main_window }
+, show_menu { create_menu && !mobileMode() }
+, shortcuts_blocked { false }
+, general_toolbar { nullptr }
+, file_menu { nullptr }
+, has_opened_file { false }
+, has_unsaved_changes { false }
+, has_autosave_conflict { false }
+, maximized_before_fullscreen { false }
+, homescreen_disabled { false }
+{
+ setWindowIcon(QIcon(QString::fromLatin1(":/images/mapper.png")));
setAttribute(Qt::WA_DeleteOnClose);
status_label = new QLabel();
@@ -119,7 +107,7 @@ MainWindow::MainWindow(bool as_main_window)
installEventFilter(this);
#endif
- connect(&Settings::getInstance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
+ connect(&Settings::getInstance(), &Settings::settingsChanged, this, &MainWindow::settingsChanged);
}
MainWindow::~MainWindow()
@@ -137,29 +125,24 @@ void MainWindow::settingsChanged()
updateRecentFileActions();
}
-const QString& MainWindow::appName() const
+QString MainWindow::appName() const
{
- static QString app_name(APP_NAME);
- return app_name;
+ return APP_NAME;
}
-bool MainWindow::mobileMode() const
+#ifndef Q_OS_ANDROID
+bool MainWindow::mobileMode()
{
-#ifdef Q_OS_ANDROID
- static bool mobile_mode = qEnvironmentVariableIsSet("MAPPER_MOBILE_GUI")
- ? (qgetenv("MAPPER_MOBILE_GUI") != "0")
- : 1;
-#else
static bool mobile_mode = qEnvironmentVariableIsSet("MAPPER_MOBILE_GUI")
? (qgetenv("MAPPER_MOBILE_GUI") != "0")
: 0;
-#endif
return mobile_mode;
}
+#endif
void MainWindow::setCentralWidget(QWidget* widget)
{
- if (widget != NULL)
+ if (widget)
{
// Main window shall not resize to central widget size hint.
widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
@@ -181,24 +164,34 @@ void MainWindow::setHomeScreenDisabled(bool disabled)
homescreen_disabled = disabled;
}
+void MainWindow::setController(MainWindowController* new_controller)
+{
+ setController(new_controller, false);
+ setCurrentPath({});
+}
+
void MainWindow::setController(MainWindowController* new_controller, const QString& path)
+{
+ setController(new_controller, true);
+ setCurrentPath(path);
+}
+
+void MainWindow::setController(MainWindowController* new_controller, bool has_file)
{
if (controller)
{
controller->detach();
delete controller;
- controller = NULL;
+ controller = nullptr;
if (show_menu)
menuBar()->clear();
delete general_toolbar;
- general_toolbar = NULL;
+ general_toolbar = nullptr;
}
- has_opened_file = false;
- has_unsaved_changes = false;
- disable_shortcuts = false;
- setCurrentPath(path);
+ has_opened_file = has_file;
+ shortcuts_blocked = false;
if (create_menu)
createFileMenu();
@@ -208,7 +201,7 @@ void MainWindow::setController(MainWindowController* new_controller, const QStri
if (create_menu)
createHelpMenu();
-
+
#if defined(Q_OS_MAC)
if (isVisible() && qApp->activeWindow() == this)
{
@@ -218,77 +211,78 @@ void MainWindow::setController(MainWindowController* new_controller, const QStri
qApp->focusWindowChanged(qApp->focusWindow());
}
#endif
+
+ setHasAutosaveConflict(false);
+ setHasUnsavedChanges(false);
}
void MainWindow::createFileMenu()
{
- QAction* new_act = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
+ QAction* new_act = new QAction(QIcon(QString::fromLatin1(":/images/new.png")), tr("&New"), this);
new_act->setShortcuts(QKeySequence::New);
new_act->setStatusTip(tr("Create a new map"));
- new_act->setWhatsThis("See more");
- connect(new_act, SIGNAL(triggered()), this, SLOT(showNewMapWizard()));
+ new_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(new_act, &QAction::triggered, this, &MainWindow::showNewMapWizard);
- QAction* open_act = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+ QAction* open_act = new QAction(QIcon(QString::fromLatin1(":/images/open.png")), tr("&Open..."), this);
open_act->setShortcuts(QKeySequence::Open);
open_act->setStatusTip(tr("Open an existing file"));
- open_act->setWhatsThis("See more");
- connect(open_act, SIGNAL(triggered()), this, SLOT(showOpenDialog()));
+ open_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(open_act, &QAction::triggered, this, &MainWindow::showOpenDialog);
open_recent_menu = new QMenu(tr("Open &recent"), this);
- open_recent_menu->setWhatsThis("See more");
+ open_recent_menu->setWhatsThis(Util::makeWhatThis("file_menu.html"));
for (int i = 0; i < max_recent_files; ++i)
{
recent_file_act[i] = new QAction(this);
- connect(recent_file_act[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
+ connect(recent_file_act[i], &QAction::triggered, this, &MainWindow::openRecentFile);
}
open_recent_menu_inserted = false;
// NOTE: if you insert something between open_recent_menu and save_act, adjust updateRecentFileActions()!
- save_act = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
+ save_act = new QAction(QIcon(QString::fromLatin1(":/images/save.png")), tr("&Save"), this);
save_act->setShortcuts(QKeySequence::Save);
- save_act->setWhatsThis("See more");
- connect(save_act, SIGNAL(triggered()), this, SLOT(save()));
+ save_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(save_act, &QAction::triggered, this, &MainWindow::save);
- save_as_act = new QAction(tr("Save &as..."), this);
+ auto save_as_act = new QAction(tr("Save &as..."), this);
if (QKeySequence::keyBindings(QKeySequence::SaveAs).empty())
save_as_act->setShortcut(tr("Ctrl+Shift+S"));
else
save_as_act->setShortcuts(QKeySequence::SaveAs);
- save_as_act->setWhatsThis("See more");
- connect(save_as_act, SIGNAL(triggered()), this, SLOT(showSaveAsDialog()));
+ save_as_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(save_as_act, &QAction::triggered, this, &MainWindow::showSaveAsDialog);
settings_act = new QAction(tr("Settings..."), this);
-#if defined(Q_OS_MAC)
settings_act->setShortcut(QKeySequence::Preferences);
settings_act->setMenuRole(QAction::PreferencesRole);
-#endif
- connect(settings_act, SIGNAL(triggered()), this, SLOT(showSettings()));
+ connect(settings_act, &QAction::triggered, this, &MainWindow::showSettings);
- close_act = new QAction(QIcon(":/images/close.png"), tr("Close"), this);
+ close_act = new QAction(QIcon(QString::fromLatin1(":/images/close.png")), tr("Close"), this);
close_act->setShortcut(QKeySequence::Close);
close_act->setStatusTip(tr("Close this file"));
- close_act->setWhatsThis("See more");
- connect(close_act, SIGNAL(triggered()), this, SLOT(closeFile()));
+ close_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(close_act, &QAction::triggered, this, &MainWindow::closeFile);
QAction* exit_act = new QAction(tr("E&xit"), this);
exit_act->setShortcuts(QKeySequence::Quit);
exit_act->setStatusTip(tr("Exit the application"));
-#if defined(Q_OS_MAC)
exit_act->setMenuRole(QAction::QuitRole);
-#endif
- exit_act->setWhatsThis("See more");
- connect(exit_act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+ exit_act->setWhatsThis(Util::makeWhatThis("file_menu.html"));
+ connect(exit_act, &QAction::triggered, qApp, &QApplication::closeAllWindows);
if (show_menu)
+ {
file_menu = menuBar()->addMenu(tr("&File"));
+ }
else
{
delete file_menu;
file_menu = new QMenu(this);
}
- file_menu->setWhatsThis("See more");
+ file_menu->setWhatsThis(Util::makeWhatThis("file_menu.html"));
file_menu->addAction(new_act);
file_menu->addAction(open_act);
file_menu->addAction(save_act);
@@ -300,38 +294,34 @@ void MainWindow::createFileMenu()
file_menu->addAction(exit_act);
general_toolbar = new QToolBar(tr("General"));
- general_toolbar->setObjectName("General toolbar");
+ general_toolbar->setObjectName(QString::fromLatin1("General toolbar"));
general_toolbar->addAction(new_act);
general_toolbar->addAction(open_act);
general_toolbar->addAction(save_act);
- save_act->setEnabled(false);
- save_as_act->setEnabled(false);
- close_act->setEnabled(false);
+ save_act->setEnabled(has_opened_file);
+ save_as_act->setEnabled(has_opened_file);
+ close_act->setEnabled(has_opened_file);
updateRecentFileActions();
}
void MainWindow::createHelpMenu()
{
// Help menu
- QAction* manualAct = new QAction(QIcon(":/images/help.png"), tr("Open &Manual"), this);
+ QAction* manualAct = new QAction(QIcon(QString::fromLatin1(":/images/help.png")), tr("Open &Manual"), this);
manualAct->setStatusTip(tr("Show the help file for this application"));
manualAct->setShortcut(QKeySequence::HelpContents);
- connect(manualAct, SIGNAL(triggered()), this, SLOT(showHelp()));
+ connect(manualAct, &QAction::triggered, this, &MainWindow::showHelp);
- QAction* aboutAct = new QAction(tr("&About %1").arg(APP_NAME), this);
+ QAction* aboutAct = new QAction(tr("&About %1").arg(appName()), this);
aboutAct->setStatusTip(tr("Show information about this application"));
-#if defined(Q_OS_MAC)
aboutAct->setMenuRole(QAction::AboutRole);
-#endif
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(showAbout()));
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::showAbout);
QAction* aboutQtAct = new QAction(tr("About &Qt"), this);
aboutQtAct->setStatusTip(tr("Show information about Qt"));
-#if defined(Q_OS_MAC)
aboutQtAct->setMenuRole(QAction::AboutQtRole);
-#endif
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(aboutQtAct, &QAction::triggered, qApp, QApplication::aboutQt);
if (show_menu)
{
@@ -346,11 +336,19 @@ void MainWindow::createHelpMenu()
void MainWindow::setCurrentPath(const QString& path)
{
- if (current_path != path)
+ Q_ASSERT(has_opened_file || path.isEmpty());
+
+ QString window_file_path;
+ current_path.clear();
+ if (has_opened_file)
{
- current_path = QFileInfo(path).canonicalFilePath();
- updateWindowTitle();
+ window_file_path = QFileInfo(path).canonicalFilePath();
+ if (window_file_path.isEmpty())
+ window_file_path = tr("Unsaved file");
+ else
+ current_path = window_file_path;
}
+ setWindowFilePath(window_file_path);
}
void MainWindow::setMostRecentlyUsedFile(const QString& path)
@@ -361,7 +359,7 @@ void MainWindow::setMostRecentlyUsedFile(const QString& path)
// Update least recently used directory
const QString open_directory = QFileInfo(path).canonicalPath();
- QSettings().setValue("openFileDirectory", open_directory);
+ QSettings().setValue(QString::fromLatin1("openFileDirectory"), open_directory);
// Update recent file lists
QStringList files = settings.getSettingCached(Settings::General_RecentFilesList).toStringList();
@@ -373,32 +371,14 @@ void MainWindow::setMostRecentlyUsedFile(const QString& path)
}
}
-void MainWindow::setHasOpenedFile(bool value)
+void MainWindow::setHasUnsavedChanges(bool value)
{
- if (create_menu)
+ if (hasOpenedFile())
{
- if (value && !has_opened_file)
- {
- save_act->setEnabled(true);
- save_as_act->setEnabled(true);
- close_act->setEnabled(true);
- }
- else if (!value && has_opened_file)
- {
- save_act->setEnabled(false);
- save_as_act->setEnabled(false);
- close_act->setEnabled(false);
- }
+ has_unsaved_changes = value;
+ setAutosaveNeeded(has_unsaved_changes && !has_autosave_conflict);
}
- has_opened_file = value;
- updateWindowTitle();
-}
-
-void MainWindow::setHasUnsavedChanges(bool value)
-{
- has_unsaved_changes = value;
- setAutosaveNeeded(has_unsaved_changes && !has_autosave_conflict);
- updateWindowTitle();
+ setWindowModified(has_unsaved_changes);
}
void MainWindow::setStatusBarText(const QString& text)
@@ -429,6 +409,11 @@ void MainWindow::clearStatusBarMessage()
#endif
}
+void MainWindow::setShortcutsBlocked(bool blocked)
+{
+ shortcuts_blocked = blocked;
+}
+
bool MainWindow::closeFile()
{
bool closed = !has_opened_file || showSaveOnCloseDialog();
@@ -449,7 +434,7 @@ bool MainWindow::closeFile()
bool MainWindow::event(QEvent* event)
{
- if (event->type() == QEvent::ShortcutOverride && disable_shortcuts)
+ if (event->type() == QEvent::ShortcutOverride && shortcutsBlocked())
event->accept();
return QMainWindow::event(event);
@@ -512,13 +497,13 @@ bool MainWindow::showSaveOnCloseDialog()
QMessageBox::StandardButton ret;
if (!has_unsaved_changes && actual_path != autosavePath(currentPath()))
{
- ret = QMessageBox::warning(this, APP_NAME,
+ ret = QMessageBox::warning(this, appName(),
tr("Do you want to remove the autosaved version?"),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
}
else
{
- ret = QMessageBox::warning(this, APP_NAME,
+ ret = QMessageBox::warning(this, appName(),
tr("The file has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
@@ -539,9 +524,9 @@ bool MainWindow::showSaveOnCloseDialog()
case QMessageBox::Save:
if (!save())
return false;
- // fall through
+ // fall through
- case QMessageBox::Yes:
+ case QMessageBox::Yes:
setHasAutosaveConflict(false);
removeAutosaveFile();
break;
@@ -565,10 +550,10 @@ void MainWindow::saveWindowSettings()
#if !defined(Q_OS_ANDROID)
QSettings settings;
- settings.beginGroup("MainWindow");
- settings.setValue("pos", pos());
- settings.setValue("size", size());
- settings.setValue("maximized", isMaximized());
+ settings.beginGroup(QString::fromLatin1("MainWindow"));
+ settings.setValue(QString::fromLatin1("pos"), pos());
+ settings.setValue(QString::fromLatin1("size"), size());
+ settings.setValue(QString::fromLatin1("maximized"), isMaximized());
settings.endGroup();
#endif
}
@@ -581,10 +566,10 @@ void MainWindow::loadWindowSettings()
#else
QSettings settings;
- settings.beginGroup("MainWindow");
- QPoint pos = settings.value("pos", QPoint(100, 100)).toPoint();
- QSize size = settings.value("size", QSize(800, 600)).toSize();
- bool maximized = settings.value("maximized", false).toBool();
+ settings.beginGroup(QString::fromLatin1("MainWindow"));
+ QPoint pos = settings.value(QString::fromLatin1("pos"), QPoint(100, 100)).toPoint();
+ QSize size = settings.value(QString::fromLatin1("size"), QSize(800, 600)).toSize();
+ bool maximized = settings.value(QString::fromLatin1("maximized"), false).toBool();
settings.endGroup();
move(pos);
@@ -598,37 +583,17 @@ MainWindow* MainWindow::findMainWindow(const QString& file_name)
{
QString canonical_file_path = QFileInfo(file_name).canonicalFilePath();
if (canonical_file_path.isEmpty())
- return NULL;
+ return nullptr;
- for (auto widget : qApp->topLevelWidgets())
+ const auto top_level_widgets = qApp->topLevelWidgets();
+ for (auto widget : top_level_widgets)
{
MainWindow* other = qobject_cast(widget);
if (other && other->currentPath() == canonical_file_path)
return other;
}
- return NULL;
-}
-
-void MainWindow::updateWindowTitle()
-{
- QString window_title = "";
-
- if (has_unsaved_changes)
- window_title += "(*)";
-
- if (has_opened_file)
- {
- const QString current_file_path = currentPath();
- if (current_file_path.isEmpty())
- window_title += tr("Unsaved file") + " - ";
- else
- window_title += QFileInfo(current_file_path).fileName() + " - ";
- }
-
- window_title += APP_NAME + " " + APP_VERSION;
-
- setWindowTitle(window_title);
+ return nullptr;
}
void MainWindow::showNewMapWizard()
@@ -643,28 +608,39 @@ void MainWindow::showNewMapWizard()
Map* new_map = new Map();
QString symbol_set_path = newMapDialog.getSelectedSymbolSetPath();
if (symbol_set_path.isEmpty())
+ {
new_map->setScaleDenominator(newMapDialog.getSelectedScale());
+ }
else
{
- new_map->loadFrom(symbol_set_path, this, NULL, true);
+ new_map->loadFrom(symbol_set_path, this, nullptr, true);
if (new_map->getScaleDenominator() != newMapDialog.getSelectedScale())
{
if (QMessageBox::question(this, tr("Warning"), tr("The selected map scale is 1:%1, but the chosen symbol set has a nominal scale of 1:%2.\n\nDo you want to scale the symbols to the selected scale?").arg(newMapDialog.getSelectedScale()).arg(new_map->getScaleDenominator()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
- double factor = new_map->getScaleDenominator() / (double)newMapDialog.getSelectedScale();
+ double factor = double(new_map->getScaleDenominator()) / newMapDialog.getSelectedScale();
new_map->scaleAllSymbols(factor);
}
new_map->setScaleDenominator(newMapDialog.getSelectedScale());
}
+
+ for (int i = new_map->getNumSymbols(); i > 0; i = qMin(i, new_map->getNumSymbols()))
+ {
+ --i;
+ auto symbol = new_map->getSymbol(i);
+ if (symbol->isHidden()
+ && !new_map->existsObjectWithSymbol(symbol))
+ {
+ new_map->deleteSymbol(i);
+ }
+ }
}
+ new_map->setHasUnsavedChanges(false);
+ new_map->undoManager().clear();
- MainWindow* new_window;
- if (has_opened_file)
- new_window = new MainWindow(true);
- else
- new_window = this;
- new_window->setController(new MapEditorController(MapEditorController::MapEditor, new_map));
+ MainWindow* new_window = hasOpenedFile() ? new MainWindow() : this;
+ new_window->setController(new MapEditorController(MapEditorController::MapEditor, new_map), QString());
new_window->show();
new_window->raise();
@@ -675,11 +651,8 @@ void MainWindow::showNewMapWizard()
void MainWindow::showOpenDialog()
{
QString path = getOpenFileName(this, tr("Open file"), FileFormat::AllFiles);
-
- if (path.isEmpty())
- return;
-
- openPath(path);
+ if (!path.isEmpty())
+ openPath(path);
}
bool MainWindow::openPath(const QString &path)
@@ -701,7 +674,7 @@ bool MainWindow::openPath(const QString &path)
// Check a blocker that prevents immediate re-opening of crashing files.
// Needed for stopping auto-loading a crashing file on startup.
- static const QString reopen_blocker = "open_in_progress";
+ static const QString reopen_blocker = QString::fromLatin1("open_in_progress");
QSettings settings;
const QString open_in_progress(settings.value(reopen_blocker).toString());
if (open_in_progress == path)
@@ -752,7 +725,7 @@ bool MainWindow::openPath(const QString &path)
MainWindow* open_window = this;
#if !defined(Q_OS_ANDROID)
if (has_opened_file)
- open_window = new MainWindow(true);
+ open_window = new MainWindow();
#endif
open_window->setController(new_controller, path);
@@ -770,14 +743,14 @@ bool MainWindow::openPath(const QString &path)
// Assuming large screen. Android handled above.
if (new_autosave_conflict)
{
- QDialog* autosave_dialog = new AutosaveDialog(path, autosave_path, new_actual_path, open_window, Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+ auto autosave_dialog = new AutosaveDialog(path, autosave_path, new_actual_path, open_window, Qt::WindowTitleHint | Qt::CustomizeWindowHint);
autosave_dialog->move(open_window->rect().right() - autosave_dialog->width(), open_window->rect().top());
autosave_dialog->show();
autosave_dialog->raise();
- connect(autosave_dialog, SIGNAL(pathSelected(QString)), open_window, SLOT(switchActualPath(QString)));
- connect(open_window, SIGNAL(actualPathChanged(QString)), autosave_dialog, SLOT(setSelectedPath(QString)));
- connect(open_window, SIGNAL(autosaveConflictResolved()), autosave_dialog, SLOT(autosaveConflictResolved()));
+ connect(autosave_dialog, &AutosaveDialog::pathSelected, open_window, &MainWindow::switchActualPath);
+ connect(open_window, &MainWindow::actualPathChanged, autosave_dialog, &AutosaveDialog::setSelectedPath);
+ connect(open_window, &MainWindow::autosaveConflictResolved, autosave_dialog, &AutosaveDialog::autosaveConflictResolved);
}
#endif
@@ -796,7 +769,7 @@ void MainWindow::switchActualPath(const QString& path)
int ret = QMessageBox::Ok;
if (has_unsaved_changes)
{
- ret = QMessageBox::warning(this, APP_NAME,
+ ret = QMessageBox::warning(this, appName(),
tr("The file has been modified.\n"
"Do you want to discard your changes?"),
QMessageBox::Discard | QMessageBox::Cancel);
@@ -826,15 +799,14 @@ void MainWindow::openPathLater(const QString& path)
void MainWindow::openPathBacklog()
{
- for (auto&& path : path_backlog)
+ for (const auto& path : qAsConst(path_backlog))
openPath(path);
path_backlog.clear();
}
void MainWindow::openRecentFile()
{
- QAction *action = qobject_cast(sender());
- if (action)
+ if (auto action = qobject_cast(sender()))
openPath(action->data().toString());
}
@@ -845,7 +817,7 @@ void MainWindow::updateRecentFileActions()
QStringList files = Settings::getInstance().getSettingCached(Settings::General_RecentFilesList).toStringList();
- int num_recent_files = qMin(files.size(), (int)max_recent_files);
+ int num_recent_files = qMin(files.size(), max_recent_files);
open_recent_menu->clear();
for (int i = 0; i < num_recent_files; ++i) {
@@ -942,7 +914,7 @@ bool MainWindow::savePath(const QString &path)
setHasAutosaveConflict(false);
removeAutosaveFile();
- if (path != current_path)
+ if (path != currentPath())
{
setCurrentPath(path);
removeAutosaveFile();
@@ -957,7 +929,7 @@ QString MainWindow::getOpenFileName(QWidget* parent, const QString& title, FileF
{
// Get the saved directory to start in, defaulting to the user's home directory.
QSettings settings;
- QString open_directory = settings.value("openFileDirectory", QDir::homePath()).toString();
+ QString open_directory = settings.value(QString::fromLatin1("openFileDirectory"), QDir::homePath()).toString();
// Build the list of supported file filters based on the file format registry
QString filters, extensions;
@@ -971,21 +943,21 @@ QString MainWindow::getOpenFileName(QWidget* parent, const QString& title, FileF
if (filters.isEmpty())
{
filters = format->filter();
- extensions = "*." % format->fileExtensions().join(" *.");
+ extensions = QLatin1String("*.") + format->fileExtensions().join(QString::fromLatin1(" *."));
}
else
{
- filters = filters % ";;" % format->filter();
- extensions = extensions % " *." % format->fileExtensions().join(" *.");
+ filters = filters + QLatin1String(";;") + format->filter();
+ extensions = extensions + QLatin1String(" *.") + format->fileExtensions().join(QString::fromLatin1(" *."));
}
}
}
filters =
- tr("All maps") % " (" % extensions % ");;" %
- filters % ";;";
+ tr("All maps") + QLatin1String(" (") + extensions + QLatin1String(");;") +
+ filters + QLatin1String(";;");
}
- filters += tr("All files") % " (*.*)";
+ filters += tr("All files") + QLatin1String(" (*.*)");
QString path = QFileDialog::getOpenFileName(parent, title, open_directory, filters);
QFileInfo info(path);
@@ -1004,7 +976,7 @@ bool MainWindow::showSaveAsDialog()
{
// revert to least recently used directory or home directory.
QSettings settings;
- save_directory = settings.value("openFileDirectory", QDir::homePath()).toString();
+ save_directory = settings.value(QString::fromLatin1("openFileDirectory"), QDir::homePath()).toString();
}
// Build the list of supported file filters based on the file format registry
@@ -1016,11 +988,11 @@ bool MainWindow::showSaveAsDialog()
if (filters.isEmpty())
filters = format->filter();
else
- filters = filters % ";;" % format->filter();
+ filters = filters + QLatin1String(";;") + format->filter();
}
}
- QString filter = NULL; // will be set to the selected filter by QFileDialog
+ QString filter; // will be set to the selected filter by QFileDialog
QString path = QFileDialog::getSaveFileName(this, tr("Save file"), save_directory, filters, &filter);
// On Windows, when the user enters "sample", we get "sample.omap *.xmap".
@@ -1029,7 +1001,7 @@ bool MainWindow::showSaveAsDialog()
// This results in an error later, because "*" is not a valid character.
// But it is reasonable to apply the workaround to all platforms,
// due to the special meaning of "*" in shell patterns.
- const int extensions_quirk = path.indexOf(" *.");
+ const int extensions_quirk = path.indexOf(QLatin1String(" *."));
if (extensions_quirk >= 0)
{
path.truncate(extensions_quirk);
@@ -1039,11 +1011,11 @@ bool MainWindow::showSaveAsDialog()
return false;
const FileFormat *format = FileFormats.findFormatByFilter(filter);
- if (NULL == format)
+ if (!format)
{
QMessageBox::information(this, tr("Error"),
- tr("File could not be saved:") % "\n" %
- tr("There was a problem in determining the file format.") % "\n\n" %
+ tr("File could not be saved:") + QLatin1Char('\n') +
+ tr("There was a problem in determining the file format.") + QLatin1Char('\n') + QLatin1Char('\n') +
tr("Please report this as a bug.") );
return false;
}
@@ -1051,11 +1023,11 @@ bool MainWindow::showSaveAsDialog()
// Ensure that the provided filename has a correct file extension.
// Among other things, this will ensure that FileFormats.formatForFilename()
// returns the same thing the user selected in the dialog.
-// QString selected_extension = "." % format->primaryExtension();
+// QString selected_extension = "." + format->primaryExtension();
QStringList selected_extensions(format->fileExtensions());
- selected_extensions.replaceInStrings(QRegExp("^"), ".");
+ selected_extensions.replaceInStrings(QRegExp(QString::fromLatin1("^")), QString::fromLatin1("."));
bool has_extension = false;
- for (auto selected_extension : selected_extensions)
+ for (auto selected_extension : qAsConst(selected_extensions))
{
if (path.endsWith(selected_extension, Qt::CaseInsensitive))
{
@@ -1064,7 +1036,7 @@ bool MainWindow::showSaveAsDialog()
}
}
if (!has_extension)
- path.append(".").append(format->primaryExtension());
+ path += QLatin1Char('.') + format->primaryExtension();
// Ensure that the file name matches the format.
Q_ASSERT(format->fileExtensions().contains(QFileInfo(path).suffix()));
// Fails when using different formats for import and export:
@@ -1077,13 +1049,9 @@ void MainWindow::toggleFullscreenMode()
{
if (isFullScreen())
{
+ showNormal();
if (maximized_before_fullscreen)
- {
- showNormal();
showMaximized();
- }
- else
- showNormal();
}
else
{
@@ -1107,7 +1075,7 @@ void MainWindow::showAbout()
void MainWindow::showHelp()
{
#ifdef Q_OS_ANDROID
- const QString manual_path = MapperResource::locate(MapperResource::MANUAL, "index.html");
+ const QString manual_path = MapperResource::locate(MapperResource::MANUAL, QString::fromLatin1("index.html"));
const QUrl help_url = QUrl::fromLocalFile(manual_path);
TextBrowserDialog help_dialog(help_url, this);
help_dialog.exec();
@@ -1118,16 +1086,16 @@ void MainWindow::showHelp()
void MainWindow::linkClicked(const QString &link)
{
- if (link.compare("settings:", Qt::CaseInsensitive) == 0)
+ if (link.compare(QLatin1String("settings:"), Qt::CaseInsensitive) == 0)
showSettings();
- else if (link.compare("help:", Qt::CaseInsensitive) == 0)
+ else if (link.compare(QLatin1String("help:"), Qt::CaseInsensitive) == 0)
showHelp();
- else if (link.compare("about:", Qt::CaseInsensitive) == 0)
+ else if (link.compare(QLatin1String("about:"), Qt::CaseInsensitive) == 0)
showAbout();
- else if (link.startsWith("examples:", Qt::CaseInsensitive))
+ else if (link.startsWith(QLatin1String("examples:"), Qt::CaseInsensitive))
{
auto example = link.midRef(9);
- openPathLater(MapperResource::locate(MapperResource::EXAMPLE) % '/' % example);
+ openPathLater(MapperResource::locate(MapperResource::EXAMPLE) + QLatin1Char('/') + example);
}
else
QDesktopServices::openUrl(link);
@@ -1142,13 +1110,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event)
case QEvent::WhatsThisClicked:
{
QWhatsThisClickedEvent* e = static_cast(event);
- QStringList parts = e->href().split("#");
- if(parts.size() == 0)
- Util::showHelp(this);
- else if(parts.size() == 1)
- Util::showHelp(this, parts.at(0));
- else if(parts.size() == 2)
- Util::showHelp(this, parts.at(0), parts.at(1));
+ Util::showHelp(this, e->href());
};
break;
#if defined(Q_OS_ANDROID)
diff --git a/src/gui/main_window.h b/src/gui/main_window.h
index 6e462781a..38fba7f8e 100644
--- a/src/gui/main_window.h
+++ b/src/gui/main_window.h
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
- * Copyright 2014 Thomas Schöps, Kai Pastor
+ * Copyright 2013-2016 Kai Pastor
*
* This file is part of OpenOrienteering.
*
@@ -19,8 +19,8 @@
*/
-#ifndef _OPENORIENTEERING_MAIN_WINDOW_H_
-#define _OPENORIENTEERING_MAIN_WINDOW_H_
+#ifndef OPENORIENTEERING_MAIN_WINDOW_H
+#define OPENORIENTEERING_MAIN_WINDOW_H
#include
@@ -35,96 +35,137 @@ QT_END_NAMESPACE
class MainWindowController;
-/** The MainWindow class provides the generic application window.
- * It always has an active controller (class MainWindowController)
- * which provides the specific window content and behaviours.
- * The controller can be exchanged while the window is visible.
+/**
+ * The MainWindow class provides the generic application window.
+ *
+ * It always has an active controller (class MainWindowController)
+ * which provides the specific window content and behaviours.
+ * The controller can be exchanged while the window is visible.
*/
class MainWindow : public QMainWindow, private Autosave
{
Q_OBJECT
public:
- /** Creates a new main window.
- * FIXME: as_main_window seems to be contradictory and is used only
- * with value false (in SymbolSettingDialog).
- * @param as_main_window if false, disables the loading of save windows geometry and hides the bottom-right handle for resizing.
+ /**
+ * Creates a new main window.
+ */
+ explicit MainWindow(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
+
+private:
+ /**
+ * Creates a new main window.
+ *
+ * The flag as_main_window is a contradiction to the general intent of this
+ * class. The value fals is used only once, in SymbolSettingDialog. For this
+ * case, it disables some features such as the main menu.
+ *
+ * \todo Refactor to remove the flag as_main_window.
*/
- explicit MainWindow(bool as_main_window = true);
+ explicit MainWindow(bool as_main_window, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
+
+ friend class SymbolSettingDialog;
+public:
/** Destroys a main window. */
- virtual ~MainWindow();
+ ~MainWindow() override;
- /** Returns the application's name. */
- const QString& appName() const;
+ /** Returns the application's localized name. */
+ QString appName() const;
/**
* Returns whether the window is operating in mobile mode.
*
- * Mobile mode is the default on Android. The default may be overwritten by
+ * On the desktop, the default (desktop) mode may be overwritten by
* setting the environment variable MAPPER_MOBILE_GUI to 0 or 1.
+ *
+ * For Android, this evaluates to constexpr true so that the compiler
+ * may optimize away desktop code in conditional blocks.
*/
- bool mobileMode() const;
+#ifndef Q_OS_ANDROID
+ static bool mobileMode();
+#else
+ static constexpr bool mobileMode() { return true; }
+#endif
+
+ /**
+ * Changes the controller.
+ *
+ * The new controller does not edit a file.
+ */
+ void setController(MainWindowController* new_controller);
- /** Change the controller to new_controller. */
- void setController(MainWindowController* new_controller, const QString& path = QString());
+ /**
+ * Changes the controller.
+ *
+ * The new controller edits the file with the given path.
+ * The path may be empty for a new (unnamed) file.
+ */
+ void setController(MainWindowController* new_controller, const QString& path);
+private:
+ void setController(MainWindowController* new_controller, bool has_file);
+
+public:
/** Returns the current controller. */
- inline MainWindowController* getController() const {return controller;}
+ MainWindowController* getController() const;
/** Returns the canonical path of the currently open file or
* an empty string if no file is open.
*/
- inline const QString& currentPath() const {return current_path;}
+ const QString& currentPath() const;
- /** @brief Registers the given path as most recently used file.
+ /** Registers the given path as most recently used file.
+ *
* The path is added at (or moved to) the top of the list of most recently
* used files, and the directory is saved as most recently used directory.
*/
static void setMostRecentlyUsedFile(const QString& path);
- /** Sets the opened-file state to value. */
- void setHasOpenedFile(bool value);
-
/** Returns true if a file is opened in this main window. */
- inline bool hasOpenedFile() const {return has_opened_file;}
+ bool hasOpenedFile() const;
/** Returns true if the opened file is marked as having unsaved changes. */
- inline bool hasUnsavedChanges() const {return has_unsaved_changes;}
+ bool hasUnsavedChanges() const;
/** Sets the text in the status bar. */
void setStatusBarText(const QString& text);
+
/** Shows a temporary message in the status bar. */
void showStatusBarMessage(const QString& text, int timeout = 0);
+
/** Clears temporary messages set in the status bar with showStatusBarMessage(). */
void clearStatusBarMessage();
- /** Enable or disable shortcuts.
- * During text input, it may be neccessary to disable shortcuts.
- * @param enable true for enabling shortcuts, false for disabling.
+ /**
+ * Blocks shortcuts.
+ *
+ * During text input, it may be neccessary to disable shortcuts.
+ *
+ * @param blocked true for blocking shortcuts, false for normal behaviour.
*/
- inline void setShortcutsEnabled(bool enable) {disable_shortcuts = !enable;}
+ void setShortcutsBlocked(bool blocked);
/** Returns true if shortcuts are currently disabled. */
- inline bool areShortcutsDisabled() const {return disable_shortcuts;}
+ bool shortcutsBlocked() const;
/** Returns the main window's file menu so that it can be extended. */
- inline QMenu* getFileMenu() const {return file_menu;}
+ QMenu* getFileMenu() const;
/** Returns an QAction which serves as extension point in the file menu. */
- inline QAction* getFileMenuExtensionAct() const {return settings_act;}
+ QAction* getFileMenuExtensionAct() const;
/** Returns the save action. */
- inline QAction* getSaveAct() const {return save_act;}
+ QAction* getSaveAct() const;
/** Returns the close action. */
- inline QAction* getCloseAct() const {return close_act;}
+ QAction* getCloseAct() const;
/**
@@ -133,7 +174,7 @@ Q_OBJECT
* The MainWindowController is responsible to add it to the main window.
* It will be destroyed (and recreated) when the controller changes.
*/
- inline QToolBar* getGeneralToolBar() const { return general_toolbar; }
+ QToolBar* getGeneralToolBar() const;
/** Open the file with the given path after all events have been processed.
@@ -155,6 +196,7 @@ Q_OBJECT
/**
* Sets the MainWindow's effective central widget.
+ *
* Any previously set widget will be hidden and scheduled for deletion.
*
* Hides an implementation in QMainWindow which causes problems with
@@ -181,50 +223,65 @@ Q_OBJECT
void setHomeScreenDisabled(bool disabled);
public slots:
- /** Show a wizard for creating new maps.
- * May open a new main window.
+ /**
+ * Show a wizard for creating new maps.
+ *
+ * May open a new main window.
*/
void showNewMapWizard();
- /** Show a file-open dialog and load the select file.
- * May open a new main window.
- * If loading is successful, the selected path will become
- * the [new] window's current path.
+ /**
+ * Show a file-open dialog and load the select file.
+ *
+ * May open a new main window.
+ * If loading is successful, the selected path will become
+ * the [new] window's current path.
*/
void showOpenDialog();
- /** Show a file-save dialog.
- * If saving is successful, the selected path will become
- * this window's current path.
- * @return true if saving was succesful, false otherwise
+ /**
+ * Show a file-save dialog.
+ *
+ * If saving is successful, the selected path will become
+ * this window's current path.
+ *
+ * @return true if saving was succesful, false otherwise
*/
bool showSaveAsDialog();
- /** Open the file with the given path.
- * May open a new main window.
- * If loading is successful, the selected path will become
- * the [new] window's current path.
- * @return true if loading was succesful, false otherwise
+ /**
+ * Open the file with the given path.
+ *
+ * May open a new main window.
+ * If loading is successful, the selected path will become
+ * the [new] window's current path.
+ *
+ * @return true if loading was succesful, false otherwise
*/
bool openPath(const QString &path);
- /** Open the file specified in the sending action's data.
- * This is intended for opening recent files.
+ /**
+ * Open the file specified in the sending action's data.
+ *
+ * This is intended for opening recent files.
*/
void openRecentFile();
- /** Notify the main window of a change to the list of recent files.
+ /**
+ * Notify the main window of a change to the list of recent files.
*/
void updateRecentFileActions();
- /** Save the current content to the current path.
- * This will trigger a file-save dialog if the current path is not set (i.e. empty).
+ /**
+ * Save the current content to the current path.
+ *
+ * This will trigger a file-save dialog if the current path is not set (i.e. empty).
*/
bool save();
/** Save the current content to the current path.
*/
- virtual Autosave::AutosaveResult autosave();
+ Autosave::AutosaveResult autosave() override;
/**
* Close the file currently opened.
@@ -264,6 +321,11 @@ public slots:
/**
* Notifies this window of unsaved changes.
+ *
+ * If the controller was set as having an opened file, setting this value to
+ * true will start the autosave countdown if the previous value was false.
+ *
+ * This will update the window title via QWidget::setWindowModified().
*/
void setHasUnsavedChanges(bool value);
@@ -310,16 +372,17 @@ protected slots:
protected:
/**
- * @brief Sets the path of the file edited by this windows' controller.
+ * Sets the path of the file edited by this windows' controller.
*
- * This will trigger updates to the window title,
- * to the list of recently used files, and
- * to the least recently used directory.
+ * This will update the window title via QWidget::setWindowFilePath().
+ *
+ * If the controller was not set as having an opened file,
+ * the path must be empty.
*/
void setCurrentPath(const QString& path);
/**
- * @brief Notifies the windows of autosave conflicts.
+ * Notifies the windows of autosave conflicts.
*
* An autosave conflict is the situation where a autosaved file exists
* when the original file is opened. This autosaved file indicates that
@@ -329,28 +392,30 @@ protected slots:
void setHasAutosaveConflict(bool value);
/**
- * @brief Removes the autosave file if it exists.
+ * Removes the autosave file if it exists.
*
* Returns true if the file was removed or didn't exist, false otherwise.
*/
bool removeAutosaveFile() const;
- virtual bool event(QEvent* event);
- virtual void closeEvent(QCloseEvent *event);
- virtual void keyPressEvent(QKeyEvent* event);
- virtual void keyReleaseEvent(QKeyEvent* event);
+ bool event(QEvent* event) override;
+ void closeEvent(QCloseEvent *event) override;
+ void keyPressEvent(QKeyEvent* event) override;
+ void keyReleaseEvent(QKeyEvent* event) override;
- virtual bool eventFilter(QObject* object, QEvent* event);
+ bool eventFilter(QObject* object, QEvent* event) override;
private:
- enum {
- max_recent_files = 10
- };
+ static constexpr int max_recent_files = 10;
- /** If this main window has an opened file with unsaved changes, shows
- * a dialog which lets the user save the file, discard the changes or
- * cancel.
- * Returns true if the window can be closed, false otherwise.
+ /**
+ * Conditionally shows a dialog for saving pending changes.
+ *
+ * If this main window has an opened file with unsaved changes, shows
+ * a dialog which lets the user save the file, discard the changes or
+ * cancel.
+ *
+ * Returns true if the window can be closed, false otherwise.
*/
bool showSaveOnCloseDialog();
@@ -362,8 +427,6 @@ protected slots:
void loadWindowSettings();
- void updateWindowTitle();
-
void createFileMenu();
void createHelpMenu();
@@ -372,14 +435,13 @@ protected slots:
/// The active controller
MainWindowController* controller;
- bool create_menu;
+ const bool create_menu;
bool show_menu;
- bool disable_shortcuts;
+ bool shortcuts_blocked;
QToolBar* general_toolbar;
QMenu* file_menu;
QAction* save_act;
- QAction* save_as_act;
QMenu* open_recent_menu;
bool open_recent_menu_inserted;
QAction* recent_file_act[max_recent_files];
@@ -416,6 +478,66 @@ protected slots:
// ### MainWindow inline code ###
+inline
+MainWindowController* MainWindow::getController() const
+{
+ return controller;
+}
+
+inline
+const QString& MainWindow::currentPath() const
+{
+ return current_path;
+}
+
+inline
+bool MainWindow::hasOpenedFile() const
+{
+ return has_opened_file;
+}
+
+inline
+bool MainWindow::hasUnsavedChanges() const
+{
+ return has_unsaved_changes;
+}
+
+inline
+bool MainWindow::shortcutsBlocked() const
+{
+ return shortcuts_blocked;
+}
+
+inline
+QMenu* MainWindow::getFileMenu() const
+{
+ return file_menu;
+}
+
+inline
+QAction* MainWindow::getFileMenuExtensionAct() const
+{
+ return settings_act;
+}
+
+inline
+QAction* MainWindow::getSaveAct() const
+{
+ return save_act;
+}
+
+inline
+QAction* MainWindow::getCloseAct() const
+{
+ return close_act;
+}
+
+inline
+QToolBar* MainWindow::getGeneralToolBar() const
+{
+ return general_toolbar;
+}
+
inline
bool MainWindow::homeScreenDisabled() const
{
diff --git a/src/gui/print_widget.cpp b/src/gui/print_widget.cpp
index 5e3186eb4..fe6b92faa 100644
--- a/src/gui/print_widget.cpp
+++ b/src/gui/print_widget.cpp
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
- * Copyright 2012-2015 Kai Pastor
+ * Copyright 2012-2016 Kai Pastor
*
* This file is part of OpenOrienteering.
*
@@ -45,8 +45,11 @@
#include
#include
+#include
+
#include "main_window.h"
#include "print_progress_dialog.h"
+#include "print_tool.h"
#include "../core/map_printer.h"
#include "../map.h"
#include "../map_editor.h"
@@ -54,13 +57,13 @@
#include "../settings.h"
#include "../util.h"
#include "../util_gui.h"
+#include "../util/backports.h"
#include "../util/scoped_signals_blocker.h"
-#include "print_tool.h"
namespace
{
- QToolButton* createPrintModeButton(const QIcon& icon, const QString& label, QWidget* parent = NULL)
+ QToolButton* createPrintModeButton(const QIcon& icon, const QString& label, QWidget* parent = nullptr)
{
static const QSize icon_size(48,48);
QToolButton* button = new QToolButton(parent);
@@ -77,17 +80,17 @@ namespace
//### PrintWidget ###
PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view, MapEditorController* editor, QWidget* parent)
-: QWidget(parent),
- task(UNDEFINED_TASK),
- map(map),
- map_printer(new MapPrinter(*map, main_view)),
- main_window(main_window),
- main_view(main_view),
- editor(editor),
- print_tool(NULL),
- active(false)
+: QWidget { parent }
+, task { UNDEFINED_TASK }
+, map { map }
+, map_printer { new MapPrinter(*map, main_view) }
+, main_window { main_window }
+, main_view { main_view }
+, editor { editor }
+, print_tool { nullptr }
+, active { false }
{
- Q_ASSERT(main_window != NULL);
+ Q_ASSERT(main_window);
layout = new QFormLayout();
@@ -95,6 +98,17 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
target_combo->setMinimumWidth(1); // Not zero, but not as long as the items
layout->addRow(Util::Headline::create(tr("Printer:")), target_combo);
+ if (PlatformPrinterProperties::dialogSupported())
+ {
+ printer_properties_button = new QToolButton();
+ printer_properties_button->setText(tr("Properties"));
+ layout->addRow(nullptr, printer_properties_button);
+ }
+ else
+ {
+ printer_properties_button = nullptr;
+ }
+
paper_size_combo = new QComboBox();
layout->addRow(tr("Page format:"), paper_size_combo);
@@ -105,11 +119,11 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
page_width_edit = Util::SpinBox::create(1, 0.1, 1000.0, tr("mm"), 1.0);
page_width_edit->setEnabled(false);
page_size_layout->addWidget(page_width_edit, 1);
- page_size_layout->addWidget(new QLabel("x"), 0);
+ page_size_layout->addWidget(new QLabel(QString::fromLatin1("x")), 0);
page_height_edit = Util::SpinBox::create(1, 0.1, 1000.0, tr("mm"), 1.0);
page_height_edit->setEnabled(false);
page_size_layout->addWidget(page_height_edit, 1);
- layout->addRow("", page_size_widget);
+ layout->addRow({}, page_size_widget);
page_orientation_widget = new QWidget();
QBoxLayout* page_orientation_layout = new QHBoxLayout();
@@ -161,9 +175,9 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
mode_widget->setLayout(mode_layout);
mode_layout->setMargin(0);
- vector_mode_button = createPrintModeButton(QIcon(":/images/print-mode-vector.png"), tr("Vector\ngraphics"));
- raster_mode_button = createPrintModeButton(QIcon(":/images/print-mode-raster.png"), tr("Raster\ngraphics"));
- separations_mode_button = createPrintModeButton(QIcon(":/images/print-mode-separations.png"), tr("Color\nseparations"));
+ vector_mode_button = createPrintModeButton(QIcon(QString::fromLatin1(":/images/print-mode-vector.png")), tr("Vector\ngraphics"));
+ raster_mode_button = createPrintModeButton(QIcon(QString::fromLatin1(":/images/print-mode-raster.png")), tr("Raster\ngraphics"));
+ separations_mode_button = createPrintModeButton(QIcon(QString::fromLatin1(":/images/print-mode-separations.png")), tr("Color\nseparations"));
vector_mode_button->setChecked(true);
QButtonGroup* mode_button_group = new QButtonGroup(this);
@@ -180,15 +194,15 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
dpi_combo = new QComboBox();
dpi_combo->setEditable(true);
- dpi_combo->setValidator(new QRegExpValidator(QRegExp("^[1-9]\\d{1,4} dpi$|^[1-9]\\d{1,4}$"), dpi_combo));
+ dpi_combo->setValidator(new QRegExpValidator(QRegExp(QString::fromLatin1("^[1-9]\\d{1,4} dpi$|^[1-9]\\d{1,4}$")), dpi_combo));
// TODO: Implement spinbox-style " dpi" suffix
layout->addRow(tr("Resolution:"), dpi_combo);
different_scale_check = new QCheckBox(tr("Print in different scale:"));
// Limit the difference between nominal and printing scale in order to limit the number of page breaks.
- int min_scale = qMax((unsigned int)1, map->getScaleDenominator() / 10000 * 100);
- different_scale_edit = Util::SpinBox::create(min_scale, std::numeric_limits::max(), "", 500);
- different_scale_edit->setPrefix("1 : ");
+ int min_scale = qMax(1, int(map->getScaleDenominator() / 10000) * 100);
+ different_scale_edit = Util::SpinBox::create(min_scale, std::numeric_limits::max(), {}, 500);
+ different_scale_edit->setPrefix(QString::fromLatin1("1 : "));
different_scale_edit->setEnabled(false);
int different_scale_height = qMax(
different_scale_edit->minimumSizeHint().height(),
@@ -255,53 +269,54 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
setLayout(outer_layout);
- connect(target_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(targetChanged(int)));
- connect(paper_size_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(paperSizeChanged(int)));
- connect(page_width_edit, SIGNAL(valueChanged(double)), this, SLOT(paperDimensionsChanged()));
- connect(page_orientation_group, SIGNAL(buttonClicked(int)), this, SLOT(pageOrientationChanged(int)));
- connect(page_height_edit, SIGNAL(valueChanged(double)), this, SLOT(paperDimensionsChanged()));
-
- connect(top_edit, SIGNAL(valueChanged(double)), this, SLOT(printAreaMoved()));
- connect(left_edit, SIGNAL(valueChanged(double)), this, SLOT(printAreaMoved()));
- connect(width_edit, SIGNAL(valueChanged(double)), this, SLOT(printAreaResized()));
- connect(height_edit, SIGNAL(valueChanged(double)), this, SLOT(printAreaResized()));
- connect(overlap_edit, SIGNAL(valueChanged(double)), this, SLOT(overlapEdited(double)));
-
- connect(mode_button_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(printModeChanged(QAbstractButton*)));
- connect(dpi_combo->lineEdit(), SIGNAL(editingFinished()), this, SLOT(resolutionEdited()));
- connect(different_scale_check, SIGNAL(clicked(bool)), this, SLOT(differentScaleClicked(bool)));
- connect(different_scale_edit, SIGNAL(valueChanged(int)), this, SLOT(differentScaleEdited(int)));
- connect(show_templates_check, SIGNAL(clicked(bool)), this, SLOT(showTemplatesClicked(bool)));
- connect(show_grid_check, SIGNAL(clicked(bool)), this, SLOT(showGridClicked(bool)));
- connect(overprinting_check, SIGNAL(clicked(bool)), this, SLOT(overprintingClicked(bool)));
+ connect(target_combo, QOverload::of(&QComboBox::currentIndexChanged), this, &PrintWidget::targetChanged);
+ if (printer_properties_button)
+ connect(printer_properties_button, &QAbstractButton::clicked, this, &PrintWidget::propertiesClicked, Qt::QueuedConnection);
+ connect(paper_size_combo, QOverload::of(&QComboBox::currentIndexChanged), this, &PrintWidget::paperSizeChanged);
+ connect(page_width_edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &PrintWidget::paperDimensionsChanged);
+ connect(page_orientation_group, QOverload