1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 09:05:14 +01:00

Fixed options/settings handling isses.

This commit is contained in:
Martin Tůma 2016-12-06 21:02:44 +01:00
parent 4cf027df58
commit 34e48199b2
4 changed files with 56 additions and 23 deletions

View File

@ -70,6 +70,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
setWindowIcon(QIcon(QPixmap(APP_ICON))); setWindowIcon(QIcon(QPixmap(APP_ICON)));
setWindowTitle(APP_NAME); setWindowTitle(APP_NAME);
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
setAcceptDrops(true);
_trackCount = 0; _trackCount = 0;
_routeCount = 0; _routeCount = 0;
@ -85,8 +86,6 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
updateStatusBarInfo(); updateStatusBarInfo();
readSettings(); readSettings();
setAcceptDrops(true);
} }
GUI::~GUI() GUI::~GUI()
@ -1271,7 +1270,9 @@ void GUI::writeSettings()
settings.endGroup(); settings.endGroup();
settings.beginGroup(SETTINGS_SETTINGS_GROUP); settings.beginGroup(SETTINGS_SETTINGS_GROUP);
settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked() if ((_imperialUnitsAction->isChecked() ? Imperial : Metric) !=
UNITS_DEFAULT)
settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked()
? Imperial : Metric); ? Imperial : Metric);
if (_showToolbarsAction->isChecked() != SHOW_TOOLBARS_DEFAULT) if (_showToolbarsAction->isChecked() != SHOW_TOOLBARS_DEFAULT)
settings.setValue(SHOW_TOOLBARS_SETTING, settings.setValue(SHOW_TOOLBARS_SETTING,
@ -1302,15 +1303,17 @@ void GUI::writeSettings()
if (_overlapPOIAction->isChecked() != OVERLAP_POI_DEFAULT) if (_overlapPOIAction->isChecked() != OVERLAP_POI_DEFAULT)
settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked()); settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked());
settings.remove(DISABLED_POI_FILE_SETTINGS_PREFIX); int j = 0;
settings.beginWriteArray(DISABLED_POI_FILE_SETTINGS_PREFIX); for (int i = 0; i < _poiFilesActions.count(); i++) {
for (int i = 0, j = 0; i < _poiFilesActions.count(); i++) {
if (!_poiFilesActions.at(i)->isChecked()) { if (!_poiFilesActions.at(i)->isChecked()) {
if (j == 0)
settings.beginWriteArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
settings.setArrayIndex(j++); settings.setArrayIndex(j++);
settings.setValue(DISABLED_POI_FILE_SETTING, _poi->files().at(i)); settings.setValue(DISABLED_POI_FILE_SETTING, _poi->files().at(i));
} }
} }
settings.endArray(); if (j != 0)
settings.endArray();
settings.endGroup(); settings.endGroup();
settings.beginGroup(DATA_SETTINGS_GROUP); settings.beginGroup(DATA_SETTINGS_GROUP);
@ -1513,16 +1516,35 @@ void GUI::readSettings()
(int)TRACK_STYLE_DEFAULT).toInt(); (int)TRACK_STYLE_DEFAULT).toInt();
_options.routeStyle = (Qt::PenStyle) settings.value(ROUTE_STYLE_SETTING, _options.routeStyle = (Qt::PenStyle) settings.value(ROUTE_STYLE_SETTING,
(int)ROUTE_STYLE_DEFAULT).toInt(); (int)ROUTE_STYLE_DEFAULT).toInt();
_options.graphWidth = settings.value(GRAPH_WIDTH_SETTING,
GRAPH_WIDTH_DEFAULT).toInt();
_options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT) _options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT)
.toBool(); .toBool();
_options.graphWidth = settings.value(GRAPH_WIDTH_SETTING,
GRAPH_WIDTH_DEFAULT).toInt();
_options.graphAntiAliasing = settings.value(GRAPH_AA_SETTING, _options.graphAntiAliasing = settings.value(GRAPH_AA_SETTING,
GRAPH_AA_DEFAULT).toBool(); GRAPH_AA_DEFAULT).toBool();
_options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT) _options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT)
.toInt(); .toInt();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT) _options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool(); .toBool();
_pathView->setPalette(_options.palette);
_pathView->setTrackWidth(_options.trackWidth);
_pathView->setRouteWidth(_options.routeWidth);
_pathView->setTrackStyle(_options.trackStyle);
_pathView->setRouteStyle(_options.routeStyle);
_pathView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
if (_options.useOpenGL)
_pathView->useOpenGL(true);
for (int i = 0; i < _tabs.count(); i++) {
_tabs.at(i)->setPalette(_options.palette);
_tabs.at(i)->setGraphWidth(_options.graphWidth);
_tabs.at(i)->setRenderHint(QPainter::Antialiasing,
_options.graphAntiAliasing);
}
_poi->setRadius(_options.poiRadius);
settings.endGroup(); settings.endGroup();
} }

View File

@ -36,3 +36,11 @@ void Palette::reset()
{ {
_state = _h; _state = _h;
} }
QDebug operator<<(QDebug dbg, const Palette &palette)
{
dbg.nospace() << "Palette(" << palette.color() << ", " << palette.shift()
<< ")";
return dbg.maybeSpace();
}

View File

@ -2,13 +2,14 @@
#define PALETTE_H #define PALETTE_H
#include <QColor> #include <QColor>
#include <QDebug>
class Palette class Palette
{ {
public: public:
Palette(const QColor &color = Qt::blue, qreal shift = 0.62); Palette(const QColor &color = Qt::blue, qreal shift = 0.62);
QColor color() const {return QColor::fromHsvF(_h, _s, _v, _a);} QColor color() const {return QColor::fromHsvF(_h, _s, _v, _a).toRgb();}
qreal shift() const {return _shift;} qreal shift() const {return _shift;}
void setColor(const QColor &color); void setColor(const QColor &color);
void setShift(qreal shift); void setShift(qreal shift);
@ -27,4 +28,6 @@ private:
qreal _state; qreal _state;
}; };
QDebug operator<<(QDebug dbg, const Palette &palette);
#endif // PALLETE_H #endif // PALLETE_H

View File

@ -1,6 +1,9 @@
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H
#define IMPERIAL_UNITS() \
(QLocale::system().measurementSystem() == QLocale::ImperialSystem)
#define WINDOW_SETTINGS_GROUP "Window" #define WINDOW_SETTINGS_GROUP "Window"
#define WINDOW_SIZE_SETTING "size" #define WINDOW_SIZE_SETTING "size"
#define WINDOW_SIZE_DEFAULT QSize(600, 800) #define WINDOW_SIZE_DEFAULT QSize(600, 800)
@ -9,9 +12,7 @@
#define SETTINGS_SETTINGS_GROUP "Settings" #define SETTINGS_SETTINGS_GROUP "Settings"
#define UNITS_SETTING "units" #define UNITS_SETTING "units"
#define UNITS_DEFAULT \ #define UNITS_DEFAULT (IMPERIAL_UNITS() ? Imperial : Metric)
(QLocale::system().measurementSystem() == QLocale::ImperialSystem) \
? Imperial : Metric
#define SHOW_TOOLBARS_SETTING "toolbar" #define SHOW_TOOLBARS_SETTING "toolbar"
#define SHOW_TOOLBARS_DEFAULT true #define SHOW_TOOLBARS_DEFAULT true
@ -54,20 +55,19 @@
#define PAPER_ORIENTATION_SETTING "orientation" #define PAPER_ORIENTATION_SETTING "orientation"
#define PAPER_ORIENTATION_DEFAULT QPrinter::Portrait #define PAPER_ORIENTATION_DEFAULT QPrinter::Portrait
#define PAPER_SIZE_SETTING "size" #define PAPER_SIZE_SETTING "size"
#define PAPER_SIZE_DEFAULT \ #define PAPER_SIZE_DEFAULT (IMPERIAL_UNITS() ? QPrinter::Letter \
(QLocale::system().measurementSystem() == QLocale::ImperialSystem) \ : QPrinter::A4)
? QPrinter::Letter : QPrinter::A4
#define MARGIN_LEFT_SETTING "marginLeft" #define MARGIN_LEFT_SETTING "marginLeft"
#define MARGIN_LEFT_DEFAULT 5 #define MARGIN_LEFT_DEFAULT 5 /* mm */
#define MARGIN_TOP_SETTING "marginTop" #define MARGIN_TOP_SETTING "marginTop"
#define MARGIN_TOP_DEFAULT 5 #define MARGIN_TOP_DEFAULT 5 /* mm */
#define MARGIN_RIGHT_SETTING "marginRight" #define MARGIN_RIGHT_SETTING "marginRight"
#define MARGIN_RIGHT_DEFAULT 5 #define MARGIN_RIGHT_DEFAULT 5 /* mm */
#define MARGIN_BOTTOM_SETTING "marginBottom" #define MARGIN_BOTTOM_SETTING "marginBottom"
#define MARGIN_BOTTOM_DEFAULT 5 #define MARGIN_BOTTOM_DEFAULT 5 /* mm */
#define EXPORT_FILENAME_SETTING "fileName" #define EXPORT_FILENAME_SETTING "fileName"
#define EXPORT_FILENAME_DEFAULT \ #define EXPORT_FILENAME_DEFAULT QString("%1/export.pdf"). \
QString("%1/export.pdf").arg(QDir::currentPath()) arg(QDir::currentPath())
#define OPTIONS_SETTINGS_GROUP "Options" #define OPTIONS_SETTINGS_GROUP "Options"
#define PALETTE_COLOR_SETTING "paletteColor" #define PALETTE_COLOR_SETTING "paletteColor"
@ -89,7 +89,7 @@
#define GRAPH_AA_SETTING "graphAntiAliasing" #define GRAPH_AA_SETTING "graphAntiAliasing"
#define GRAPH_AA_DEFAULT false #define GRAPH_AA_DEFAULT false
#define POI_RADIUS_SETTING "poiRadius" #define POI_RADIUS_SETTING "poiRadius"
#define POI_RADIUS_DEFAULT 1000 #define POI_RADIUS_DEFAULT 1000 /* m */
#define USE_OPENGL_SETTING "useOpenGL" #define USE_OPENGL_SETTING "useOpenGL"
#define USE_OPENGL_DEFAULT false #define USE_OPENGL_DEFAULT false