Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions core/Gridsquare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,32 @@ const QRegularExpression Gridsquare::gridExtRegEx()
}

double Gridsquare::distance2localeUnitDistance(double km,
QString &unit)
QString &unit,
const LogLocale &locale)
{
FCT_IDENTIFICATION;

unit = QObject::tr("km");
double ret = km;

// All imperial systems
if ( QLocale::system().measurementSystem() != QLocale::MetricSystem)
{
UnitFormat chosenUnit = locale.getSettingUnitFormat();
switch (chosenUnit) {
case UnitFormat::System:
// All imperial systems
if ( QLocale::system().measurementSystem() != QLocale::MetricSystem)
{
unit = QObject::tr("miles");
ret = km * localeDistanceCoef();
}
break;
case UnitFormat::Imperial:
unit = QObject::tr("miles");
ret = km * localeDistanceCoef();
break;
case UnitFormat::Metric:
break;
}

return ret;
}

Expand Down
4 changes: 3 additions & 1 deletion core/Gridsquare.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <QString>
#include <QDebug>

#include "core/LogLocale.h"

class Gridsquare
{
public:
Expand All @@ -14,7 +16,7 @@ class Gridsquare
static const QRegularExpression gridRegEx();
static const QRegularExpression gridVUCCRegEx();
static const QRegularExpression gridExtRegEx();
static double distance2localeUnitDistance(double km, QString &unit);
static double distance2localeUnitDistance(double km, QString &unit, const LogLocale &locale);
static double localeDistanceCoef();

bool isValid() const;
Expand Down
15 changes: 15 additions & 0 deletions core/LogLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ void LogLocale::setSettingUseSystemDateFormat(bool value)
settings.setValue("usesystemdateformat", value);
}

const UnitFormat LogLocale::getSettingUnitFormat() const
{
QVariant value = settings.value("useunitformat", unit_format);

int savedUnit = value.value<int>();
UnitFormat unit = static_cast<UnitFormat>(savedUnit);

return unit;
}

void LogLocale::setSettingUnitFormat(UnitFormat value)
{
settings.setValue("useunitformat", value);
}

const QString LogLocale::getSettingDateFormat() const
{
return settings.value("customdateformatstring", systemDateFormat).toString();
Expand Down
7 changes: 7 additions & 0 deletions core/LogLocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <QLocale>
#include <QRegularExpression>

enum UnitFormat { System, Imperial, Metric };

class LogLocale : public QLocale
{
public:
Expand All @@ -21,16 +23,21 @@ class LogLocale : public QLocale
bool getSettingUseSystemDateFormat() const;
void setSettingUseSystemDateFormat(bool value);

const UnitFormat getSettingUnitFormat() const;
void setSettingUnitFormat(UnitFormat value);

const QString getSettingDateFormat() const;
void setSettingDateFormat(const QString &value);

private:
const QRegularExpression regexp;
bool is24hUsed;
UnitFormat unit_format;
QSettings settings;
QString systemDateFormat;

void changeTime12_24Format(QString &formatString) const;
};


#endif // QLOG_CORE_LOGLOCALE_H
2 changes: 1 addition & 1 deletion ui/NewContactWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ void NewContactWidget::updateCoordinates(double lat, double lon, CoordPrecision
{
dxDistance = distance;
QString unit;
double showDistance = Gridsquare::distance2localeUnitDistance(dxDistance, unit);
double showDistance = Gridsquare::distance2localeUnitDistance(dxDistance, unit, locale);
double LPBearing = bearing - 180;

if ( LPBearing < 0 )
Expand Down
2 changes: 1 addition & 1 deletion ui/QSODetailDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ void QSODetailDialog::drawDXOnMap(const QString &label, const Gridsquare &dxGrid
double distance = 0;

if (dxGrid.distanceTo(myGrid, distance)) {
distance = Gridsquare::distance2localeUnitDistance(distance, unit);
distance = Gridsquare::distance2localeUnitDistance(distance, unit, locale);
popupString.append(QString("</br> %1 %2").arg(QString::number(distance, 'f', 0), unit));
}

Expand Down
33 changes: 33 additions & 0 deletions ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,24 @@ void SettingsDialog::readSettings() {
ui->timeFormat24RadioButton->setChecked(timeformat24);
ui->timeFormat12RadioButton->setChecked(!timeformat24);

UnitFormat unitFormat = locale.getSettingUnitFormat();
switch (unitFormat) {
case UnitFormat::System:
ui->unitFormatSystemRadioButton->setChecked(true);
ui->unitFormatImperialRadioButton->setChecked(false);
ui->unitFormatMetricRadioButton->setChecked(false);
break;
case UnitFormat::Imperial:
ui->unitFormatSystemRadioButton->setChecked(false);
ui->unitFormatImperialRadioButton->setChecked(true);
ui->unitFormatMetricRadioButton->setChecked(false);
break;
case UnitFormat::Metric:
ui->unitFormatSystemRadioButton->setChecked(false);
ui->unitFormatImperialRadioButton->setChecked(false);
ui->unitFormatMetricRadioButton->setChecked(true);
break;
}
bool dateSystemFormat = locale.getSettingUseSystemDateFormat();
ui->dateFormatSystemRadioButton->setChecked(dateSystemFormat);
ui->dateFormatCustomRadioButton->setChecked(!dateSystemFormat);
Expand Down Expand Up @@ -2486,12 +2504,27 @@ void SettingsDialog::writeSettings() {
/*******/
/* GUI */
/*******/
// Time format
locale.setSettingUse24hformat(ui->timeFormat24RadioButton->isChecked());

// Date format
bool systemDateChecked = ui->dateFormatSystemRadioButton->isChecked();
locale.setSettingUseSystemDateFormat(systemDateChecked);
if ( !systemDateChecked )
locale.setSettingDateFormat(ui->dateFormatStringEdit->text());

// Unit format
UnitFormat chosenUnit = getChosenUnitFormat();
locale.setSettingUnitFormat(chosenUnit);
}
UnitFormat SettingsDialog::getChosenUnitFormat() {
if (ui->unitFormatMetricRadioButton->isChecked()) {
return UnitFormat::Metric;
} else if (ui->unitFormatImperialRadioButton->isChecked()) {
return UnitFormat::Imperial;
} else {
return UnitFormat::System;
}
}

/* this function is called when user modify rig progile
Expand Down
2 changes: 2 additions & 0 deletions ui/SettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public slots:
QString getMemberListComboValue(const QComboBox *);
void generateMembershipCheckboxes();

UnitFormat getChosenUnitFormat();

QSqlTableModel* modeTableModel;
QSqlTableModel* bandTableModel;
StationProfilesManager *stationProfManager;
Expand Down
52 changes: 48 additions & 4 deletions ui/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>9</number>
</property>
<property name="documentMode">
<bool>false</bool>
Expand Down Expand Up @@ -3601,8 +3601,7 @@
<string>Browse</string>
</property>
<property name="icon">
<iconset theme="folder-open">
<normaloff>.</normaloff>.</iconset>
<iconset theme="folder-open"/>
</property>
</widget>
</item>
Expand Down Expand Up @@ -4366,6 +4365,51 @@
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_37" stretch="0,0,0,0">
<item>
<widget class="QRadioButton" name="unitFormatSystemRadioButton">
<property name="text">
<string>System</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="unitFormatImperialRadioButton">
<property name="text">
<string>Imperial</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="unitFormatMetricRadioButton">
<property name="text">
<string>Metric</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="unitSystemLabel">
<property name="text">
<string>Unit Format</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -5684,7 +5728,7 @@
<slot>updateDateFormatResult()</slot>
</slots>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
4 changes: 2 additions & 2 deletions ui/StatisticsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void StatisticsWidget::refreshGraph()
break;
case 2: // ODX
QString unit;
Gridsquare::distance2localeUnitDistance(0, unit);
Gridsquare::distance2localeUnitDistance(0, unit, locale);
QString distCoef = QString::number(Gridsquare::localeDistanceCoef());
QString sel = QString("SELECT callsign || '<br>' || CAST(ROUND(distance * %1,0) AS INT) || ' %2', gridsquare, my_gridsquare, ").arg(distCoef, unit);

Expand Down Expand Up @@ -735,7 +735,7 @@ void StatisticsWidget::setSubTypesCombo(int mainTypeIdx)
case 3:
{
QString unit;
Gridsquare::distance2localeUnitDistance(0, unit);
Gridsquare::distance2localeUnitDistance(0, unit, locale);
ui->statTypeSecCombo->addItem(tr("Distance") + QString(" [%1]").arg(unit));
}
break;
Expand Down
4 changes: 3 additions & 1 deletion ui/StyleItemDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class UnitFormatDelegate : public QStyledItemDelegate {
};

class DistanceFormatDelegate : public QStyledItemDelegate {
private:
LogLocale locale;
public:
DistanceFormatDelegate(int precision, double step, QObject* parent = 0) :
QStyledItemDelegate(parent), precision(precision), step(step) { }
Expand All @@ -218,7 +220,7 @@ class DistanceFormatDelegate : public QStyledItemDelegate {

QString displayText(const QVariant& value, const QLocale&) const {
QString unit;
double displayValue = Gridsquare::distance2localeUnitDistance(value.toDouble(), unit);
double displayValue = Gridsquare::distance2localeUnitDistance(value.toDouble(), unit, locale);
return QString("%1 %2").arg(QString::number(displayValue, 'f', precision), unit);
}

Expand Down
2 changes: 1 addition & 1 deletion ui/WsjtxFilterDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WsjtxFilterDialog::WsjtxFilterDialog(QWidget *parent) :
ui->setupUi(this);

QString unit;
Gridsquare::distance2localeUnitDistance(0, unit);
Gridsquare::distance2localeUnitDistance(0, unit, locale);
ui->distanceSpinBox->setSuffix(" " + unit);

/*********************/
Expand Down
2 changes: 2 additions & 0 deletions ui/WsjtxFilterDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QDialog>
#include <QCheckBox>
#include <QSet>
#include "core/LogLocale.h"

namespace Ui {
class WsjtxFilterDialog;
Expand All @@ -22,6 +23,7 @@ class WsjtxFilterDialog : public QDialog
Ui::WsjtxFilterDialog *ui;
QList<QCheckBox*> memberListCheckBoxes;
QSet<QString> dxMemberFilter;
LogLocale locale;

void generateMembershipCheckboxes();

Expand Down
2 changes: 1 addition & 1 deletion ui/WsjtxWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void WsjtxWidget::decodeReceived(WsjtxDecode decode)

if ( entry.dxcc.cont.contains(contregexp)
&& ( entry.status & dxccStatusFilter )
&& Gridsquare::distance2localeUnitDistance(entry.distance, unit) >= distanceFilter
&& Gridsquare::distance2localeUnitDistance(entry.distance, unit, locale) >= distanceFilter
&& entry.decode.snr >= snrFilter
&& ( dxMemberFilter.size() == 0
|| (dxMemberFilter.size() && entry.memberList2Set().intersects(dxMemberFilter)))
Expand Down
2 changes: 2 additions & 0 deletions ui/WsjtxWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "data/WsjtxEntry.h"
#include "models/WsjtxTableModel.h"
#include "rig/Rig.h"
#include "core/LogLocale.h"

namespace Ui {
class WsjtxWidget;
Expand Down Expand Up @@ -64,6 +65,7 @@ private slots:
QSet<QString> dxMemberFilter;
void saveTableHeaderState();
void restoreTableHeaderState();
LogLocale locale;
};

#endif // QLOG_UI_WSJTXWIDGET_H