swift
settingsvatsimreaderscomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "ui_settingsvatsimreaderscomponent.h"
7 
8 using namespace swift::misc;
9 using namespace swift::misc::physical_quantities;
10 using namespace swift::core;
11 using namespace swift::core::vatsim;
12 
13 namespace swift::gui::components
14 {
15  CSettingsVatsimReadersComponent::CSettingsVatsimReadersComponent(QWidget *parent)
16  : QFrame(parent), ui(new Ui::CSettingsVatsimReadersComponent)
17  {
18  ui->setupUi(this);
19  connect(ui->pb_Save, &QPushButton::clicked, this, &CSettingsVatsimReadersComponent::save);
20  connect(ui->pb_Reload, &QPushButton::clicked, this, &CSettingsVatsimReadersComponent::reload);
21  this->initValues();
22  }
23 
25 
26  void CSettingsVatsimReadersComponent::onSettingsChanged() { this->initValues(); }
27 
28  void CSettingsVatsimReadersComponent::save()
29  {
30  const int metarSec = m_settingsMetars.get().getPeriodicTime().toMs() / 1000;
31  const int dataFileSec = m_settingsDataFile.get().getPeriodicTime().toMs() / 1000;
32 
33  const int newMetarSec = ui->sb_Metar->value();
34  if (newMetarSec != metarSec)
35  {
36  m_settingsMetars.setAndSaveProperty(
37  CReaderSettings::IndexPeriodicTime,
38  CVariant::fromValue(CTime { static_cast<double>(newMetarSec), CTimeUnit::s() }));
39  }
40  const int newDataFileSec = ui->sb_DataFile->value();
41  if (newDataFileSec != dataFileSec)
42  {
43  m_settingsDataFile.setAndSaveProperty(
44  CReaderSettings::IndexPeriodicTime,
45  CVariant::fromValue(CTime { static_cast<double>(newDataFileSec), CTimeUnit::s() }));
46  }
47  }
48 
49  void CSettingsVatsimReadersComponent::reload() { this->initValues(); }
50 
51  void CSettingsVatsimReadersComponent::initValues()
52  {
53  const int metarSec = m_settingsMetars.get().getPeriodicTime().toMs() / 1000;
54  const int dataFileSec = m_settingsDataFile.get().getPeriodicTime().toMs() / 1000;
55 
56  ui->sb_Metar->setValue(metarSec);
57  ui->sb_DataFile->setValue(dataFileSec);
58  }
59 } // namespace swift::gui::components
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
CStatusMessage setAndSaveProperty(CPropertyIndexRef index, const CVariant &value, qint64 timestamp=0)
Write a property and save in the same step. Must be called from the thread in which the owner lives.
Definition: valuecache.h:434
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Free functions in swift::misc.