1 /*
2 * Stellarium
3 * Copyright (C) 2020 Alexander Wolf
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17 */
18
19 #include "StelApp.hpp"
20 #include "Dialog.hpp"
21 #include "StelTranslator.hpp"
22 #include "StelObjectMgr.hpp"
23
24 #include "AstroCalcCustomStepsDialog.hpp"
25 #include "ui_astroCalcCustomStepsDialog.h"
26
AstroCalcCustomStepsDialog()27 AstroCalcCustomStepsDialog::AstroCalcCustomStepsDialog() : StelDialog("AstroCalcCustomSteps")
28 {
29 ui = new Ui_astroCalcCustomStepsDialogForm;
30 conf = StelApp::getInstance().getSettings();
31 }
32
~AstroCalcCustomStepsDialog()33 AstroCalcCustomStepsDialog::~AstroCalcCustomStepsDialog()
34 {
35 delete ui;
36 ui=Q_NULLPTR;
37 }
38
retranslate()39 void AstroCalcCustomStepsDialog::retranslate()
40 {
41 if (dialog)
42 {
43 ui->retranslateUi(dialog);
44 populateUnitMeasurementsList();
45 }
46 }
47
48
createDialogContent()49 void AstroCalcCustomStepsDialog::createDialogContent()
50 {
51 ui->setupUi(dialog);
52
53 //Signals and slots
54 connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
55 connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close()));
56 connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
57
58 ui->timeStepDoubleSpinBox->setValue(conf->value("astrocalc/custom_time_step", 1.0).toDouble());
59 connect(ui->timeStepDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(saveTimeStep(double)));
60
61 populateUnitMeasurementsList();
62 connect(ui->unitMeasurementComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveUnitMeasurement(int)));
63 }
64
populateUnitMeasurementsList()65 void AstroCalcCustomStepsDialog::populateUnitMeasurementsList()
66 {
67 Q_ASSERT(ui->unitMeasurementComboBox);
68
69 QComboBox* steps = ui->unitMeasurementComboBox;
70
71 steps->blockSignals(true);
72 int index = steps->currentIndex();
73 QVariant selectedCategoryId = steps->itemData(index);
74 steps->clear();
75 // NOTE: Update AstroCalc::getCustomTimeStep() after changes!
76 steps->addItem(qc_("minute","unit of measurement"), "1");
77 steps->addItem(qc_("hour","unit of measurement"), "2");
78 steps->addItem(qc_("solar day","unit of measurement"), "3");
79 steps->addItem(qc_("sidereal day","unit of measurement"), "4");
80 steps->addItem(qc_("Julian day","unit of measurement"), "5");
81 steps->addItem(qc_("synodic month","unit of measurement"), "6");
82 steps->addItem(qc_("draconic month","unit of measurement"), "7");
83 steps->addItem(qc_("mean tropical month","unit of measurement"), "8");
84 steps->addItem(qc_("anomalistic month","unit of measurement"), "9");
85 steps->addItem(qc_("sidereal year","unit of measurement"), "10");
86 steps->addItem(qc_("Julian year","unit of measurement"), "11");
87 steps->addItem(qc_("Gaussian year","unit of measurement"), "12");
88 steps->addItem(qc_("anomalistic year","unit of measurement"), "13");
89 steps->addItem(qc_("saros","unit of measurement"), "14");
90
91 index = steps->findData(selectedCategoryId, Qt::UserRole, Qt::MatchCaseSensitive);
92 if (index < 0) // read config data
93 index = steps->findData(conf->value("astrocalc/custom_time_step_unit", "3").toString(), Qt::UserRole, Qt::MatchCaseSensitive);
94
95 if (index < 0) // Unknown yet? Default step: solar day
96 index = steps->findData("3", Qt::UserRole, Qt::MatchCaseSensitive);
97
98 steps->setCurrentIndex(index);
99 steps->model()->sort(0);
100 steps->blockSignals(false);
101 }
102
saveUnitMeasurement(int index)103 void AstroCalcCustomStepsDialog::saveUnitMeasurement(int index)
104 {
105 Q_ASSERT(ui->unitMeasurementComboBox);
106 QComboBox* category = ui->unitMeasurementComboBox;
107 conf->setValue("astrocalc/custom_time_step_unit", category->itemData(index).toInt());
108 }
109
saveTimeStep(double value)110 void AstroCalcCustomStepsDialog::saveTimeStep(double value)
111 {
112 conf->setValue("astrocalc/custom_time_step", value);
113 }
114