diff options
author | Bogdan Marinov <bogdan.marinov84@gmail.com> | 2014-03-27 16:22:46 +0200 |
---|---|---|
committer | Bogdan Marinov <bogdan.marinov84@gmail.com> | 2014-03-27 16:22:46 +0200 |
commit | ca37ef6ce4c61c5dac2959e4a1e9bfde660f6fca (patch) | |
tree | 7dca97b553bb72dd16827d45b08df5b94ca3ed66 | |
parent | 6e063378d502211278cfe7da3fa870e09fe7596e (diff) |
delta-T cleanup: use a model to display delta-T listsystem-dependent-time-zones
-rw-r--r-- | src/core/StelDeltaTMgr.cpp | 16 | ||||
-rw-r--r-- | src/core/StelDeltaTMgr.hpp | 2 | ||||
-rw-r--r-- | src/gui/ConfigurationDialog.cpp | 50 | ||||
-rw-r--r-- | src/gui/ConfigurationDialog.hpp | 4 | ||||
-rw-r--r-- | src/gui/configurationDialog.ui | 8 |
5 files changed, 46 insertions, 34 deletions
diff --git a/src/core/StelDeltaTMgr.cpp b/src/core/StelDeltaTMgr.cpp index 7aa52f0559..e895e8f5d2 100644 --- a/src/core/StelDeltaTMgr.cpp +++ b/src/core/StelDeltaTMgr.cpp @@ -76,10 +76,11 @@ StelDeltaTMgr::getAvailableAlgorithmIds() const return algorithms.keys(); } -void -StelDeltaTMgr::populateAvailableAlgorithmsModel(QStandardItemModel* model) +void StelDeltaTMgr::populateAvailableAlgorithmsModel(QAbstractItemModel* baseModel) { - Q_ASSERT(model); + QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(baseModel); + if(model == NULL) + return; model->clear(); QMapIterator<QString,DeltaTAlgorithm*> a(algorithms); @@ -88,6 +89,7 @@ StelDeltaTMgr::populateAvailableAlgorithmsModel(QStandardItemModel* model) a.next(); QStandardItem* item = new QStandardItem(a.value()->getName()); + //item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemNeverHasChildren); //QComboBox uses UserRole by default item->setData(a.key(), Qt::UserRole); @@ -100,15 +102,15 @@ StelDeltaTMgr::populateAvailableAlgorithmsModel(QStandardItemModel* model) } if (a.value() == defaultAlgorithm) { - description.append("<br/></br/>"); + description.append("<br/></br/>\n"); description.append("<strong>"); // TRANSLATORS: Indicates the default DeltaT algorithm in the GUI. description.append(q_("Used by default.")); description.append("</strong>"); - QFont font (model->itemPrototype()->font()); - font.setBold(true); - item->setFont(font); +// QFont font = item->font(); +// font.setBold(true); +// item->setFont(font); } item->setData(description, Qt::UserRole + 1); diff --git a/src/core/StelDeltaTMgr.hpp b/src/core/StelDeltaTMgr.hpp index 1ac2a17c3d..c6f4628944 100644 --- a/src/core/StelDeltaTMgr.hpp +++ b/src/core/StelDeltaTMgr.hpp @@ -43,7 +43,7 @@ public: QList<QString> getAvailableAlgorithmIds() const; //! Returns a data model describing the available DeltaT algorithms. //! @todo return object or pointer? - void populateAvailableAlgorithmsModel(QStandardItemModel* model); + void populateAvailableAlgorithmsModel(QAbstractItemModel* baseModel); //! Calculates DeltaT correction using the currently selected algorithm. diff --git a/src/gui/ConfigurationDialog.cpp b/src/gui/ConfigurationDialog.cpp index c82a2f2d3c..aa360ff8ed 100644 --- a/src/gui/ConfigurationDialog.cpp +++ b/src/gui/ConfigurationDialog.cpp @@ -34,6 +34,7 @@ #include "StelProgressController.hpp" #include "StelCore.hpp" +#include "StelDeltaTMgr.hpp" #include "StelMovementMgr.hpp" #include "StelModuleMgr.hpp" #include "StelSkyDrawer.hpp" @@ -209,7 +210,8 @@ void ConfigurationDialog::createDialogContent() if (idx==-1) { // Use Espenak & Meeus (2006) as default - idx = ui->deltaTAlgorithmComboBox->findData(QVariant("EspenakMeeus"), Qt::UserRole, Qt::MatchCaseSensitive); + //idx = ui->deltaTAlgorithmComboBox->findData(QVariant("EspenakMeeus"), Qt::UserRole, Qt::MatchCaseSensitive); + idx = 0; // TODO: Fix this after entering all the algorithms! --BM } ui->deltaTAlgorithmComboBox->setCurrentIndex(idx); connect(ui->deltaTAlgorithmComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setDeltaTAlgorithm(int))); @@ -1151,12 +1153,9 @@ void ConfigurationDialog::populateDeltaTAlgorithmsList() ui->deltaTLabel->setText(QString("%1 %2T:").arg(q_("Algorithm of")).arg(QChar(0x0394))); QComboBox* algorithms = ui->deltaTAlgorithmComboBox; - - //Save the current selection to be restored later - algorithms->blockSignals(true); - int index = algorithms->currentIndex(); - QVariant selectedAlgorithmId = algorithms->itemData(index); +/* algorithms->clear(); + //For each algorithm, display the localized name and store the key as user //data. Unfortunately, there's no other way to do this than with a cycle. algorithms->addItem(q_("Without correction"), "WithoutCorrection"); @@ -1190,31 +1189,42 @@ void ConfigurationDialog::populateDeltaTAlgorithmsList() algorithms->addItem(q_("Banjevic (2006)"), "Banjevic"); algorithms->addItem(q_("Islam, Sadiq & Qureshi (2008, 2013)"), "IslamSadiqQureshi"); algorithms->addItem(q_("Custom equation of %1T").arg(QChar(0x0394)), "Custom"); + */ - //Restore the selection - index = algorithms->findData(selectedAlgorithmId, Qt::UserRole, Qt::MatchCaseSensitive); + StelCore* core = StelApp::getInstance().getCore(); + StelDeltaTMgr* timeCorrectionMgr = core->getTimeCorrectionMgr(); + timeCorrectionMgr->populateAvailableAlgorithmsModel(algorithms->model()); + algorithms->setView(new QListView()); // Prevents some unpleasant effects + algorithms->view()->setSelectionMode(QAbstractItemView::SingleSelection); + + QString id = timeCorrectionMgr->getCurrentAlgorithmId(); + int index = algorithms->findData(id); + if (index < 0) + index = 0; + algorithms->blockSignals(true); algorithms->setCurrentIndex(index); - //algorithms->model()->sort(0); + displayDeltaTAlgorithmDescription(index); algorithms->blockSignals(false); - setDeltaTAlgorithmDescription(); } -void ConfigurationDialog::setDeltaTAlgorithm(int algorithmID) +void ConfigurationDialog::setDeltaTAlgorithm(int index) { + QComboBox* comboBox = ui->deltaTAlgorithmComboBox; + QString id = comboBox->itemData(index).toString(); + StelCore* core = StelApp::getInstance().getCore(); - QString currentAlgorithm = ui->deltaTAlgorithmComboBox->itemData(algorithmID).toString(); - core->setCurrentDeltaTAlgorithmKey(currentAlgorithm); - setDeltaTAlgorithmDescription(); - if (currentAlgorithm.contains("Custom")) - ui->pushButtonCustomDeltaTEquationDialog->setEnabled(true); - else - ui->pushButtonCustomDeltaTEquationDialog->setEnabled(false); + core->setCurrentDeltaTAlgorithmKey(id); + + displayDeltaTAlgorithmDescription(index); + bool isCustom = comboBox->itemData(index, Qt::UserRole+2).toBool(); + ui->pushButtonCustomDeltaTEquationDialog->setEnabled(isCustom); } -void ConfigurationDialog::setDeltaTAlgorithmDescription() +void ConfigurationDialog::displayDeltaTAlgorithmDescription(int index) { ui->deltaTAlgorithmDescription->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet)); - ui->deltaTAlgorithmDescription->setHtml(StelApp::getInstance().getCore()->getCurrentDeltaTAlgorithmDescription()); + QString description = ui->deltaTAlgorithmComboBox->itemData(index, Qt::UserRole+1).toString(); + ui->deltaTAlgorithmDescription->setHtml(description); } void ConfigurationDialog::showCustomDeltaTEquationDialog() diff --git a/src/gui/ConfigurationDialog.hpp b/src/gui/ConfigurationDialog.hpp index 406467ca74..0b4467a870 100644 --- a/src/gui/ConfigurationDialog.hpp +++ b/src/gui/ConfigurationDialog.hpp @@ -123,8 +123,8 @@ private slots: void setUpdatesFlag(bool b); void populateDeltaTAlgorithmsList(); - void setDeltaTAlgorithm(int algorithmID); - void setDeltaTAlgorithmDescription(); + void setDeltaTAlgorithm(int index); + void displayDeltaTAlgorithmDescription(int index); void showCustomDeltaTEquationDialog(); #ifndef DISABLE_SCRIPTING diff --git a/src/gui/configurationDialog.ui b/src/gui/configurationDialog.ui index 3ac6393c4a..ee5d67be8e 100644 --- a/src/gui/configurationDialog.ui +++ b/src/gui/configurationDialog.ui @@ -148,7 +148,7 @@ <item row="1" column="0"> <widget class="QStackedWidget" name="configurationStackedWidget"> <property name="currentIndex"> - <number>3</number> + <number>2</number> </property> <widget class="QWidget" name="page"> <layout class="QVBoxLayout" name="verticalLayout_10"> @@ -966,12 +966,12 @@ </item> <item> <widget class="QComboBox" name="deltaTAlgorithmComboBox"> - <property name="editable"> - <bool>true</bool> - </property> <property name="insertPolicy"> <enum>QComboBox::NoInsert</enum> </property> + <property name="sizeAdjustPolicy"> + <enum>QComboBox::AdjustToContents</enum> + </property> </widget> </item> <item> |