8#include "stellarsolverprofileeditor.h"
13#include "ksmessagebox.h"
14#include "stellarsolverprofile.h"
16#include <KConfigDialog>
17#include <QInputDialog>
20#include <stellarsolver.h>
25void StellarSolverProfileEditor::showEvent(
QShowEvent *e)
34 QString currentProfile = optionsProfile->currentText();
36 optionsProfile->setCurrentText(currentProfile);
39StellarSolverProfileEditor::StellarSolverProfileEditor(
QWidget *parent, ProfileGroup group,
46 m_ConfigDialog = dialog;
48 setProfileGroup(group);
49 optionsProfileGroup->setEnabled(
false);
72 copyProfile->setVisible(
false);
84 reloadProfiles->setIcon(
89 loadDefaults->setIcon(
102 disconnectOptionsProfileComboBox();
103 SSolver::Parameters params = getSettingsFromUI();
104 params.listName =
name;
105 optionsList.
append(params);
106 optionsProfile->addItem(name);
107 optionsProfile->setCurrentText(name);
108 openOptionsProfileNum = optionsProfile->
count() - 1;
109 settingJustChanged();
110 connectOptionsProfileComboBox();
116 if(optionsList.count() == 0)
118 int item = optionsProfile->currentIndex();
119 disconnectOptionsProfileComboBox();
120 optionsProfile->removeItem(item);
121 optionsList.removeAt(item);
122 if(optionsProfile->count() > 0)
124 if(item > optionsList.count() - 1)
126 openOptionsProfileNum = item;
127 loadOptionsProfileIgnoreOldSettings(item);
129 settingJustChanged();
130 connectOptionsProfileComboBox();
146 if(combo != optionsProfile)
154 if(selectedProfileGroup != AlignProfiles)
155 astrometryOptions->setVisible(
false);
160void StellarSolverProfileEditor::setProfileGroup(ProfileGroup group,
bool warn)
162 selectedProfileGroup = group;
163 optionsProfileGroup->setCurrentIndex(
static_cast<int>(group));
165 switch(selectedProfileGroup)
168 profileGroupFileName =
"SavedAlignProfiles.ini";
171 profileGroupFileName =
"SavedFocusProfiles.ini";
174 profileGroupFileName =
"SavedGuideProfiles.ini";
177 profileGroupFileName =
"SavedHFRProfiles.ini";
185void StellarSolverProfileEditor::connectOptionsProfileComboBox()
188 &StellarSolverProfileEditor::loadOptionsProfile);
191void StellarSolverProfileEditor::disconnectOptionsProfileComboBox()
194 &StellarSolverProfileEditor::loadOptionsProfile);
197void StellarSolverProfileEditor::settingJustChanged()
199 optionsAreSaved =
false;
203void StellarSolverProfileEditor::loadProfile(
const QString &profile)
205 optionsProfile->setCurrentText(profile);
208void StellarSolverProfileEditor::loadOptionsProfile()
210 if(optionsProfile->count() == 0)
212 if(openOptionsProfileNum < optionsList.count() && openOptionsProfileNum > 0)
214 SSolver::Parameters editorOptions = getSettingsFromUI();
215 SSolver::Parameters currentProfile = optionsList.
at(openOptionsProfileNum);
216 if(!(editorOptions == currentProfile) || editorOptions.description != currentProfile.description)
218 editorOptions.listName = currentProfile.listName;
219 optionsList.replace(openOptionsProfileNum, editorOptions);
222 SSolver::Parameters newProfile = optionsList.at(optionsProfile->currentIndex());
224 for(
QWidget *control : controls)
225 control->blockSignals(
true);
226 sendSettingsToUI(newProfile);
227 for(
QWidget *control : controls)
228 control->blockSignals(
false);
229 openOptionsProfileNum = optionsProfile->currentIndex();
232void StellarSolverProfileEditor::loadOptionsProfileIgnoreOldSettings(
int index)
234 if(index >= optionsProfile->count())
236 SSolver::Parameters newProfile = optionsList.at(index);
238 for(
QWidget *control : controls)
239 control->blockSignals(
true);
240 sendSettingsToUI(newProfile);
241 optionsProfile->setCurrentIndex(index);
242 openOptionsProfileNum = optionsProfile->currentIndex();
243 for(
QWidget *control : controls)
244 control->blockSignals(
false);
250SSolver::Parameters StellarSolverProfileEditor::getSettingsFromUI()
252 SSolver::Parameters params;
253 params.description = description->toPlainText();
255 params.apertureShape = (SSolver::Shape) apertureShape->currentIndex();
256 params.kron_fact = kron_fact->text().toDouble();
257 params.subpix = subpix->text().toInt() ;
258 params.r_min = r_min->text().toFloat();
259 params.magzero = magzero->text().toFloat();
260 params.threshold_bg_multiple = threshMultiple->text().toFloat();
261 params.threshold_offset = threshOffset->text().toFloat();
262 params.minarea = minarea->text().toFloat();
263 params.deblend_thresh = deblend_thresh->text().toInt();
264 params.deblend_contrast = deblend_contrast->text().toFloat();
265 params.clean = (cleanCheckBox->isChecked()) ? 1 : 0;
266 params.clean_param = clean_param->text().toDouble();
267 params.convFilterType = (SSolver::ConvFilterType) convFilter->currentIndex();
268 params.fwhm = fwhm->value();
271 params.resort = resort->isChecked();
272 params.maxSize = maxSize->text().toDouble();
273 params.minSize = minSize->text().toDouble();
274 params.maxEllipse = maxEllipse->text().toDouble();
275 params.initialKeep = initialKeep->text().toInt();
276 params.keepNum = keepNum->text().toInt();
277 params.removeBrightest = brightestPercent->text().toDouble();
278 params.removeDimmest = dimmestPercent->text().toDouble();
279 params.saturationLimit = saturationLimit->text().toDouble();
283 params.maxwidth = maxWidth->text().toDouble();
284 params.minwidth = minWidth->text().toDouble();
285 params.inParallel = inParallel->isChecked();
286 params.multiAlgorithm = (SSolver::MultiAlgo)multiAlgo->currentIndex();
287 params.solverTimeLimit = solverTimeLimit->text().toInt();
289 params.resort = resort->isChecked();
290 params.autoDownsample = autoDownsample->isChecked();
291 params.downsample = downsample->value();
292 params.search_radius = radius->text().toDouble();
297void StellarSolverProfileEditor::sendSettingsToUI(SSolver::Parameters a)
300 description->setText(a.description);
303 apertureShape->setCurrentIndex(a.apertureShape);
314 cleanCheckBox->setChecked(a.clean == 1);
316 convFilter->setCurrentIndex(a.convFilterType);
317 fwhm->setValue(a.fwhm);
332 autoDownsample->setChecked(a.autoDownsample);
333 downsample->setValue(a.downsample);
334 inParallel->setChecked(a.inParallel);
335 multiAlgo->setCurrentIndex(a.multiAlgorithm);
340 resort->setChecked(a.resort);
343void StellarSolverProfileEditor::copySingleProfile()
348void StellarSolverProfileEditor::openSingleProfile()
363 settings.beginGroup(group);
367 map.insert(key, settings.value(key));
368 SSolver::Parameters newParams = SSolver::Parameters::convertFromMap(map);
369 optionsList.append(newParams);
370 optionsProfile->addItem(group);
372 if(optionsProfile->count() > 0)
373 loadProfile(groups.first());
377void StellarSolverProfileEditor::loadProfiles(
bool warn)
379 if(warn && !optionsAreSaved )
382 "You made unsaved changes in the settings, do you really wish to overwrite them?") ==
QMessageBox::No)
386 optionsAreSaved =
true;
388 disconnectOptionsProfileComboBox();
389 optionsProfile->clear();
390 if(
QFile(savedOptionsProfiles).exists())
391 optionsList = StellarSolver::loadSavedOptionsProfiles(savedOptionsProfiles);
393 optionsList = getDefaultProfiles();
394 if (selectedProfileGroup == FocusProfiles)
396 bool defaultProfile =
false;
397 bool defaultProfileDonut =
false;
398 for(SSolver::Parameters params : optionsList)
400 optionsProfile->addItem(params.listName);
401 if (params.listName == FOCUS_DEFAULT_NAME)
402 defaultProfile =
true;
403 else if (params.listName == FOCUS_DEFAULT_DONUT_NAME)
404 defaultProfileDonut =
true;
408 optionsList.append(getFocusOptionsProfileDefault());
409 optionsProfile->addItem(FOCUS_DEFAULT_NAME);
411 if (!defaultProfileDonut)
413 optionsList.append(getFocusOptionsProfileDefaultDonut());
414 optionsProfile->addItem(FOCUS_DEFAULT_DONUT_NAME);
419 for(SSolver::Parameters params : optionsList)
420 optionsProfile->addItem(params.listName);
422 if(optionsList.count() > 0)
424 sendSettingsToUI(optionsList.at(0));
425 openOptionsProfileNum = 0;
427 connectOptionsProfileComboBox();
431void StellarSolverProfileEditor::saveSingleProfile()
438 SSolver::Parameters params = optionsList.at(optionsProfile->currentIndex());
439 settings.beginGroup(params.listName);
445 settings.setValue(it.key(), it.value());
450void StellarSolverProfileEditor::saveProfiles()
453 for(
int i = 0 ; i < optionsList.count(); i++)
455 SSolver::Parameters params = optionsList.at(i);
456 settings.beginGroup(params.listName);
462 settings.setValue(it.key(), it.value());
469 bool groupInList =
false;
470 for(SSolver::Parameters params : optionsList)
472 if(params.listName == group)
476 settings.remove(group);
482 switch(selectedProfileGroup)
485 return getDefaultFocusOptionsProfiles();
487 return getDefaultHFROptionsProfiles();
489 return getDefaultGuideOptionsProfiles();
492 return getDefaultAlignOptionsProfiles();
496void StellarSolverProfileEditor::loadDefaultProfiles()
498 if( !optionsAreSaved )
501 "You made unsaved changes in the settings, do you really wish to overwrite them?") ==
QMessageBox::No)
505 optionsAreSaved =
true;
507 disconnectOptionsProfileComboBox();
508 optionsList = getDefaultProfiles();
509 optionsProfile->clear();
510 for(SSolver::Parameters param : optionsList)
511 optionsProfile->addItem(param.listName);
512 connectOptionsProfileComboBox();
513 if(optionsProfile->count() > 0)
514 loadOptionsProfileIgnoreOldSettings(0);
518void StellarSolverProfileEditor::saveBackupProfiles()
525 for(
int i = 0 ; i < optionsList.count(); i++)
527 SSolver::Parameters params = optionsList.at(i);
528 settings.beginGroup(params.listName);
534 settings.setValue(it.key(), it.value());
540void StellarSolverProfileEditor::openBackupProfiles()
551 disconnectOptionsProfileComboBox();
557 settings.beginGroup(group);
561 map.insert(key, settings.value(key));
562 SSolver::Parameters newParams = SSolver::Parameters::convertFromMap(map);
563 optionsList.append(newParams);
564 optionsProfile->addItem(group);
566 if(optionsProfile->count() > 0)
567 loadOptionsProfileIgnoreOldSettings(0);
568 connectOptionsProfileComboBox();
572void StellarSolverProfileEditor::slotApply()
574 int index = optionsProfile->currentIndex();
575 SSolver::Parameters currentParams = getSettingsFromUI();
577 if (index >= 0 && index < optionsList.count())
579 SSolver::Parameters savedParams = optionsList.at(index);
580 if(!(currentParams == savedParams) || currentParams.description != savedParams.description)
582 currentParams.listName = savedParams.listName;
583 optionsList.replace(index, currentParams);
586 optionsAreSaved =
true;
589 emit optionsProfilesUpdated();
This is the main window for KStars.
Ekos is an advanced Astrophotography tool for Linux.
QString name(StandardAction id)
void stateChanged(int state)
void currentIndexChanged(int index)
QString filePath(const QString &fileName) const const
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
bool exists() const const
QIcon fromTheme(const QString &name)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
void textEdited(const QString &text)
StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
qsizetype count() const const
QString & append(QChar ch)
const QChar at(qsizetype position) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)