File indexing completed on 2024-04-28 15:11:24
0001 /* 0002 SPDX-FileCopyrightText: 2013 Samikshan Bairagya <samikshan@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "wiequipsettings.h" 0008 #include "oal/equipmentwriter.h" 0009 #include "kstars.h" 0010 #include "Options.h" 0011 0012 #include <QListWidgetItem> 0013 0014 WIEquipSettings::WIEquipSettings() : QFrame(KStars::Instance()) 0015 { 0016 setupUi(this); 0017 0018 ScopeListWidget->setSelectionMode(QAbstractItemView::SingleSelection); 0019 binoDetailsFrame->setEnabled(kcfg_BinocularsCheck->isChecked()); 0020 scopeFrame->setEnabled(kcfg_TelescopeCheck->isChecked()); 0021 0022 connect(kcfg_TelescopeCheck, SIGNAL(toggled(bool)), this, SLOT(slotTelescopeCheck(bool))); 0023 connect(kcfg_BinocularsCheck, SIGNAL(toggled(bool)), this, SLOT(slotBinocularsCheck(bool))); 0024 connect(ScopeListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(slotScopeSelected(int))); 0025 connect(saveNewScopeButton, SIGNAL(clicked()), this, SLOT(slotAddNewScope())); 0026 0027 populateScopeListWidget(); 0028 } 0029 0030 void WIEquipSettings::populateScopeListWidget() 0031 { 0032 ScopeListWidget->clear(); 0033 ///Get telescope list from KStars user database. 0034 KStars::Instance()->data()->userdb()->GetAllScopes(m_ScopeList); 0035 foreach (OAL::Scope *scope, m_ScopeList) 0036 { 0037 QListWidgetItem *scopeItem = new QListWidgetItem; 0038 scopeItem->setText(scope->vendor()); 0039 scopeItem->setData(Vendor, scope->vendor()); 0040 scopeItem->setData(Model, scope->model()); 0041 scopeItem->setData(Aperture, scope->aperture()); 0042 scopeItem->setData(FocalLength, scope->focalLength()); 0043 scopeItem->setData(Type, scope->type()); 0044 0045 ScopeListWidget->addItem(scopeItem); 0046 } 0047 if (ScopeListWidget->count() == 0) 0048 return; 0049 0050 vendorText->setText(ScopeListWidget->item(0)->data(Vendor).toString()); 0051 modelText->setText(ScopeListWidget->item(0)->data(Model).toString()); 0052 apertureText->setText(ScopeListWidget->item(0)->data(Aperture).toString().append(" mm")); 0053 0054 ScopeListWidget->setCurrentRow(Options::scopeListIndex()); 0055 } 0056 0057 void WIEquipSettings::slotTelescopeCheck(bool on) 0058 { 0059 scopeFrame->setEnabled(on); 0060 Options::setTelescopeCheck(on); 0061 } 0062 0063 void WIEquipSettings::slotBinocularsCheck(bool on) 0064 { 0065 binoDetailsFrame->setEnabled(on); 0066 Options::setBinocularsCheck(on); 0067 } 0068 0069 void WIEquipSettings::slotScopeSelected(int row) 0070 { 0071 if (row == -1) 0072 return; 0073 0074 QListWidgetItem *item = ScopeListWidget->item(row); 0075 0076 if (item == nullptr) 0077 return; 0078 0079 vendorText->setText(item->data(Vendor).toString()); 0080 modelText->setText(item->data(Model).toString()); 0081 apertureText->setText(item->data(Aperture).toString().append(" mm")); 0082 0083 if (item->data(Type).toString() == "Reflector") 0084 m_TelType = ObsConditions::Reflector; 0085 else if (item->data(Type).toString() == "Refractor") 0086 m_TelType = ObsConditions::Refractor; 0087 0088 Options::setScopeListIndex(row); 0089 } 0090 0091 void WIEquipSettings::slotAddNewScope() 0092 { 0093 EquipmentWriter equipmentdlg; 0094 equipmentdlg.loadEquipment(); 0095 equipmentdlg.exec(); 0096 0097 populateScopeListWidget(); //Reload scope list widget 0098 } 0099 0100 void WIEquipSettings::setAperture() 0101 { 0102 double telAperture = INVALID_APERTURE; 0103 double binoAperture = INVALID_APERTURE; 0104 0105 if (kcfg_TelescopeCheck->isChecked() && ScopeListWidget->selectedItems().isEmpty() == false) 0106 telAperture = ScopeListWidget->currentItem()->data(Aperture).toDouble(); 0107 if (kcfg_BinocularsCheck->isChecked()) 0108 binoAperture = kcfg_BinocularsAperture->value(); 0109 m_Aperture = telAperture > binoAperture ? telAperture : binoAperture; 0110 0111 // JM 2016-05-11: This is way over-complicated 0112 /* 0113 if (ScopeListWidget->count() == 0) 0114 { 0115 if (Options::binocularsCheck()z) 0116 { 0117 m_Aperture = kcfg_BinocularsAperture->value(); 0118 return; 0119 } 0120 else 0121 { 0122 m_Aperture = INVALID_APERTURE; 0123 return; 0124 } 0125 } 0126 0127 if (!Options::telescopeCheck() && !Options::binocularsCheck()) 0128 { 0129 m_Aperture = INVALID_APERTURE; 0130 } 0131 else if (!Options::telescopeCheck()) //No telescope available, but binoculars available 0132 { 0133 m_Aperture = kcfg_BinocularsAperture->value(); 0134 } 0135 else if (!Options::binocularsCheck()) //No binoculars available, but telescope available 0136 { 0137 if (ScopeListWidget->count() == 0) 0138 { 0139 m_Aperture = INVALID_APERTURE; 0140 return; 0141 } 0142 else 0143 m_Aperture = ScopeListWidget->currentItem()->data(Aperture).toDouble(); 0144 } 0145 else //Both Telescope and Binoculars available 0146 { 0147 if (ScopeListWidget->count() == 0) 0148 { 0149 m_Aperture = kcfg_BinocularsAperture->value(); 0150 return; 0151 } 0152 //If both Binoculars and Telescope available then select bigger aperture 0153 double telAperture = ScopeListWidget->currentItem()->data(Aperture).toDouble(); 0154 double binoAperture = kcfg_BinocularsAperture->value(); 0155 m_Aperture = telAperture > binoAperture ? telAperture : binoAperture; 0156 }*/ 0157 }