Skip to content

Commit

Permalink
Fixed #573 - Setting dialog contains a 12/24 Time Format option
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Jan 22, 2025
1 parent 89787a0 commit e09ff55
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 20 deletions.
25 changes: 23 additions & 2 deletions core/LogLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@

MODULE_IDENTIFICATION("qlog.core.loglocale");

LogLocale::LogLocale()
LogLocale::LogLocale() :
regexp(QRegularExpression(R"(, tttt|\(t\)|\bt\b)")),
is24hUsed(!timeFormat(QLocale::ShortFormat).contains("ap", Qt::CaseInsensitive))
{
FCT_IDENTIFICATION;
}

void LogLocale::changeTime12_24Format(QString &formatString) const
{
if ( getSettingUse24hformat() )
formatString.remove("ap", Qt::CaseInsensitive).remove("a", Qt::CaseInsensitive);
else if ( is24hUsed )
formatString += " AP";
}

QString LogLocale::formatTimeLongWithoutTZ() const
{
FCT_IDENTIFICATION;

QString ret = timeFormat(QLocale::LongFormat).replace(", tttt", "").replace("(t)", "").replace(" t", "").replace("t", "");
QString ret = timeFormat(QLocale::LongFormat).remove(regexp);

changeTime12_24Format(ret);
qCDebug(runtime) << "format:" << ret;
return ret;
}
Expand All @@ -24,6 +35,7 @@ QString LogLocale::formatTimeShort() const

QString ret = timeFormat(QLocale::ShortFormat);

changeTime12_24Format(ret);
qCDebug(runtime) << "format:" << ret;
return ret;
}
Expand Down Expand Up @@ -64,5 +76,14 @@ QString LogLocale::formatDateTimeShortWithYYYY() const

qCDebug(runtime) << "format:" << ret;
return ret;
}

bool LogLocale::getSettingUse24hformat() const
{
return settings.value("use24hformat", is24hUsed).toBool();
}

void LogLocale::setSettingUse24hformat(bool value)
{
settings.setValue("use24hformat", value);
}
12 changes: 12 additions & 0 deletions core/LogLocale.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#ifndef QLOG_CORE_LOGLOCALE_H
#define QLOG_CORE_LOGLOCALE_H

#include <QSettings>
#include <QLocale>
#include <QRegularExpression>

class LogLocale : public QLocale
{
public:
LogLocale();

QString formatTimeLongWithoutTZ() const;
QString formatTimeShort() const;
QString formatTimeLong() const;
QString formatDateShortWithYYYY() const;
QString formatDateTimeShortWithYYYY() const;
bool getSettingUse24hformat() const;
void setSettingUse24hformat(bool value);

private:
const QRegularExpression regexp;
bool is24hUsed;
QSettings settings;

void changeTime12_24Format(QString &formatString) const;
};

#endif // QLOG_CORE_LOGLOCALE_H
1 change: 1 addition & 0 deletions ui/LogbookWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ void LogbookWidget::reloadSetting()
/* Refresh dynamic Club selection combobox */
refreshClubFilter();
callbookManager.initCallbooks();
updateTable();
}

void LogbookWidget::sendDXCSpot()
Expand Down
1 change: 1 addition & 0 deletions ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ MainWindow::MainWindow(QWidget* parent) :
connect(this, &MainWindow::settingsChanged, ui->bandmapWidget, &BandmapWidget::recalculateDxccStatus);
connect(this, &MainWindow::settingsChanged, ui->alertsWidget, &AlertWidget::recalculateDxccStatus);
connect(this, &MainWindow::settingsChanged, ui->chatWidget, &ChatWidget::recalculateDxccStatus);
connect(this, &MainWindow::settingsChanged, ui->newContactWidget, &NewContactWidget::readGlobalSettings);
connect(this, &MainWindow::altBackslash, Rig::instance(), &Rig::setPTT);
connect(this, &MainWindow::manualMode, ui->newContactWidget, &NewContactWidget::setManualMode);
connect(this, &MainWindow::contestStopped, ui->newContactWidget, &NewContactWidget::stopContest);
Expand Down
16 changes: 0 additions & 16 deletions ui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1098,22 +1098,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>MainWindow</sender>
<signal>settingsChanged()</signal>
<receiver>newContactWidget</receiver>
<slot>readGlobalSettings()</slot>
<hints>
<hint type="sourcelabel">
<x>404</x>
<y>264</y>
</hint>
<hint type="destinationlabel">
<x>607</x>
<y>500</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionConnectRig</sender>
<signal>toggled(bool)</signal>
Expand Down
4 changes: 4 additions & 0 deletions ui/NewContactWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ void NewContactWidget::readGlobalSettings()

ui->freqRXEdit->loadBands();
ui->freqTXEdit->loadBands();

updatePartnerLocTime();
ui->dateEdit->setDisplayFormat(locale.formatDateShortWithYYYY());
ui->timeOnEdit->setDisplayFormat(locale.formatTimeLongWithoutTZ());
}

/* function is called when an operator change Callsign Edit */
Expand Down
12 changes: 12 additions & 0 deletions ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,13 @@ void SettingsDialog::readSettings() {
ui->notifSpotAlertEdit->setText(NetworkNotification::getNotifSpotAlertAddrs());
ui->notifRigEdit->setText(NetworkNotification::getNotifRigStateAddrs());

/*******/
/* GUI */
/*******/
bool timeformat24 = locale.getSettingUse24hformat();
ui->timeFormat24RadioButton->setChecked(timeformat24);
ui->timeFormat12RadioButton->setChecked(!timeformat24);

/******************/
/* END OF Reading */
/******************/
Expand Down Expand Up @@ -2459,6 +2466,11 @@ void SettingsDialog::writeSettings() {
NetworkNotification::saveNotifWSJTXCQSpotAddrs(ui->notifWSJTXCQSpotsEdit->text());
NetworkNotification::saveNotifSpotAlertAddrs(ui->notifSpotAlertEdit->text());
NetworkNotification::saveNotifRigStateAddrs(ui->notifRigEdit->text());

/*******/
/* GUI */
/*******/
locale.setSettingUse24hformat(ui->timeFormat24RadioButton->isChecked());
}

/* this function is called when user modify rig progile
Expand Down
85 changes: 83 additions & 2 deletions ui/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4205,11 +4205,87 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="shortcutsTab">
<widget class="QWidget" name="guiTab">
<attribute name="title">
<string>Shortcuts</string>
<string>GUI</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<layout class="QHBoxLayout" name="timeLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_34">
<property name="spacing">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="timeFormatLabel">
<property name="text">
<string>Time Format</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QRadioButton" name="timeFormat24RadioButton">
<property name="text">
<string>24-hour</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="timeFormat12RadioButton">
<property name="text">
<string>AM/PM</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<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>
</layout>
</item>
<item>
<widget class="QLabel" name="shortcutInfoLabel">
<property name="text">
Expand Down Expand Up @@ -4411,6 +4487,8 @@
<tabstop>tabWidget_3</tabstop>
<tabstop>kstUsernameEdit</tabstop>
<tabstop>kstPasswordEdit</tabstop>
<tabstop>timeFormat24RadioButton</tabstop>
<tabstop>timeFormat12RadioButton</tabstop>
<tabstop>shortcutsTableView</tabstop>
</tabstops>
<resources/>
Expand Down Expand Up @@ -5455,4 +5533,7 @@
<slot>rigPTTTypeChanged(int)</slot>
<slot>adjustOperatorTextColor()</slot>
</slots>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit e09ff55

Please sign in to comment.