(pair.first);
if(line_edit != nullptr){
auto validator = new QRegularExpressionValidator(pair.second,line_edit);
line_edit->setValidator(validator);
}else{
DEB << "Error: Line Edit not found: "<< pair.first << " - skipping.";
}
}
}
/*!
* \brief SettingsWidget::updatePersonalDetails Updates the database with the users personal details.
*/
void SettingsWidget::updatePersonalDetails()
{
RowData_T user_data;
switch (ui->aliasComboBox->currentIndex()) {
case 0:
user_data.insert(Opl::Db::PILOTS_ALIAS, QStringLiteral("self"));
break;
case 1:
user_data.insert(Opl::Db::PILOTS_ALIAS, QStringLiteral("SELF"));
break;
case 2:{
QString name;
name.append(ui->lastnameLineEdit->text());
name.append(QLatin1String(", "));
name.append(ui->firstnameLineEdit->text().leftRef(1));
name.append(QLatin1Char('.'));
user_data.insert(Opl::Db::PILOTS_ALIAS, name);
}
break;
default:
break;
}
user_data.insert(Opl::Db::PILOTS_LASTNAME, ui->lastnameLineEdit->text());
user_data.insert(Opl::Db::PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
user_data.insert(Opl::Db::PILOTS_COMPANY, ui->companyLineEdit->text());
user_data.insert(Opl::Db::PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
user_data.insert(Opl::Db::PILOTS_PHONE, ui->phoneLineEdit->text());
user_data.insert(Opl::Db::PILOTS_EMAIL, ui->emailLineEdit->text());
auto user = APilotEntry(1);
user.setData(user_data);
aDB->commit(user);
}
/*
* Slots
*/
/*
* Personal Tab
*/
void SettingsWidget::on_lastnameLineEdit_editingFinished()
{
updatePersonalDetails();
}
void SettingsWidget::on_firstnameLineEdit_editingFinished()
{
updatePersonalDetails();
}
void SettingsWidget::on_companyLineEdit_editingFinished()
{
updatePersonalDetails();
}
void SettingsWidget::on_employeeidLineEdit_editingFinished()
{
updatePersonalDetails();
}
void SettingsWidget::on_emailLineEdit_editingFinished()
{
updatePersonalDetails();
}
void SettingsWidget::on_phoneLineEdit_editingFinished()
{
updatePersonalDetails();
}
/*
* Flight Logging Tab
*/
void SettingsWidget::on_aliasComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::UserData::DisplaySelfAs, index);
updatePersonalDetails();
}
void SettingsWidget::on_functionComboBox_currentIndexChanged(const QString &arg1)
{
ASettings::write(ASettings::FlightLogging::Function, arg1);
}
void SettingsWidget::on_rulesComboBox_currentIndexChanged(const QString &arg1)
{
ASettings::write(ASettings::FlightLogging::Rules, arg1);
}
void SettingsWidget::on_approachComboBox_currentIndexChanged(const QString &arg1)
{
ASettings::write(ASettings::FlightLogging::Approach, arg1);
}
void SettingsWidget::on_nightComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::FlightLogging::NightLoggingEnabled, index);
switch (index) {
case 1:
ASettings::write(ASettings::FlightLogging::NightAngle, -6);
break;
case 2:
ASettings::write(ASettings::FlightLogging::NightAngle, 0);
break;
default:
ASettings::write(ASettings::FlightLogging::NightAngle, -6);
}
}
void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
{
ASettings::write(ASettings::FlightLogging::FlightNumberPrefix, arg1);
}
/*
* Misc Tab
*/
void SettingsWidget::on_logbookViewComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::Main::LogbookView, index);
emit settingChanged(SettingSignal::LogbookWidget);
}
void SettingsWidget::on_pilotSortComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::UserData::PilotSortColumn, index);
emit settingChanged(PilotsWidget);
}
void SettingsWidget::on_acftSortComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::UserData::TailSortColumn, index);
emit settingChanged(AircraftWidget);
}
QT_DEPRECATED
void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::UserData::AcftAllowIncomplete, index);
if (index) {
QMessageBox::StandardButton reply;
reply = QMessageBox::warning(this, tr("Warning"),
tr("Enabling incomplete logging will enable you to add aircraft with incomplete data.
"
"If you do not fill out the aircraft details, "
"it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time. "
"This will also impact statistics and auto-logging capabilites as well as jeopardise database integrity.
"
"It is highly recommended to keep this option off unless you have a specific reason not to.
"
"Are you sure you want to proceed?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
ASettings::write(ASettings::UserData::AcftAllowIncomplete, index);
} else {
ui->acAllowIncompleteComboBox->setCurrentIndex(0);
}
}
}
/*
* About Tab
*/
/*!
* \brief SettingsWidget::on_aboutPushButton_clicked Displays Application Version and Licensing information
*/
void SettingsWidget::on_aboutPushButton_clicked()
{
QMessageBox message_box(this);
QPixmap icon = QPixmap(Opl::Assets::ICON_MAIN);
message_box.setIconPixmap(icon.scaledToWidth(64, Qt::TransformationMode::SmoothTransformation));
QString SQLITE_VERSION = aDB->sqliteVersion();
QString text = QMessageBox::tr(
"About openPilotLog
"
"
"
"© 2020-2021 Felix Turowsky"
"
"
"This is a collaboratively developed Free and Open Source Application. "
"Visit us here for more information.
"
"This program is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version.
"
"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 for more details.
"
"You should have received a copy of the GNU General Public License "
"along with this program. If not, "
"please click here.
"
"
"
"This program uses Qt version %4 and "
"SQLite version %6
"
).arg(QStringLiteral("github.com/fiffty-50/openpilotlog"),
QStringLiteral("gnu.org/licenses/"),
QStringLiteral("qt.io"),
QT_VERSION_STR,
QStringLiteral("sqlite.org/about.html"),
SQLITE_VERSION);
message_box.setText(text);
message_box.exec();
}
void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& new_style_setting)
{
if (new_style_setting == QLatin1String("Dark-Palette")) {
AStyle::setStyle(AStyle::darkPalette());
ASettings::write(ASettings::Main::Style, new_style_setting);
return;
}
for (const auto &style_name : AStyle::styles) {
if (new_style_setting == style_name) {
AStyle::setStyle(style_name);
ASettings::write(ASettings::Main::Style, new_style_setting);
return;
}
}
for (const auto &style_sheet : AStyle::styleSheets) {
if (new_style_setting == style_sheet.styleSheetName) {
AStyle::setStyle(style_sheet);
ASettings::write(ASettings::Main::Style, new_style_setting);
return;
}
}
}
void SettingsWidget::on_fontComboBox_currentFontChanged(const QFont &f)
{
qApp->setFont(f);
ASettings::write(ASettings::Main::Font, f.toString());
DEB << "Setting Font:" << f.toString();
}
void SettingsWidget::on_fontSpinBox_valueChanged(int arg1)
{
QFont f = qApp->font();
f.setPointSize(arg1);
qApp->setFont(f);
ASettings::write(ASettings::Main::FontSize, arg1);
DEB << "Setting Font:" << f.toString();
}
void SettingsWidget::on_fontCheckBox_stateChanged(int arg1)
{
if (usingStylesheet() && arg1 == Qt::Unchecked) {
WARN(tr("The style you have currently selected may not be fully compatible "
"with changing to a custom font while the application is running.
"
"Applying your changes may require restarting the application.
"));
}
switch (arg1) {
case Qt::Unchecked:
{
ui->fontComboBox->setEnabled(true);
ui->fontSpinBox->setEnabled(true);
ASettings::write(ASettings::Main::UseSystemFont, false);
QFont font(ui->fontComboBox->currentFont());
font.setPointSize(ui->fontSpinBox->value());
qApp->setFont(font);
LOG << "Setting Font:" << font.toString();
break;
}
case Qt::Checked:
{
ui->fontComboBox->setEnabled(false);
ui->fontSpinBox->setEnabled(false);
ASettings::write(ASettings::Main::UseSystemFont, true);
INFO(tr("The application will be restarted for this change to take effect."));
qApp->quit();
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
}
break;
default:
break;
}
}
/*!
* \brief Determines if the user has selected a stylesheet or is using a Qt Style Factory Style
*/
bool SettingsWidget::usingStylesheet()
{
for (const auto &style_sheet : AStyle::styleSheets) {
if (style_sheet.styleSheetName == ui->styleComboBox->currentText())
return true;
}
return false;
}
void SettingsWidget::on_resetStylePushButton_clicked()
{
LOG << "Resetting style to default...";
ui->styleComboBox->setCurrentText(AStyle::defaultStyle);
ui->fontCheckBox->setChecked(true);
}
void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Licence, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::TypeRating, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::LineCheck, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Medical, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom1, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currCustom2DateEdit_userDateChanged(const QDate &date)
{
ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom2, date);
aDB->commit(entry);
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currToLdgCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowToLgdCurrency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowToLgdCurrency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currLicCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowLicCurrency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowLicCurrency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currTrCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowTrCurrency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowTrCurrency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currLckCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowLckCurrency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowLckCurrency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currMedCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowMedCurrency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowMedCurrency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currCustom1CheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowCustom1Currency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowCustom1Currency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currCustom2CheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::ShowCustom2Currency, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::ShowCustom2Currency, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currWarningCheckBox_stateChanged(int arg1)
{
switch (arg1) {
case Qt::CheckState::Checked:
ASettings::write(ASettings::UserData::CurrWarningEnabled, true);
break;
case Qt::CheckState::Unchecked:
ASettings::write(ASettings::UserData::CurrWarningEnabled, false);
break;
default:
break;
}
emit settingChanged(HomeWidget);
}
void SettingsWidget::on_currWarningThresholdSpinBox_valueChanged(int arg1)
{
ASettings::write(ASettings::UserData::CurrWarningThreshold, arg1);
emit settingChanged(SettingSignal::HomeWidget);
}
void SettingsWidget::on_currCustom1LineEdit_editingFinished()
{
ASettings::write(ASettings::UserData::Custom1CurrencyName, ui->currCustom1LineEdit->text());
}
void SettingsWidget::on_currCustom2LineEdit_editingFinished()
{
ASettings::write(ASettings::UserData::Custom2CurrencyName, ui->currCustom2LineEdit->text());
}
void SettingsWidget::on_dateFormatComboBox_currentIndexChanged(int index)
{
ASettings::write(ASettings::Main::DateFormat, index);
const auto date_edits = this->findChildren();
for (const auto & date_edit : date_edits) {
date_edit->setDisplayFormat(
ADate::getFormatString(
static_cast(ASettings::read(ASettings::Main::DateFormat).toInt())));
}
}
void SettingsWidget::on_languageComboBox_activated(const QString &arg1)
{
if (arg1 != Opl::L10N_NAMES[Opl::Translations::English]) {
INFO(tr("Translations are not yet available. If you are interested in making openPilotLog available in your native "
"language, visit us here for more information."
).arg(QStringLiteral("github.com/fiffty-50/openpilotlog/wiki/Translations")));
ui->languageComboBox->setCurrentIndex(0);
}
}