From 40118f4867d9117616957c0544aaa809c4855968 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 2 Aug 2021 13:21:50 +0200 Subject: [PATCH 01/28] Fix: name of the list empty when name of the list is empty, now, save/close button is disabled --- src/gui/ObsListCreateEditDialog.cpp | 28 ++++++++++++++++++++++++++-- src/gui/ObsListCreateEditDialog.hpp | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 1a25bdc39471b..8e05f77e73bb2 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -88,6 +88,7 @@ void ObsListCreateEditDialog::createDialogContent() connect ( ui->obsListRemoveObjectButton, SIGNAL ( clicked() ), this, SLOT ( obsListRemoveObjectButtonPressed() ) ); connect ( ui->obsListImportListButton, SIGNAL ( clicked() ), this, SLOT ( obsListImportListButtonPresssed() ) ); connect ( ui->obsListExportListButton, SIGNAL ( clicked() ), this, SLOT ( obsListExportListButtonPressed() ) ); + connect(ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange); //Initializing the list of observing list obsListListModel->setColumnCount ( ColumnCount ); @@ -112,6 +113,14 @@ void ObsListCreateEditDialog::createDialogContent() QHeaderView * header = ui->obsListCreationEditionTreeView->header(); connect ( header, SIGNAL ( sectionClicked ( int ) ), this, SLOT ( headerClicked ( int ) ) ); + // In case of creation le nameOfListLineEdit is empty and button save/close must be disabled + // In case on edition the nameOfListLineEdit is not empty and the button save//close must be enable + if(ui->nameOfListLineEdit->text().isEmpty()){ + ui->obsListSaveButton->setEnabled(false); + } else { + ui->obsListSaveButton->setEnabled(true); + } + if ( listUuid_.size() == 0 ) { // case of creation mode isCreationMode = true; @@ -695,9 +704,9 @@ void ObsListCreateEditDialog::loadObservingList() return; } } - + objectMgr->unSelect(); - + } catch ( std::runtime_error &e ) { qWarning() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); return; @@ -705,6 +714,21 @@ void ObsListCreateEditDialog::loadObservingList() } } + +/* + * Called when the text of the nameOfListLineEdit change +*/ +void ObsListCreateEditDialog::nameOfListTextChange() +{ + if(ui->nameOfListLineEdit->text().isEmpty()){ + ui->obsListSaveButton->setEnabled(false); + } else { + ui->obsListSaveButton->setEnabled(true); + } + +} + + /* * Destructor of singleton */ diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 5b5c614e390d3..9e9ffa7feeea2 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -99,6 +99,7 @@ private slots: void obsListSaveButtonPressed(); void obsListExitButtonPressed(); void headerClicked ( int index ); + void nameOfListTextChange(); signals: //To notified that the exit button is clicked From 232a5415b836400f4382105457726a3bcb6abcf0 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Tue, 3 Aug 2021 13:04:23 +0200 Subject: [PATCH 02/28] fix: pull request - modification for pull request - deletion of empty item in lists combobox - new way for signal/slot connection --- src/gui/ObsListCreateEditDialog.cpp | 26 +++--- src/gui/ObsListCreateEditDialog.hpp | 4 +- src/gui/ObsListDialog.cpp | 134 ++++++++++++---------------- src/gui/ObsListDialog.hpp | 4 +- src/gui/ObservingListCommon.hpp | 20 ++--- src/gui/obsListCreateEditDialog.ui | 4 +- src/gui/obsListDialog.ui | 2 +- 7 files changed, 88 insertions(+), 106 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 8e05f77e73bb2..6bbef799e3b90 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -82,12 +82,12 @@ void ObsListCreateEditDialog::createDialogContent() connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); - connect ( ui->obsListAddObjectButton, SIGNAL ( clicked() ), this, SLOT ( obsListAddObjectButtonPressed() ) ); - connect ( ui->obsListExitButton, SIGNAL ( clicked() ), this, SLOT ( obsListExitButtonPressed() ) ); - connect ( ui->obsListSaveButton, SIGNAL ( clicked() ), this, SLOT ( obsListSaveButtonPressed() ) ); - connect ( ui->obsListRemoveObjectButton, SIGNAL ( clicked() ), this, SLOT ( obsListRemoveObjectButtonPressed() ) ); - connect ( ui->obsListImportListButton, SIGNAL ( clicked() ), this, SLOT ( obsListImportListButtonPresssed() ) ); - connect ( ui->obsListExportListButton, SIGNAL ( clicked() ), this, SLOT ( obsListExportListButtonPressed() ) ); + connect( ui->obsListAddObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListAddObjectButtonPressed); + connect(ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed); + connect(ui->obsListSaveButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListSaveButtonPressed); + connect(ui->obsListRemoveObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListRemoveObjectButtonPressed); + connect(ui->obsListImportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListImportListButtonPresssed); + connect(ui->obsListExportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExportListButtonPressed); connect(ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange); //Initializing the list of observing list @@ -128,7 +128,7 @@ void ObsListCreateEditDialog::createDialogContent() } else { // case of edit mode isCreationMode = false; - ui->stelWindowTitle->setText ( "Observing list modification mode" ); + ui->stelWindowTitle->setText ( "Observing list editor mode" ); loadObservingList(); } } @@ -158,11 +158,11 @@ void ObsListCreateEditDialog::styleChanged() void ObsListCreateEditDialog::setObservingListHeaderNames() { const QStringList headerStrings = { - "UUID", // Hided column + "UUID", // Hidden column q_ ( "Object name" ), - q_ ( "Object Name I18N" ), // Hided column + q_ ( "Object name I18N" ), // Hidden column q_ ( "Type" ), - q_ ( "Right ascencion" ), + q_ ( "Right ascension" ), q_ ( "Declination" ), q_ ( "Magnitude" ), q_ ( "Constellation" ), @@ -379,7 +379,7 @@ void ObsListCreateEditDialog::saveObservedObject() JDString = QString::number ( JD, 'f', 6 ); - // No JD modifications in modification mode + // No JD modifications in editor mode if ( !isCreationMode ) { QString uuidQs = QString::fromStdString ( this->listUuid_ ); QVariantMap currentList = allListsMap.value ( uuidQs ).toMap(); @@ -440,8 +440,8 @@ void ObsListCreateEditDialog::saveObservedObject() } } - mapFromJsonFile.insert ( KEY_VERSION, "1.0" ); - mapFromJsonFile.insert ( KEY_SHORT_NAME, "Observing lists for Stellarium" ); + mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); + mapFromJsonFile.insert ( KEY_SHORT_NAME, "Observing list for Stellarium" ); allListsMap.insert ( oblListUuid, observingListDataList ); mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 9e9ffa7feeea2..3db915c55f8f3 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -61,7 +61,7 @@ class ObsListCreateEditDialog : public StelDialog QString observingListJsonPath; QHash observingListItemCollection; - //! Sorting of the list ex: right ascencion + //! Sorting of the list ex: right ascension QString sorting; //! Set header names for observing list table @@ -72,7 +72,7 @@ class ObsListCreateEditDialog : public StelDialog //! @param uuid id of the record //! @param name name or the designation of the object //! @param type type of the object - //! @param ra right ascencion of the object + //! @param ra right ascension of the object //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index bf2016a8fd981..de9803cd91589 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -80,7 +80,7 @@ void ObsListDialog::createDialogContent() //BookmarksListCombo connect ( ui->obsListComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( loadSelectedObservingList ( int ) ) ); - //Initializing the list of observing list + //Initialize the list of observing lists obsListListModel->setColumnCount ( ColumnCount ); setObservingListHeaderNames(); @@ -100,13 +100,11 @@ void ObsListDialog::createDialogContent() //Enable the sort for columns ui->obsListTreeView->setSortingEnabled ( true ); - //First item of the combobox is an empty headerStrings - ui->obsListComboBox->addItem ( "" ); //By default buttons are disable ui->obsListEditListButton->setEnabled ( false ); ui->obsListHighlightAllButton->setEnabled ( false ); ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled(false); + ui->obsListDeleteButton->setEnabled ( false ); QFile jsonFile ( observingListJsonPath ); if ( jsonFile.exists() ) { @@ -141,19 +139,19 @@ void ObsListDialog::styleChanged() void ObsListDialog::setObservingListHeaderNames() { const QStringList headerStrings = { - "UUID", // Hided column + "UUID", // Hidden column q_ ( "Object name" ), - q_ ( "Object Name I18N" ), // Hided column + q_ ( "Object name I18N" ), // Hidden column q_ ( "Type" ), - q_ ( "Right ascencion" ), + q_ ( "Right ascension" ), q_ ( "Declination" ), q_ ( "Magnitude" ), q_ ( "Constellation" ), - q_ ( "Date" ), // Hided column - q_ ( "Location" ) // Hided column + q_ ( "Date" ), // Hidden column + q_ ( "Location" ) // Hidden column }; - obsListListModel->setHorizontalHeaderLabels ( headerStrings );; + obsListListModel->setHorizontalHeaderLabels ( headerStrings ); } /* @@ -305,7 +303,6 @@ void ObsListDialog::loadListsName() // init combo box ui->obsListComboBox->clear(); - ui->obsListComboBox->addItem ( "" ); // Get the default list uuid QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); @@ -361,12 +358,12 @@ void ObsListDialog::loadObservingList ( QString listUuid ) qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); } else { try { - listOfObjects = loadListFromJson(jsonFile, listUuid); + listOfObjects = loadListFromJson ( jsonFile, listUuid ); if ( listOfObjects.size() > 0 ) { ui->obsListHighlightAllButton->setEnabled ( true ); ui->obsListClearHighlightButton->setEnabled ( true ); - ui->obsListDeleteButton->setEnabled(true); + ui->obsListDeleteButton->setEnabled ( true ); for ( QVariant object: listOfObjects ) { QVariantMap objectMap; @@ -468,7 +465,7 @@ void ObsListDialog::loadObservingList ( QString listUuid ) } else { ui->obsListHighlightAllButton->setEnabled ( false ); ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled(false); + ui->obsListDeleteButton->setEnabled ( false ); } objectMgr->unSelect(); @@ -482,35 +479,35 @@ void ObsListDialog::loadObservingList ( QString listUuid ) /* * Load the list from JSON file */ -QVariantList ObsListDialog::loadListFromJson(QFile &jsonFile, QString listUuid) +QVariantList ObsListDialog::loadListFromJson ( QFile &jsonFile, QString listUuid ) { QVariantMap map; map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - jsonFile.close(); + jsonFile.close(); - observingListItemCollection.clear(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); - QVariantList listOfObjects; + observingListItemCollection.clear(); + QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); + QVariantList listOfObjects; - QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); - ui->obsListDescriptionTextEdit->setPlainText ( listDescription ); + QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); + ui->obsListDescriptionTextEdit->setPlainText ( listDescription ); - // Displaying the creation date - QString JDs = observingListMap.value ( QString ( KEY_JD ) ).value(); - double JD = JDs.toDouble(); - QString listCreationDate = JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); - ui->obsListCreationDateLineEdit->setText ( listCreationDate ); + // Displaying the creation date + QString JDs = observingListMap.value ( QString ( KEY_JD ) ).value(); + double JD = JDs.toDouble(); + QString listCreationDate = JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + ui->obsListCreationDateLineEdit->setText ( listCreationDate ); - if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) { - QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); - listOfObjects = data.value(); - } else { - qCritical() << "[ObservingList] conversion error"; - } + if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) { + QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); + listOfObjects = data.value(); + } else { + qCritical() << "[ObservingList] conversion error"; + } - // Clear model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - return listOfObjects; + // Clear model + obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); + return listOfObjects; } @@ -598,69 +595,54 @@ void ObsListDialog::selectAndGoToObject ( QModelIndex index ) */ void ObsListDialog::loadSelectedObservingList ( int selectedIndex ) { - if ( selectedIndex > 0 ) { - ui->obsListEditListButton->setEnabled ( true ); - ui->obsListDeleteButton->setEnabled(true); - QString listUuid = ui->obsListComboBox->itemData ( selectedIndex ).toString(); - selectedObservingListUuid = listUuid.toStdString(); - loadObservingList ( listUuid ); - } else { - selectedObservingListUuid = ""; - // Button obsListEditListButton, obsListHighlightAllButton and - // obsListClearHighlightButtonmust be disable if no list is selected - ui->obsListEditListButton->setEnabled ( false ); - ui->obsListHighlightAllButton->setEnabled ( false ); - ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled(false); - // Clear list description - ui->obsListDescriptionTextEdit->setPlainText ( "" ); - // Clear model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - qWarning() << "[ObservingList] No list selected !"; - } + ui->obsListEditListButton->setEnabled ( true ); + ui->obsListDeleteButton->setEnabled ( true ); + QString listUuid = ui->obsListComboBox->itemData ( selectedIndex ).toString(); + selectedObservingListUuid = listUuid.toStdString(); + loadObservingList ( listUuid ); } /* - * Delete the selected list + * Delete the selected list */ void ObsListDialog::obsListDeleteButtonPressed() { - qDebug() << QString::fromStdString(selectedObservingListUuid); + qDebug() << QString::fromStdString ( selectedObservingListUuid ); QVariantMap map; QFile jsonFile ( observingListJsonPath ); if ( !jsonFile.open ( QIODevice::ReadWrite ) ) { qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); - }else{ + } else { try { QVariantMap newMap; QVariantMap newObsListMap; map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - - newMap.insert(QString(KEY_DEFAULT_LIST_UUID), map.value(QString(KEY_DEFAULT_LIST_UUID))); - QVariantMap obsListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); - + + newMap.insert ( QString ( KEY_DEFAULT_LIST_UUID ), map.value ( QString ( KEY_DEFAULT_LIST_UUID ) ) ); + QVariantMap obsListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + QMap::iterator i; - for(i = obsListMap.begin(); i != obsListMap.end(); ++i){ - if(i.key().compare(QString::fromStdString(selectedObservingListUuid))!=0){ - newObsListMap.insert(i.key(),i.value()); + for ( i = obsListMap.begin(); i != obsListMap.end(); ++i ) { + if ( i.key().compare ( QString::fromStdString ( selectedObservingListUuid ) ) !=0 ) { + newObsListMap.insert ( i.key(),i.value() ); } } - - newMap.insert(QString(KEY_OBSERVING_LISTS),newObsListMap); - newMap.insert(QString(KEY_SHORT_NAME), map.value(QString(KEY_SHORT_NAME))); - newMap.insert(QString(KEY_VERSION), map.value(QString(KEY_VERSION))); + + newMap.insert ( QString ( KEY_OBSERVING_LISTS ),newObsListMap ); + newMap.insert ( QString ( KEY_SHORT_NAME ), map.value ( QString ( KEY_SHORT_NAME ) ) ); + newMap.insert ( QString ( KEY_VERSION ), map.value ( QString ( KEY_VERSION ) ) ); objectMgr->unSelect(); observingListItemCollection.clear(); // Clear model obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - ui->obsListCreationDateLineEdit->setText(""); + ui->obsListCreationDateLineEdit->setText ( "" ); int currentIndex = ui->obsListComboBox->currentIndex(); - ui->obsListComboBox->removeItem(currentIndex); - - int index = ui->obsListComboBox->findData(""); - ui->obsListComboBox->setCurrentIndex(index); - ui->obsListDescriptionTextEdit->setPlainText(""); - + ui->obsListComboBox->removeItem ( currentIndex ); + + int index = ui->obsListComboBox->findData ( "" ); + ui->obsListComboBox->setCurrentIndex ( index ); + ui->obsListDescriptionTextEdit->setPlainText ( "" ); + jsonFile.resize ( 0 ); StelJsonParser::write ( newMap, &jsonFile ); jsonFile.flush(); diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 2c255287cfb5a..6f5ddcdad6c22 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -69,7 +69,7 @@ class ObsListDialog : public StelDialog //! @param uuid id of the record //! @param name name or the designation of the object //! @param type type of the object - //! @param ra right ascencion of the object + //! @param ra right assencion of the object //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located @@ -79,7 +79,7 @@ class ObsListDialog : public StelDialog //! @param listUuid the uuid of the list void loadObservingList ( QString listUuid ); - //! Load the lists names for populate the combo box and get the default list uuid + //! Load the lists names to populate the combo box and get the default list uuid void loadListsName(); //! Load the default list diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 7ec57bbb558cd..9628f69b0a636 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -36,17 +36,17 @@ struct observingListItem { Q_DECLARE_METATYPE ( observingListItem ) enum ObsListColumns { - ColumnUUID, //! UUID of object - ColumnName, //! Name or designation of object - ColumnNameI18n, //! Localized name of object - ColumnType, //! Type of the object - ColumnRa, //! Right ascencion of the object - ColumnDec, //! Declination of the object + ColumnUUID, //! UUID of object + ColumnName, //! Name or designation of object + ColumnNameI18n, //! Localized name of object + ColumnType, //! Type of the object + ColumnRa, //! Right ascension of the object + ColumnDec, //! Declination of the object ColumnMagnitude, //! Magnitude of the object - ColumnConstellation, //! Constellation in which the object is located - ColumnJD, //! Date in julian day - ColumnLocation, //! Location where the object is observed - ColumnCount //! Total number of columns + ColumnConstellation, //! Constellation in which the object is located + ColumnJD, //! Date in julian day + ColumnLocation, //! Location where the object is observed + ColumnCount //! Total number of columns }; static constexpr char const * JSON_FILE_NAME = "observingList.json"; diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index 0cca03d980ca7..2aa295dac3288 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -82,7 +82,7 @@ - Observing Lists creation/edition + Observing Lists editor @@ -223,7 +223,7 @@ - Save and Close + Save and close diff --git a/src/gui/obsListDialog.ui b/src/gui/obsListDialog.ui index 030e5057cb50a..67b4add3cd899 100644 --- a/src/gui/obsListDialog.ui +++ b/src/gui/obsListDialog.ui @@ -138,7 +138,7 @@ - List(s): + List: From dc268c2390470fec756b768560cf8e47316e870f Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 9 Aug 2021 13:10:35 +0200 Subject: [PATCH 03/28] feat: adding visible error message - adding error message in case of list name duplication, - loading default list whenn opening obsListDialog, - sort list name in combo box. --- src/gui/ObsListCreateEditDialog.cpp | 64 +++++++++++++++++++---------- src/gui/ObsListCreateEditDialog.hpp | 9 +++- src/gui/ObsListDialog.cpp | 24 ++++++++++- src/gui/ObsListDialog.hpp | 3 ++ src/gui/obsListCreateEditDialog.ui | 14 +++++++ 5 files changed, 90 insertions(+), 24 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 6bbef799e3b90..66fde4a53f06d 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -66,7 +66,6 @@ ObsListCreateEditDialog * ObsListCreateEditDialog::Instance ( string listUuid ) if ( m_instance == nullptr ) { m_instance = new ObsListCreateEditDialog ( listUuid ); } - return m_instance; } @@ -82,13 +81,13 @@ void ObsListCreateEditDialog::createDialogContent() connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); - connect( ui->obsListAddObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListAddObjectButtonPressed); - connect(ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed); - connect(ui->obsListSaveButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListSaveButtonPressed); - connect(ui->obsListRemoveObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListRemoveObjectButtonPressed); - connect(ui->obsListImportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListImportListButtonPresssed); - connect(ui->obsListExportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExportListButtonPressed); - connect(ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange); + connect ( ui->obsListAddObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListAddObjectButtonPressed ); + connect ( ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed ); + connect ( ui->obsListSaveButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListSaveButtonPressed ); + connect ( ui->obsListRemoveObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListRemoveObjectButtonPressed ); + connect ( ui->obsListImportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListImportListButtonPresssed ); + connect ( ui->obsListExportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExportListButtonPressed ); + connect ( ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange ); //Initializing the list of observing list obsListListModel->setColumnCount ( ColumnCount ); @@ -113,12 +112,18 @@ void ObsListCreateEditDialog::createDialogContent() QHeaderView * header = ui->obsListCreationEditionTreeView->header(); connect ( header, SIGNAL ( sectionClicked ( int ) ), this, SLOT ( headerClicked ( int ) ) ); + // We hide the closeStelWindow to have only two possibilities to close the dialog: + // Save and close and Exit + ui->closeStelWindow->setHidden ( true ); + + ui->obsListErrorMessage->setHidden(true); + // In case of creation le nameOfListLineEdit is empty and button save/close must be disabled // In case on edition the nameOfListLineEdit is not empty and the button save//close must be enable - if(ui->nameOfListLineEdit->text().isEmpty()){ - ui->obsListSaveButton->setEnabled(false); + if ( ui->nameOfListLineEdit->text().isEmpty() ) { + ui->obsListSaveButton->setEnabled ( false ); } else { - ui->obsListSaveButton->setEnabled(true); + ui->obsListSaveButton->setEnabled ( true ); } if ( listUuid_.size() == 0 ) { @@ -495,8 +500,7 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); if ( observingListMap.size() == 1 ) { - QMap::const_iterator i; - listUuid_ = i.value().toString().toStdString(); + listUuid_ = observingListMap.keys().at ( 0 ).toStdString(); } else { // define error message if needed return; @@ -507,7 +511,6 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() } loadObservingList(); observingListJsonPath = originalobservingListJsonPath; - saveObservedObject(); } } @@ -516,9 +519,19 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() */ void ObsListCreateEditDialog::obsListSaveButtonPressed() { - saveObservedObject(); - this->close(); - emit exitButtonClicked(); + if ( !this->listName_.isEmpty() && this->listName_.contains ( ui->nameOfListLineEdit->text() ) ) { + QString errorMessage; + errorMessage.append("Error: a list with the name ").append(ui->nameOfListLineEdit->text()).append(" already exists !"); + qWarning() << "[ObservingList Creation/Edition] Error: a list with the name " << ui->nameOfListLineEdit->text() << " already exists !"; + ui->obsListErrorMessage->setHidden(false); + ui->obsListErrorMessage->setText(errorMessage); + } else { + ui->obsListErrorMessage->setHidden(true); + saveObservedObject(); + this->close(); + emit exitButtonClicked(); + } + } /* @@ -714,20 +727,27 @@ void ObsListCreateEditDialog::loadObservingList() } } - /* * Called when the text of the nameOfListLineEdit change */ void ObsListCreateEditDialog::nameOfListTextChange() { - if(ui->nameOfListLineEdit->text().isEmpty()){ - ui->obsListSaveButton->setEnabled(false); + ui->obsListErrorMessage->setHidden(true); + if ( ui->nameOfListLineEdit->text().isEmpty() ) { + ui->obsListSaveButton->setEnabled ( false ); } else { - ui->obsListSaveButton->setEnabled(true); + ui->obsListSaveButton->setEnabled ( true ); } - + } +/* + * Setter for listName +*/ +void ObsListCreateEditDialog::setListName ( QList listName ) +{ + this->listName_ = listName; +} /* * Destructor of singleton diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 3db915c55f8f3..b26248e426817 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -40,10 +40,12 @@ class ObsListCreateEditDialog : public StelDialog //! Notify that the application style changed void styleChanged(); - + //! called when click on button close in top right corner void close(); + void setListName ( QList listName ); + protected: static ObsListCreateEditDialog * m_instance; Ui_obsListCreateEditDialogForm *ui; @@ -61,6 +63,9 @@ class ObsListCreateEditDialog : public StelDialog QString observingListJsonPath; QHash observingListItemCollection; + //List names + QList listName_; + //! Sorting of the list ex: right ascension QString sorting; @@ -89,6 +94,8 @@ class ObsListCreateEditDialog : public StelDialog virtual ~ObsListCreateEditDialog(); + + public slots: void retranslate(); private slots: diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index de9803cd91589..12c35b74c1a1e 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -36,6 +36,7 @@ #include "LabelMgr.hpp" #include "ui_obsListDialog.h" +#include using namespace std; @@ -77,8 +78,9 @@ void ObsListDialog::createDialogContent() connect ( ui->obsListDeleteButton, SIGNAL ( clicked() ), this, SLOT ( obsListDeleteButtonPressed() ) ); connect ( ui->obsListTreeView, SIGNAL ( doubleClicked ( QModelIndex ) ), this, SLOT ( selectAndGoToObject ( QModelIndex ) ) ); - //BookmarksListCombo + //obsListCombo settings connect ( ui->obsListComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( loadSelectedObservingList ( int ) ) ); + ui->obsListComboBox->model()->sort(0); //Initialize the list of observing lists obsListListModel->setColumnCount ( ColumnCount ); @@ -283,6 +285,7 @@ void ObsListDialog::invokeObsListCreateEditDialog ( string listUuid ) { createEditDialog_instance = ObsListCreateEditDialog::Instance ( listUuid ); connect ( createEditDialog_instance, SIGNAL ( exitButtonClicked() ), this, SLOT ( obsListCreateEditDialogClosed() ) ); + createEditDialog_instance->setListName(listName); createEditDialog_instance->setVisible ( true ); } @@ -317,11 +320,14 @@ void ObsListDialog::loadListsName() QVariant var = i.value(); QVariantMap data = var.value(); QString listName = data.value ( KEY_NAME ).value(); + this->listName.append(listName); ui->obsListComboBox->addItem ( listName, listUuid ); if ( defaultListUuid == listUuid ) { defaultListUuid_ = defaultListUuid; } } + //ui->obsListComboBox->model()->sort(0); + //loadDefaultList(); } } catch ( std::runtime_error &e ) { qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); @@ -681,6 +687,22 @@ void ObsListDialog::obsListCreateEditDialogClosed() } +/* + * Override of the StelDialog::setVisible((bool) methode + * We need to load the default liste when opening the obsListDialog +*/ +void ObsListDialog::setVisible ( bool v ) +{ + if (v){ + StelDialog::setVisible(true); + this->loadDefaultList(); + }else{ + StelDialog::setVisible(false); + } +} + + + diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 6f5ddcdad6c22..6fe515e625370 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -40,6 +40,8 @@ class ObsListDialog : public StelDialog //! Notify that the application style changed void styleChanged(); + + void setVisible ( bool v ); protected: Ui_obsListDialogForm *ui; @@ -56,6 +58,7 @@ class ObsListDialog : public StelDialog QHash observingListItemCollection; QList highlightLabelIDs; QString defaultListUuid_; + QList listName; //! Set header names for observing list table void setObservingListHeaderNames(); diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index 2aa295dac3288..7053c80cacfcf 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -319,6 +319,20 @@ + + + + + + QLabel {color : red;} + + + TextLabel + + + + + From 93047e170eb94bc66cba27e55d1096ee1e347ee9 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 25 Oct 2021 10:14:29 +0200 Subject: [PATCH 04/28] Fix merge Fix merge master into ObservingLists-fix --- src/gui/ObsListCreateEditDialog.cpp | 847 ++++++++++++++-------------- src/gui/ObsListCreateEditDialog.hpp | 56 +- src/gui/ObsListDialog.cpp | 715 +++++++++++------------ src/gui/ObsListDialog.hpp | 64 +-- 4 files changed, 818 insertions(+), 864 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index bba4cc03d7963..66fde4a53f06d 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -42,20 +42,20 @@ ObsListCreateEditDialog * ObsListCreateEditDialog::m_instance = nullptr; ObsListCreateEditDialog::ObsListCreateEditDialog ( string listUuid ) { - listUuid_ = listUuid; - - ui = new Ui_obsListCreateEditDialogForm(); - core = StelApp::getInstance().getCore(); - objectMgr = GETSTELMODULE ( StelObjectMgr ); - obsListListModel = new QStandardItemModel ( 0,ColumnCount ); - observingListJsonPath = StelFileMgr::findFile ( "data", static_cast( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); - sorting = ""; + listUuid_ = listUuid; + + ui = new Ui_obsListCreateEditDialogForm(); + core = StelApp::getInstance().getCore(); + objectMgr = GETSTELMODULE ( StelObjectMgr ); + obsListListModel = new QStandardItemModel ( 0,ColumnCount ); + observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); + sorting = ""; } ObsListCreateEditDialog::~ObsListCreateEditDialog() { - delete ui; - delete obsListListModel; + delete ui; + delete obsListListModel; } /** @@ -75,11 +75,11 @@ ObsListCreateEditDialog * ObsListCreateEditDialog::Instance ( string listUuid ) */ void ObsListCreateEditDialog::createDialogContent() { - ui->setupUi ( dialog ); + ui->setupUi ( dialog ); - //Signals and slots - connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); - connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); + //Signals and slots + connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); + connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); connect ( ui->obsListAddObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListAddObjectButtonPressed ); connect ( ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed ); @@ -89,28 +89,28 @@ void ObsListCreateEditDialog::createDialogContent() connect ( ui->obsListExportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExportListButtonPressed ); connect ( ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange ); - //Initializing the list of observing list - obsListListModel->setColumnCount ( ColumnCount ); - setObservingListHeaderNames(); - - ui->obsListCreationEditionTreeView->setModel ( obsListListModel ); - ui->obsListCreationEditionTreeView->header()->setSectionsMovable ( false ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setStretchLastSection ( true ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnUUID ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnNameI18n ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnJD ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnLocation ); - //Enable the sort for columns - ui->obsListCreationEditionTreeView->setSortingEnabled ( true ); - - QHeaderView * header = ui->obsListCreationEditionTreeView->header(); - connect ( header, SIGNAL ( sectionClicked ( int ) ), this, SLOT ( headerClicked ( int ) ) ); + //Initializing the list of observing list + obsListListModel->setColumnCount ( ColumnCount ); + setObservingListHeaderNames(); + + ui->obsListCreationEditionTreeView->setModel ( obsListListModel ); + ui->obsListCreationEditionTreeView->header()->setSectionsMovable ( false ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); + ui->obsListCreationEditionTreeView->header()->setStretchLastSection ( true ); + ui->obsListCreationEditionTreeView->hideColumn ( ColumnUUID ); + ui->obsListCreationEditionTreeView->hideColumn ( ColumnNameI18n ); + ui->obsListCreationEditionTreeView->hideColumn ( ColumnJD ); + ui->obsListCreationEditionTreeView->hideColumn ( ColumnLocation ); + //Enable the sort for columns + ui->obsListCreationEditionTreeView->setSortingEnabled ( true ); + + QHeaderView * header = ui->obsListCreationEditionTreeView->header(); + connect ( header, SIGNAL ( sectionClicked ( int ) ), this, SLOT ( headerClicked ( int ) ) ); // We hide the closeStelWindow to have only two possibilities to close the dialog: // Save and close and Exit @@ -143,8 +143,9 @@ void ObsListCreateEditDialog::createDialogContent() */ void ObsListCreateEditDialog::retranslate() { - if ( dialog ) - ui->retranslateUi ( dialog ); + if ( dialog ) { + ui->retranslateUi ( dialog ); + } } /* @@ -152,7 +153,7 @@ void ObsListCreateEditDialog::retranslate() */ void ObsListCreateEditDialog::styleChanged() { - // Nothing for now + // Nothing for now } /* @@ -174,7 +175,7 @@ void ObsListCreateEditDialog::setObservingListHeaderNames() q_ ( "Location" ) // Hided column }; - obsListListModel->setHorizontalHeaderLabels ( headerStrings ); + obsListListModel->setHorizontalHeaderLabels ( headerStrings ); } @@ -183,42 +184,43 @@ void ObsListCreateEditDialog::setObservingListHeaderNames() */ void ObsListCreateEditDialog::addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) { - QStandardItem* item = Q_NULLPTR; + QStandardItem* item = Q_NULLPTR; - item = new QStandardItem ( uuid ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnUUID, item ); + item = new QStandardItem ( uuid ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnUUID, item ); - item = new QStandardItem ( name ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnName, item ); + item = new QStandardItem ( name ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnName, item ); - item = new QStandardItem ( nameI18n ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnNameI18n, item ); + item = new QStandardItem ( nameI18n ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnNameI18n, item ); - item = new QStandardItem ( type ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnType, item ); + item = new QStandardItem ( type ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnType, item ); - item = new QStandardItem ( ra ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnRa, item ); + item = new QStandardItem ( ra ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnRa, item ); - item = new QStandardItem ( dec ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnDec, item ); + item = new QStandardItem ( dec ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnDec, item ); - item = new QStandardItem ( magnitude ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnMagnitude, item ); + item = new QStandardItem ( magnitude ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnMagnitude, item ); - item = new QStandardItem ( constellation ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnConstellation, item ); + item = new QStandardItem ( constellation ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnConstellation, item ); - for ( int i = 0; i < ColumnCount; ++i ) - ui->obsListCreationEditionTreeView->resizeColumnToContents ( i ); + for ( int i = 0; i < ColumnCount; ++i ) { + ui->obsListCreationEditionTreeView->resizeColumnToContents ( i ); + } } @@ -227,109 +229,110 @@ void ObsListCreateEditDialog::addModelRow ( int number, QString uuid, QString na */ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) - { - // No duplicate item in the same list - bool is_already_in_list = false; - QHash::const_iterator i; - for ( i = observingListItemCollection.begin(); i != observingListItemCollection.end(); i++ ) - { - if ( i.value().name.compare ( selectedObject[0]->getEnglishName() ) == 0 ) - { - is_already_in_list = true; - break; - } - } - - if ( !is_already_in_list ) - { - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - - QString objectName = selectedObject[0]->getEnglishName(); - QString objectNameI18n = selectedObject[0]->getNameI18n(); - if ( selectedObject[0]->getType() =="Nebula" ) - objectName = GETSTELMODULE ( NebulaMgr )->getLatestSelectedDSODesignation(); - - QString objectRaStr = "", objectDecStr = ""; - bool visibleFlag = false; - double fov = -1.0; - - QString objectType = selectedObject[0]->getType(); - - double ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) - visibleFlag = true; - - if ( objectName.isEmpty() ) - { - objectName = QString ( "%1, %2" ).arg ( objectRaStr, objectDecStr ); - objectNameI18n = q_( "Unnamed object" ); - fov = GETSTELMODULE ( StelMovementMgr )->getCurrentFov(); - } - - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); - - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); - QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) - objectConstellation = objectConstellationVariant.value(); - - QString JDs = ""; - double JD = core->getJD(); - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); - - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - else - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); - - observingListItem item; - item.name = objectName; - item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) - item.type = objectType; - - if ( !objectRaStr.isEmpty() ) - item.ra = objectRaStr; - - if ( !objectDecStr.isEmpty() ) - item.dec = objectDecStr; - - if ( !objectMagnitudeStr.isEmpty() ) - item.magnitude = objectMagnitudeStr; - - if ( !objectConstellation.isEmpty() ) - item.constellation = objectConstellation; - - if ( !JDs.isEmpty() ) - item.jd = QString::number ( JD, 'f', 6 ); - - if ( !Location.isEmpty() ) - QHash::iterator i; - item.location = Location; - - if ( !visibleFlag ) - item.isVisibleMarker = visibleFlag; - - if ( fov > 0.0 ) - item.fov = fov; - - observingListItemCollection.insert ( objectUuid,item ); - } - } - else - qWarning() << "selected object is empty !"; + const QList& selectedObject = objectMgr->getSelectedObject(); + if ( !selectedObject.isEmpty() ) { + // No duplicate item in the same list + bool is_already_in_list = false; + QHash::const_iterator i; + for ( i = observingListItemCollection.begin(); i != observingListItemCollection.end(); i++ ) { + if ( i.value().name.compare ( selectedObject[0]->getEnglishName() ) == 0 ) { + is_already_in_list = true; + break; + } + } + + if ( !is_already_in_list ) { + int lastRow = obsListListModel->rowCount(); + QString objectUuid = QUuid::createUuid().toString(); + + QString objectName = selectedObject[0]->getEnglishName(); + QString objectNameI18n = selectedObject[0]->getNameI18n(); + if ( selectedObject[0]->getType() =="Nebula" ) { + objectName = GETSTELMODULE ( NebulaMgr )->getLatestSelectedDSODesignation(); + } + + QString objectRaStr = "", objectDecStr = ""; + bool visibleFlag = false; + double fov = -1.0; + + QString objectType = selectedObject[0]->getType(); + + float ra, dec; + StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); + objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); + objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); + if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + visibleFlag = true; + } + + if ( objectName.isEmpty() ) { + objectName = QString ( "%1, %2" ).arg ( objectRaStr, objectDecStr ); + objectNameI18n = q_ ( "Unnamed object" ); + fov = GETSTELMODULE ( StelMovementMgr )->getCurrentFov(); + } + + float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); + QString objectMagnitudeStr = QString::number ( objectMagnitude ); + + QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); + QVariant objectConstellationVariant = objectMap["iauConstellation"]; + QString objectConstellation ( "unknown" ); + if ( objectConstellationVariant.canConvert() ) { + objectConstellation = objectConstellationVariant.value(); + } + + QString JDs = ""; + double JD = core->getJD(); + JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + } + + addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); + + observingListItem item; + item.name = objectName; + item.nameI18n = objectNameI18n; + if ( !objectType.isEmpty() ) { + item.type = objectType; + } + if ( !objectRaStr.isEmpty() ) { + item.ra = objectRaStr; + } + if ( !objectDecStr.isEmpty() ) { + item.dec = objectDecStr; + } + if ( !objectMagnitudeStr.isEmpty() ) { + item.magnitude = objectMagnitudeStr; + } + if ( !objectConstellation.isEmpty() ) { + item.constellation = objectConstellation; + } + if ( !JDs.isEmpty() ) { + item.jd = QString::number ( JD, 'f', 6 ); + } + if ( !Location.isEmpty() ) { + QHash::iterator i; + item.location = Location; + } + if ( !visibleFlag ) { + item.isVisibleMarker = visibleFlag; + } + if ( fov > 0.0 ) { + item.fov = fov; + } + + observingListItemCollection.insert ( objectUuid,item ); + } + + } else { + qWarning() << "selected object is empty !"; + } } /* @@ -337,10 +340,10 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() */ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() { - int number = ui->obsListCreationEditionTreeView->currentIndex().row(); - QString uuid = obsListListModel->index ( number, ColumnUUID ).data().toString(); - obsListListModel->removeRow ( number ); - observingListItemCollection.remove ( uuid ); + int number = ui->obsListCreationEditionTreeView->currentIndex().row(); + QString uuid = obsListListModel->index ( number, ColumnUUID ).data().toString(); + obsListListModel->removeRow ( number ); + observingListItemCollection.remove ( uuid ); } /* @@ -348,41 +351,37 @@ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() */ void ObsListCreateEditDialog::saveObservedObject() { - QString listName = ui->nameOfListLineEdit->text(); - if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) - { - qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; - return; - } - - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) - { - qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for reading and writing:" + QString listName = ui->nameOfListLineEdit->text(); + if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) { + qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; + return; + } + + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { + qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for reading and writing:" << QDir::toNativeSeparators ( observingListJsonPath ); - return; - } + return; + } - try - { - QVariantMap mapFromJsonFile; - QVariantMap allListsMap; - if ( jsonFile.size() > 0 ) - { - mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); - } + try { + QVariantMap mapFromJsonFile; + QVariantMap allListsMap; + if ( jsonFile.size() > 0 ) { + mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + } - QVariantMap observingListDataList; + QVariantMap observingListDataList; - // Description - QString description = ui->descriptionLineEdit->text(); - observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); + // Description + QString description = ui->descriptionLineEdit->text(); + observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); - // Julian day - QString JDString = ""; - double JD = core->getJD(); - JDString = QString::number ( JD, 'f', 6 ); + // Julian day + QString JDString = ""; + double JD = core->getJD(); + JDString = QString::number ( JD, 'f', 6 ); // No JD modifications in editor mode @@ -400,62 +399,66 @@ void ObsListCreateEditDialog::saveObservedObject() observingListDataList.insert ( QString ( KEY_JD ), JDString ); } - // Location - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - else - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - - observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); - - // Name of the liste - QString name = ui->nameOfListLineEdit->text(); - observingListDataList.insert ( QString ( KEY_NAME ), name ); - - // List of objects - QVariantList listOfObjects; - QHashIterator i ( observingListItemCollection ); - while ( i.hasNext() ) - { - i.next(); - - observingListItem item = i.value(); - QVariantMap obl; - QString objectName = item.name; - obl.insert ( QString ( KEY_DESIGNATION ), objectName ); - listOfObjects.push_back ( obl ); - } - - observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); - observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); - - QString oblListUuid; - if ( isCreationMode ) - oblListUuid = QUuid::createUuid().toString(); - else - oblListUuid = QString::fromStdString ( listUuid_ ); + // Location + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + } + observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); + + // Name of the liste + QString name = ui->nameOfListLineEdit->text(); + observingListDataList.insert ( QString ( KEY_NAME ), name ); + + // List of objects + QVariantList listOfObjects; + QHashIterator i ( observingListItemCollection ); + while ( i.hasNext() ) { + i.next(); + + observingListItem item = i.value(); + QVariantMap obl; + QString objectName = item.name; + obl.insert ( QString ( KEY_DESIGNATION ), objectName ); + listOfObjects.push_back ( obl ); + } + + observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); + observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); + + QString oblListUuid; + if ( isCreationMode ) { + oblListUuid = QUuid::createUuid().toString(); + } else { + oblListUuid = QString::fromStdString ( listUuid_ ); + } + + if ( ui->obsListDefaultListCheckBox->isChecked() ) { + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if ( defaultListUuid == oblListUuid ) { + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + } mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); mapFromJsonFile.insert ( KEY_SHORT_NAME, "Observing list for Stellarium" ); - mapFromJsonFile.insert ( KEY_VERSION, "1.0" ); - mapFromJsonFile.insert ( KEY_SHORT_NAME, "Observing lists for Stellarium" ); - - allListsMap.insert ( oblListUuid, observingListDataList ); - mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); - - jsonFile.resize ( 0 ); - StelJsonParser::write ( mapFromJsonFile, &jsonFile ); - jsonFile.flush(); - jsonFile.close(); - } - catch ( std::runtime_error &e ) - { - qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); - return; - } + allListsMap.insert ( oblListUuid, observingListDataList ); + mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); + + jsonFile.resize ( 0 ); + StelJsonParser::write ( mapFromJsonFile, &jsonFile ); + jsonFile.flush(); + jsonFile.close(); + } catch ( std::runtime_error &e ) { + qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); + return; + } } /* @@ -463,15 +466,15 @@ void ObsListCreateEditDialog::saveObservedObject() */ void ObsListCreateEditDialog::obsListExportListButtonPressed() { - QString originalobservingListJsonPath = observingListJsonPath; - - QString filter = "JSON (*.json)"; - observingListJsonPath = QFileDialog::getSaveFileName ( Q_NULLPTR, - q_ ( "Export observing list as..." ), - QDir::homePath() + "/" + JSON_FILE_NAME, - filter ); - saveObservedObject(); - observingListJsonPath = originalobservingListJsonPath; + QString originalobservingListJsonPath = observingListJsonPath; + + QString filter = "JSON (*.json)"; + observingListJsonPath = QFileDialog::getSaveFileName ( Q_NULLPTR, + q_ ( "Export observing list as..." ), + QDir::homePath() + "/" + JSON_FILE_NAME, + filter ); + saveObservedObject(); + observingListJsonPath = originalobservingListJsonPath; } /* @@ -479,23 +482,16 @@ void ObsListCreateEditDialog::obsListExportListButtonPressed() */ void ObsListCreateEditDialog::obsListImportListButtonPresssed() { - QString originalobservingListJsonPath = observingListJsonPath; + QString originalobservingListJsonPath = observingListJsonPath; - QString filter = "JSON (*.json)"; - observingListJsonPath = QFileDialog::getOpenFileName ( Q_NULLPTR, q_ ( "Import observing list" ), QDir::homePath(), filter ); + QString filter = "JSON (*.json)"; + observingListJsonPath = QFileDialog::getOpenFileName ( Q_NULLPTR, q_ ( "Import observing list" ), QDir::homePath(), filter ); - QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) - qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); - else - { - try - { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - jsonFile.close(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + QVariantMap map; + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { + qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); } else { try { @@ -543,8 +539,8 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() */ void ObsListCreateEditDialog::obsListExitButtonPressed() { - this->close(); - emit exitButtonClicked(); + this->close(); + emit exitButtonClicked(); } /* @@ -552,8 +548,8 @@ void ObsListCreateEditDialog::obsListExitButtonPressed() */ void ObsListCreateEditDialog::close() { - this->setVisible ( false );; - emit this->exitButtonClicked(); + this->setVisible ( false );; + emit this->exitButtonClicked(); } /* @@ -561,31 +557,30 @@ void ObsListCreateEditDialog::close() */ void ObsListCreateEditDialog::headerClicked ( int index ) { - switch ( index ) - { - case ColumnName: - sorting = QString ( SORTING_BY_NAME ); - break; - case ColumnType: - sorting = QString ( SORTING_BY_TYPE ); - break; - case ColumnRa: - sorting = QString ( SORTING_BY_RA ); - break; - case ColumnDec: - sorting = QString ( SORTING_BY_DEC ); - break; - case ColumnMagnitude: - sorting = QString ( SORTING_BY_MAGNITUDE ); - break; - case ColumnConstellation: - sorting = QString ( SORTING_BY_CONSTTELLATION );; - break; - default: - sorting = ""; - break; - } - qDebug() << "Sorting = " << sorting; + switch ( index ) { + case ColumnName: + sorting = QString ( SORTING_BY_NAME ); + break; + case ColumnType: + sorting = QString ( SORTING_BY_TYPE ); + break; + case ColumnRa: + sorting = QString ( SORTING_BY_RA ); + break; + case ColumnDec: + sorting = QString ( SORTING_BY_DEC ); + break; + case ColumnMagnitude: + sorting = QString ( SORTING_BY_MAGNITUDE ); + break; + case ColumnConstellation: + sorting = QString ( SORTING_BY_CONSTTELLATION );; + break; + default: + sorting = ""; + break; + } + qDebug() << "Sorting = " << sorting; } /* @@ -593,106 +588,126 @@ void ObsListCreateEditDialog::headerClicked ( int index ) */ void ObsListCreateEditDialog::loadObservingList() { - QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) - qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); - else - { - try - { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - jsonFile.close(); - - // Get the default list uuid - QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if ( defaultListUuid.toStdString() == listUuid_ ) - ui->obsListDefaultListCheckBox->setChecked ( true ); - - observingListItemCollection.clear(); - const QString keyUuid = QString::fromStdString ( listUuid_ ); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( keyUuid ).toMap(); - QVariantList listOfObjects; - - QString listeName = observingListMap.value ( QString ( KEY_NAME ) ).value(); - ui->nameOfListLineEdit->setText ( listeName ); - QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); - ui->descriptionLineEdit->setText ( listDescription ); - - if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) - { - QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); - listOfObjects = data.value(); - } - else - { - qCritical() << "[ObservingList Creation/Edition] conversion error"; - return; - } - - for ( QVariant object: listOfObjects ) - { - QVariantMap objectMap; - if ( object.canConvert() ) - { - objectMap = object.value(); - QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); - - if ( objectMgr->findAndSelect ( objectName ) ) - { - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) - { - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - QString objectNameI18n = selectedObject[0]->getNameI18n(); - QString objectRaStr = "", objectDecStr = ""; - bool visibleFlag = false; - double fov = -1.0; - - QString objectType = selectedObject[0]->getType(); - - double ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) - visibleFlag = true; - - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); - - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); - QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) - objectConstellation = objectConstellationVariant.value(); - - QString JDs = ""; - double JD = core->getJD(); - - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); - - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - else - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); - - observingListItem item; - item.name = objectName; - item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) - item.type = objectType; - - if ( !objectRaStr.isEmpty() ) - item.ra = objectRaStr; - - if ( !objectDecStr.isEmpty() ) - item.dec = objectDecStr; + QVariantMap map; + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { + qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + } else { + try { + map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + jsonFile.close(); + + // Get the default list uuid + QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if ( defaultListUuid.toStdString() == listUuid_ ) { + ui->obsListDefaultListCheckBox->setChecked ( true ); + } + + observingListItemCollection.clear(); + const QString keyUuid = QString::fromStdString ( listUuid_ ); + QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( keyUuid ).toMap(); + QVariantList listOfObjects; + + QString listeName = observingListMap.value ( QString ( KEY_NAME ) ).value(); + ui->nameOfListLineEdit->setText ( listeName ); + QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); + ui->descriptionLineEdit->setText ( listDescription ); + + if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) { + QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); + listOfObjects = data.value(); + } else { + qCritical() << "[ObservingList Creation/Edition] conversion error"; + return; + } + + for ( QVariant object: listOfObjects ) { + QVariantMap objectMap; + if ( object.canConvert() ) { + objectMap = object.value(); + QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); + + if ( objectMgr->findAndSelect ( objectName ) ) { + const QList& selectedObject = objectMgr->getSelectedObject(); + if ( !selectedObject.isEmpty() ) { + int lastRow = obsListListModel->rowCount(); + QString objectUuid = QUuid::createUuid().toString(); + QString objectNameI18n = selectedObject[0]->getNameI18n(); + QString objectRaStr = "", objectDecStr = ""; + bool visibleFlag = false; + double fov = -1.0; + + QString objectType = selectedObject[0]->getType(); + + float ra, dec; + StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); + objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); + objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); + if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + visibleFlag = true; + } + + float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); + QString objectMagnitudeStr = QString::number ( objectMagnitude ); + + QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); + QVariant objectConstellationVariant = objectMap["iauConstellation"]; + QString objectConstellation ( "unknown" ); + if ( objectConstellationVariant.canConvert() ) { + objectConstellation = objectConstellationVariant.value(); + } + + QString JDs = ""; + double JD = core->getJD(); + + JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + } + + addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); + + observingListItem item; + item.name = objectName; + item.nameI18n = objectNameI18n; + if ( !objectType.isEmpty() ) { + item.type = objectType; + } + if ( !objectRaStr.isEmpty() ) { + item.ra = objectRaStr; + } + if ( !objectDecStr.isEmpty() ) { + item.dec = objectDecStr; + } + if ( !objectMagnitudeStr.isEmpty() ) { + item.magnitude = objectMagnitudeStr; + } + if ( !objectConstellation.isEmpty() ) { + item.constellation = objectConstellation; + } + if ( !JDs.isEmpty() ) { + item.jd = JDs; + } + if ( !Location.isEmpty() ) { + item.location = Location; + } + if ( !visibleFlag ) { + item.isVisibleMarker = visibleFlag; + } + if ( fov > 0.0 ) { + item.fov = fov; + } + + observingListItemCollection.insert ( objectUuid,item ); + + } else { + qWarning() << "[ObservingList Creation/Edition] selected object is empty !"; + } } else { qWarning() << "[ObservingList Creation/Edition] object: " << objectName << " not found !" ; @@ -739,9 +754,15 @@ void ObsListCreateEditDialog::setListName ( QList listName ) */ void ObsListCreateEditDialog::kill() { - if ( m_instance != nullptr ) - { - delete m_instance; - m_instance = nullptr; - } + if ( m_instance != nullptr ) { + delete m_instance; + m_instance = nullptr; + } } + + + + + + + diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 677722c5c60de..b26248e426817 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -32,11 +32,11 @@ class Ui_obsListCreateEditDialogForm; class ObsListCreateEditDialog : public StelDialog { - Q_OBJECT + Q_OBJECT public: - static ObsListCreateEditDialog * Instance ( std::string listUuid ); - static void kill(); + static ObsListCreateEditDialog * Instance ( std::string listUuid ); + static void kill(); //! Notify that the application style changed void styleChanged(); @@ -47,21 +47,21 @@ class ObsListCreateEditDialog : public StelDialog void setListName ( QList listName ); protected: - static ObsListCreateEditDialog * m_instance; - Ui_obsListCreateEditDialogForm *ui; - //! Initialize the dialog widgets and connect the signals/slots. - virtual void createDialogContent() Q_DECL_OVERRIDE; + static ObsListCreateEditDialog * m_instance; + Ui_obsListCreateEditDialogForm *ui; + //! Initialize the dialog widgets and connect the signals/slots. + virtual void createDialogContent(); private: - //! To know if the dialog is open in creation mode or editionn mode - // if true we are in creation mode otherwise in edition mode - bool isCreationMode; - QStandardItemModel * obsListListModel; - class StelCore* core; - class StelObjectMgr* objectMgr; - std::string listUuid_; - QString observingListJsonPath; - QHash observingListItemCollection; + //! To know if the dialog is open in creation mode or editionn mode + // if true we are in creation mode otherwise in edition mode + bool isCreationMode; + QStandardItemModel * obsListListModel; + class StelCore* core; + class StelObjectMgr* objectMgr; + std::string listUuid_; + QString observingListJsonPath; + QHash observingListItemCollection; //List names QList listName_; @@ -69,8 +69,8 @@ class ObsListCreateEditDialog : public StelDialog //! Sorting of the list ex: right ascension QString sorting; - //! Set header names for observing list table - void setObservingListHeaderNames(); + //! Set header names for observing list table + void setObservingListHeaderNames(); //! Add row in the obsListListModel //! @param number row number @@ -83,21 +83,21 @@ class ObsListCreateEditDialog : public StelDialog //! @param constellation constellation in which the object is located void addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); - //! Save the object informations into json file - void saveObservedObject(); + //! Save the object informations into json file + void saveObservedObject(); - //! Load the observing liste in case of edit mode - void loadObservingList(); + //! Load the observing liste in case of edit mode + void loadObservingList(); - //Private constructor and destructor - ObsListCreateEditDialog ( std::string listUuid ); - virtual ~ObsListCreateEditDialog() Q_DECL_OVERRIDE; + //Private constructor and destructor + ObsListCreateEditDialog ( std::string listUuid ); + virtual ~ObsListCreateEditDialog(); public slots: - void retranslate() Q_DECL_OVERRIDE; + void retranslate(); private slots: void obsListAddObjectButtonPressed(); void obsListRemoveObjectButtonPressed(); @@ -109,8 +109,8 @@ private slots: void nameOfListTextChange(); signals: - //To notified that the exit button is clicked - void exitButtonClicked(); + //To notified that the exit button is clicked + void exitButtonClicked(); }; #endif // OBSLISTCREATEEDITDIALOG_H diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 1e942b8a04740..12c35b74c1a1e 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -43,20 +43,20 @@ using namespace std; ObsListDialog::ObsListDialog ( QObject* parent ) : StelDialog ( "Observing list", parent ) { - ui = new Ui_obsListDialogForm(); - core = StelApp::getInstance().getCore(); - objectMgr = GETSTELMODULE ( StelObjectMgr ); - labelMgr = GETSTELMODULE ( LabelMgr ); - obsListListModel = new QStandardItemModel ( 0,ColumnCount ); - observingListJsonPath = StelFileMgr::findFile ( "data", static_cast( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); - createEditDialog_instance = Q_NULLPTR; - defaultListUuid_ = ""; + ui = new Ui_obsListDialogForm(); + core = StelApp::getInstance().getCore(); + objectMgr = GETSTELMODULE ( StelObjectMgr ); + labelMgr = GETSTELMODULE ( LabelMgr ); + obsListListModel = new QStandardItemModel ( 0,ColumnCount ); + observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); + createEditDialog_instance = Q_NULLPTR; + defaultListUuid_ = ""; } ObsListDialog::~ObsListDialog() { - delete ui; - delete obsListListModel; + delete ui; + delete obsListListModel; } /* @@ -64,19 +64,19 @@ ObsListDialog::~ObsListDialog() */ void ObsListDialog::createDialogContent() { - ui->setupUi ( dialog ); + ui->setupUi ( dialog ); - //Signals and slots - connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); - connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); + //Signals and slots + connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); + connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); - connect ( ui->obsListNewListButton, SIGNAL ( clicked() ), this, SLOT ( obsListNewListButtonPressed() ) ); - connect ( ui->obsListEditListButton, SIGNAL ( clicked() ), this, SLOT ( obsListEditButtonPressed() ) ); - connect ( ui->obsListClearHighlightButton, SIGNAL ( clicked() ), this, SLOT ( obsListClearHighLightButtonPressed() ) ); - connect ( ui->obsListHighlightAllButton, SIGNAL ( clicked() ), this, SLOT ( obsListHighLightAllButtonPressed() ) ); - connect ( ui->obsListExitButton, SIGNAL ( clicked() ), this, SLOT ( obsListExitButtonPressed() ) ); - connect ( ui->obsListDeleteButton, SIGNAL ( clicked() ), this, SLOT ( obsListDeleteButtonPressed() ) ); - connect ( ui->obsListTreeView, SIGNAL ( doubleClicked ( QModelIndex ) ), this, SLOT ( selectAndGoToObject ( QModelIndex ) ) ); + connect ( ui->obsListNewListButton, SIGNAL ( clicked() ), this, SLOT ( obsListNewListButtonPressed() ) ); + connect ( ui->obsListEditListButton, SIGNAL ( clicked() ), this, SLOT ( obsListEditButtonPressed() ) ); + connect ( ui->obsListClearHighlightButton, SIGNAL ( clicked() ), this, SLOT ( obsListClearHighLightButtonPressed() ) ); + connect ( ui->obsListHighlightAllButton, SIGNAL ( clicked() ), this, SLOT ( obsListHighLightAllButtonPressed() ) ); + connect ( ui->obsListExitButton, SIGNAL ( clicked() ), this, SLOT ( obsListExitButtonPressed() ) ); + connect ( ui->obsListDeleteButton, SIGNAL ( clicked() ), this, SLOT ( obsListDeleteButtonPressed() ) ); + connect ( ui->obsListTreeView, SIGNAL ( doubleClicked ( QModelIndex ) ), this, SLOT ( selectAndGoToObject ( QModelIndex ) ) ); //obsListCombo settings connect ( ui->obsListComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( loadSelectedObservingList ( int ) ) ); @@ -86,21 +86,21 @@ void ObsListDialog::createDialogContent() obsListListModel->setColumnCount ( ColumnCount ); setObservingListHeaderNames(); - ui->obsListTreeView->setModel ( obsListListModel ); - ui->obsListTreeView->header()->setSectionsMovable ( false ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setStretchLastSection ( true ); - ui->obsListTreeView->hideColumn ( ColumnUUID ); - ui->obsListTreeView->hideColumn ( ColumnNameI18n ); - ui->obsListTreeView->hideColumn ( ColumnJD ); - ui->obsListTreeView->hideColumn ( ColumnLocation ); - //Enable the sort for columns - ui->obsListTreeView->setSortingEnabled ( true ); + ui->obsListTreeView->setModel ( obsListListModel ); + ui->obsListTreeView->header()->setSectionsMovable ( false ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); + ui->obsListTreeView->header()->setStretchLastSection ( true ); + ui->obsListTreeView->hideColumn ( ColumnUUID ); + ui->obsListTreeView->hideColumn ( ColumnNameI18n ); + ui->obsListTreeView->hideColumn ( ColumnJD ); + ui->obsListTreeView->hideColumn ( ColumnLocation ); + //Enable the sort for columns + ui->obsListTreeView->setSortingEnabled ( true ); //By default buttons are disable ui->obsListEditListButton->setEnabled ( false ); @@ -108,12 +108,11 @@ void ObsListDialog::createDialogContent() ui->obsListClearHighlightButton->setEnabled ( false ); ui->obsListDeleteButton->setEnabled ( false ); - QFile jsonFile ( observingListJsonPath ); - if ( jsonFile.exists() ) - { - loadListsName(); - loadDefaultList(); - } + QFile jsonFile ( observingListJsonPath ); + if ( jsonFile.exists() ) { + loadListsName(); + loadDefaultList(); + } } /* @@ -121,11 +120,10 @@ void ObsListDialog::createDialogContent() */ void ObsListDialog::retranslate() { - if ( dialog ) - { - ui->retranslateUi ( dialog ); - setObservingListHeaderNames(); - } + if ( dialog ) { + ui->retranslateUi ( dialog ); + setObservingListHeaderNames(); + } } /* @@ -133,7 +131,7 @@ void ObsListDialog::retranslate() */ void ObsListDialog::styleChanged() { - // Nothing for now + // Nothing for now } /* @@ -163,43 +161,43 @@ void ObsListDialog::setObservingListHeaderNames() */ void ObsListDialog::addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) { - QStandardItem* item = Q_NULLPTR; + QStandardItem* item = Q_NULLPTR; - item = new QStandardItem ( uuid ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnUUID, item ); + item = new QStandardItem ( uuid ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnUUID, item ); - item = new QStandardItem ( name ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnName, item ); + item = new QStandardItem ( name ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnName, item ); - item = new QStandardItem ( nameI18n ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnNameI18n, item ); + item = new QStandardItem ( nameI18n ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnNameI18n, item ); - item = new QStandardItem ( type ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnType, item ); + item = new QStandardItem ( type ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnType, item ); - item = new QStandardItem ( ra ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnRa, item ); + item = new QStandardItem ( ra ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnRa, item ); - item = new QStandardItem ( dec ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnDec, item ); + item = new QStandardItem ( dec ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnDec, item ); - item = new QStandardItem ( magnitude ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnMagnitude, item ); + item = new QStandardItem ( magnitude ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnMagnitude, item ); - item = new QStandardItem ( constellation ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnConstellation, item ); + item = new QStandardItem ( constellation ); + item->setEditable ( false ); + obsListListModel->setItem ( number, ColumnConstellation, item ); - for ( int i = 0; i < ColumnCount; ++i ) { - ui->obsListTreeView->resizeColumnToContents ( i ); - } + for ( int i = 0; i < ColumnCount; ++i ) { + ui->obsListTreeView->resizeColumnToContents ( i ); + } } /* @@ -207,44 +205,42 @@ void ObsListDialog::addModelRow ( int number, QString uuid, QString name, QStrin */ void ObsListDialog::obsListHighLightAllButtonPressed() { - QList highlights; - highlights.clear(); - obsListClearHighLightButtonPressed(); // Enable fool protection - int fontSize = StelApp::getInstance().getScreenFontSize(); - HighlightMgr* hlMgr = GETSTELMODULE ( HighlightMgr ); - QString color = hlMgr->getColor().toHtmlColor(); - float distance = hlMgr->getMarkersSize(); - - for ( auto item : observingListItemCollection ) - { - QString name = item.name; - QString raStr = item.ra.trimmed(); - QString decStr = item.dec.trimmed(); - - Vec3d pos; - bool status = false; - if ( !raStr.isEmpty() && !decStr.isEmpty() ) - { - StelUtils::spheToRect ( StelUtils::getDecAngle ( raStr ), StelUtils::getDecAngle ( decStr ), pos ); - status = true; - } - else - { - status = objectMgr->findAndSelect ( name ); - const QList& selected = objectMgr->getSelectedObject(); - if ( !selected.isEmpty() ) - pos = selected[0]->getJ2000EquatorialPos ( core ); - } - - if ( status ) - highlights.append ( pos ); - - objectMgr->unSelect(); - // Add labels for named highlights (name in top right corner) - highlightLabelIDs.append ( labelMgr->labelObject ( name, name, true, fontSize, color, "NE", distance ) ); - } - - hlMgr->fillHighlightList ( highlights ); + QList highlights; + highlights.clear(); + obsListClearHighLightButtonPressed(); // Enable fool protection + int fontSize = StelApp::getInstance().getScreenFontSize(); + HighlightMgr* hlMgr = GETSTELMODULE ( HighlightMgr ); + QString color = hlMgr->getColor().toHtmlColor(); + float distance = hlMgr->getMarkersSize(); + + for ( auto item : observingListItemCollection ) { + QString name = item.name; + QString raStr = item.ra.trimmed(); + QString decStr = item.dec.trimmed(); + + Vec3d pos; + bool status = false; + if ( !raStr.isEmpty() && !decStr.isEmpty() ) { + StelUtils::spheToRect ( StelUtils::getDecAngle ( raStr ), StelUtils::getDecAngle ( decStr ), pos ); + status = true; + } else { + status = objectMgr->findAndSelect ( name ); + const QList& selected = objectMgr->getSelectedObject(); + if ( !selected.isEmpty() ) { + pos = selected[0]->getJ2000EquatorialPos ( core ); + } + } + + if ( status ) { + highlights.append ( pos ); + } + + objectMgr->unSelect(); + // Add labels for named highlights (name in top right corner) + highlightLabelIDs.append ( labelMgr->labelObject ( name, name, true, fontSize, color, "NE", distance ) ); + } + + hlMgr->fillHighlightList ( highlights ); } /* @@ -252,13 +248,13 @@ void ObsListDialog::obsListHighLightAllButtonPressed() */ void ObsListDialog::obsListClearHighLightButtonPressed() { - objectMgr->unSelect(); - GETSTELMODULE ( HighlightMgr )->cleanHighlightList(); - // Clear labels - for ( auto l : highlightLabelIDs ) - labelMgr->deleteLabel ( l ); - - highlightLabelIDs.clear(); + objectMgr->unSelect(); + GETSTELMODULE ( HighlightMgr )->cleanHighlightList(); + // Clear labels + for ( auto l : highlightLabelIDs ) { + labelMgr->deleteLabel ( l ); + } + highlightLabelIDs.clear(); } /* @@ -266,8 +262,8 @@ void ObsListDialog::obsListClearHighLightButtonPressed() */ void ObsListDialog::obsListNewListButtonPressed() { - string listUuid = string(); - invokeObsListCreateEditDialog ( listUuid ); + string listUuid = string(); + invokeObsListCreateEditDialog ( listUuid ); } /* @@ -275,10 +271,11 @@ void ObsListDialog::obsListNewListButtonPressed() */ void ObsListDialog::obsListEditButtonPressed() { - if ( !selectedObservingListUuid.empty() ) - invokeObsListCreateEditDialog ( selectedObservingListUuid ); - else - qWarning() << "The selected observing list uuid is empty"; + if ( !selectedObservingListUuid.empty() ) { + invokeObsListCreateEditDialog ( selectedObservingListUuid ); + } else { + qWarning() << "The selected observing list uuid is empty"; + } } /** @@ -297,29 +294,23 @@ void ObsListDialog::invokeObsListCreateEditDialog ( string listUuid ) */ void ObsListDialog::loadListsName() { - QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); - else - { - try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - jsonFile.close(); - - // init combo box - ui->obsListComboBox->clear(); - ui->obsListComboBox->addItem ( "" ); + QVariantMap map; + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + + } else { + try { + map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + jsonFile.close(); // init combo box ui->obsListComboBox->clear(); - QVariantMap observingListsMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + // Get the default list uuid + QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); - QMap::iterator i; - for ( i = observingListsMap.begin(); i != observingListsMap.end(); ++i ) - { - QString listUuid = i.key(); + QVariantMap observingListsMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); QMap::iterator i; for ( i = observingListsMap.begin(); i != observingListsMap.end(); ++i ) { @@ -350,17 +341,15 @@ void ObsListDialog::loadListsName() */ void ObsListDialog::loadDefaultList() { - if ( defaultListUuid_ != "" ) - { - int index = ui->obsListComboBox->findData ( defaultListUuid_ ); - if ( index != -1 ) - { - ui->obsListComboBox->setCurrentIndex ( index ); - ui->obsListEditListButton->setEnabled ( true ); - selectedObservingListUuid = defaultListUuid_.toStdString(); - loadObservingList ( defaultListUuid_ ); - } - } + if ( defaultListUuid_ != "" ) { + int index = ui->obsListComboBox->findData ( defaultListUuid_ ); + if ( index != -1 ) { + ui->obsListComboBox->setCurrentIndex ( index ); + ui->obsListEditListButton->setEnabled ( true ); + selectedObservingListUuid = defaultListUuid_.toStdString(); + loadObservingList ( defaultListUuid_ ); + } + } } /* @@ -382,72 +371,94 @@ void ObsListDialog::loadObservingList ( QString listUuid ) ui->obsListClearHighlightButton->setEnabled ( true ); ui->obsListDeleteButton->setEnabled ( true ); - for ( QVariant object: listOfObjects ) - { - QVariantMap objectMap; - if ( object.canConvert() ) - { - objectMap = object.value(); - QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); - - if ( objectMgr->findAndSelect ( objectName ) ) - { - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) - { - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - QString objectNameI18n = selectedObject[0]->getNameI18n(); - QString objectRaStr = "", objectDecStr = ""; - bool visibleFlag = false; - double fov = -1.0; - - QString objectType = selectedObject[0]->getType(); - - double ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) - visibleFlag = true; - - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); - - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); - QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) - objectConstellation = objectConstellationVariant.value(); - - QString JDs = ""; - double JD = core->getJD(); - - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); - - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - else - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); - - observingListItem item; - item.name = objectName; - item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) - item.type = objectType; - - if ( !objectRaStr.isEmpty() ) - item.ra = objectRaStr; - - if ( !objectDecStr.isEmpty() ) - item.dec = objectDecStr; - - if ( !objectMagnitudeStr.isEmpty() ) - item.magnitude = objectMagnitudeStr; + for ( QVariant object: listOfObjects ) { + QVariantMap objectMap; + if ( object.canConvert() ) { + objectMap = object.value(); + QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); + + if ( objectMgr->findAndSelect ( objectName ) ) { + const QList& selectedObject = objectMgr->getSelectedObject(); + if ( !selectedObject.isEmpty() ) { + + int lastRow = obsListListModel->rowCount(); + QString objectUuid = QUuid::createUuid().toString(); + QString objectNameI18n = selectedObject[0]->getNameI18n(); + QString objectRaStr = "", objectDecStr = ""; + bool visibleFlag = false; + double fov = -1.0; + + QString objectType = selectedObject[0]->getType(); + + float ra, dec; + StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); + objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); + objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); + if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + visibleFlag = true; + } + + float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); + QString objectMagnitudeStr = QString::number ( objectMagnitude ); + + QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); + QVariant objectConstellationVariant = objectMap["iauConstellation"]; + QString objectConstellation ( "unknown" ); + if ( objectConstellationVariant.canConvert() ) { + objectConstellation = objectConstellationVariant.value(); + } + + QString JDs = ""; + double JD = core->getJD(); + + JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + } + + addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); + + observingListItem item; + item.name = objectName; + item.nameI18n = objectNameI18n; + if ( !objectType.isEmpty() ) { + item.type = objectType; + } + if ( !objectRaStr.isEmpty() ) { + item.ra = objectRaStr; + } + if ( !objectDecStr.isEmpty() ) { + item.dec = objectDecStr; + } + if ( !objectMagnitudeStr.isEmpty() ) { + item.magnitude = objectMagnitudeStr; + } + if ( !objectConstellation.isEmpty() ) { + item.constellation = objectConstellation; + } + if ( !JDs.isEmpty() ) { + item.jd = QString::number ( JD, 'f', 6 ); + } + if ( !Location.isEmpty() ) { + item.location = Location; + } + if ( !visibleFlag ) { + item.isVisibleMarker = visibleFlag; + } + if ( fov > 0.0 ) { + item.fov = fov; + } + + observingListItemCollection.insert ( objectUuid,item ); + + } else { + qWarning() << "[ObservingList] selected object is empty !"; + } } else { qWarning() << "[ObservingList] object: " << objectName << " not found !" ; @@ -463,48 +474,12 @@ void ObsListDialog::loadObservingList ( QString listUuid ) ui->obsListDeleteButton->setEnabled ( false ); } - if ( !JDs.isEmpty() ) - item.jd = QString::number ( JD, 'f', 6 ); - - if ( !Location.isEmpty() ) - item.location = Location; - - if ( !visibleFlag ) - item.isVisibleMarker = visibleFlag; - - if ( fov > 0.0 ) - item.fov = fov; - - observingListItemCollection.insert ( objectUuid,item ); - } - else - qWarning() << "[ObservingList] selected object is empty !"; - } - else - qWarning() << "[ObservingList] object: " << objectName << " not found !" ; - } - else - { - qCritical() << "[ObservingList] conversion error"; - return; - } - } - } - else - { - ui->obsListHighlightAllButton->setEnabled ( false ); - ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled(false); - } - - objectMgr->unSelect(); - } - catch ( std::runtime_error &e ) - { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); - return; - } - } + objectMgr->unSelect(); + } catch ( std::runtime_error &e ) { + qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + return; + } + } } /* @@ -547,81 +522,78 @@ QVariantList ObsListDialog::loadListFromJson ( QFile &jsonFile, QString listUuid */ void ObsListDialog::selectAndGoToObject ( QModelIndex index ) { - QStandardItem * selectedItem = obsListListModel->itemFromIndex ( index ); - int rawNumber = selectedItem->row(); - - QStandardItem * uuidItem = obsListListModel->item ( rawNumber, ColumnUUID ); - QString itemUuid = uuidItem->text(); - observingListItem item = observingListItemCollection.value ( itemUuid ); - - if ( !item.jd.isEmpty() ) - core->setJD ( item.jd.toDouble() ); - - if ( !item.location.isEmpty() ) - { - StelLocationMgr* locationMgr = &StelApp::getInstance().getLocationMgr(); - core->moveObserverTo ( locationMgr->locationForString ( item.location ) ); - } - - StelMovementMgr* mvmgr = GETSTELMODULE ( StelMovementMgr ); - objectMgr->unSelect(); - - bool status = objectMgr->findAndSelect ( item.name ); - float amd = mvmgr->getAutoMoveDuration(); - if ( !item.ra.isEmpty() && !item.dec.isEmpty() && !status ) - { - Vec3d pos; - StelUtils::spheToRect ( StelUtils::getDecAngle ( item.ra.trimmed() ), StelUtils::getDecAngle ( item.dec.trimmed() ), pos ); - if ( item.name.contains ( "marker", Qt::CaseInsensitive ) ) - { - // Add a custom object on the sky - GETSTELMODULE ( CustomObjectMgr )->addCustomObject ( item.name, pos, item.isVisibleMarker ); - status = objectMgr->findAndSelect ( item.name ); - } - else - { - // The unnamed stars - StelObjectP sobj; - const StelProjectorP prj = core->getProjection ( StelCore::FrameJ2000 ); - double fov = 5.0; - if ( item.fov > 0.0 ) - fov = item.fov; - - mvmgr->zoomTo ( fov, 0.0 ); - mvmgr->moveToJ2000 ( pos, mvmgr->mountFrameToJ2000 ( Vec3d ( 0., 0., 1. ) ), 0.0 ); - - QList candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); - if ( candidates.empty() ) - { // The FOV is too big, let's reduce it - mvmgr->zoomTo ( 0.5*fov, 0.0 ); - candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); - } - - double best_object_value = M_PI; - for ( const auto& obj : candidates ) - { - double distance=pos.angle(obj->getJ2000EquatorialPos(core)); - if ( distance < best_object_value ) - { - best_object_value = distance; - sobj = obj; - } - } - - if ( sobj ) - status = objectMgr->setSelectedObject ( sobj ); - } - } - - if ( status ) - { - const QList newSelected = objectMgr->getSelectedObject(); - if ( !newSelected.empty() ) - { - mvmgr->moveToObject ( newSelected[0], amd ); - mvmgr->setFlagTracking ( true ); - } - } + QStandardItem * selectedItem = obsListListModel->itemFromIndex ( index ); + int rawNumber = selectedItem->row(); + + QStandardItem * uuidItem = obsListListModel->item ( rawNumber, ColumnUUID ); + QString itemUuid = uuidItem->text(); + observingListItem item = observingListItemCollection.value ( itemUuid ); + + if ( !item.jd.isEmpty() ) { + core->setJD ( item.jd.toDouble() ); + } + if ( !item.location.isEmpty() ) { + StelLocationMgr* locationMgr = &StelApp::getInstance().getLocationMgr(); + core->moveObserverTo ( locationMgr->locationForString ( item.location ) ); + } + + StelMovementMgr* mvmgr = GETSTELMODULE ( StelMovementMgr ); + objectMgr->unSelect(); + + bool status = objectMgr->findAndSelect ( item.name ); + float amd = mvmgr->getAutoMoveDuration(); + if ( !item.ra.isEmpty() && !item.dec.isEmpty() && !status ) { + Vec3d pos; + StelUtils::spheToRect ( StelUtils::getDecAngle ( item.ra.trimmed() ), StelUtils::getDecAngle ( item.dec.trimmed() ), pos ); + if ( item.name.contains ( "marker", Qt::CaseInsensitive ) ) { + // Add a custom object on the sky + GETSTELMODULE ( CustomObjectMgr )->addCustomObject ( item.name, pos, item.isVisibleMarker ); + status = objectMgr->findAndSelect ( item.name ); + } else { + // The unnamed stars + StelObjectP sobj; + const StelProjectorP prj = core->getProjection ( StelCore::FrameJ2000 ); + double fov = 5.0; + if ( item.fov > 0.0 ) { + fov = item.fov; + } + + mvmgr->zoomTo ( fov, 0.0 ); + mvmgr->moveToJ2000 ( pos, mvmgr->mountFrameToJ2000 ( Vec3d ( 0., 0., 1. ) ), 0.0 ); + + QList candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); + if ( candidates.empty() ) { // The FOV is too big, let's reduce it + mvmgr->zoomTo ( 0.5*fov, 0.0 ); + candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); + } + + Vec3d winpos; + prj->project ( pos, winpos ); + float xpos = winpos[0]; + float ypos = winpos[1]; + float best_object_value = 1000.f; + for ( const auto& obj : candidates ) { + prj->project ( obj->getJ2000EquatorialPos ( core ), winpos ); + float distance = std::sqrt ( ( xpos-winpos[0] ) * ( xpos-winpos[0] ) + ( ypos-winpos[1] ) * ( ypos-winpos[1] ) ); + if ( distance < best_object_value ) { + best_object_value = distance; + sobj = obj; + } + } + + if ( sobj ) { + status = objectMgr->setSelectedObject ( sobj ); + } + } + } + + if ( status ) { + const QList newSelected = objectMgr->getSelectedObject(); + if ( !newSelected.empty() ) { + mvmgr->moveToObject ( newSelected[0], amd ); + mvmgr->setFlagTracking ( true ); + } + } } /* @@ -682,43 +654,11 @@ void ObsListDialog::obsListDeleteButtonPressed() jsonFile.flush(); jsonFile.close(); - newMap.insert(QString(KEY_DEFAULT_LIST_UUID), map.value(QString(KEY_DEFAULT_LIST_UUID))); - QVariantMap obsListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); - - QMap::iterator i; - for(i = obsListMap.begin(); i != obsListMap.end(); ++i) - { - if(i.key().compare(QString::fromStdString(selectedObservingListUuid))!=0) - newObsListMap.insert(i.key(),i.value()); - } - - newMap.insert(QString(KEY_OBSERVING_LISTS),newObsListMap); - newMap.insert(QString(KEY_SHORT_NAME), map.value(QString(KEY_SHORT_NAME))); - newMap.insert(QString(KEY_VERSION), map.value(QString(KEY_VERSION))); - objectMgr->unSelect(); - observingListItemCollection.clear(); - // Clear model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - ui->obsListCreationDateLineEdit->setText(""); - int currentIndex = ui->obsListComboBox->currentIndex(); - ui->obsListComboBox->removeItem(currentIndex); - - int index = ui->obsListComboBox->findData(""); - ui->obsListComboBox->setCurrentIndex(index); - ui->obsListDescriptionTextEdit->setPlainText(""); - - jsonFile.resize ( 0 ); - StelJsonParser::write ( newMap, &jsonFile ); - jsonFile.flush(); - jsonFile.close(); - - } - catch ( std::runtime_error &e ) - { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); - return; - } - } + } catch ( std::runtime_error &e ) { + qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + return; + } + } } /* @@ -726,7 +666,7 @@ void ObsListDialog::obsListDeleteButtonPressed() */ void ObsListDialog::obsListExitButtonPressed() { - this->close(); + this->close(); } /* @@ -734,17 +674,16 @@ void ObsListDialog::obsListExitButtonPressed() */ void ObsListDialog::obsListCreateEditDialogClosed() { - // We must reload the list of list name - loadListsName(); - int index = ui->obsListComboBox->findData ( QString::fromStdString ( selectedObservingListUuid ) ) ; - if ( index != -1 ) - { - ui->obsListComboBox->setCurrentIndex ( index ); - loadSelectedObservingList ( index ); - } - - ObsListCreateEditDialog::kill(); - createEditDialog_instance = Q_NULLPTR; + // We must reload the list of list name + loadListsName(); + int index = ui->obsListComboBox->findData ( QString::fromStdString ( selectedObservingListUuid ) ) ; + if ( index != -1 ) { + ui->obsListComboBox->setCurrentIndex ( index ); + loadSelectedObservingList ( index ); + } + + ObsListCreateEditDialog::kill(); + createEditDialog_instance = Q_NULLPTR; } diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 691b8f8bd00c9..6fe515e625370 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -32,11 +32,11 @@ class Ui_obsListDialogForm; class ObsListDialog : public StelDialog { - Q_OBJECT + Q_OBJECT public: - ObsListDialog ( QObject* parent ); - virtual ~ObsListDialog() Q_DECL_OVERRIDE; + ObsListDialog ( QObject* parent ); + virtual ~ObsListDialog(); //! Notify that the application style changed void styleChanged(); @@ -44,9 +44,9 @@ class ObsListDialog : public StelDialog void setVisible ( bool v ); protected: - Ui_obsListDialogForm *ui; - //! Initialize the dialog widgets and connect the signals/slots. - virtual void createDialogContent() Q_DECL_OVERRIDE; + Ui_obsListDialogForm *ui; + //! Initialize the dialog widgets and connect the signals/slots. + virtual void createDialogContent(); private: QStandardItemModel * obsListListModel; @@ -60,12 +60,12 @@ class ObsListDialog : public StelDialog QString defaultListUuid_; QList listName; - //! Set header names for observing list table - void setObservingListHeaderNames(); + //! Set header names for observing list table + void setObservingListHeaderNames(); - void invokeObsListCreateEditDialog ( std::string listUuid ); + void invokeObsListCreateEditDialog ( std::string listUuid ); - ObsListCreateEditDialog * createEditDialog_instance; + ObsListCreateEditDialog * createEditDialog_instance; //! Add row in the obsListListModel //! @param number row number @@ -78,9 +78,9 @@ class ObsListDialog : public StelDialog //! @param constellation constellation in which the object is located void addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); - //! Load the selected observing list - //! @param listUuid the uuid of the list - void loadObservingList ( QString listUuid ); + //! Load the selected observing list + //! @param listUuid the uuid of the list + void loadObservingList ( QString listUuid ); //! Load the lists names to populate the combo box and get the default list uuid void loadListsName(); @@ -91,32 +91,26 @@ class ObsListDialog : public StelDialog //! Load list from JSON file QVariantList loadListFromJson(QFile &jsonFile, QString listUuid); - //! Load the default list - void loadDefaultList(); - - //! Load list from JSON file - QVariantList loadListFromJson(QFile &jsonFile, QString listUuid); - public slots: - virtual void retranslate() Q_DECL_OVERRIDE; + void retranslate(); private slots: - void obsListHighLightAllButtonPressed(); - void obsListClearHighLightButtonPressed(); - void obsListNewListButtonPressed(); - void obsListEditButtonPressed(); - void obsListCreateEditDialogClosed(); - void obsListExitButtonPressed(); - void obsListDeleteButtonPressed(); - - //! Method called when a list name is selected in the combobox - //! @param selectedIndex the index of the list name in the combo box - void loadSelectedObservingList ( int selectedIndex ); - - //! Select and go to object - //! @param index the QModelIndex of the list - void selectAndGoToObject ( QModelIndex index ); + void obsListHighLightAllButtonPressed(); + void obsListClearHighLightButtonPressed(); + void obsListNewListButtonPressed(); + void obsListEditButtonPressed(); + void obsListCreateEditDialogClosed(); + void obsListExitButtonPressed(); + void obsListDeleteButtonPressed(); + + //! Method called when a list name is selected in the combobox + //! @param selectedIndex the index of the list name in the combo box + void loadSelectedObservingList ( int selectedIndex ); + + //! Select and go to object + //! @param index the QModelIndex of the list + void selectAndGoToObject ( QModelIndex index ); }; #endif // OBSLISTDIALOG_H From 5e7b3e5697dd1d711f6f0a3c9a2af83a1ed50244 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Tue, 26 Oct 2021 17:10:03 +0200 Subject: [PATCH 05/28] Sort list in combo Correction of the sort list in combo --- po/stellarium/fr.po | 2 +- src/gui/ObsListCreateEditDialog.cpp | 6 +- src/gui/ObsListDialog.cpp | 85 ++++++++++++++++++++--------- src/gui/ObsListDialog.hpp | 10 ++++ src/gui/obsListCreateEditDialog.ui | 4 +- stellarium.kdev4 | 4 ++ 6 files changed, 80 insertions(+), 31 deletions(-) create mode 100644 stellarium.kdev4 diff --git a/po/stellarium/fr.po b/po/stellarium/fr.po index 050d062a5478d..b740afbfc3352 100644 --- a/po/stellarium/fr.po +++ b/po/stellarium/fr.po @@ -13396,7 +13396,7 @@ msgstr "Exporter la liste" #: src/ui_obsListCreateEditDialog.h:264 msgid "Import list" -msgstr "Exporter la liste" +msgstr "Importer la liste" #: src/ui_obsListCreateEditDialog.h:265 msgid "Save and Close " diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 66fde4a53f06d..0b417e0d2b9b7 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -290,7 +290,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() if ( loc.name.isEmpty() ) { Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); } addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); @@ -405,7 +405,7 @@ void ObsListCreateEditDialog::saveObservedObject() if ( loc.name.isEmpty() ) { Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); } observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); @@ -667,7 +667,7 @@ void ObsListCreateEditDialog::loadObservingList() if ( loc.name.isEmpty() ) { Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); } addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 12c35b74c1a1e..f43b068f42c8c 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -80,7 +80,6 @@ void ObsListDialog::createDialogContent() //obsListCombo settings connect ( ui->obsListComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( loadSelectedObservingList ( int ) ) ); - ui->obsListComboBox->model()->sort(0); //Initialize the list of observing lists obsListListModel->setColumnCount ( ColumnCount ); @@ -285,7 +284,7 @@ void ObsListDialog::invokeObsListCreateEditDialog ( string listUuid ) { createEditDialog_instance = ObsListCreateEditDialog::Instance ( listUuid ); connect ( createEditDialog_instance, SIGNAL ( exitButtonClicked() ), this, SLOT ( obsListCreateEditDialogClosed() ) ); - createEditDialog_instance->setListName(listName); + createEditDialog_instance->setListName ( listName ); createEditDialog_instance->setVisible ( true ); } @@ -311,24 +310,9 @@ void ObsListDialog::loadListsName() QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); QVariantMap observingListsMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + populateListNameInComboBox ( observingListsMap ); + populateDataInComboBox ( observingListsMap, defaultListUuid ); - QMap::iterator i; - for ( i = observingListsMap.begin(); i != observingListsMap.end(); ++i ) { - QString listUuid = i.key(); - - if ( i.value().canConvert() ) { - QVariant var = i.value(); - QVariantMap data = var.value(); - QString listName = data.value ( KEY_NAME ).value(); - this->listName.append(listName); - ui->obsListComboBox->addItem ( listName, listUuid ); - if ( defaultListUuid == listUuid ) { - defaultListUuid_ = defaultListUuid; - } - } - //ui->obsListComboBox->model()->sort(0); - //loadDefaultList(); - } } catch ( std::runtime_error &e ) { qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); return; @@ -336,6 +320,54 @@ void ObsListDialog::loadListsName() } } + +/* + * Populate the list names into combo box +*/ +void ObsListDialog::populateListNameInComboBox ( QVariantMap map ) +{ + QMap::iterator i; + for ( i = map.begin(); i != map.end(); ++i ) { + if ( i.value().canConvert() ) { + QVariant var = i.value(); + QVariantMap data = var.value(); + QString listName = data.value ( KEY_NAME ).value(); + listNamesModel.append ( listName ); + } + } + listNamesModel.sort ( Qt::CaseInsensitive ); + ui->obsListComboBox->addItems ( listNamesModel ); +} + +/* + * Populate data into combo box +*/ +void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultListUuid ) +{ + QMap::iterator i; + for ( i = map.begin(); i != map.end(); ++i ) { + QString listUuid = i.key(); + if ( i.value().canConvert() ) { + QVariant var = i.value(); + QVariantMap data = var.value(); + QString listName = data.value ( KEY_NAME ).value(); + + foreach ( QString str, listNamesModel ) { + if ( QString::compare ( str, listName ) == 0 ) { + int index = listNamesModel.indexOf ( listName, 0 ); + ui->obsListComboBox->setItemData ( index,listUuid ); + break; + } + } + } + if ( defaultListUuid == listUuid ) { + defaultListUuid_ = defaultListUuid; + } + } +} + + + /* * Load the default list */ @@ -418,7 +450,7 @@ void ObsListDialog::loadObservingList ( QString listUuid ) if ( loc.name.isEmpty() ) { Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.country ); + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); } addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); @@ -676,7 +708,10 @@ void ObsListDialog::obsListCreateEditDialogClosed() { // We must reload the list of list name loadListsName(); - int index = ui->obsListComboBox->findData ( QString::fromStdString ( selectedObservingListUuid ) ) ; + int index = 0; + if ( !selectedObservingListUuid.empty() ) { + index = ui->obsListComboBox->findData ( QString::fromStdString ( selectedObservingListUuid ) ) ; + } if ( index != -1 ) { ui->obsListComboBox->setCurrentIndex ( index ); loadSelectedObservingList ( index ); @@ -693,11 +728,11 @@ void ObsListDialog::obsListCreateEditDialogClosed() */ void ObsListDialog::setVisible ( bool v ) { - if (v){ - StelDialog::setVisible(true); + if ( v ) { + StelDialog::setVisible ( true ); this->loadDefaultList(); - }else{ - StelDialog::setVisible(false); + } else { + StelDialog::setVisible ( false ); } } diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 6fe515e625370..7b4b380dadd3e 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -22,6 +22,7 @@ #include #include +#include #include "StelDialog.hpp" #include "StelCore.hpp" @@ -59,6 +60,7 @@ class ObsListDialog : public StelDialog QList highlightLabelIDs; QString defaultListUuid_; QList listName; + QStringList listNamesModel; //! Set header names for observing list table void setObservingListHeaderNames(); @@ -90,6 +92,12 @@ class ObsListDialog : public StelDialog //! Load list from JSON file QVariantList loadListFromJson(QFile &jsonFile, QString listUuid); + + //! Populate list names into combo box + void populateListNameInComboBox(QVariantMap map); + + //! Populate data into combo box + void populateDataInComboBox(QVariantMap map, QString defaultListUuid); public slots: @@ -103,6 +111,8 @@ private slots: void obsListCreateEditDialogClosed(); void obsListExitButtonPressed(); void obsListDeleteButtonPressed(); + + //! Method called when a list name is selected in the combobox //! @param selectedIndex the index of the list name in the combo box diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index 7053c80cacfcf..a5dcf41449599 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -193,7 +193,7 @@ - Create a new observing list + Export list 3 @@ -206,7 +206,7 @@ - Edit the selected list + Import list 3 diff --git a/stellarium.kdev4 b/stellarium.kdev4 new file mode 100644 index 0000000000000..b4a438370b981 --- /dev/null +++ b/stellarium.kdev4 @@ -0,0 +1,4 @@ +[Project] +CreatedFrom=CMakeLists.txt +Manager=KDevCMakeManager +Name=stellarium From 5879f9ea052d2659b88eb9a344dfdb03caa24ec0 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 27 Oct 2021 17:34:54 +0200 Subject: [PATCH 06/28] Adding legacy bookmarks adding legacy bookmarks into observing list --- src/gui/ObsListCreateEditDialog.cpp | 7 +- src/gui/ObsListDialog.cpp | 171 ++++++++++++++++++++++++++++ src/gui/ObsListDialog.hpp | 5 + src/gui/ObservingListCommon.hpp | 32 +++++- 4 files changed, 210 insertions(+), 5 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 0b417e0d2b9b7..2d782574fc3d0 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -410,8 +410,7 @@ void ObsListCreateEditDialog::saveObservedObject() observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); // Name of the liste - QString name = ui->nameOfListLineEdit->text(); - observingListDataList.insert ( QString ( KEY_NAME ), name ); + observingListDataList.insert ( QString ( KEY_NAME ), listName ); // List of objects QVariantList listOfObjects; @@ -446,7 +445,7 @@ void ObsListCreateEditDialog::saveObservedObject() } mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); - mapFromJsonFile.insert ( KEY_SHORT_NAME, "Observing list for Stellarium" ); + mapFromJsonFile.insert ( KEY_SHORT_NAME, SHORT_NAME_VALUE ); allListsMap.insert ( oblListUuid, observingListDataList ); mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); @@ -574,7 +573,7 @@ void ObsListCreateEditDialog::headerClicked ( int index ) sorting = QString ( SORTING_BY_MAGNITUDE ); break; case ColumnConstellation: - sorting = QString ( SORTING_BY_CONSTTELLATION );; + sorting = QString ( SORTING_BY_CONSTELLATION );; break; default: sorting = ""; diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index f43b068f42c8c..301fc82d3de72 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -49,6 +49,7 @@ ObsListDialog::ObsListDialog ( QObject* parent ) : StelDialog ( "Observing list" labelMgr = GETSTELMODULE ( LabelMgr ); obsListListModel = new QStandardItemModel ( 0,ColumnCount ); observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); + bookmarksJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_BOOKMARKS_FILE_NAME ); createEditDialog_instance = Q_NULLPTR; defaultListUuid_ = ""; } @@ -107,11 +108,20 @@ void ObsListDialog::createDialogContent() ui->obsListClearHighlightButton->setEnabled ( false ); ui->obsListDeleteButton->setEnabled ( false ); + + // For no regression we must take into account the legacy bookmarks file + QFile jsonBookmarksFile ( bookmarksJsonPath ); + if ( jsonBookmarksFile.exists() ) { + qDebug() << "Fichiers bookmarks détecté"; + loadBookmarksInObservingList(); + } + QFile jsonFile ( observingListJsonPath ); if ( jsonFile.exists() ) { loadListsName(); loadDefaultList(); } + } /* @@ -549,6 +559,167 @@ QVariantList ObsListDialog::loadListFromJson ( QFile &jsonFile, QString listUuid } +/* + * Load the bookmarks of bookmarks.json file into observing lists file + * For no regression with must take into account the legacy bookmarks.json file +*/ +void ObsListDialog::loadBookmarksInObservingList() +{ + QHash bookmarksCollection; + QVariantMap map; + + QFile jsonFile ( bookmarksJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( bookmarksJsonPath ); + } else { + + try { + + map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + jsonFile.close(); + QVariantMap bookmarksMap = map.value ( KEY_BOOKMARKS ).toMap(); + + for ( auto bookmarkKey : bookmarksMap.keys() ) { + + QVariantMap bookmarkData = bookmarksMap.value ( bookmarkKey ).toMap(); + bookmark item; + + QString JDs = ""; + + item.name = bookmarkData.value ( KEY_NAME ).toString(); + QString nameI18n = bookmarkData.value ( KEY_NAME_I18N ).toString(); + if ( !nameI18n.isEmpty() ) { + item.nameI18n = nameI18n; + } + + QString JD = bookmarkData.value ( KEY_JD ).toString(); + if ( !JD.isEmpty() ) { + item.jd = JD; + JDs = StelUtils::julianDayToISO8601String ( JD.toDouble() + core->getUTCOffset ( JD.toDouble() ) /24. ).replace ( "T", " " ); + } + + QString Location = bookmarkData.value ( KEY_LOCATION ).toString(); + if ( !Location.isEmpty() ) { + item.location = Location; + } + + QString RA = bookmarkData.value ( KEY_RA ).toString(); + if ( !RA.isEmpty() ) { + item.ra = RA; + } + + QString Dec = bookmarkData.value ( KEY_DEC ).toString(); + if ( !Dec.isEmpty() ) { + item.dec = Dec; + } + + item.isVisibleMarker = bookmarkData.value ( KEY_IS_VISIBLE_MARKER, false ).toBool(); + double fov = bookmarkData.value ( KEY_FOV ).toDouble(); + if ( fov > 0.0 ) { + item.fov = fov; + } + + bookmarksCollection.insert ( bookmarkKey, item ); + + } + + saveBookmarks(bookmarksCollection); + + } catch ( std::runtime_error &e ) { + qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + return; + } + } +} + + +/* + * Save the bookmarks into observing list file +*/ +void ObsListDialog::saveBookmarks ( QHash bookmarksCollection ) +{ + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { + qWarning() << "[ObservingList] bookmarks list can not be saved. A file can not be open for reading and writing:" + << QDir::toNativeSeparators ( observingListJsonPath ); + return; + } + + try { + + QVariantMap mapFromJsonFile; + QVariantMap allListsMap; + QVariantMap observingListDataList; + if ( jsonFile.size() > 0 ) { + mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + } + + // Description + QString description = QString(BOOKMARKS_LIST_DESCRIPTION); + observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); + + // Julian day + QString JDString = ""; + double JD = core->getJD(); + JDString = QString::number ( JD, 'f', 6 ); + observingListDataList.insert ( QString ( KEY_JD ), JDString ); + + // Location + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); + } + observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); + + // Name of the liste + observingListDataList.insert ( QString ( KEY_NAME ), BOOKMARKS_LIST_NAME ); + + // List of objects + QVariantList listOfObjects; + QHashIterator i ( bookmarksCollection ); + while ( i.hasNext() ) { + i.next(); + + bookmark item = i.value(); + QVariantMap obl; + QString objectName = item.name; + obl.insert ( QString ( KEY_DESIGNATION ), objectName ); + listOfObjects.push_back ( obl ); + } + + observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); + observingListDataList.insert ( QString ( KEY_SORTING ), SORTING_BY_NAME ); + + QList keys = bookmarksCollection.keys(); + QString oblListUuid; + if(keys.empty()){ + oblListUuid = QUuid::createUuid().toString(); + } else { + oblListUuid = keys.at(0); + } + + mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); + mapFromJsonFile.insert ( KEY_SHORT_NAME,SHORT_NAME_VALUE ); + + allListsMap.insert ( oblListUuid, observingListDataList ); + mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); + + jsonFile.resize ( 0 ); + StelJsonParser::write ( mapFromJsonFile, &jsonFile ); + jsonFile.flush(); + jsonFile.close(); + + } catch ( std::runtime_error &e ) { + qCritical() << "[ObservingList] File format is wrong! Error: " << e.what(); + return; + } +} + + /* * Select and go to object */ diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 7b4b380dadd3e..260045c12007b 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -56,6 +56,7 @@ class ObsListDialog : public StelDialog class LabelMgr* labelMgr; std::string selectedObservingListUuid; QString observingListJsonPath; + QString bookmarksJsonPath; QHash observingListItemCollection; QList highlightLabelIDs; QString defaultListUuid_; @@ -90,6 +91,10 @@ class ObsListDialog : public StelDialog //! Load the default list void loadDefaultList(); + //! Load the bookmarks of bookmarks.json file into observing lists file + void loadBookmarksInObservingList(); + void saveBookmarks(QHash bookmarksCollection); + //! Load list from JSON file QVariantList loadListFromJson(QFile &jsonFile, QString listUuid); diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 9628f69b0a636..5344dcc7bda27 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -35,6 +35,22 @@ struct observingListItem { }; Q_DECLARE_METATYPE ( observingListItem ) +//TODO certain champ peuvent ne pas servir - penser à les supprimer +// à vérifier après la V2 +struct bookmark +{ + QString name; + QString nameI18n; + QString ra; + QString dec; + bool isVisibleMarker; + QString jd; + QString location; + double fov; + +}; +Q_DECLARE_METATYPE(bookmark) + enum ObsListColumns { ColumnUUID, //! UUID of object ColumnName, //! Name or designation of object @@ -49,13 +65,26 @@ enum ObsListColumns { ColumnCount //! Total number of columns }; +//TODO certaine clé peuvent ne pas servir - penser à les supprimer +// à vérifier après la V2 + static constexpr char const * JSON_FILE_NAME = "observingList.json"; static constexpr char const * FILE_VERSION = "1.0"; +static constexpr char const * JSON_BOOKMARKS_FILE_NAME = "bookmarks.json"; +static constexpr char const * BOOKMARKS_LIST_NAME = "bookmarks list"; +static constexpr char const * BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version"; +static constexpr char const * SHORT_NAME_VALUE = "Observing list for Stellarium"; + static constexpr char const * KEY_DEFAULT_LIST_UUID = "defaultListUuid"; static constexpr char const * KEY_OBSERVING_LISTS = "observingLists"; +static constexpr char const * KEY_BOOKMARKS = "bookmarks"; static constexpr char const * KEY_NAME = "name"; +static constexpr char const * KEY_NAME_I18N = "nameI18n"; static constexpr char const * KEY_JD = "jd"; +static constexpr char const * KEY_RA = "ra"; +static constexpr char const * KEY_DEC = "dec"; +static constexpr char const * KEY_FOV = "fov"; static constexpr char const * KEY_DESCRIPTION = "description"; static constexpr char const * KEY_OBJECTS = "objects"; static constexpr char const * KEY_DESIGNATION = "designation"; @@ -63,13 +92,14 @@ static constexpr char const * KEY_SORTING = "sorting"; static constexpr char const * KEY_LOCATION = "location"; static constexpr char const * KEY_VERSION = "version"; static constexpr char const * KEY_SHORT_NAME = "shortName"; +static constexpr char const * KEY_IS_VISIBLE_MARKER = "isVisibleMarker"; static constexpr char const * SORTING_BY_NAME = "name"; static constexpr char const * SORTING_BY_TYPE = "type"; static constexpr char const * SORTING_BY_RA = "right ascension"; static constexpr char const * SORTING_BY_DEC = "declination"; static constexpr char const * SORTING_BY_MAGNITUDE = "magnitude"; -static constexpr char const * SORTING_BY_CONSTTELLATION = "constellation"; +static constexpr char const * SORTING_BY_CONSTELLATION = "constellation"; #endif // OBSLISTDIALOG_H From 251fd55de0e05476f0e8d407d7e04aeeb560808a Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Thu, 28 Oct 2021 19:09:48 +0200 Subject: [PATCH 07/28] Sorting objects in obsListTreeView Sorting objects when the list is loaded. --- src/gui/ObsListDialog.cpp | 101 ++++++++++++++++++++++++-------- src/gui/ObsListDialog.hpp | 6 +- src/gui/ObservingListCommon.hpp | 9 ++- 3 files changed, 90 insertions(+), 26 deletions(-) diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 301fc82d3de72..1feb65466df9a 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -406,7 +406,12 @@ void ObsListDialog::loadObservingList ( QString listUuid ) qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); } else { try { - listOfObjects = loadListFromJson ( jsonFile, listUuid ); + + map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); + QString sortingBy = observingListMap.value ( KEY_SORTING ).toString(); + + listOfObjects = loadListFromJson ( map, listUuid ); if ( listOfObjects.size() > 0 ) { ui->obsListHighlightAllButton->setEnabled ( true ); @@ -517,21 +522,23 @@ void ObsListDialog::loadObservingList ( QString listUuid ) } objectMgr->unSelect(); + if ( !sortingBy.isEmpty() ) { + sortObsListTreeViewByColumnName ( sortingBy ); + } + jsonFile.close(); } catch ( std::runtime_error &e ) { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + qWarning() << "[ObservingList] Load selected observing list: File format is wrong! Error: " << e.what(); + jsonFile.close(); return; } } } /* - * Load the list from JSON file + * Load the list from JSON file QVariantMap map */ -QVariantList ObsListDialog::loadListFromJson ( QFile &jsonFile, QString listUuid ) +QVariantList ObsListDialog::loadListFromJson ( QVariantMap map, QString listUuid ) { - QVariantMap map; - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - jsonFile.close(); observingListItemCollection.clear(); QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); @@ -622,11 +629,11 @@ void ObsListDialog::loadBookmarksInObservingList() bookmarksCollection.insert ( bookmarkKey, item ); } - - saveBookmarks(bookmarksCollection); + + saveBookmarks ( bookmarksCollection ); } catch ( std::runtime_error &e ) { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + qWarning() << "[ObservingList] Load bookmarks in observing list: File format is wrong! Error: " << e.what(); return; } } @@ -646,7 +653,7 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection } try { - + QVariantMap mapFromJsonFile; QVariantMap allListsMap; QVariantMap observingListDataList; @@ -654,17 +661,22 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); } - + + if ( checkIfBookmarksListExists ( allListsMap ) ) { + //the bookmarks file is already loaded + return; + } + // Description - QString description = QString(BOOKMARKS_LIST_DESCRIPTION); + QString description = QString ( BOOKMARKS_LIST_DESCRIPTION ); observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); - + // Julian day QString JDString = ""; double JD = core->getJD(); JDString = QString::number ( JD, 'f', 6 ); observingListDataList.insert ( QString ( KEY_JD ), JDString ); - + // Location QString Location = ""; StelLocation loc = core->getCurrentLocation(); @@ -674,10 +686,10 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); } observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); - + // Name of the liste observingListDataList.insert ( QString ( KEY_NAME ), BOOKMARKS_LIST_NAME ); - + // List of objects QVariantList listOfObjects; QHashIterator i ( bookmarksCollection ); @@ -690,29 +702,29 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection obl.insert ( QString ( KEY_DESIGNATION ), objectName ); listOfObjects.push_back ( obl ); } - + observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); observingListDataList.insert ( QString ( KEY_SORTING ), SORTING_BY_NAME ); - + QList keys = bookmarksCollection.keys(); QString oblListUuid; - if(keys.empty()){ + if ( keys.empty() ) { oblListUuid = QUuid::createUuid().toString(); } else { - oblListUuid = keys.at(0); + oblListUuid = keys.at ( 0 ); } - + mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); mapFromJsonFile.insert ( KEY_SHORT_NAME,SHORT_NAME_VALUE ); allListsMap.insert ( oblListUuid, observingListDataList ); mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); - + jsonFile.resize ( 0 ); StelJsonParser::write ( mapFromJsonFile, &jsonFile ); jsonFile.flush(); jsonFile.close(); - + } catch ( std::runtime_error &e ) { qCritical() << "[ObservingList] File format is wrong! Error: " << e.what(); return; @@ -720,6 +732,28 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection } +/* + * Check if bookmarks list already exists in observing list file, + * in fact if the file of bookarks has already be loaded. +*/ +bool ObsListDialog::checkIfBookmarksListExists ( QVariantMap allListsMap ) +{ + + for ( auto bookmarkKey : allListsMap.keys() ) { + + QVariantMap bookmarkData = allListsMap.value ( bookmarkKey ).toMap(); + QString listName = bookmarkData.value ( KEY_NAME ).toString(); + + if ( QString::compare ( QString ( BOOKMARKS_LIST_NAME ), listName ) == 0 ) { + return true; + } + } + + return false; +} + + + /* * Select and go to object */ @@ -907,6 +941,25 @@ void ObsListDialog::setVisible ( bool v ) } } +/* + * Sort the obsListTreeView by the column name given in parameter +*/ +void ObsListDialog::sortObsListTreeViewByColumnName ( QString columnName ) +{ + if ( QString::compare ( columnName,SORTING_BY_NAME ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_NAME, Qt::AscendingOrder ); + } else if ( QString::compare ( columnName,SORTING_BY_TYPE ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_TYPE, Qt::AscendingOrder ); + } else if ( QString::compare ( columnName,SORTING_BY_RA ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_RA, Qt::AscendingOrder ); + } else if ( QString::compare ( columnName,SORTING_BY_DEC ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_DEC, Qt::AscendingOrder ); + } else if ( QString::compare ( columnName,SORTING_BY_MAGNITUDE ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_MAGNITUDE, Qt::AscendingOrder ); + } else if ( QString::compare ( columnName,SORTING_BY_CONSTELLATION ) == 0 ) { + obsListListModel->sort ( COLUMN_NUMBER_CONSTELLATION, Qt::AscendingOrder ); + } +} diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 260045c12007b..c75be43b9e0ea 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -94,15 +94,19 @@ class ObsListDialog : public StelDialog //! Load the bookmarks of bookmarks.json file into observing lists file void loadBookmarksInObservingList(); void saveBookmarks(QHash bookmarksCollection); + bool checkIfBookmarksListExists(QVariantMap allListsMap); //! Load list from JSON file - QVariantList loadListFromJson(QFile &jsonFile, QString listUuid); + QVariantList loadListFromJson(QVariantMap map, QString listUuid); //! Populate list names into combo box void populateListNameInComboBox(QVariantMap map); //! Populate data into combo box void populateDataInComboBox(QVariantMap map, QString defaultListUuid); + + //! Sort the obsListTreeView by the column name given in parameter + void sortObsListTreeViewByColumnName(QString columnName); public slots: diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 5344dcc7bda27..fe06473d12d05 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -73,7 +73,7 @@ static constexpr char const * FILE_VERSION = "1.0"; static constexpr char const * JSON_BOOKMARKS_FILE_NAME = "bookmarks.json"; static constexpr char const * BOOKMARKS_LIST_NAME = "bookmarks list"; -static constexpr char const * BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version"; +static constexpr char const * BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version."; static constexpr char const * SHORT_NAME_VALUE = "Observing list for Stellarium"; static constexpr char const * KEY_DEFAULT_LIST_UUID = "defaultListUuid"; @@ -101,5 +101,12 @@ static constexpr char const * SORTING_BY_DEC = "declination"; static constexpr char const * SORTING_BY_MAGNITUDE = "magnitude"; static constexpr char const * SORTING_BY_CONSTELLATION = "constellation"; +static constexpr int COLUMN_NUMBER_NAME = 1; +static constexpr int COLUMN_NUMBER_TYPE = 3; +static constexpr int COLUMN_NUMBER_RA = 4; +static constexpr int COLUMN_NUMBER_DEC = 5; +static constexpr int COLUMN_NUMBER_MAGNITUDE = 6; +static constexpr int COLUMN_NUMBER_CONSTELLATION = 7; + #endif // OBSLISTDIALOG_H From 9fdaaeecacd118c2611a933546136da8fc291d67 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 29 Oct 2021 17:25:50 +0200 Subject: [PATCH 08/28] Bugs corrections: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The key defaultlist doesn’t appear in the observingList file, - The list is not loaded in the tree view, when there is no default list, - Lost of existing sort when we modify a list. --- src/gui/ObsListCreateEditDialog.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 2d782574fc3d0..c454620b6aa1b 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -385,10 +385,12 @@ void ObsListCreateEditDialog::saveObservedObject() // No JD modifications in editor mode + QString existingSorting; if ( !isCreationMode ) { QString uuidQs = QString::fromStdString ( this->listUuid_ ); QVariantMap currentList = allListsMap.value ( uuidQs ).toMap(); QVariant existingJD = currentList.value ( QString ( KEY_JD ) ); + existingSorting = currentList.value(QString(KEY_SORTING)).toString(); QString existingJDs = existingJD.toString(); if ( existingJDs.isEmpty() ) { observingListDataList.insert ( QString ( KEY_JD ), JDString ); @@ -426,7 +428,14 @@ void ObsListCreateEditDialog::saveObservedObject() } observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); - observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); + + + if(sorting.isEmpty()){ + observingListDataList.insert ( QString ( KEY_SORTING ), existingSorting ); + }else { + observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); + } + QString oblListUuid; if ( isCreationMode ) { From fc649dc7c5a307867ddde6c32e074b2885370d4f Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 29 Oct 2021 17:26:54 +0200 Subject: [PATCH 09/28] Bugs corrections: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The key defaultlist doesn’t appear in the observingList file, - The list is not loaded in the tree view, when there is no default list, - Lost of existing sort when we modify a list. --- src/gui/ObsListDialog.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 1feb65466df9a..573c50b9bd373 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -337,6 +337,8 @@ void ObsListDialog::loadListsName() void ObsListDialog::populateListNameInComboBox ( QVariantMap map ) { QMap::iterator i; + ui->obsListComboBox->clear(); + listNamesModel.clear(); for ( i = map.begin(); i != map.end(); ++i ) { if ( i.value().canConvert() ) { QVariant var = i.value(); @@ -391,6 +393,9 @@ void ObsListDialog::loadDefaultList() selectedObservingListUuid = defaultListUuid_.toStdString(); loadObservingList ( defaultListUuid_ ); } + } else { + ui->obsListComboBox->setCurrentIndex ( 0 ); + loadSelectedObservingList(0); } } @@ -662,6 +667,11 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); } + QString defaultListValue = mapFromJsonFile.value(QString(KEY_DEFAULT_LIST_UUID)).toString(); + if(defaultListValue.isEmpty()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + if ( checkIfBookmarksListExists ( allListsMap ) ) { //the bookmarks file is already loaded return; From 27135932176e597911a20f68a3e6bddd6a0c92ce Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Tue, 2 Nov 2021 16:59:29 +0100 Subject: [PATCH 10/28] Add confirmation popup When we delete a list, now we have a confirmation popup. --- src/gui/ObsListCreateEditDialog.cpp | 2 + src/gui/ObsListCreateEditDialog.hpp | 1 + src/gui/ObsListDialog.cpp | 100 ++++++++++++++++------------ 3 files changed, 59 insertions(+), 44 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index c454620b6aa1b..0eb19c9e031c8 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -56,6 +56,8 @@ ObsListCreateEditDialog::~ObsListCreateEditDialog() { delete ui; delete obsListListModel; + ui = Q_NULLPTR; + obsListListModel = Q_NULLPTR; } /** diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index b26248e426817..08f51280964d8 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -98,6 +98,7 @@ class ObsListCreateEditDialog : public StelDialog public slots: void retranslate(); + private slots: void obsListAddObjectButtonPressed(); void obsListRemoveObjectButtonPressed(); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 573c50b9bd373..961600d76bf3a 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -58,6 +58,8 @@ ObsListDialog::~ObsListDialog() { delete ui; delete obsListListModel; + ui = Q_NULLPTR; + obsListListModel = Q_NULLPTR; } /* @@ -395,7 +397,7 @@ void ObsListDialog::loadDefaultList() } } else { ui->obsListComboBox->setCurrentIndex ( 0 ); - loadSelectedObservingList(0); + loadSelectedObservingList ( 0 ); } } @@ -667,11 +669,11 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); } - QString defaultListValue = mapFromJsonFile.value(QString(KEY_DEFAULT_LIST_UUID)).toString(); - if(defaultListValue.isEmpty()){ + QString defaultListValue = mapFromJsonFile.value ( QString ( KEY_DEFAULT_LIST_UUID ) ).toString(); + if ( defaultListValue.isEmpty() ) { mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); } - + if ( checkIfBookmarksListExists ( allListsMap ) ) { //the bookmarks file is already loaded return; @@ -860,52 +862,62 @@ void ObsListDialog::loadSelectedObservingList ( int selectedIndex ) */ void ObsListDialog::obsListDeleteButtonPressed() { - qDebug() << QString::fromStdString ( selectedObservingListUuid ); - QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadWrite ) ) { - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); - } else { - try { - QVariantMap newMap; - QVariantMap newObsListMap; - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - - newMap.insert ( QString ( KEY_DEFAULT_LIST_UUID ), map.value ( QString ( KEY_DEFAULT_LIST_UUID ) ) ); - QVariantMap obsListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + bool res = askConfirmation(); - QMap::iterator i; - for ( i = obsListMap.begin(); i != obsListMap.end(); ++i ) { - if ( i.key().compare ( QString::fromStdString ( selectedObservingListUuid ) ) !=0 ) { - newObsListMap.insert ( i.key(),i.value() ); + if ( res ) { + QVariantMap map; + QFile jsonFile ( observingListJsonPath ); + if ( !jsonFile.open ( QIODevice::ReadWrite ) ) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + } else { + try { + QVariantMap newMap; + QVariantMap newObsListMap; + map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + + newMap.insert ( QString ( KEY_DEFAULT_LIST_UUID ), map.value ( QString ( KEY_DEFAULT_LIST_UUID ) ) ); + QVariantMap obsListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + + QMap::iterator i; + for ( i = obsListMap.begin(); i != obsListMap.end(); ++i ) { + if ( i.key().compare ( QString::fromStdString ( selectedObservingListUuid ) ) !=0 ) { + newObsListMap.insert ( i.key(),i.value() ); + } } - } - newMap.insert ( QString ( KEY_OBSERVING_LISTS ),newObsListMap ); - newMap.insert ( QString ( KEY_SHORT_NAME ), map.value ( QString ( KEY_SHORT_NAME ) ) ); - newMap.insert ( QString ( KEY_VERSION ), map.value ( QString ( KEY_VERSION ) ) ); - objectMgr->unSelect(); - observingListItemCollection.clear(); - // Clear model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - ui->obsListCreationDateLineEdit->setText ( "" ); - int currentIndex = ui->obsListComboBox->currentIndex(); - ui->obsListComboBox->removeItem ( currentIndex ); - - int index = ui->obsListComboBox->findData ( "" ); - ui->obsListComboBox->setCurrentIndex ( index ); - ui->obsListDescriptionTextEdit->setPlainText ( "" ); - - jsonFile.resize ( 0 ); - StelJsonParser::write ( newMap, &jsonFile ); - jsonFile.flush(); - jsonFile.close(); + newMap.insert ( QString ( KEY_OBSERVING_LISTS ),newObsListMap ); + newMap.insert ( QString ( KEY_SHORT_NAME ), map.value ( QString ( KEY_SHORT_NAME ) ) ); + newMap.insert ( QString ( KEY_VERSION ), map.value ( QString ( KEY_VERSION ) ) ); + objectMgr->unSelect(); + observingListItemCollection.clear(); + + // Clear model + obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); + ui->obsListCreationDateLineEdit->setText ( "" ); + ui->obsListDescriptionTextEdit->setPlainText ( "" ); + int currentIndex = ui->obsListComboBox->currentIndex(); + ui->obsListComboBox->removeItem ( currentIndex ); + selectedObservingListUuid = ""; + + + jsonFile.resize ( 0 ); + StelJsonParser::write ( newMap, &jsonFile ); + jsonFile.flush(); + jsonFile.close(); + + if ( ui->obsListComboBox->count() > 0 ) { + ui->obsListComboBox->setCurrentIndex ( 0 ); + loadSelectedObservingList ( 0 ); + } - } catch ( std::runtime_error &e ) { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); - return; + } catch ( std::runtime_error &e ) { + qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + return; + } } } + + } /* From 4dd20cf62ac215a595f84f8da21140627458635c Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 3 Nov 2021 17:29:29 +0100 Subject: [PATCH 11/28] Multiple fix. clear highlight after delete a list, default uuid, etc... --- src/gui/ObsListCreateEditDialog.cpp | 29 ++++++++++++++++++++++++++++- src/gui/ObsListDialog.cpp | 26 ++++++++++++++++++++++++-- src/gui/ObsListDialog.hpp | 5 ++++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 0eb19c9e031c8..edff567bebdf0 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -353,13 +353,20 @@ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() */ void ObsListCreateEditDialog::saveObservedObject() { + bool isFileExits = false; QString listName = ui->nameOfListLineEdit->text(); if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) { qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; return; } + QFile jsonFile ( observingListJsonPath ); + + if(jsonFile.exists()){ + isFileExits = true; + } + if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for reading and writing:" << QDir::toNativeSeparators ( observingListJsonPath ); @@ -446,6 +453,26 @@ void ObsListCreateEditDialog::saveObservedObject() oblListUuid = QString::fromStdString ( listUuid_ ); } + if(ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if(defaultListUuid.isEmpty()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + } + + //TODO delete after + /*if(!isFileExits && !ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } else if(ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if(defaultListUuid.isEmpty()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + } if ( ui->obsListDefaultListCheckBox->isChecked() ) { mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); } else { @@ -453,7 +480,7 @@ void ObsListCreateEditDialog::saveObservedObject() if ( defaultListUuid == oblListUuid ) { mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); } - } + }*/ mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); mapFromJsonFile.insert ( KEY_SHORT_NAME, SHORT_NAME_VALUE ); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 961600d76bf3a..57e25dcc65919 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -258,6 +258,14 @@ void ObsListDialog::obsListHighLightAllButtonPressed() * Slot for button obsListClearHighLightButton */ void ObsListDialog::obsListClearHighLightButtonPressed() +{ + clearHighlight(); +} + +/* + * Clear highlight +*/ +void ObsListDialog::clearHighlight() { objectMgr->unSelect(); GETSTELMODULE ( HighlightMgr )->cleanHighlightList(); @@ -296,7 +304,7 @@ void ObsListDialog::invokeObsListCreateEditDialog ( string listUuid ) { createEditDialog_instance = ObsListCreateEditDialog::Instance ( listUuid ); connect ( createEditDialog_instance, SIGNAL ( exitButtonClicked() ), this, SLOT ( obsListCreateEditDialogClosed() ) ); - createEditDialog_instance->setListName ( listName ); + createEditDialog_instance->setListName ( listName_ ); createEditDialog_instance->setVisible ( true ); } @@ -341,12 +349,14 @@ void ObsListDialog::populateListNameInComboBox ( QVariantMap map ) QMap::iterator i; ui->obsListComboBox->clear(); listNamesModel.clear(); + listName_.clear(); for ( i = map.begin(); i != map.end(); ++i ) { if ( i.value().canConvert() ) { QVariant var = i.value(); QVariantMap data = var.value(); QString listName = data.value ( KEY_NAME ).value(); listNamesModel.append ( listName ); + listName_.append(listName); } } listNamesModel.sort ( Qt::CaseInsensitive ); @@ -891,12 +901,18 @@ void ObsListDialog::obsListDeleteButtonPressed() objectMgr->unSelect(); observingListItemCollection.clear(); - // Clear model + // Clear row in model obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); ui->obsListCreationDateLineEdit->setText ( "" ); ui->obsListDescriptionTextEdit->setPlainText ( "" ); int currentIndex = ui->obsListComboBox->currentIndex(); ui->obsListComboBox->removeItem ( currentIndex ); + + //TODO pas utile car listeName_ est réinitialiséé et rechargée dans loadListsName(). + //TODO a supprimer après les tests finaux. + //QString listName = ui->obsListComboBox->itemText(currentIndex); + //listName_.removeOne(listName); + selectedObservingListUuid = ""; @@ -904,6 +920,9 @@ void ObsListDialog::obsListDeleteButtonPressed() StelJsonParser::write ( newMap, &jsonFile ); jsonFile.flush(); jsonFile.close(); + + clearHighlight(); + loadListsName(); if ( ui->obsListComboBox->count() > 0 ) { ui->obsListComboBox->setCurrentIndex ( 0 ); @@ -943,6 +962,9 @@ void ObsListDialog::obsListCreateEditDialogClosed() ui->obsListComboBox->setCurrentIndex ( index ); loadSelectedObservingList ( index ); } + + //TODO remove after + qDebug() << "obsListCreateEditDialogClosed() before kill ObsListCreateEditDialog"; ObsListCreateEditDialog::kill(); createEditDialog_instance = Q_NULLPTR; diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index c75be43b9e0ea..afd84888f962b 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -60,7 +60,7 @@ class ObsListDialog : public StelDialog QHash observingListItemCollection; QList highlightLabelIDs; QString defaultListUuid_; - QList listName; + QList listName_; QStringList listNamesModel; //! Set header names for observing list table @@ -107,6 +107,9 @@ class ObsListDialog : public StelDialog //! Sort the obsListTreeView by the column name given in parameter void sortObsListTreeViewByColumnName(QString columnName); + + //! Clear highlights + void clearHighlight(); public slots: From 7104c7717619326214687e31e80415497b707ee3 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Thu, 3 Feb 2022 13:19:11 +0100 Subject: [PATCH 12/28] Observing List V2 --- src/gui/ObsListCreateEditDialog.cpp | 1024 ++++++++++++++++----------- src/gui/ObsListCreateEditDialog.hpp | 10 +- src/gui/ObsListDialog.cpp | 53 +- src/gui/ObsListDialog.hpp | 18 +- src/gui/ObservingListCommon.hpp | 11 +- src/gui/obsListCreateEditDialog.ui | 106 ++- 6 files changed, 726 insertions(+), 496 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index edff567bebdf0..d5ecbc75cdfe5 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -17,43 +17,43 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include #include #include +#include #include +#include +#include +#include "NebulaMgr.hpp" #include "StelCore.hpp" #include "StelFileMgr.hpp" -#include "StelObjectMgr.hpp" +#include "StelJsonParser.hpp" #include "StelModuleMgr.hpp" -#include "NebulaMgr.hpp" #include "StelMovementMgr.hpp" +#include "StelObjectMgr.hpp" #include "StelUtils.hpp" -#include "StelJsonParser.hpp" #include "ObsListCreateEditDialog.hpp" #include "ui_obsListCreateEditDialog.h" using namespace std; -ObsListCreateEditDialog * ObsListCreateEditDialog::m_instance = nullptr; +ObsListCreateEditDialog *ObsListCreateEditDialog::m_instance = nullptr; -ObsListCreateEditDialog::ObsListCreateEditDialog ( string listUuid ) -{ - listUuid_ = listUuid; +ObsListCreateEditDialog::ObsListCreateEditDialog(string listUuid) { + listOlud_ = listUuid; ui = new Ui_obsListCreateEditDialogForm(); core = StelApp::getInstance().getCore(); - objectMgr = GETSTELMODULE ( StelObjectMgr ); - obsListListModel = new QStandardItemModel ( 0,ColumnCount ); - observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); + objectMgr = GETSTELMODULE(StelObjectMgr); + obsListListModel = new QStandardItemModel(0, ColumnCount); + observingListJsonPath = + StelFileMgr::findFile("data", (StelFileMgr::Flags) (StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + QString(JSON_FILE_NAME); sorting = ""; } -ObsListCreateEditDialog::~ObsListCreateEditDialog() -{ +ObsListCreateEditDialog::~ObsListCreateEditDialog() { delete ui; delete obsListListModel; ui = Q_NULLPTR; @@ -62,274 +62,299 @@ ObsListCreateEditDialog::~ObsListCreateEditDialog() /** * Get instance of class -*/ -ObsListCreateEditDialog * ObsListCreateEditDialog::Instance ( string listUuid ) -{ - if ( m_instance == nullptr ) { - m_instance = new ObsListCreateEditDialog ( listUuid ); + */ +ObsListCreateEditDialog *ObsListCreateEditDialog::Instance(string listUuid) { + if (m_instance == nullptr) { + m_instance = new ObsListCreateEditDialog(listUuid); } return m_instance; } - /* * Initialize the dialog widgets and connect the signals/slots. -*/ -void ObsListCreateEditDialog::createDialogContent() -{ - ui->setupUi ( dialog ); - - //Signals and slots - connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); - connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); - - connect ( ui->obsListAddObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListAddObjectButtonPressed ); - connect ( ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed ); - connect ( ui->obsListSaveButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListSaveButtonPressed ); - connect ( ui->obsListRemoveObjectButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListRemoveObjectButtonPressed ); - connect ( ui->obsListImportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListImportListButtonPresssed ); - connect ( ui->obsListExportListButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExportListButtonPressed ); - connect ( ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange ); - - //Initializing the list of observing list - obsListListModel->setColumnCount ( ColumnCount ); + */ +void ObsListCreateEditDialog::createDialogContent() { + ui->setupUi(dialog); + + // Signals and slots + connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate())); + connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())); + + connect(ui->obsListAddObjectButton, &QPushButton::clicked, this, + &ObsListCreateEditDialog::obsListAddObjectButtonPressed); + connect(ui->obsListExitButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListExitButtonPressed); + connect(ui->obsListSaveButton, &QPushButton::clicked, this, &ObsListCreateEditDialog::obsListSaveButtonPressed); + connect(ui->obsListRemoveObjectButton, &QPushButton::clicked, this, + &ObsListCreateEditDialog::obsListRemoveObjectButtonPressed); + connect(ui->obsListImportListButton, &QPushButton::clicked, this, + &ObsListCreateEditDialog::obsListImportListButtonPresssed); + connect(ui->obsListExportListButton, &QPushButton::clicked, this, + &ObsListCreateEditDialog::obsListExportListButtonPressed); + connect(ui->nameOfListLineEdit, &QLineEdit::textChanged, this, &ObsListCreateEditDialog::nameOfListTextChange); + + // Initializing the list of observing list + obsListListModel->setColumnCount(ColumnCount); setObservingListHeaderNames(); - ui->obsListCreationEditionTreeView->setModel ( obsListListModel ); - ui->obsListCreationEditionTreeView->header()->setSectionsMovable ( false ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); - ui->obsListCreationEditionTreeView->header()->setStretchLastSection ( true ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnUUID ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnNameI18n ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnJD ); - ui->obsListCreationEditionTreeView->hideColumn ( ColumnLocation ); - //Enable the sort for columns - ui->obsListCreationEditionTreeView->setSortingEnabled ( true ); - - QHeaderView * header = ui->obsListCreationEditionTreeView->header(); - connect ( header, SIGNAL ( sectionClicked ( int ) ), this, SLOT ( headerClicked ( int ) ) ); + ui->obsListCreationEditionTreeView->setModel(obsListListModel); + ui->obsListCreationEditionTreeView->header()->setSectionsMovable(false); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnName, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnType, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnRa, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnConstellation, + QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setStretchLastSection(true); + ui->obsListCreationEditionTreeView->hideColumn(ColumnUUID); + ui->obsListCreationEditionTreeView->hideColumn(ColumnNameI18n); + ui->obsListCreationEditionTreeView->hideColumn(ColumnJD); + ui->obsListCreationEditionTreeView->hideColumn(ColumnLocation); + // Enable the sort for columns + ui->obsListCreationEditionTreeView->setSortingEnabled(true); + + QHeaderView *header = ui->obsListCreationEditionTreeView->header(); + connect(header, SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int))); // We hide the closeStelWindow to have only two possibilities to close the dialog: // Save and close and Exit - ui->closeStelWindow->setHidden ( true ); - + ui->closeStelWindow->setHidden(true); + ui->obsListErrorMessage->setHidden(true); - // In case of creation le nameOfListLineEdit is empty and button save/close must be disabled - // In case on edition the nameOfListLineEdit is not empty and the button save//close must be enable - if ( ui->nameOfListLineEdit->text().isEmpty() ) { - ui->obsListSaveButton->setEnabled ( false ); + // In case of creation the nameOfListLineEdit is empty and button save/close must be disabled + // In case on edition the nameOfListLineEdit is not empty and the button save/close must be enable + if (ui->nameOfListLineEdit->text().isEmpty()) { + ui->obsListSaveButton->setEnabled(false); } else { - ui->obsListSaveButton->setEnabled ( true ); + ui->obsListSaveButton->setEnabled(true); } - if ( listUuid_.size() == 0 ) { + if (listOlud_.size() == 0) { // case of creation mode isCreationMode = true; - ui->stelWindowTitle->setText ( "Observing list creation mode" ); + ui->stelWindowTitle->setText("Observing list creation mode"); } else { // case of edit mode isCreationMode = false; - ui->stelWindowTitle->setText ( "Observing list editor mode" ); + ui->stelWindowTitle->setText("Observing list editor mode"); loadObservingList(); } } /* * Retranslate dialog -*/ -void ObsListCreateEditDialog::retranslate() -{ - if ( dialog ) { - ui->retranslateUi ( dialog ); + */ +void ObsListCreateEditDialog::retranslate() { + if (dialog) { + ui->retranslateUi(dialog); } } /* * Style changed -*/ -void ObsListCreateEditDialog::styleChanged() -{ + */ +void ObsListCreateEditDialog::styleChanged() { // Nothing for now } /* * Set the header for the observing list table * (obsListTreeVView) -*/ -void ObsListCreateEditDialog::setObservingListHeaderNames() -{ + */ +void ObsListCreateEditDialog::setObservingListHeaderNames() { const QStringList headerStrings = { - "UUID", // Hidden column - q_ ( "Object name" ), - q_ ( "Object name I18N" ), // Hidden column - q_ ( "Type" ), - q_ ( "Right ascension" ), - q_ ( "Declination" ), - q_ ( "Magnitude" ), - q_ ( "Constellation" ), - q_ ( "Date" ), // Hided column - q_ ( "Location" ) // Hided column + "UUID", // Hidden column + q_("Object name"), + q_("Object name I18N"), // Hidden column + q_("Type"), + q_("Right ascension"), + q_("Declination"), + q_("Magnitude"), + q_("Constellation"), + q_("Date"), // Hided column + q_("Location") // Hided column }; - obsListListModel->setHorizontalHeaderLabels ( headerStrings ); + obsListListModel->setHorizontalHeaderLabels(headerStrings); } - /* * Add row in the obsListListModel -*/ -void ObsListCreateEditDialog::addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) -{ - QStandardItem* item = Q_NULLPTR; - - item = new QStandardItem ( uuid ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnUUID, item ); - - item = new QStandardItem ( name ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnName, item ); - - item = new QStandardItem ( nameI18n ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnNameI18n, item ); - - item = new QStandardItem ( type ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnType, item ); - - item = new QStandardItem ( ra ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnRa, item ); - - item = new QStandardItem ( dec ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnDec, item ); - - item = new QStandardItem ( magnitude ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnMagnitude, item ); - - item = new QStandardItem ( constellation ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnConstellation, item ); - - for ( int i = 0; i < ColumnCount; ++i ) { - ui->obsListCreationEditionTreeView->resizeColumnToContents ( i ); + */ +void ObsListCreateEditDialog::addModelRow(int number, + QString uuid, + QString name, + QString nameI18n, + QString type, + QString ra, + QString dec, + QString magnitude, + QString constellation) { + QStandardItem *item = Q_NULLPTR; + + item = new QStandardItem(uuid); + item->setEditable(false); + obsListListModel->setItem(number, ColumnUUID, item); + + item = new QStandardItem(name); + item->setEditable(false); + obsListListModel->setItem(number, ColumnName, item); + + item = new QStandardItem(nameI18n); + item->setEditable(false); + obsListListModel->setItem(number, ColumnNameI18n, item); + + item = new QStandardItem(type); + item->setEditable(false); + obsListListModel->setItem(number, ColumnType, item); + + item = new QStandardItem(ra); + item->setEditable(false); + obsListListModel->setItem(number, ColumnRa, item); + + item = new QStandardItem(dec); + item->setEditable(false); + obsListListModel->setItem(number, ColumnDec, item); + + item = new QStandardItem(magnitude); + item->setEditable(false); + obsListListModel->setItem(number, ColumnMagnitude, item); + + item = new QStandardItem(constellation); + item->setEditable(false); + obsListListModel->setItem(number, ColumnConstellation, item); + + for (int i = 0; i < ColumnCount; ++i) { + ui->obsListCreationEditionTreeView->resizeColumnToContents(i); } } - /* * Slot for button obsListAddObjectButton -*/ -void ObsListCreateEditDialog::obsListAddObjectButtonPressed() -{ - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) { + */ +void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { + const QList &selectedObject = objectMgr->getSelectedObject(); + if (!selectedObject.isEmpty()) { + // No duplicate item in the same list bool is_already_in_list = false; - QHash::const_iterator i; - for ( i = observingListItemCollection.begin(); i != observingListItemCollection.end(); i++ ) { - if ( i.value().name.compare ( selectedObject[0]->getEnglishName() ) == 0 ) { + QHash::const_iterator i; + for (i = observingListItemCollection.begin(); i != observingListItemCollection.end(); i++) { + if (i.value().name.compare(selectedObject[0]->getEnglishName()) == 0) { is_already_in_list = true; break; } } - if ( !is_already_in_list ) { - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); + if (!is_already_in_list) { + const int lastRow = obsListListModel->rowCount(); + const QString objectUuid = QUuid::createUuid().toString(); + // Object name QString objectName = selectedObject[0]->getEnglishName(); QString objectNameI18n = selectedObject[0]->getNameI18n(); - if ( selectedObject[0]->getType() =="Nebula" ) { - objectName = GETSTELMODULE ( NebulaMgr )->getLatestSelectedDSODesignation(); + if (selectedObject[0]->getType() == "Nebula") { + objectName = GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation(); } + // Object type + QString objectType = selectedObject[0]->getType(); + + // Ra & Dec QString objectRaStr = "", objectDecStr = ""; bool visibleFlag = false; double fov = -1.0; - QString objectType = selectedObject[0]->getType(); - float ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); + if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { + objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); + } + if (ui->obsListDecCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { + objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); + } + //TODO delete after + qDebug() << "ra value" << objectRaStr; + qDebug() << "dec value" << objectDecStr; + + // Visible flag + if (objectName.contains("marker", Qt::CaseInsensitive)) { visibleFlag = true; } - if ( objectName.isEmpty() ) { - objectName = QString ( "%1, %2" ).arg ( objectRaStr, objectDecStr ); - objectNameI18n = q_ ( "Unnamed object" ); - fov = GETSTELMODULE ( StelMovementMgr )->getCurrentFov(); + if (objectName.isEmpty()) { + objectName = QString("%1, %2").arg(objectRaStr, objectDecStr); + objectNameI18n = q_("Unnamed object"); + fov = GETSTELMODULE(StelMovementMgr)->getCurrentFov(); } - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); + float objectMagnitude = selectedObject[0]->getVMagnitude(core); + QString objectMagnitudeStr = QString::number(objectMagnitude); - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); + QVariantMap objectMap = selectedObject[0]->getInfoMap(core); QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) { + QString objectConstellation("unknown"); + if (objectConstellationVariant.canConvert()) { objectConstellation = objectConstellationVariant.value(); } QString JDs = ""; double JD = core->getJD(); - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); QString Location = ""; StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + if (loc.name.isEmpty()) { + Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); + Location = QString("%1, %2").arg(loc.name).arg(loc.region); } - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); + addModelRow(lastRow, + objectUuid, + objectName, + objectNameI18n, + objectType, + objectRaStr, + objectDecStr, + objectMagnitudeStr, + objectConstellation); observingListItem item; item.name = objectName; item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) { + if (!objectType.isEmpty()) { item.type = objectType; } - if ( !objectRaStr.isEmpty() ) { + if (!objectRaStr.isEmpty()) { item.ra = objectRaStr; } - if ( !objectDecStr.isEmpty() ) { + if (!objectDecStr.isEmpty()) { item.dec = objectDecStr; } - if ( !objectMagnitudeStr.isEmpty() ) { + if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } - if ( !objectConstellation.isEmpty() ) { + if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } - if ( !JDs.isEmpty() ) { - item.jd = QString::number ( JD, 'f', 6 ); + if (!JDs.isEmpty()) { + //item.jd = QString::number(JD, 'f', 6); + item.jd = JD; } - if ( !Location.isEmpty() ) { + if (!Location.isEmpty()) { QHash::iterator i; item.location = Location; } - if ( !visibleFlag ) { + if (!visibleFlag) { item.isVisibleMarker = visibleFlag; } - if ( fov > 0.0 ) { + if (fov > 0.0 && (ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT)) { item.fov = fov; } - observingListItemCollection.insert ( objectUuid,item ); + observingListItemCollection.insert(objectUuid, item); } } else { @@ -339,210 +364,334 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() /* * Slot for button obsListRemoveObjectButton -*/ -void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() -{ + */ +void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() { int number = ui->obsListCreationEditionTreeView->currentIndex().row(); - QString uuid = obsListListModel->index ( number, ColumnUUID ).data().toString(); - obsListListModel->removeRow ( number ); - observingListItemCollection.remove ( uuid ); + QString uuid = obsListListModel->index(number, ColumnUUID).data().toString(); + obsListListModel->removeRow(number); + observingListItemCollection.remove(uuid); } /* * Save observed object into json file -*/ -void ObsListCreateEditDialog::saveObservedObject() -{ - bool isFileExits = false; - QString listName = ui->nameOfListLineEdit->text(); - if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) { + */ +void ObsListCreateEditDialog::saveObservedObject() { + + if (observingListJsonPath.isEmpty()) { qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; return; } - - QFile jsonFile ( observingListJsonPath ); - - if(jsonFile.exists()){ - isFileExits = true; - } - - if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { - qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for reading and writing:" - << QDir::toNativeSeparators ( observingListJsonPath ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadWrite | QIODevice::Text)) { + qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for " + "reading and writing:" + << QDir::toNativeSeparators(observingListJsonPath); return; } + // Name of the list + const QString listName = ui->nameOfListLineEdit->text(); + try { QVariantMap mapFromJsonFile; QVariantMap allListsMap; - if ( jsonFile.size() > 0 ) { - mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + const QString oludQs = QString::fromStdString(this->listOlud_); + const QVariantMap currentList = allListsMap.value(oludQs).toMap(); + if (jsonFile.size() > 0) { + mapFromJsonFile = StelJsonParser::parse(jsonFile.readAll()).toMap(); + allListsMap = mapFromJsonFile.value(QString(KEY_OBSERVING_LISTS)).toMap(); } QVariantMap observingListDataList; - // Description - QString description = ui->descriptionLineEdit->text(); - observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); - - // Julian day - QString JDString = ""; - double JD = core->getJD(); - JDString = QString::number ( JD, 'f', 6 ); - - - // No JD modifications in editor mode - QString existingSorting; - if ( !isCreationMode ) { - QString uuidQs = QString::fromStdString ( this->listUuid_ ); - QVariantMap currentList = allListsMap.value ( uuidQs ).toMap(); - QVariant existingJD = currentList.value ( QString ( KEY_JD ) ); - existingSorting = currentList.value(QString(KEY_SORTING)).toString(); - QString existingJDs = existingJD.toString(); - if ( existingJDs.isEmpty() ) { - observingListDataList.insert ( QString ( KEY_JD ), JDString ); - } else { - observingListDataList.insert ( QString ( KEY_JD ), existingJDs ); - } - } else { - observingListDataList.insert ( QString ( KEY_JD ), JDString ); - } - - // Location - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - } - observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); - // Name of the liste - observingListDataList.insert ( QString ( KEY_NAME ), listName ); + observingListDataList.insert(QString(KEY_NAME), listName); + + // Description of the list + QString description = ui->descriptionLineEdit->text(); + observingListDataList.insert(QString(KEY_DESCRIPTION), description); // List of objects QVariantList listOfObjects; - QHashIterator i ( observingListItemCollection ); - while ( i.hasNext() ) { + QHashIterator i(observingListItemCollection); + while (i.hasNext()) { i.next(); - observingListItem item = i.value(); QVariantMap obl; - QString objectName = item.name; - obl.insert ( QString ( KEY_DESIGNATION ), objectName ); - listOfObjects.push_back ( obl ); - } - observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); - - - if(sorting.isEmpty()){ - observingListDataList.insert ( QString ( KEY_SORTING ), existingSorting ); - }else { - observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); + // Designation + obl.insert(QString(KEY_DESIGNATION), item.name); + //TODO delete after + qDebug() << "name: " << item.name; + + // Fov + obl.insert(QString(KEY_FOV), item.fov); + //TODO delete after + qDebug() << "fov: " << item.fov; + + // Jd + obl.insert(QString(KEY_JD), item.jd); + //TODO delete after + qDebug() << "jd: " << item.jd; + + // Location + obl.insert(QString(KEY_LOCATION), item.location); + //TODO delete after + qDebug() << "location: " << item.location; + + // Ra + obl.insert(QString(KEY_RA), item.ra); + //TODO delete after + qDebug() << "ra: " << item.ra; + + // Dec + obl.insert(QString(KEY_DEC), item.dec); + //TODO delete after + qDebug() << "dec: " << item.dec; + + // Object type + obl.insert(QString(KEY_OBJECTS_TYPE), item.type); + //TODO delete after + qDebug() << "object type: " << item.type; + + listOfObjects.push_back(obl); } - + observingListDataList.insert(QString(KEY_OBJECTS), listOfObjects); - QString oblListUuid; - if ( isCreationMode ) { - oblListUuid = QUuid::createUuid().toString(); + // Sorting + QString existingSorting; + if (!isCreationMode) { + existingSorting = currentList.value(QString(KEY_SORTING)).toString(); + } + if (sorting.isEmpty()) { + observingListDataList.insert(QString(KEY_SORTING), existingSorting); } else { - oblListUuid = QString::fromStdString ( listUuid_ ); + observingListDataList.insert(QString(KEY_SORTING), sorting); } - if(ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + // Olud + QString oblListOlud; + if (isCreationMode || isSaveAs) { + oblListOlud = QUuid::createUuid().toString(); } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if(defaultListUuid.isEmpty()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } + oblListOlud = QString::fromStdString(listOlud_); } - - //TODO delete after - /*if(!isFileExits && !ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } else if(ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + + if (ui->obsListDefaultListCheckBox->isChecked()) { + mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, oblListOlud); } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if(defaultListUuid.isEmpty()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + QString defaultListUuid = mapFromJsonFile.value(KEY_DEFAULT_LIST_OLUD).toString(); + if (defaultListUuid.isEmpty()) { + mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); } } - if ( ui->obsListDefaultListCheckBox->isChecked() ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); - } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if ( defaultListUuid == oblListUuid ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } - }*/ - mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); - mapFromJsonFile.insert ( KEY_SHORT_NAME, SHORT_NAME_VALUE ); + // Version + mapFromJsonFile.insert(KEY_VERSION, FILE_VERSION); + // Short name + mapFromJsonFile.insert(KEY_SHORT_NAME, SHORT_NAME_VALUE); - allListsMap.insert ( oblListUuid, observingListDataList ); - mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); + allListsMap.insert(oblListOlud, observingListDataList); + mapFromJsonFile.insert(QString(KEY_OBSERVING_LISTS), allListsMap); - jsonFile.resize ( 0 ); - StelJsonParser::write ( mapFromJsonFile, &jsonFile ); + jsonFile.resize(0); + StelJsonParser::write(mapFromJsonFile, &jsonFile); jsonFile.flush(); jsonFile.close(); - } catch ( std::runtime_error &e ) { + + } catch (std::runtime_error &e) { qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); return; } + + /*bool isFileExits = false; + QString listName = ui->nameOfListLineEdit->text(); + if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) { + qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; + return; + } + + + QFile jsonFile ( observingListJsonPath ); + + if(jsonFile.exists()){ + isFileExits = true; + } + + if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { + qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for + reading and writing:" + << QDir::toNativeSeparators ( observingListJsonPath ); + return; + } + + try { + QVariantMap mapFromJsonFile; + QVariantMap allListsMap; + if ( jsonFile.size() > 0 ) { + mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + } + + QVariantMap observingListDataList; + + // Description + QString description = ui->descriptionLineEdit->text(); + observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); + + // Julian day + QString JDString = ""; + double JD = core->getJD(); + JDString = QString::number ( JD, 'f', 6 ); + + + // No JD modifications in editor mode + QString existingSorting; + if ( !isCreationMode ) { + QString uuidQs = QString::fromStdString ( this->listOlud_ ); + QVariantMap currentList = allListsMap.value ( uuidQs ).toMap(); + QVariant existingJD = currentList.value ( QString ( KEY_JD ) ); + existingSorting = currentList.value(QString(KEY_SORTING)).toString(); + QString existingJDs = existingJD.toString(); + if ( existingJDs.isEmpty() ) { + observingListDataList.insert ( QString ( KEY_JD ), JDString ); + } else { + observingListDataList.insert ( QString ( KEY_JD ), existingJDs ); + } + } else { + observingListDataList.insert ( QString ( KEY_JD ), JDString ); + } + + // Location + QString Location = ""; + StelLocation loc = core->getCurrentLocation(); + if ( loc.name.isEmpty() ) { + Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + } else { + Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); + } + observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); + + // Name of the liste + observingListDataList.insert ( QString ( KEY_NAME ), listName ); + + // List of objects + QVariantList listOfObjects; + QHashIterator i ( observingListItemCollection ); + while ( i.hasNext() ) { + i.next(); + + observingListItem item = i.value(); + QVariantMap obl; + QString objectName = item.name; + obl.insert ( QString ( KEY_DESIGNATION ), objectName ); + listOfObjects.push_back ( obl ); + } + + observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); + + + if(sorting.isEmpty()){ + observingListDataList.insert ( QString ( KEY_SORTING ), existingSorting ); + }else { + observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); + } + + + QString oblListUuid; + if ( isCreationMode ) { + oblListUuid = QUuid::createUuid().toString(); + } else { + oblListUuid = QString::fromStdString ( listOlud_ ); + } + + if(ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if(defaultListUuid.isEmpty()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + }*/ + + // TODO delete after + /*if(!isFileExits && !ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } else if(ui->obsListDefaultListCheckBox->isChecked()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if(defaultListUuid.isEmpty()){ + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + } + if ( ui->obsListDefaultListCheckBox->isChecked() ) { + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); + } else { + QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); + if ( defaultListUuid == oblListUuid ) { + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + } + }*/ + + /*mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); + mapFromJsonFile.insert ( KEY_SHORT_NAME, SHORT_NAME_VALUE ); + + allListsMap.insert ( oblListUuid, observingListDataList ); + mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); + + jsonFile.resize ( 0 ); + StelJsonParser::write ( mapFromJsonFile, &jsonFile ); + jsonFile.flush(); + jsonFile.close(); + } catch ( std::runtime_error &e ) { + qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); + return; + }*/ } /* * Slot for button obsListExportListButton -*/ -void ObsListCreateEditDialog::obsListExportListButtonPressed() -{ + */ +void ObsListCreateEditDialog::obsListExportListButtonPressed() { QString originalobservingListJsonPath = observingListJsonPath; QString filter = "JSON (*.json)"; - observingListJsonPath = QFileDialog::getSaveFileName ( Q_NULLPTR, - q_ ( "Export observing list as..." ), - QDir::homePath() + "/" + JSON_FILE_NAME, - filter ); + observingListJsonPath = QFileDialog::getSaveFileName(Q_NULLPTR, q_("Export observing list as..."), + QDir::homePath() + "/" + JSON_FILE_NAME, filter); saveObservedObject(); observingListJsonPath = originalobservingListJsonPath; } /* * Slot for button obsListImportListButton -*/ -void ObsListCreateEditDialog::obsListImportListButtonPresssed() -{ + */ +void ObsListCreateEditDialog::obsListImportListButtonPresssed() { QString originalobservingListJsonPath = observingListJsonPath; QString filter = "JSON (*.json)"; - observingListJsonPath = QFileDialog::getOpenFileName ( Q_NULLPTR, q_ ( "Import observing list" ), QDir::homePath(), filter ); - + observingListJsonPath = QFileDialog::getOpenFileName(Q_NULLPTR, q_("Import observing list"), QDir::homePath(), + filter); QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { - qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); } else { try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); jsonFile.close(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); - if ( observingListMap.size() == 1 ) { - listUuid_ = observingListMap.keys().at ( 0 ).toStdString(); + if (observingListMap.size() == 1) { + listOlud_ = observingListMap.keys().at(0).toStdString(); } else { // define error message if needed return; } - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); return; } @@ -553,201 +702,229 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() /* * Slot for button obsListSaveButton -*/ -void ObsListCreateEditDialog::obsListSaveButtonPressed() -{ - if ( !this->listName_.isEmpty() && this->listName_.contains ( ui->nameOfListLineEdit->text() ) ) { + */ +void ObsListCreateEditDialog::obsListSaveButtonPressed() { + QString listName = ui->nameOfListLineEdit->text(); + bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode || + (listName.compare( + currentListName) != + 0 && + !isCreationMode)); + if (isListAlreadyExists) { + QString errorMessage; + errorMessage.append("Error: a list with the name ") + .append(ui->nameOfListLineEdit->text()) + .append(" already exists !"); + qWarning() << "[ObservingList Creation/Edition] Error: a list with the name " << ui->nameOfListLineEdit->text() + << " already exists !"; + ui->obsListErrorMessage->setHidden(false); + ui->obsListErrorMessage->setText(errorMessage); + } else if (ui->nameOfListLineEdit->text().isEmpty()) { QString errorMessage; - errorMessage.append("Error: a list with the name ").append(ui->nameOfListLineEdit->text()).append(" already exists !"); - qWarning() << "[ObservingList Creation/Edition] Error: a list with the name " << ui->nameOfListLineEdit->text() << " already exists !"; + errorMessage.append("Error: the list name is empty."); + qWarning() << "[ObservingList Creation/Edition] Error: the list name is empty."; ui->obsListErrorMessage->setHidden(false); ui->obsListErrorMessage->setText(errorMessage); } else { ui->obsListErrorMessage->setHidden(true); + if (listName.compare(currentListName) != 0 && !isCreationMode) { + isSaveAs = true; + } else { + isSaveAs = false; + } saveObservedObject(); this->close(); emit exitButtonClicked(); } - } /* * Slot for button obsListExitButton -*/ -void ObsListCreateEditDialog::obsListExitButtonPressed() -{ + */ +void ObsListCreateEditDialog::obsListExitButtonPressed() { this->close(); emit exitButtonClicked(); } /* * Overload StelDialog::close() -*/ -void ObsListCreateEditDialog::close() -{ - this->setVisible ( false );; + */ +void ObsListCreateEditDialog::close() { + this->setVisible(false);; emit this->exitButtonClicked(); } /* * Slot for obsListCreationEditionTreeView header -*/ -void ObsListCreateEditDialog::headerClicked ( int index ) -{ - switch ( index ) { - case ColumnName: - sorting = QString ( SORTING_BY_NAME ); - break; - case ColumnType: - sorting = QString ( SORTING_BY_TYPE ); - break; - case ColumnRa: - sorting = QString ( SORTING_BY_RA ); - break; - case ColumnDec: - sorting = QString ( SORTING_BY_DEC ); - break; - case ColumnMagnitude: - sorting = QString ( SORTING_BY_MAGNITUDE ); - break; - case ColumnConstellation: - sorting = QString ( SORTING_BY_CONSTELLATION );; - break; - default: - sorting = ""; - break; + */ +void ObsListCreateEditDialog::headerClicked(int index) { + switch (index) { + case ColumnName: + sorting = QString(SORTING_BY_NAME); + break; + case ColumnType: + sorting = QString(SORTING_BY_TYPE); + break; + case ColumnRa: + sorting = QString(SORTING_BY_RA); + break; + case ColumnDec: + sorting = QString(SORTING_BY_DEC); + break; + case ColumnMagnitude: + sorting = QString(SORTING_BY_MAGNITUDE); + break; + case ColumnConstellation: + sorting = QString(SORTING_BY_CONSTELLATION);; + break; + default: + sorting = ""; + break; } qDebug() << "Sorting = " << sorting; } /* * Load the observing list in case of edit mode -*/ -void ObsListCreateEditDialog::loadObservingList() -{ + */ +void ObsListCreateEditDialog::loadObservingList() { QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { - qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); } else { try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); jsonFile.close(); // Get the default list uuid - QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if ( defaultListUuid.toStdString() == listUuid_ ) { - ui->obsListDefaultListCheckBox->setChecked ( true ); + QString defaultListOlud = map.value(KEY_DEFAULT_LIST_OLUD).toString(); + if (defaultListOlud.toStdString() == listOlud_) { + ui->obsListDefaultListCheckBox->setChecked(true); } observingListItemCollection.clear(); - const QString keyUuid = QString::fromStdString ( listUuid_ ); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( keyUuid ).toMap(); + const QString keyOlud = QString::fromStdString(listOlud_); + QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(keyOlud).toMap(); QVariantList listOfObjects; - QString listeName = observingListMap.value ( QString ( KEY_NAME ) ).value(); - ui->nameOfListLineEdit->setText ( listeName ); - QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); - ui->descriptionLineEdit->setText ( listDescription ); + QString listName = observingListMap.value(QString(KEY_NAME)).value(); - if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) { - QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); + // List name + currentListName = listName; + ui->nameOfListLineEdit->setText(listName); + + // List description + QString listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); + ui->descriptionLineEdit->setText(listDescription); + + if (observingListMap.value(QString(KEY_OBJECTS)).canConvert()) { + QVariant data = observingListMap.value(QString(KEY_OBJECTS)); listOfObjects = data.value(); } else { qCritical() << "[ObservingList Creation/Edition] conversion error"; return; } - for ( QVariant object: listOfObjects ) { + for (QVariant object: listOfObjects) { QVariantMap objectMap; - if ( object.canConvert() ) { + if (object.canConvert()) { objectMap = object.value(); - QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); + QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); - if ( objectMgr->findAndSelect ( objectName ) ) { - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) { + if (objectMgr->findAndSelect(objectName)) { + const QList &selectedObject = objectMgr->getSelectedObject(); + if (!selectedObject.isEmpty()) { int lastRow = obsListListModel->rowCount(); QString objectUuid = QUuid::createUuid().toString(); QString objectNameI18n = selectedObject[0]->getNameI18n(); QString objectRaStr = "", objectDecStr = ""; bool visibleFlag = false; - double fov = -1.0; - QString objectType = selectedObject[0]->getType(); + // Fov + double fov = objectMap.value(QString(KEY_FOV)).value(); + + // Object type + QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); - float ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + // Ra & dec + objectRaStr = objectMap.value(QString(KEY_RA)).value(); + objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + + if (objectName.contains("marker", Qt::CaseInsensitive)) { visibleFlag = true; } - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); + // Magnitude + float objectMagnitude = selectedObject[0]->getVMagnitude(core); + QString objectMagnitudeStr = QString::number(objectMagnitude); - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); + QVariantMap objectMap = selectedObject[0]->getInfoMap(core); QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) { + QString objectConstellation("unknown"); + if (objectConstellationVariant.canConvert()) { objectConstellation = objectConstellationVariant.value(); } + // Julian Day QString JDs = ""; - double JD = core->getJD(); + double JD = objectMap.value(QString(KEY_DEC)).value(); + JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", + " "); - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + // Location + QString location = objectMap.value(QString(KEY_LOCATION)).value();; - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - } + // Add data into model row + addModelRow(lastRow, + objectUuid, + objectName, + objectNameI18n, + objectType, + objectRaStr, + objectDecStr, + objectMagnitudeStr, + objectConstellation); - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); observingListItem item; item.name = objectName; item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) { + if (!objectType.isEmpty()) { item.type = objectType; } - if ( !objectRaStr.isEmpty() ) { + if (!objectRaStr.isEmpty()) { item.ra = objectRaStr; } - if ( !objectDecStr.isEmpty() ) { + if (!objectDecStr.isEmpty()) { item.dec = objectDecStr; } - if ( !objectMagnitudeStr.isEmpty() ) { + if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } - if ( !objectConstellation.isEmpty() ) { + if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } - if ( !JDs.isEmpty() ) { - item.jd = JDs; + if (!JDs.isEmpty()) { + item.jd = JD; } - if ( !Location.isEmpty() ) { - item.location = Location; + if (!location.isEmpty()) { + item.location = location; } - if ( !visibleFlag ) { + if (!visibleFlag) { item.isVisibleMarker = visibleFlag; } - if ( fov > 0.0 ) { + if (fov > 0.0) { item.fov = fov; } - - observingListItemCollection.insert ( objectUuid,item ); + observingListItemCollection.insert(objectUuid, item); } else { qWarning() << "[ObservingList Creation/Edition] selected object is empty !"; } } else { - qWarning() << "[ObservingList Creation/Edition] object: " << objectName << " not found !" ; + qWarning() << "[ObservingList Creation/Edition] object: " << objectName << " not found !"; } } else { qCritical() << "[ObservingList Creation/Edition] conversion error"; @@ -757,7 +934,7 @@ void ObsListCreateEditDialog::loadObservingList() objectMgr->unSelect(); - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); return; } @@ -766,40 +943,29 @@ void ObsListCreateEditDialog::loadObservingList() /* * Called when the text of the nameOfListLineEdit change -*/ -void ObsListCreateEditDialog::nameOfListTextChange() -{ + */ +void ObsListCreateEditDialog::nameOfListTextChange() { ui->obsListErrorMessage->setHidden(true); - if ( ui->nameOfListLineEdit->text().isEmpty() ) { - ui->obsListSaveButton->setEnabled ( false ); + if (ui->nameOfListLineEdit->text().isEmpty()) { + ui->obsListSaveButton->setEnabled(false); } else { - ui->obsListSaveButton->setEnabled ( true ); + ui->obsListSaveButton->setEnabled(true); } - } /* * Setter for listName -*/ -void ObsListCreateEditDialog::setListName ( QList listName ) -{ - this->listName_ = listName; + */ +void ObsListCreateEditDialog::setListName(QList listName) { + this->listNames_ = listName; } /* * Destructor of singleton -*/ -void ObsListCreateEditDialog::kill() -{ - if ( m_instance != nullptr ) { + */ +void ObsListCreateEditDialog::kill() { + if (m_instance != nullptr) { delete m_instance; m_instance = nullptr; } } - - - - - - - diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 08f51280964d8..a547256133e83 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -56,15 +56,19 @@ class ObsListCreateEditDialog : public StelDialog //! To know if the dialog is open in creation mode or editionn mode // if true we are in creation mode otherwise in edition mode bool isCreationMode; + bool isSaveAs; QStandardItemModel * obsListListModel; class StelCore* core; class StelObjectMgr* objectMgr; - std::string listUuid_; + std::string listOlud_; QString observingListJsonPath; QHash observingListItemCollection; //List names - QList listName_; + QList listNames_; + + //Current list name + QString currentListName; //! Sorting of the list ex: right ascension QString sorting; @@ -94,8 +98,6 @@ class ObsListCreateEditDialog : public StelDialog virtual ~ObsListCreateEditDialog(); - - public slots: void retranslate(); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 57e25dcc65919..f2240d7b668e0 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -51,7 +51,7 @@ ObsListDialog::ObsListDialog ( QObject* parent ) : StelDialog ( "Observing list" observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); bookmarksJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_BOOKMARKS_FILE_NAME ); createEditDialog_instance = Q_NULLPTR; - defaultListUuid_ = ""; + defaultListOlud_ = ""; } ObsListDialog::~ObsListDialog() @@ -170,11 +170,11 @@ void ObsListDialog::setObservingListHeaderNames() /* * Add row in the obsListListModel */ -void ObsListDialog::addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) +void ObsListDialog::addModelRow (int number, QString olud, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) { QStandardItem* item = Q_NULLPTR; - item = new QStandardItem ( uuid ); + item = new QStandardItem (olud ); item->setEditable ( false ); obsListListModel->setItem ( number, ColumnUUID, item ); @@ -300,9 +300,9 @@ void ObsListDialog::obsListEditButtonPressed() /** * Open the observing list create/edit dialog */ -void ObsListDialog::invokeObsListCreateEditDialog ( string listUuid ) +void ObsListDialog::invokeObsListCreateEditDialog ( string listOlud ) { - createEditDialog_instance = ObsListCreateEditDialog::Instance ( listUuid ); + createEditDialog_instance = ObsListCreateEditDialog::Instance (listOlud ); connect ( createEditDialog_instance, SIGNAL ( exitButtonClicked() ), this, SLOT ( obsListCreateEditDialogClosed() ) ); createEditDialog_instance->setListName ( listName_ ); createEditDialog_instance->setVisible ( true ); @@ -327,7 +327,7 @@ void ObsListDialog::loadListsName() ui->obsListComboBox->clear(); // Get the default list uuid - QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_UUID ).toString(); + QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_OLUD ).toString(); QVariantMap observingListsMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); populateListNameInComboBox ( observingListsMap ); @@ -366,7 +366,7 @@ void ObsListDialog::populateListNameInComboBox ( QVariantMap map ) /* * Populate data into combo box */ -void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultListUuid ) +void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultListOlud ) { QMap::iterator i; for ( i = map.begin(); i != map.end(); ++i ) { @@ -384,8 +384,8 @@ void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultLis } } } - if ( defaultListUuid == listUuid ) { - defaultListUuid_ = defaultListUuid; + if (defaultListOlud == listUuid ) { + defaultListOlud_ = defaultListOlud; } } } @@ -397,13 +397,13 @@ void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultLis */ void ObsListDialog::loadDefaultList() { - if ( defaultListUuid_ != "" ) { - int index = ui->obsListComboBox->findData ( defaultListUuid_ ); + if (defaultListOlud_ != "" ) { + int index = ui->obsListComboBox->findData (defaultListOlud_ ); if ( index != -1 ) { ui->obsListComboBox->setCurrentIndex ( index ); ui->obsListEditListButton->setEnabled ( true ); - selectedObservingListUuid = defaultListUuid_.toStdString(); - loadObservingList ( defaultListUuid_ ); + selectedObservingListUuid = defaultListOlud_.toStdString(); + loadObservingList (defaultListOlud_ ); } } else { ui->obsListComboBox->setCurrentIndex ( 0 ); @@ -414,7 +414,7 @@ void ObsListDialog::loadDefaultList() /* * Load selected observing list */ -void ObsListDialog::loadObservingList ( QString listUuid ) +void ObsListDialog:: loadObservingList ( QString listOlud ) { QVariantMap map; QVariantList listOfObjects; @@ -425,10 +425,10 @@ void ObsListDialog::loadObservingList ( QString listUuid ) try { map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); + QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value (listOlud ).toMap(); QString sortingBy = observingListMap.value ( KEY_SORTING ).toString(); - listOfObjects = loadListFromJson ( map, listUuid ); + listOfObjects = loadListFromJson (map, listOlud ); if ( listOfObjects.size() > 0 ) { ui->obsListHighlightAllButton->setEnabled ( true ); @@ -506,7 +506,8 @@ void ObsListDialog::loadObservingList ( QString listUuid ) item.constellation = objectConstellation; } if ( !JDs.isEmpty() ) { - item.jd = QString::number ( JD, 'f', 6 ); + //item.jd = QString::number ( JD, 'f', 6 ); + item.jd = JD; } if ( !Location.isEmpty() ) { item.location = Location; @@ -554,11 +555,11 @@ void ObsListDialog::loadObservingList ( QString listUuid ) /* * Load the list from JSON file QVariantMap map */ -QVariantList ObsListDialog::loadListFromJson ( QVariantMap map, QString listUuid ) +QVariantList ObsListDialog::loadListFromJson ( QVariantMap map, QString listOlud ) { observingListItemCollection.clear(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value ( listUuid ).toMap(); + QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value (listOlud ).toMap(); QVariantList listOfObjects; QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); @@ -679,9 +680,9 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); } - QString defaultListValue = mapFromJsonFile.value ( QString ( KEY_DEFAULT_LIST_UUID ) ).toString(); + QString defaultListValue = mapFromJsonFile.value ( QString ( KEY_DEFAULT_LIST_OLUD ) ).toString(); if ( defaultListValue.isEmpty() ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); + mapFromJsonFile.insert ( KEY_DEFAULT_LIST_OLUD, "" ); } if ( checkIfBookmarksListExists ( allListsMap ) ) { @@ -788,9 +789,11 @@ void ObsListDialog::selectAndGoToObject ( QModelIndex index ) QString itemUuid = uuidItem->text(); observingListItem item = observingListItemCollection.value ( itemUuid ); - if ( !item.jd.isEmpty() ) { + /*if ( !item.jd.isEmpty() ) { core->setJD ( item.jd.toDouble() ); - } + }*/ + core->setJD ( item.jd); + if ( !item.location.isEmpty() ) { StelLocationMgr* locationMgr = &StelApp::getInstance().getLocationMgr(); core->moveObserverTo ( locationMgr->locationForString ( item.location ) ); @@ -885,7 +888,7 @@ void ObsListDialog::obsListDeleteButtonPressed() QVariantMap newObsListMap; map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - newMap.insert ( QString ( KEY_DEFAULT_LIST_UUID ), map.value ( QString ( KEY_DEFAULT_LIST_UUID ) ) ); + newMap.insert ( QString ( KEY_DEFAULT_LIST_OLUD ), map.value ( QString ( KEY_DEFAULT_LIST_OLUD ) ) ); QVariantMap obsListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); QMap::iterator i; @@ -911,7 +914,7 @@ void ObsListDialog::obsListDeleteButtonPressed() //TODO pas utile car listeName_ est réinitialiséé et rechargée dans loadListsName(). //TODO a supprimer après les tests finaux. //QString listName = ui->obsListComboBox->itemText(currentIndex); - //listName_.removeOne(listName); + //listNames_.removeOne(listName); selectedObservingListUuid = ""; diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index afd84888f962b..0fae274b14e22 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -59,33 +59,33 @@ class ObsListDialog : public StelDialog QString bookmarksJsonPath; QHash observingListItemCollection; QList highlightLabelIDs; - QString defaultListUuid_; + QString defaultListOlud_; QList listName_; QStringList listNamesModel; //! Set header names for observing list table void setObservingListHeaderNames(); - void invokeObsListCreateEditDialog ( std::string listUuid ); + void invokeObsListCreateEditDialog ( std::string listOlud ); ObsListCreateEditDialog * createEditDialog_instance; //! Add row in the obsListListModel //! @param number row number - //! @param uuid id of the record + //! @param olud id of the record //! @param name name or the designation of the object //! @param type type of the object //! @param ra right assencion of the object //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); + void addModelRow (int number, QString olud, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); //! Load the selected observing list - //! @param listUuid the uuid of the list - void loadObservingList ( QString listUuid ); + //! @param listOlud the olud (id) of the list + void loadObservingList ( QString listOlud ); - //! Load the lists names to populate the combo box and get the default list uuid + //! Load the lists names to populate the combo box and get the default list olud void loadListsName(); //! Load the default list @@ -97,13 +97,13 @@ class ObsListDialog : public StelDialog bool checkIfBookmarksListExists(QVariantMap allListsMap); //! Load list from JSON file - QVariantList loadListFromJson(QVariantMap map, QString listUuid); + QVariantList loadListFromJson(QVariantMap map, QString listOlud); //! Populate list names into combo box void populateListNameInComboBox(QVariantMap map); //! Populate data into combo box - void populateDataInComboBox(QVariantMap map, QString defaultListUuid); + void populateDataInComboBox(QVariantMap map, QString defaultListOlud); //! Sort the obsListTreeView by the column name given in parameter void sortObsListTreeViewByColumnName(QString columnName); diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index fe06473d12d05..0045d4a166448 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -26,12 +26,12 @@ struct observingListItem { QString type; QString ra; QString dec; - QString magnitude; + QString magnitude; //TODO voir si c'est utilisé QString constellation; - QString jd; + double jd; QString location; double fov; - bool isVisibleMarker; + bool isVisibleMarker; //TODO voir si c'est vraiment utilisé }; Q_DECLARE_METATYPE ( observingListItem ) @@ -76,7 +76,7 @@ static constexpr char const * BOOKMARKS_LIST_NAME = "bookmarks list"; static constexpr char const * BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version."; static constexpr char const * SHORT_NAME_VALUE = "Observing list for Stellarium"; -static constexpr char const * KEY_DEFAULT_LIST_UUID = "defaultListUuid"; +static constexpr char const * KEY_DEFAULT_LIST_OLUD = "defaultListOlud"; static constexpr char const * KEY_OBSERVING_LISTS = "observingLists"; static constexpr char const * KEY_BOOKMARKS = "bookmarks"; static constexpr char const * KEY_NAME = "name"; @@ -87,6 +87,7 @@ static constexpr char const * KEY_DEC = "dec"; static constexpr char const * KEY_FOV = "fov"; static constexpr char const * KEY_DESCRIPTION = "description"; static constexpr char const * KEY_OBJECTS = "objects"; +static constexpr char const * KEY_OBJECTS_TYPE = "objtype"; static constexpr char const * KEY_DESIGNATION = "designation"; static constexpr char const * KEY_SORTING = "sorting"; static constexpr char const * KEY_LOCATION = "location"; @@ -108,5 +109,7 @@ static constexpr int COLUMN_NUMBER_DEC = 5; static constexpr int COLUMN_NUMBER_MAGNITUDE = 6; static constexpr int COLUMN_NUMBER_CONSTELLATION = 7; +static constexpr char const * CUSTOM_OBJECT = "CustomObject"; + #endif // OBSLISTDIALOG_H diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index a5dcf41449599..16a61b7fe7460 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -127,7 +127,7 @@ - + @@ -143,20 +143,59 @@ - + + + + + Right ascension + + + 3 + + + Ra + + + + + + + Declination + + + 3 + + + Dec + + + - + - Set the list as default + Fiel Of View 3 - Set list as default + Fov + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -252,17 +291,17 @@ - - + + - + - Name of the list: + Description: - + Qt::Horizontal @@ -271,35 +310,49 @@ - 39 + 67 20 - + + + + + + + + + + QLabel {color : red;} + + + TextLabel + + - + -1 - - + + - + - Description: + Name of the list: - + Qt::Horizontal @@ -308,26 +361,29 @@ - 67 + 39 20 - + - + - - - QLabel {color : red;} + + + Set the list as default + + + 3 - TextLabel + Set list as default From b47e3c0966723e2be0e23e36d8c4a686e53dbcfc Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 9 May 2022 14:04:37 +0200 Subject: [PATCH 13/28] ObservingList Multiple corrections and modifications --- src/gui/ObsListCreateEditDialog.cpp | 185 ++++-- src/gui/ObsListCreateEditDialog.hpp | 27 +- src/gui/ObsListDialog.cpp | 958 +++++++++++++++------------- src/gui/ObsListDialog.hpp | 32 +- src/gui/ObservingListCommon.hpp | 6 +- src/gui/obsListCreateEditDialog.ui | 123 ++-- src/gui/obsListDialog.ui | 70 +- 7 files changed, 831 insertions(+), 570 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index d5ecbc75cdfe5..ee69d468fbc44 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -18,11 +18,11 @@ */ #include -#include #include #include #include #include +#include #include "NebulaMgr.hpp" #include "StelCore.hpp" @@ -31,26 +31,25 @@ #include "StelModuleMgr.hpp" #include "StelMovementMgr.hpp" #include "StelObjectMgr.hpp" +#include "LandscapeMgr.hpp" #include "StelUtils.hpp" #include "ObsListCreateEditDialog.hpp" #include "ui_obsListCreateEditDialog.h" -using namespace std; - ObsListCreateEditDialog *ObsListCreateEditDialog::m_instance = nullptr; -ObsListCreateEditDialog::ObsListCreateEditDialog(string listUuid) { - listOlud_ = listUuid; - - ui = new Ui_obsListCreateEditDialogForm(); - core = StelApp::getInstance().getCore(); +ObsListCreateEditDialog::ObsListCreateEditDialog(std::string listUuid) : ui(new Ui_obsListCreateEditDialogForm()), + obsListListModel( + new QStandardItemModel(0, ColumnCount)), + core(StelApp::getInstance().getCore()), + listOlud_(std::move(listUuid)), sorting("") { objectMgr = GETSTELMODULE(StelObjectMgr); - obsListListModel = new QStandardItemModel(0, ColumnCount); + landscapeMgr = GETSTELMODULE(LandscapeMgr); observingListJsonPath = - StelFileMgr::findFile("data", (StelFileMgr::Flags) (StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + QString(JSON_FILE_NAME); - sorting = ""; + } ObsListCreateEditDialog::~ObsListCreateEditDialog() { @@ -63,9 +62,9 @@ ObsListCreateEditDialog::~ObsListCreateEditDialog() { /** * Get instance of class */ -ObsListCreateEditDialog *ObsListCreateEditDialog::Instance(string listUuid) { +auto ObsListCreateEditDialog::Instance(std::string listUuid) -> ObsListCreateEditDialog * { if (m_instance == nullptr) { - m_instance = new ObsListCreateEditDialog(listUuid); + m_instance = new ObsListCreateEditDialog(std::move(listUuid)); } return m_instance; } @@ -130,7 +129,7 @@ void ObsListCreateEditDialog::createDialogContent() { ui->obsListSaveButton->setEnabled(true); } - if (listOlud_.size() == 0) { + if (listOlud_.empty()) { // case of creation mode isCreationMode = true; ui->stelWindowTitle->setText("Observing list creation mode"); @@ -146,7 +145,7 @@ void ObsListCreateEditDialog::createDialogContent() { * Retranslate dialog */ void ObsListCreateEditDialog::retranslate() { - if (dialog) { + if (dialog != nullptr) { ui->retranslateUi(dialog); } } @@ -183,14 +182,14 @@ void ObsListCreateEditDialog::setObservingListHeaderNames() { * Add row in the obsListListModel */ void ObsListCreateEditDialog::addModelRow(int number, - QString uuid, - QString name, - QString nameI18n, - QString type, - QString ra, - QString dec, - QString magnitude, - QString constellation) { + const QString& uuid, + const QString& name, + const QString& nameI18n, + const QString& type, + const QString& ra, + const QString& dec, + const QString& magnitude, + const QString& constellation) { QStandardItem *item = Q_NULLPTR; item = new QStandardItem(uuid); @@ -231,7 +230,8 @@ void ObsListCreateEditDialog::addModelRow(int number, } /* - * Slot for button obsListAddObjectButton + * Slot for button obsListAddObjectButton. + * Save selected object into the list of observed objects. */ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { const QList &selectedObject = objectMgr->getSelectedObject(); @@ -239,7 +239,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // No duplicate item in the same list bool is_already_in_list = false; - QHash::const_iterator i; + QHash::iterator i; for (i = observingListItemCollection.begin(); i != observingListItemCollection.end(); i++) { if (i.value().name.compare(selectedObject[0]->getEnglishName()) == 0) { is_already_in_list = true; @@ -251,7 +251,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { const int lastRow = obsListListModel->rowCount(); const QString objectUuid = QUuid::createUuid().toString(); - // Object name + // Object name (designation) QString objectName = selectedObject[0]->getEnglishName(); QString objectNameI18n = selectedObject[0]->getNameI18n(); if (selectedObject[0]->getType() == "Nebula") { @@ -261,11 +261,13 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Object type QString objectType = selectedObject[0]->getType(); - // Ra & Dec - QString objectRaStr = "", objectDecStr = ""; + // Fov + QString objectRaStr = ""; + QString objectDecStr = ""; bool visibleFlag = false; double fov = -1.0; + // Ra & Dec float ra, dec; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { @@ -299,16 +301,18 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { objectConstellation = objectConstellationVariant.value(); } + // JD QString JDs = ""; double JD = core->getJD(); JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); + // Location QString Location = ""; StelLocation loc = core->getCurrentLocation(); if (loc.name.isEmpty()) { - Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); + Location = QString("%1, %2").arg(loc.latitude, loc.longitude); } else { - Location = QString("%1, %2").arg(loc.name).arg(loc.region); + Location = QString("%1, %2").arg(loc.name, loc.region); } addModelRow(lastRow, @@ -322,41 +326,49 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { objectConstellation); observingListItem item; + initItem(item); item.name = objectName; item.nameI18n = objectNameI18n; + // Object Type if (!objectType.isEmpty()) { item.type = objectType; } + // Ra if (!objectRaStr.isEmpty()) { item.ra = objectRaStr; } + // Dec if (!objectDecStr.isEmpty()) { item.dec = objectDecStr; } + // Magnitude if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } + //Constellation if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } + // JD if (!JDs.isEmpty()) { //item.jd = QString::number(JD, 'f', 6); item.jd = JD; } + // Location if (!Location.isEmpty()) { QHash::iterator i; item.location = Location; } + // Visible Flag if (!visibleFlag) { item.isVisibleMarker = visibleFlag; } + // Fov if (fov > 0.0 && (ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT)) { item.fov = fov; } - observingListItemCollection.insert(objectUuid, item); } - } else { qWarning() << "selected object is empty !"; } @@ -373,9 +385,9 @@ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() { } /* - * Save observed object into json file + * Save observed objects and the list into Json file */ -void ObsListCreateEditDialog::saveObservedObject() { +void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { if (observingListJsonPath.isEmpty()) { qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; @@ -393,6 +405,10 @@ void ObsListCreateEditDialog::saveObservedObject() { // Name of the list const QString listName = ui->nameOfListLineEdit->text(); + // Creation date + double JD = core->getJD(); + QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T"," "); + try { QVariantMap mapFromJsonFile; QVariantMap allListsMap; @@ -412,6 +428,17 @@ void ObsListCreateEditDialog::saveObservedObject() { QString description = ui->descriptionLineEdit->text(); observingListDataList.insert(QString(KEY_DESCRIPTION), description); + // Creation date + observingListDataList.insert(QString(KEY_CREATION_DATE), listCreationDate); + + // Landscape + if(ui->obsListLandscapeCheckBox->isChecked()){ + QString landscapeId = landscapeMgr->getCurrentLandscapeID(); + observingListDataList.insert(QString(KEY_LANDSCAPE_ID),landscapeId); + } else { + observingListDataList.insert(QString(KEY_LANDSCAPE_ID),""); + } + // List of objects QVariantList listOfObjects; QHashIterator i(observingListItemCollection); @@ -478,12 +505,18 @@ void ObsListCreateEditDialog::saveObservedObject() { oblListOlud = QString::fromStdString(listOlud_); } + // Default list if (ui->obsListDefaultListCheckBox->isChecked()) { mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, oblListOlud); } else { QString defaultListUuid = mapFromJsonFile.value(KEY_DEFAULT_LIST_OLUD).toString(); if (defaultListUuid.isEmpty()) { mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); + } else { + int compareResult = QString::compare(defaultListUuid, QString::fromStdString(listOlud_), Qt::CaseSensitive); + if(compareResult == 0){ + mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); + } } } @@ -660,7 +693,7 @@ void ObsListCreateEditDialog::obsListExportListButtonPressed() { QString filter = "JSON (*.json)"; observingListJsonPath = QFileDialog::getSaveFileName(Q_NULLPTR, q_("Export observing list as..."), QDir::homePath() + "/" + JSON_FILE_NAME, filter); - saveObservedObject(); + saveObservedObjectsInJsonFile(); observingListJsonPath = originalobservingListJsonPath; } @@ -705,11 +738,10 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() { */ void ObsListCreateEditDialog::obsListSaveButtonPressed() { QString listName = ui->nameOfListLineEdit->text(); - bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode || - (listName.compare( - currentListName) != - 0 && - !isCreationMode)); + + // TODO il faut faire la comparaison du nom des liste en ignoreCase + bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode ||(listName.compare(currentListName) !=0 &&!isCreationMode)); + if (isListAlreadyExists) { QString errorMessage; errorMessage.append("Error: a list with the name ") @@ -732,7 +764,7 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { } else { isSaveAs = false; } - saveObservedObject(); + saveObservedObjectsInJsonFile(); this->close(); emit exitButtonClicked(); } @@ -818,6 +850,12 @@ void ObsListCreateEditDialog::loadObservingList() { QString listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); ui->descriptionLineEdit->setText(listDescription); + // Landscape + QString landscape = observingListMap.value(QString(KEY_LANDSCAPE_ID)).value(); + if(!landscape.isEmpty()){ + ui->obsListLandscapeCheckBox->setChecked(true); + } + if (observingListMap.value(QString(KEY_OBJECTS)).canConvert()) { QVariant data = observingListMap.value(QString(KEY_OBJECTS)); listOfObjects = data.value(); @@ -826,23 +864,26 @@ void ObsListCreateEditDialog::loadObservingList() { return; } - for (QVariant object: listOfObjects) { + for (const QVariant& object: listOfObjects) { QVariantMap objectMap; if (object.canConvert()) { objectMap = object.value(); QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); + // TODO il faut charger ce qui est dans lee fichier + if (objectMgr->findAndSelect(objectName)) { const QList &selectedObject = objectMgr->getSelectedObject(); if (!selectedObject.isEmpty()) { int lastRow = obsListListModel->rowCount(); QString objectUuid = QUuid::createUuid().toString(); QString objectNameI18n = selectedObject[0]->getNameI18n(); - QString objectRaStr = "", objectDecStr = ""; + QString objectRaStr = ""; + QString objectDecStr = ""; bool visibleFlag = false; // Fov - double fov = objectMap.value(QString(KEY_FOV)).value(); + auto fov = objectMap.value(QString(KEY_FOV)).value(); // Object type QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); @@ -859,21 +900,21 @@ void ObsListCreateEditDialog::loadObservingList() { float objectMagnitude = selectedObject[0]->getVMagnitude(core); QString objectMagnitudeStr = QString::number(objectMagnitude); - QVariantMap objectMap = selectedObject[0]->getInfoMap(core); - QVariant objectConstellationVariant = objectMap["iauConstellation"]; + //TODO à modifier + QVariantMap selectedObjectMap = selectedObject[0]->getInfoMap(core); + // ********************************************************* + + QVariant objectConstellationVariant = selectedObjectMap["iauConstellation"]; QString objectConstellation("unknown"); if (objectConstellationVariant.canConvert()) { objectConstellation = objectConstellationVariant.value(); } // Julian Day - QString JDs = ""; - double JD = objectMap.value(QString(KEY_DEC)).value(); - JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", - " "); + QString JDs = objectMap.value(QString(KEY_JD)).value(); // Location - QString location = objectMap.value(QString(KEY_LOCATION)).value();; + QString location = selectedObjectMap.value(QString(KEY_LOCATION)).value();; // Add data into model row addModelRow(lastRow, @@ -888,32 +929,51 @@ void ObsListCreateEditDialog::loadObservingList() { observingListItem item; + initItem(item); item.name = objectName; item.nameI18n = objectNameI18n; + + // Object type if (!objectType.isEmpty()) { item.type = objectType; } + + // Ra if (!objectRaStr.isEmpty()) { item.ra = objectRaStr; } + + // Dec if (!objectDecStr.isEmpty()) { item.dec = objectDecStr; } + + // Magnitude if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } + + // Constellation if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } + + // JD if (!JDs.isEmpty()) { - item.jd = JD; + item.jd = JDs.toDouble(); } + + // Location if (!location.isEmpty()) { item.location = location; } + + // Flag if (!visibleFlag) { item.isVisibleMarker = visibleFlag; } + + // Fov if (fov > 0.0) { item.fov = fov; } @@ -957,7 +1017,7 @@ void ObsListCreateEditDialog::nameOfListTextChange() { * Setter for listName */ void ObsListCreateEditDialog::setListName(QList listName) { - this->listNames_ = listName; + this->listNames_ = std::move(listName); } /* @@ -969,3 +1029,22 @@ void ObsListCreateEditDialog::kill() { m_instance = nullptr; } } + +/** + * Init observingListItem. + * @param item + */ +void ObsListCreateEditDialog::initItem(observingListItem &item) { + + item.jd = 0.0; + item.type = ""; + item.ra = ""; + item.dec = ""; + item.name = ""; + item.nameI18n = ""; + item.location = ""; + item.fov = 0.0; + item.constellation = ""; + item.magnitude = ""; + item.isVisibleMarker = false; +} diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index a547256133e83..485570ddeefa5 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -35,24 +35,24 @@ class ObsListCreateEditDialog : public StelDialog Q_OBJECT public: - static ObsListCreateEditDialog * Instance ( std::string listUuid ); + static auto Instance ( std::string listUuid ) -> ObsListCreateEditDialog *; static void kill(); //! Notify that the application style changed - void styleChanged(); + void styleChanged() override; //! called when click on button close in top right corner - void close(); + void close() override; void setListName ( QList listName ); protected: - static ObsListCreateEditDialog * m_instance; - Ui_obsListCreateEditDialogForm *ui; //! Initialize the dialog widgets and connect the signals/slots. - virtual void createDialogContent(); + void createDialogContent() override; private: + static ObsListCreateEditDialog * m_instance; + Ui_obsListCreateEditDialogForm * ui; //! To know if the dialog is open in creation mode or editionn mode // if true we are in creation mode otherwise in edition mode bool isCreationMode; @@ -60,8 +60,11 @@ class ObsListCreateEditDialog : public StelDialog QStandardItemModel * obsListListModel; class StelCore* core; class StelObjectMgr* objectMgr; + class LandscapeMgr* landscapeMgr; std::string listOlud_; QString observingListJsonPath; + + // Data for observed objects QHash observingListItemCollection; //List names @@ -85,21 +88,23 @@ class ObsListCreateEditDialog : public StelDialog //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow ( int number, QString uuid, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); + void addModelRow ( int number, const QString& uuid, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, const QString& dec, const QString& magnitude, const QString& constellation ); //! Save the object informations into json file - void saveObservedObject(); + void saveObservedObjectsInJsonFile(); //! Load the observing liste in case of edit mode void loadObservingList(); //Private constructor and destructor - ObsListCreateEditDialog ( std::string listUuid ); - virtual ~ObsListCreateEditDialog(); + explicit ObsListCreateEditDialog ( std::string listUuid ); + ~ObsListCreateEditDialog() override; + + void initItem(observingListItem &item); public slots: - void retranslate(); + void retranslate() override; private slots: void obsListAddObjectButtonPressed(); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index f2240d7b668e0..e933b6cfe5528 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -28,6 +28,7 @@ #include "StelFileMgr.hpp" #include "StelMovementMgr.hpp" #include "CustomObjectMgr.hpp" +#include "LandscapeMgr.hpp" #include "HighlightMgr.hpp" #include "StarMgr.hpp" #include "StelJsonParser.hpp" @@ -37,25 +38,30 @@ #include "ui_obsListDialog.h" #include +#include using namespace std; -ObsListDialog::ObsListDialog ( QObject* parent ) : StelDialog ( "Observing list", parent ) -{ - ui = new Ui_obsListDialogForm(); - core = StelApp::getInstance().getCore(); - objectMgr = GETSTELMODULE ( StelObjectMgr ); - labelMgr = GETSTELMODULE ( LabelMgr ); - obsListListModel = new QStandardItemModel ( 0,ColumnCount ); - observingListJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_FILE_NAME ); - bookmarksJsonPath = StelFileMgr::findFile ( "data", ( StelFileMgr::Flags ) ( StelFileMgr::Directory|StelFileMgr::Writable ) ) + "/" + QString ( JSON_BOOKMARKS_FILE_NAME ); - createEditDialog_instance = Q_NULLPTR; - defaultListOlud_ = ""; +ObsListDialog::ObsListDialog(QObject *parent) : StelDialog("Observing list", parent), ui(new Ui_obsListDialogForm()), + obsListListModel(new QStandardItemModel(0, ColumnCount)), + core(StelApp::getInstance().getCore()), createEditDialog_instance(Q_NULLPTR) { + + objectMgr = GETSTELMODULE (StelObjectMgr); + labelMgr = GETSTELMODULE (LabelMgr); + landscapeMgr = GETSTELMODULE(LandscapeMgr); + + observingListJsonPath = + StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + QString(JSON_FILE_NAME); + bookmarksJsonPath = + StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + QString(JSON_BOOKMARKS_FILE_NAME); + + } -ObsListDialog::~ObsListDialog() -{ +ObsListDialog::~ObsListDialog() { delete ui; delete obsListListModel; ui = Q_NULLPTR; @@ -65,62 +71,65 @@ ObsListDialog::~ObsListDialog() /* * Initialize the dialog widgets and connect the signals/slots. */ -void ObsListDialog::createDialogContent() -{ - ui->setupUi ( dialog ); +void ObsListDialog::createDialogContent() { + ui->setupUi(dialog); //Signals and slots - connect ( &StelApp::getInstance(), SIGNAL ( languageChanged() ), this, SLOT ( retranslate() ) ); - connect ( ui->closeStelWindow, SIGNAL ( clicked() ), this, SLOT ( close() ) ); + connect(&StelApp::getInstance(), SIGNAL (languageChanged()), this, SLOT (retranslate())); - connect ( ui->obsListNewListButton, SIGNAL ( clicked() ), this, SLOT ( obsListNewListButtonPressed() ) ); - connect ( ui->obsListEditListButton, SIGNAL ( clicked() ), this, SLOT ( obsListEditButtonPressed() ) ); - connect ( ui->obsListClearHighlightButton, SIGNAL ( clicked() ), this, SLOT ( obsListClearHighLightButtonPressed() ) ); - connect ( ui->obsListHighlightAllButton, SIGNAL ( clicked() ), this, SLOT ( obsListHighLightAllButtonPressed() ) ); - connect ( ui->obsListExitButton, SIGNAL ( clicked() ), this, SLOT ( obsListExitButtonPressed() ) ); - connect ( ui->obsListDeleteButton, SIGNAL ( clicked() ), this, SLOT ( obsListDeleteButtonPressed() ) ); - connect ( ui->obsListTreeView, SIGNAL ( doubleClicked ( QModelIndex ) ), this, SLOT ( selectAndGoToObject ( QModelIndex ) ) ); + connect(ui->obsListNewListButton, SIGNAL (clicked()), this, SLOT (obsListNewListButtonPressed())); + connect(ui->obsListEditListButton, SIGNAL (clicked()), this, SLOT (obsListEditButtonPressed())); + connect(ui->obsListClearHighlightButton, SIGNAL (clicked()), this, SLOT (obsListClearHighLightButtonPressed())); + connect(ui->obsListHighlightAllButton, SIGNAL (clicked()), this, SLOT (obsListHighLightAllButtonPressed())); + connect(ui->obsListExitButton, SIGNAL (clicked()), this, SLOT (obsListExitButtonPressed())); + connect(ui->obsListDeleteButton, SIGNAL (clicked()), this, SLOT (obsListDeleteButtonPressed())); + connect(ui->obsListTreeView, SIGNAL (doubleClicked(QModelIndex)), this, SLOT (selectAndGoToObject(QModelIndex))); //obsListCombo settings - connect ( ui->obsListComboBox, SIGNAL ( activated ( int ) ), this, SLOT ( loadSelectedObservingList ( int ) ) ); + connect(ui->obsListComboBox, SIGNAL (activated(int)), this, SLOT (loadSelectedObservingList(int))); //Initialize the list of observing lists - obsListListModel->setColumnCount ( ColumnCount ); + obsListListModel->setColumnCount(ColumnCount); setObservingListHeaderNames(); - ui->obsListTreeView->setModel ( obsListListModel ); - ui->obsListTreeView->header()->setSectionsMovable ( false ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnName, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnType, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnRa, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnDec, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnConstellation, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setSectionResizeMode ( ColumnMagnitude, QHeaderView::ResizeToContents ); - ui->obsListTreeView->header()->setStretchLastSection ( true ); - ui->obsListTreeView->hideColumn ( ColumnUUID ); - ui->obsListTreeView->hideColumn ( ColumnNameI18n ); - ui->obsListTreeView->hideColumn ( ColumnJD ); - ui->obsListTreeView->hideColumn ( ColumnLocation ); + ui->obsListTreeView->setModel(obsListListModel); + ui->obsListTreeView->header()->setSectionsMovable(false); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnName, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnType, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnRa, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnConstellation, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setStretchLastSection(true); + ui->obsListTreeView->hideColumn(ColumnUUID); + ui->obsListTreeView->hideColumn(ColumnNameI18n); + ui->obsListTreeView->hideColumn(ColumnJD); + ui->obsListTreeView->hideColumn(ColumnLocation); //Enable the sort for columns - ui->obsListTreeView->setSortingEnabled ( true ); + ui->obsListTreeView->setSortingEnabled(true); //By default buttons are disable - ui->obsListEditListButton->setEnabled ( false ); - ui->obsListHighlightAllButton->setEnabled ( false ); - ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled ( false ); + ui->obsListEditListButton->setEnabled(false); + ui->obsListHighlightAllButton->setEnabled(false); + ui->obsListClearHighlightButton->setEnabled(false); + ui->obsListDeleteButton->setEnabled(false); + + // We hide the closeStelWindow to have only two possibilities to close the dialog: + // Exit + ui->closeStelWindow->setHidden(true); // For no regression we must take into account the legacy bookmarks file - QFile jsonBookmarksFile ( bookmarksJsonPath ); - if ( jsonBookmarksFile.exists() ) { + QFile jsonBookmarksFile(bookmarksJsonPath); + if (jsonBookmarksFile.exists()) { qDebug() << "Fichiers bookmarks détecté"; loadBookmarksInObservingList(); } - QFile jsonFile ( observingListJsonPath ); - if ( jsonFile.exists() ) { - loadListsName(); + QFile jsonFile(observingListJsonPath); + if (jsonFile.exists()) { + loadListsNameFromJsonFile(); + defaultListOlud_ = extractDefaultListOludFromJsonFile(); loadDefaultList(); } @@ -129,10 +138,9 @@ void ObsListDialog::createDialogContent() /* * Retranslate dialog */ -void ObsListDialog::retranslate() -{ - if ( dialog ) { - ui->retranslateUi ( dialog ); +void ObsListDialog::retranslate() { + if (dialog) { + ui->retranslateUi(dialog); setObservingListHeaderNames(); } } @@ -140,8 +148,7 @@ void ObsListDialog::retranslate() /* * Style changed */ -void ObsListDialog::styleChanged() -{ +void ObsListDialog::styleChanged() { // Nothing for now } @@ -149,129 +156,125 @@ void ObsListDialog::styleChanged() * Set the header for the observing list table * (obsListTreeVView) */ -void ObsListDialog::setObservingListHeaderNames() -{ +void ObsListDialog::setObservingListHeaderNames() { const QStringList headerStrings = { - "UUID", // Hidden column - q_ ( "Object name" ), - q_ ( "Object name I18N" ), // Hidden column - q_ ( "Type" ), - q_ ( "Right ascension" ), - q_ ( "Declination" ), - q_ ( "Magnitude" ), - q_ ( "Constellation" ), - q_ ( "Date" ), // Hidden column - q_ ( "Location" ) // Hidden column + "UUID", // Hidden column + q_ ("Object name"), + q_ ("Object name I18N"), // Hidden column + q_ ("Type"), + q_ ("Right ascension"), + q_ ("Declination"), + q_ ("Magnitude"), + q_ ("Constellation"), + q_ ("Date"), // Hidden column + q_ ("Location") // Hidden column }; - obsListListModel->setHorizontalHeaderLabels ( headerStrings ); + obsListListModel->setHorizontalHeaderLabels(headerStrings); } /* * Add row in the obsListListModel */ -void ObsListDialog::addModelRow (int number, QString olud, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ) -{ - QStandardItem* item = Q_NULLPTR; +void ObsListDialog::addModelRow(int number, const QString& olud, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, + const QString& dec, const QString& magnitude, const QString& constellation) { + QStandardItem *item = Q_NULLPTR; - item = new QStandardItem (olud ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnUUID, item ); + item = new QStandardItem(olud); + item->setEditable(false); + obsListListModel->setItem(number, ColumnUUID, item); - item = new QStandardItem ( name ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnName, item ); + item = new QStandardItem(name); + item->setEditable(false); + obsListListModel->setItem(number, ColumnName, item); - item = new QStandardItem ( nameI18n ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnNameI18n, item ); + item = new QStandardItem(nameI18n); + item->setEditable(false); + obsListListModel->setItem(number, ColumnNameI18n, item); - item = new QStandardItem ( type ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnType, item ); + item = new QStandardItem(type); + item->setEditable(false); + obsListListModel->setItem(number, ColumnType, item); - item = new QStandardItem ( ra ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnRa, item ); + item = new QStandardItem(ra); + item->setEditable(false); + obsListListModel->setItem(number, ColumnRa, item); - item = new QStandardItem ( dec ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnDec, item ); + item = new QStandardItem(dec); + item->setEditable(false); + obsListListModel->setItem(number, ColumnDec, item); - item = new QStandardItem ( magnitude ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnMagnitude, item ); + item = new QStandardItem(magnitude); + item->setEditable(false); + obsListListModel->setItem(number, ColumnMagnitude, item); - item = new QStandardItem ( constellation ); - item->setEditable ( false ); - obsListListModel->setItem ( number, ColumnConstellation, item ); + item = new QStandardItem(constellation); + item->setEditable(false); + obsListListModel->setItem(number, ColumnConstellation, item); - for ( int i = 0; i < ColumnCount; ++i ) { - ui->obsListTreeView->resizeColumnToContents ( i ); + for (int i = 0; i < ColumnCount; ++i) { + ui->obsListTreeView->resizeColumnToContents(i); } } /* * Slot for button obsListHighLightAllButton */ -void ObsListDialog::obsListHighLightAllButtonPressed() -{ +void ObsListDialog::obsListHighLightAllButtonPressed() { QList highlights; highlights.clear(); obsListClearHighLightButtonPressed(); // Enable fool protection int fontSize = StelApp::getInstance().getScreenFontSize(); - HighlightMgr* hlMgr = GETSTELMODULE ( HighlightMgr ); + auto *hlMgr = GETSTELMODULE (HighlightMgr); QString color = hlMgr->getColor().toHtmlColor(); float distance = hlMgr->getMarkersSize(); - for ( auto item : observingListItemCollection ) { - QString name = item.name; - QString raStr = item.ra.trimmed(); - QString decStr = item.dec.trimmed(); + for (const auto& item: observingListItemCollection) { + QString name = item.name; + QString raStr = item.ra.trimmed(); + QString decStr = item.dec.trimmed(); Vec3d pos; - bool status = false; - if ( !raStr.isEmpty() && !decStr.isEmpty() ) { - StelUtils::spheToRect ( StelUtils::getDecAngle ( raStr ), StelUtils::getDecAngle ( decStr ), pos ); + bool status; + if (!raStr.isEmpty() && !decStr.isEmpty()) { + StelUtils::spheToRect(StelUtils::getDecAngle(raStr), StelUtils::getDecAngle(decStr), pos); status = true; } else { - status = objectMgr->findAndSelect ( name ); - const QList& selected = objectMgr->getSelectedObject(); - if ( !selected.isEmpty() ) { - pos = selected[0]->getJ2000EquatorialPos ( core ); + status = objectMgr->findAndSelect(name); + const QList &selected = objectMgr->getSelectedObject(); + if (!selected.isEmpty()) { + pos = selected[0]->getJ2000EquatorialPos(core); } } - if ( status ) { - highlights.append ( pos ); + if (status) { + highlights.append(pos); } objectMgr->unSelect(); // Add labels for named highlights (name in top right corner) - highlightLabelIDs.append ( labelMgr->labelObject ( name, name, true, fontSize, color, "NE", distance ) ); + highlightLabelIDs.append(labelMgr->labelObject(name, name, true, fontSize, color, "NE", distance)); } - hlMgr->fillHighlightList ( highlights ); + hlMgr->fillHighlightList(highlights); } /* * Slot for button obsListClearHighLightButton */ -void ObsListDialog::obsListClearHighLightButtonPressed() -{ +void ObsListDialog::obsListClearHighLightButtonPressed() { clearHighlight(); } /* * Clear highlight */ -void ObsListDialog::clearHighlight() -{ +void ObsListDialog::clearHighlight() { objectMgr->unSelect(); - GETSTELMODULE ( HighlightMgr )->cleanHighlightList(); + GETSTELMODULE (HighlightMgr)->cleanHighlightList(); // Clear labels - for ( auto l : highlightLabelIDs ) { - labelMgr->deleteLabel ( l ); + for (auto l: highlightLabelIDs) { + labelMgr->deleteLabel(l); } highlightLabelIDs.clear(); } @@ -279,19 +282,17 @@ void ObsListDialog::clearHighlight() /* * Slot for button obsListNewListButton */ -void ObsListDialog::obsListNewListButtonPressed() -{ +void ObsListDialog::obsListNewListButtonPressed() { string listUuid = string(); - invokeObsListCreateEditDialog ( listUuid ); + invokeObsListCreateEditDialog(listUuid); } /* * Slot for button obsListEditButton */ -void ObsListDialog::obsListEditButtonPressed() -{ - if ( !selectedObservingListUuid.empty() ) { - invokeObsListCreateEditDialog ( selectedObservingListUuid ); +void ObsListDialog::obsListEditButtonPressed() { + if (!selectedObservingListUuid.empty()) { + invokeObsListCreateEditDialog(selectedObservingListUuid); } else { qWarning() << "The selected observing list uuid is empty"; } @@ -300,40 +301,36 @@ void ObsListDialog::obsListEditButtonPressed() /** * Open the observing list create/edit dialog */ -void ObsListDialog::invokeObsListCreateEditDialog ( string listOlud ) -{ - createEditDialog_instance = ObsListCreateEditDialog::Instance (listOlud ); - connect ( createEditDialog_instance, SIGNAL ( exitButtonClicked() ), this, SLOT ( obsListCreateEditDialogClosed() ) ); - createEditDialog_instance->setListName ( listName_ ); - createEditDialog_instance->setVisible ( true ); +void ObsListDialog::invokeObsListCreateEditDialog(string listOlud) { + createEditDialog_instance = ObsListCreateEditDialog::Instance(std::move(listOlud)); + connect(createEditDialog_instance, SIGNAL (exitButtonClicked()), this, SLOT (obsListCreateEditDialogClosed())); + createEditDialog_instance->setListName(listName_); + createEditDialog_instance->setVisible(true); } /* - * Load the lists names for populate the combo box and get the default list uuid + * Load the lists names from Json file + * to populate the combo box and get the default list uuid */ -void ObsListDialog::loadListsName() -{ +void ObsListDialog::loadListsNameFromJsonFile() { QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); } else { try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); jsonFile.close(); // init combo box ui->obsListComboBox->clear(); - // Get the default list uuid - QString defaultListUuid = map.value ( KEY_DEFAULT_LIST_OLUD ).toString(); - - QVariantMap observingListsMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); - populateListNameInComboBox ( observingListsMap ); - populateDataInComboBox ( observingListsMap, defaultListUuid ); + QVariantMap observingListsMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); + populateListNameInComboBox(observingListsMap); + populateDataInComboBox(observingListsMap, defaultListOlud_); - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); return; } @@ -344,189 +341,226 @@ void ObsListDialog::loadListsName() /* * Populate the list names into combo box */ -void ObsListDialog::populateListNameInComboBox ( QVariantMap map ) -{ +void ObsListDialog::populateListNameInComboBox(QVariantMap map) { QMap::iterator i; ui->obsListComboBox->clear(); listNamesModel.clear(); listName_.clear(); - for ( i = map.begin(); i != map.end(); ++i ) { - if ( i.value().canConvert() ) { + for (i = map.begin(); i != map.end(); ++i) { + if (i.value().canConvert()) { QVariant var = i.value(); QVariantMap data = var.value(); - QString listName = data.value ( KEY_NAME ).value(); - listNamesModel.append ( listName ); + QString listName = data.value(KEY_NAME).value(); + listNamesModel.append(listName); listName_.append(listName); } } - listNamesModel.sort ( Qt::CaseInsensitive ); - ui->obsListComboBox->addItems ( listNamesModel ); + listNamesModel.sort(Qt::CaseInsensitive); + ui->obsListComboBox->addItems(listNamesModel); } /* * Populate data into combo box */ -void ObsListDialog::populateDataInComboBox ( QVariantMap map, QString defaultListOlud ) -{ +void ObsListDialog::populateDataInComboBox(QVariantMap map, const QString& defaultListOlud) { QMap::iterator i; - for ( i = map.begin(); i != map.end(); ++i ) { + for (i = map.begin(); i != map.end(); ++i) { QString listUuid = i.key(); - if ( i.value().canConvert() ) { + if (i.value().canConvert()) { QVariant var = i.value(); QVariantMap data = var.value(); - QString listName = data.value ( KEY_NAME ).value(); + QString listName = data.value(KEY_NAME).value(); - foreach ( QString str, listNamesModel ) { - if ( QString::compare ( str, listName ) == 0 ) { - int index = listNamesModel.indexOf ( listName, 0 ); - ui->obsListComboBox->setItemData ( index,listUuid ); - break; + foreach (QString str, listNamesModel) { + if (QString::compare(str, listName) == 0) { + int index = listNamesModel.indexOf(listName, 0); + ui->obsListComboBox->setItemData(index, listUuid); + break; + } } - } } - if (defaultListOlud == listUuid ) { + if (defaultListOlud == listUuid) { defaultListOlud_ = defaultListOlud; } } } - /* * Load the default list */ -void ObsListDialog::loadDefaultList() -{ - if (defaultListOlud_ != "" ) { - int index = ui->obsListComboBox->findData (defaultListOlud_ ); - if ( index != -1 ) { - ui->obsListComboBox->setCurrentIndex ( index ); - ui->obsListEditListButton->setEnabled ( true ); +void ObsListDialog::loadDefaultList() { + + if (defaultListOlud_ != "") { + int index = ui->obsListComboBox->findData(defaultListOlud_); + if (index != -1) { + ui->obsListComboBox->setCurrentIndex(index); + ui->obsListEditListButton->setEnabled(true); selectedObservingListUuid = defaultListOlud_.toStdString(); - loadObservingList (defaultListOlud_ ); + loadSelectedObservingListFromJsonFile(defaultListOlud_); } } else { - ui->obsListComboBox->setCurrentIndex ( 0 ); - loadSelectedObservingList ( 0 ); + // If there is no default list we load the first list in the combo box + const int currentIndex = ui->obsListComboBox->currentIndex(); + if(currentIndex != -1){ + ui->obsListComboBox->setCurrentIndex(0); + loadSelectedObservingList(0); + } } } /* - * Load selected observing list + * Load the selected observing list in the combo box, from Json file into dialog. */ -void ObsListDialog:: loadObservingList ( QString listOlud ) -{ +void ObsListDialog::loadSelectedObservingListFromJsonFile(QString listOlud) { QVariantMap map; QVariantList listOfObjects; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); } else { try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value (listOlud ).toMap(); - QString sortingBy = observingListMap.value ( KEY_SORTING ).toString(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); + QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(listOlud).toMap(); - listOfObjects = loadListFromJson (map, listOlud ); + // Check or not default list checkbox information + if(listOlud.compare(defaultListOlud_, Qt::CaseSensitive) == 0){ + ui->obsListIsDefaultListCheckBox->setChecked(true); + } else { + ui->obsListIsDefaultListCheckBox->setChecked(false); + } - if ( listOfObjects.size() > 0 ) { - ui->obsListHighlightAllButton->setEnabled ( true ); - ui->obsListClearHighlightButton->setEnabled ( true ); - ui->obsListDeleteButton->setEnabled ( true ); + // Landscape + QString landscapeId = observingListMap.value(KEY_LANDSCAPE_ID).toString(); + if(!landscapeId.isEmpty()){ + landscapeMgr->setCurrentLandscapeID(landscapeId); + } - for ( QVariant object: listOfObjects ) { + listOfObjects = loadListFromJson(map, listOlud); + + if (!listOfObjects.isEmpty()) { + ui->obsListHighlightAllButton->setEnabled(true); + ui->obsListClearHighlightButton->setEnabled(true); + ui->obsListDeleteButton->setEnabled(true); + + for (const QVariant& object: listOfObjects) { QVariantMap objectMap; - if ( object.canConvert() ) { + if (object.canConvert()) { objectMap = object.value(); - QString objectName = objectMap.value ( QString ( KEY_DESIGNATION ) ).value(); + QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); - if ( objectMgr->findAndSelect ( objectName ) ) { - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) { + if (objectMgr->findAndSelect(objectName)) { + const QList &selectedObject = objectMgr->getSelectedObject(); + if (!selectedObject.isEmpty()) { int lastRow = obsListListModel->rowCount(); QString objectUuid = QUuid::createUuid().toString(); QString objectNameI18n = selectedObject[0]->getNameI18n(); - QString objectRaStr = "", objectDecStr = ""; bool visibleFlag = false; double fov = -1.0; QString objectType = selectedObject[0]->getType(); - float ra, dec; - StelUtils::rectToSphe ( &ra, &dec, selectedObject[0]->getJ2000EquatorialPos ( core ) ); - objectRaStr = StelUtils::radToHmsStr ( ra, false ).trimmed(); - objectDecStr = StelUtils::radToDmsStr ( dec, false ).trimmed(); - if ( objectName.contains ( "marker", Qt::CaseInsensitive ) ) { + // RA & DEC + QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); + QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + + float ra = 0.0; + float dec = 0.0; + StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); + + if(objectRaStr.isEmpty()){ + objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); + } + + if(objectDecStr.isEmpty()){ + objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); + } + + if (objectName.contains("marker", Qt::CaseInsensitive)) { visibleFlag = true; } - float objectMagnitude = selectedObject[0]->getVMagnitude ( core ); - QString objectMagnitudeStr = QString::number ( objectMagnitude ); + float objectMagnitude = selectedObject[0]->getVMagnitude(core); + QString objectMagnitudeStr = QString::number(objectMagnitude); - QVariantMap objectMap = selectedObject[0]->getInfoMap ( core ); - QVariant objectConstellationVariant = objectMap["iauConstellation"]; - QString objectConstellation ( "unknown" ); - if ( objectConstellationVariant.canConvert() ) { + QVariantMap objectInfoMap = selectedObject[0]->getInfoMap(core); + QVariant objectConstellationVariant = objectInfoMap["iauConstellation"]; + QString objectConstellation("unknown"); + if (objectConstellationVariant.canConvert()) { objectConstellation = objectConstellationVariant.value(); } - QString JDs = ""; - double JD = core->getJD(); + // Julian Day + QString JDs = objectMap.value(QString(KEY_JD)).value(); - JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); + if(JDs.isEmpty()){ + double JD = core->getJD(); + JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace( + "T", " "); + } + + // Location + QString Location = objectMap.value(QString(KEY_LOCATION)).value(); + if(Location.isEmpty()){ + StelLocation loc = core->getCurrentLocation(); + if (loc.name.isEmpty()) { + Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); + } else { + Location = QString("%1, %2").arg(loc.name).arg(loc.region); + } + } - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); + // FOV + QString fovStr = objectMap.value(QString(KEY_FOV)).value(); + if(!fovStr.isEmpty()){ + fov = fovStr.toDouble(); } - addModelRow ( lastRow,objectUuid,objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation ); + + addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, + objectDecStr, objectMagnitudeStr, objectConstellation); observingListItem item; item.name = objectName; item.nameI18n = objectNameI18n; - if ( !objectType.isEmpty() ) { + if (!objectType.isEmpty()) { item.type = objectType; } - if ( !objectRaStr.isEmpty() ) { + if (!objectRaStr.isEmpty()) { item.ra = objectRaStr; } - if ( !objectDecStr.isEmpty() ) { + if (!objectDecStr.isEmpty()) { item.dec = objectDecStr; } - if ( !objectMagnitudeStr.isEmpty() ) { + if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } - if ( !objectConstellation.isEmpty() ) { + if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } - if ( !JDs.isEmpty() ) { - //item.jd = QString::number ( JD, 'f', 6 ); - item.jd = JD; + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); } - if ( !Location.isEmpty() ) { + if (!Location.isEmpty()) { item.location = Location; } - if ( !visibleFlag ) { + if (!visibleFlag) { item.isVisibleMarker = visibleFlag; } - if ( fov > 0.0 ) { + if (fov > 0.0) { item.fov = fov; } - observingListItemCollection.insert ( objectUuid,item ); + observingListItemCollection.insert(objectUuid, item); } else { qWarning() << "[ObservingList] selected object is empty !"; } } else { - qWarning() << "[ObservingList] object: " << objectName << " not found !" ; + qWarning() << "[ObservingList] object: " << objectName << " not found !"; } } else { qCritical() << "[ObservingList] conversion error"; @@ -534,17 +568,19 @@ void ObsListDialog:: loadObservingList ( QString listOlud ) } } } else { - ui->obsListHighlightAllButton->setEnabled ( false ); - ui->obsListClearHighlightButton->setEnabled ( false ); - ui->obsListDeleteButton->setEnabled ( false ); + ui->obsListHighlightAllButton->setEnabled(false); + ui->obsListClearHighlightButton->setEnabled(false); + ui->obsListDeleteButton->setEnabled(false); } objectMgr->unSelect(); - if ( !sortingBy.isEmpty() ) { - sortObsListTreeViewByColumnName ( sortingBy ); + // Sorting for the objects list. + QString sortingBy = observingListMap.value(KEY_SORTING).toString(); + if (!sortingBy.isEmpty()) { + sortObsListTreeViewByColumnName(sortingBy); } jsonFile.close(); - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList] Load selected observing list: File format is wrong! Error: " << e.what(); jsonFile.close(); return; @@ -555,31 +591,28 @@ void ObsListDialog:: loadObservingList ( QString listOlud ) /* * Load the list from JSON file QVariantMap map */ -QVariantList ObsListDialog::loadListFromJson ( QVariantMap map, QString listOlud ) -{ +auto ObsListDialog::loadListFromJson(const QVariantMap& map, QString listOlud) -> QVariantList { observingListItemCollection.clear(); - QVariantMap observingListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap().value (listOlud ).toMap(); + QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(listOlud).toMap(); QVariantList listOfObjects; - QString listDescription = observingListMap.value ( QString ( KEY_DESCRIPTION ) ).value(); - ui->obsListDescriptionTextEdit->setPlainText ( listDescription ); + QString listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); + ui->obsListDescriptionTextEdit->setPlainText(listDescription); // Displaying the creation date - QString JDs = observingListMap.value ( QString ( KEY_JD ) ).value(); - double JD = JDs.toDouble(); - QString listCreationDate = JDs = StelUtils::julianDayToISO8601String ( JD + core->getUTCOffset ( JD ) /24. ).replace ( "T", " " ); - ui->obsListCreationDateLineEdit->setText ( listCreationDate ); + QString listCreationDate = observingListMap.value(QString(KEY_CREATION_DATE)).value(); + ui->obsListCreationDateLineEdit->setText(listCreationDate); - if ( observingListMap.value ( QString ( KEY_OBJECTS ) ).canConvert() ) { - QVariant data = observingListMap.value ( QString ( KEY_OBJECTS ) ); + if (observingListMap.value(QString(KEY_OBJECTS)).canConvert()) { + QVariant data = observingListMap.value(QString(KEY_OBJECTS)); listOfObjects = data.value(); } else { qCritical() << "[ObservingList] conversion error"; } // Clear model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); + obsListListModel->removeRows(0, obsListListModel->rowCount()); return listOfObjects; } @@ -588,69 +621,79 @@ QVariantList ObsListDialog::loadListFromJson ( QVariantMap map, QString listOlud * Load the bookmarks of bookmarks.json file into observing lists file * For no regression with must take into account the legacy bookmarks.json file */ -void ObsListDialog::loadBookmarksInObservingList() -{ +void ObsListDialog::loadBookmarksInObservingList() { QHash bookmarksCollection; QVariantMap map; - QFile jsonFile ( bookmarksJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadOnly ) ) { - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( bookmarksJsonPath ); + QFile jsonFile(bookmarksJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(bookmarksJsonPath); } else { try { - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); jsonFile.close(); - QVariantMap bookmarksMap = map.value ( KEY_BOOKMARKS ).toMap(); + QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); - for ( auto bookmarkKey : bookmarksMap.keys() ) { + for (auto bookmarkKey: bookmarksMap.keys()) { - QVariantMap bookmarkData = bookmarksMap.value ( bookmarkKey ).toMap(); + QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); bookmark item; QString JDs = ""; - item.name = bookmarkData.value ( KEY_NAME ).toString(); - QString nameI18n = bookmarkData.value ( KEY_NAME_I18N ).toString(); - if ( !nameI18n.isEmpty() ) { + item.name = bookmarkData.value(KEY_NAME).toString(); + /// TODO vérifier si nameI18n est utilisé + QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); + if (!nameI18n.isEmpty()) { item.nameI18n = nameI18n; + } else{ + item.nameI18n = ""; } - QString JD = bookmarkData.value ( KEY_JD ).toString(); - if ( !JD.isEmpty() ) { - item.jd = JD; - JDs = StelUtils::julianDayToISO8601String ( JD.toDouble() + core->getUTCOffset ( JD.toDouble() ) /24. ).replace ( "T", " " ); + // Creation date + QString JD = bookmarkData.value(KEY_JD).toString(); + if (!JD.isEmpty()) { + item.jd = JD.toDouble(); + } else { + item.jd = 0.0; } - QString Location = bookmarkData.value ( KEY_LOCATION ).toString(); - if ( !Location.isEmpty() ) { + QString Location = bookmarkData.value(KEY_LOCATION).toString(); + if (!Location.isEmpty()) { item.location = Location; + } else { + item.location = ""; } - QString RA = bookmarkData.value ( KEY_RA ).toString(); - if ( !RA.isEmpty() ) { + QString RA = bookmarkData.value(KEY_RA).toString(); + if (!RA.isEmpty()) { item.ra = RA; + } else { + item.ra = ""; } - QString Dec = bookmarkData.value ( KEY_DEC ).toString(); - if ( !Dec.isEmpty() ) { + QString Dec = bookmarkData.value(KEY_DEC).toString(); + if (!Dec.isEmpty()) { item.dec = Dec; + }else { + item.dec = ""; } - item.isVisibleMarker = bookmarkData.value ( KEY_IS_VISIBLE_MARKER, false ).toBool(); - double fov = bookmarkData.value ( KEY_FOV ).toDouble(); - if ( fov > 0.0 ) { + item.isVisibleMarker = bookmarkData.value(KEY_IS_VISIBLE_MARKER, false).toBool(); + double fov = bookmarkData.value(KEY_FOV).toDouble(); + if (fov > 0.0) { item.fov = fov; } - bookmarksCollection.insert ( bookmarkKey, item ); + bookmarksCollection.insert(bookmarkKey, item); } - saveBookmarks ( bookmarksCollection ); + saveBookmarksInObsListJsonFile(bookmarksCollection); - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList] Load bookmarks in observing list: File format is wrong! Error: " << e.what(); return; } @@ -661,12 +704,12 @@ void ObsListDialog::loadBookmarksInObservingList() /* * Save the bookmarks into observing list file */ -void ObsListDialog::saveBookmarks ( QHash bookmarksCollection ) -{ - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { +void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash& bookmarksCollection) { + + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadWrite | QIODevice::Text)) { qWarning() << "[ObservingList] bookmarks list can not be saved. A file can not be open for reading and writing:" - << QDir::toNativeSeparators ( observingListJsonPath ); + << QDir::toNativeSeparators(observingListJsonPath); return; } @@ -675,80 +718,106 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection QVariantMap mapFromJsonFile; QVariantMap allListsMap; QVariantMap observingListDataList; - if ( jsonFile.size() > 0 ) { - mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + if (jsonFile.size() > 0) { + mapFromJsonFile = StelJsonParser::parse(jsonFile.readAll()).toMap(); + allListsMap = mapFromJsonFile.value(QString(KEY_OBSERVING_LISTS)).toMap(); } - QString defaultListValue = mapFromJsonFile.value ( QString ( KEY_DEFAULT_LIST_OLUD ) ).toString(); - if ( defaultListValue.isEmpty() ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_OLUD, "" ); + QString defaultListValue = mapFromJsonFile.value(QString(KEY_DEFAULT_LIST_OLUD)).toString(); + if (defaultListValue.isEmpty()) { + mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); } - if ( checkIfBookmarksListExists ( allListsMap ) ) { + if (checkIfBookmarksListExists(allListsMap)) { //the bookmarks file is already loaded return; } // Description - QString description = QString ( BOOKMARKS_LIST_DESCRIPTION ); - observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); + QString description = QString(BOOKMARKS_LIST_DESCRIPTION); + observingListDataList.insert(QString(KEY_DESCRIPTION), description); - // Julian day - QString JDString = ""; + // Creation date double JD = core->getJD(); - JDString = QString::number ( JD, 'f', 6 ); - observingListDataList.insert ( QString ( KEY_JD ), JDString ); + QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T"," "); + observingListDataList.insert(QString(KEY_CREATION_DATE), listCreationDate); // Location QString Location = ""; StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); + if (loc.name.isEmpty()) { + Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); + Location = QString("%1, %2").arg(loc.name).arg(loc.region); } - observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); + observingListDataList.insert(QString(KEY_LOCATION), Location); // Name of the liste - observingListDataList.insert ( QString ( KEY_NAME ), BOOKMARKS_LIST_NAME ); + observingListDataList.insert(QString(KEY_NAME), BOOKMARKS_LIST_NAME); // List of objects QVariantList listOfObjects; - QHashIterator i ( bookmarksCollection ); - while ( i.hasNext() ) { + QHashIterator i(bookmarksCollection); + while (i.hasNext()) { i.next(); bookmark item = i.value(); QVariantMap obl; + + // Designation QString objectName = item.name; - obl.insert ( QString ( KEY_DESIGNATION ), objectName ); - listOfObjects.push_back ( obl ); + obl.insert(QString(KEY_DESIGNATION), objectName); + + // Fov + obl.insert(QString(KEY_FOV), item.fov); + + // JD + double jd = item.jd; + QString JDs = QString::number(jd); + obl.insert(QString(KEY_JD), JDs); + + // Location + obl.insert(QString(KEY_LOCATION), item.location); + + // Ra + obl.insert(QString(KEY_RA), item.ra); + + // Dec + obl.insert(QString(KEY_DEC), item.dec); + + // Type + if (objectMgr->findAndSelect(objectName)) { + const QList &selectedObject = objectMgr->getSelectedObject(); + obl.insert(QString(KEY_OBJECTS_TYPE), selectedObject[0]->getType()); + } + + listOfObjects.push_back(obl); + } - observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); - observingListDataList.insert ( QString ( KEY_SORTING ), SORTING_BY_NAME ); + observingListDataList.insert(QString(KEY_OBJECTS), listOfObjects); + observingListDataList.insert(QString(KEY_SORTING), SORTING_BY_NAME); QList keys = bookmarksCollection.keys(); QString oblListUuid; - if ( keys.empty() ) { + if (keys.empty()) { oblListUuid = QUuid::createUuid().toString(); } else { - oblListUuid = keys.at ( 0 ); + oblListUuid = keys.at(0); } - mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); - mapFromJsonFile.insert ( KEY_SHORT_NAME,SHORT_NAME_VALUE ); + mapFromJsonFile.insert(KEY_VERSION, FILE_VERSION); + mapFromJsonFile.insert(KEY_SHORT_NAME, SHORT_NAME_VALUE); - allListsMap.insert ( oblListUuid, observingListDataList ); - mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); + allListsMap.insert(oblListUuid, observingListDataList); + mapFromJsonFile.insert(QString(KEY_OBSERVING_LISTS), allListsMap); - jsonFile.resize ( 0 ); - StelJsonParser::write ( mapFromJsonFile, &jsonFile ); + jsonFile.resize(0); + StelJsonParser::write(mapFromJsonFile, &jsonFile); jsonFile.flush(); jsonFile.close(); - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qCritical() << "[ObservingList] File format is wrong! Error: " << e.what(); return; } @@ -759,15 +828,14 @@ void ObsListDialog::saveBookmarks ( QHash bookmarksCollection * Check if bookmarks list already exists in observing list file, * in fact if the file of bookarks has already be loaded. */ -bool ObsListDialog::checkIfBookmarksListExists ( QVariantMap allListsMap ) -{ +auto ObsListDialog::checkIfBookmarksListExists(QVariantMap allListsMap) -> bool { - for ( auto bookmarkKey : allListsMap.keys() ) { + for (auto bookmarkKey: allListsMap.keys()) { - QVariantMap bookmarkData = allListsMap.value ( bookmarkKey ).toMap(); - QString listName = bookmarkData.value ( KEY_NAME ).toString(); + QVariantMap bookmarkData = allListsMap.value(bookmarkKey).toMap(); + QString listName = bookmarkData.value(KEY_NAME).toString(); - if ( QString::compare ( QString ( BOOKMARKS_LIST_NAME ), listName ) == 0 ) { + if (QString::compare(QString(BOOKMARKS_LIST_NAME), listName) == 0) { return true; } } @@ -776,84 +844,84 @@ bool ObsListDialog::checkIfBookmarksListExists ( QVariantMap allListsMap ) } - /* * Select and go to object */ -void ObsListDialog::selectAndGoToObject ( QModelIndex index ) -{ - QStandardItem * selectedItem = obsListListModel->itemFromIndex ( index ); +void ObsListDialog::selectAndGoToObject(QModelIndex index) { + QStandardItem *selectedItem = obsListListModel->itemFromIndex(index); int rawNumber = selectedItem->row(); - QStandardItem * uuidItem = obsListListModel->item ( rawNumber, ColumnUUID ); + QStandardItem *uuidItem = obsListListModel->item(rawNumber, ColumnUUID); QString itemUuid = uuidItem->text(); - observingListItem item = observingListItemCollection.value ( itemUuid ); + observingListItem item = observingListItemCollection.value(itemUuid); + - /*if ( !item.jd.isEmpty() ) { - core->setJD ( item.jd.toDouble() ); - }*/ - core->setJD ( item.jd); + if(item.jd != 0.0){ + core->setJD(item.jd); + } - if ( !item.location.isEmpty() ) { - StelLocationMgr* locationMgr = &StelApp::getInstance().getLocationMgr(); - core->moveObserverTo ( locationMgr->locationForString ( item.location ) ); + if (!item.location.isEmpty()) { + StelLocationMgr *locationMgr = &StelApp::getInstance().getLocationMgr(); + core->moveObserverTo(locationMgr->locationForString(item.location)); } - StelMovementMgr* mvmgr = GETSTELMODULE ( StelMovementMgr ); + auto *mvmgr = GETSTELMODULE (StelMovementMgr); objectMgr->unSelect(); - bool status = objectMgr->findAndSelect ( item.name ); + bool status = objectMgr->findAndSelect(item.name); float amd = mvmgr->getAutoMoveDuration(); - if ( !item.ra.isEmpty() && !item.dec.isEmpty() && !status ) { + if (!item.ra.isEmpty() && !item.dec.isEmpty() && !status) { Vec3d pos; - StelUtils::spheToRect ( StelUtils::getDecAngle ( item.ra.trimmed() ), StelUtils::getDecAngle ( item.dec.trimmed() ), pos ); - if ( item.name.contains ( "marker", Qt::CaseInsensitive ) ) { + StelUtils::spheToRect(StelUtils::getDecAngle(item.ra.trimmed()), StelUtils::getDecAngle(item.dec.trimmed()), + pos); + if (item.name.contains("marker", Qt::CaseInsensitive)) { // Add a custom object on the sky - GETSTELMODULE ( CustomObjectMgr )->addCustomObject ( item.name, pos, item.isVisibleMarker ); - status = objectMgr->findAndSelect ( item.name ); + GETSTELMODULE (CustomObjectMgr)->addCustomObject(item.name, pos, item.isVisibleMarker); + status = objectMgr->findAndSelect(item.name); } else { // The unnamed stars StelObjectP sobj; - const StelProjectorP prj = core->getProjection ( StelCore::FrameJ2000 ); + const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); double fov = 5.0; - if ( item.fov > 0.0 ) { + if (item.fov > 0.0) { fov = item.fov; } - mvmgr->zoomTo ( fov, 0.0 ); - mvmgr->moveToJ2000 ( pos, mvmgr->mountFrameToJ2000 ( Vec3d ( 0., 0., 1. ) ), 0.0 ); + mvmgr->zoomTo(fov, 0.0); + mvmgr->moveToJ2000(pos, mvmgr->mountFrameToJ2000(Vec3d(0., 0., 1.)), 0.0); - QList candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); - if ( candidates.empty() ) { // The FOV is too big, let's reduce it - mvmgr->zoomTo ( 0.5*fov, 0.0 ); - candidates = GETSTELMODULE ( StarMgr )->searchAround ( pos, 0.5, core ); + QList candidates = GETSTELMODULE (StarMgr)->searchAround(pos, 0.5, core); + if (candidates.empty()) { // The FOV is too big, let's reduce it + mvmgr->zoomTo(0.5 * fov, 0.0); + candidates = GETSTELMODULE (StarMgr)->searchAround(pos, 0.5, core); } Vec3d winpos; - prj->project ( pos, winpos ); + prj->project(pos, winpos); float xpos = winpos[0]; float ypos = winpos[1]; float best_object_value = 1000.f; - for ( const auto& obj : candidates ) { - prj->project ( obj->getJ2000EquatorialPos ( core ), winpos ); - float distance = std::sqrt ( ( xpos-winpos[0] ) * ( xpos-winpos[0] ) + ( ypos-winpos[1] ) * ( ypos-winpos[1] ) ); - if ( distance < best_object_value ) { + for (const auto &obj: candidates) { + prj->project(obj->getJ2000EquatorialPos(core), winpos); + float distance = std::sqrt( + (xpos - winpos[0]) * (xpos - winpos[0]) + (ypos - winpos[1]) * (ypos - winpos[1])); + if (distance < best_object_value) { best_object_value = distance; sobj = obj; } } - if ( sobj ) { - status = objectMgr->setSelectedObject ( sobj ); + if (sobj) { + status = objectMgr->setSelectedObject(sobj); } } } - if ( status ) { + if (status) { const QList newSelected = objectMgr->getSelectedObject(); - if ( !newSelected.empty() ) { - mvmgr->moveToObject ( newSelected[0], amd ); - mvmgr->setFlagTracking ( true ); + if (!newSelected.empty()) { + mvmgr->moveToObject(newSelected[0], amd); + mvmgr->setFlagTracking(true); } } } @@ -861,78 +929,76 @@ void ObsListDialog::selectAndGoToObject ( QModelIndex index ) /* * Method called when a list name is selected in the combobox */ -void ObsListDialog::loadSelectedObservingList ( int selectedIndex ) -{ - ui->obsListEditListButton->setEnabled ( true ); - ui->obsListDeleteButton->setEnabled ( true ); - QString listUuid = ui->obsListComboBox->itemData ( selectedIndex ).toString(); +void ObsListDialog::loadSelectedObservingList(int selectedIndex) { + ui->obsListEditListButton->setEnabled(true); + ui->obsListDeleteButton->setEnabled(true); + QString listUuid = ui->obsListComboBox->itemData(selectedIndex).toString(); selectedObservingListUuid = listUuid.toStdString(); - loadObservingList ( listUuid ); + loadSelectedObservingListFromJsonFile(listUuid); } /* * Delete the selected list */ -void ObsListDialog::obsListDeleteButtonPressed() -{ +void ObsListDialog::obsListDeleteButtonPressed() { bool res = askConfirmation(); - if ( res ) { + if (res) { QVariantMap map; - QFile jsonFile ( observingListJsonPath ); - if ( !jsonFile.open ( QIODevice::ReadWrite ) ) { - qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators ( JSON_FILE_NAME ); + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadWrite)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); } else { try { QVariantMap newMap; QVariantMap newObsListMap; - map = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); - newMap.insert ( QString ( KEY_DEFAULT_LIST_OLUD ), map.value ( QString ( KEY_DEFAULT_LIST_OLUD ) ) ); - QVariantMap obsListMap = map.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); + newMap.insert(QString(KEY_DEFAULT_LIST_OLUD), map.value(QString(KEY_DEFAULT_LIST_OLUD))); + QVariantMap obsListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); QMap::iterator i; - for ( i = obsListMap.begin(); i != obsListMap.end(); ++i ) { - if ( i.key().compare ( QString::fromStdString ( selectedObservingListUuid ) ) !=0 ) { - newObsListMap.insert ( i.key(),i.value() ); + for (i = obsListMap.begin(); i != obsListMap.end(); ++i) { + if (i.key().compare(QString::fromStdString(selectedObservingListUuid)) != 0) { + newObsListMap.insert(i.key(), i.value()); } } - newMap.insert ( QString ( KEY_OBSERVING_LISTS ),newObsListMap ); - newMap.insert ( QString ( KEY_SHORT_NAME ), map.value ( QString ( KEY_SHORT_NAME ) ) ); - newMap.insert ( QString ( KEY_VERSION ), map.value ( QString ( KEY_VERSION ) ) ); + newMap.insert(QString(KEY_OBSERVING_LISTS), newObsListMap); + newMap.insert(QString(KEY_SHORT_NAME), map.value(QString(KEY_SHORT_NAME))); + newMap.insert(QString(KEY_VERSION), map.value(QString(KEY_VERSION))); objectMgr->unSelect(); observingListItemCollection.clear(); // Clear row in model - obsListListModel->removeRows ( 0,obsListListModel->rowCount() ); - ui->obsListCreationDateLineEdit->setText ( "" ); - ui->obsListDescriptionTextEdit->setPlainText ( "" ); + obsListListModel->removeRows(0, obsListListModel->rowCount()); + ui->obsListCreationDateLineEdit->setText(""); + ui->obsListDescriptionTextEdit->setPlainText(""); int currentIndex = ui->obsListComboBox->currentIndex(); - ui->obsListComboBox->removeItem ( currentIndex ); - - //TODO pas utile car listeName_ est réinitialiséé et rechargée dans loadListsName(). + ui->obsListComboBox->removeItem(currentIndex); + + //TODO pas utile car listeName_ est réinitialiséé et rechargée dans loadListsNameFromJsonFile(). //TODO a supprimer après les tests finaux. //QString listName = ui->obsListComboBox->itemText(currentIndex); //listNames_.removeOne(listName); - + selectedObservingListUuid = ""; - jsonFile.resize ( 0 ); - StelJsonParser::write ( newMap, &jsonFile ); + jsonFile.resize(0); + StelJsonParser::write(newMap, &jsonFile); jsonFile.flush(); jsonFile.close(); - + clearHighlight(); - loadListsName(); + loadListsNameFromJsonFile(); - if ( ui->obsListComboBox->count() > 0 ) { - ui->obsListComboBox->setCurrentIndex ( 0 ); - loadSelectedObservingList ( 0 ); + if (ui->obsListComboBox->count() > 0) { + ui->obsListComboBox->setCurrentIndex(0); + loadSelectedObservingList(0); } - } catch ( std::runtime_error &e ) { + } catch (std::runtime_error &e) { qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); return; } @@ -945,27 +1011,32 @@ void ObsListDialog::obsListDeleteButtonPressed() /* * Slot for button obsListExitButton */ -void ObsListDialog::obsListExitButtonPressed() -{ +void ObsListDialog::obsListExitButtonPressed() { this->close(); } /* - * Slot to manage the close of obsListCreateEditDialog + * Slot to manage the close of obsListCreateEditDialog. */ -void ObsListDialog::obsListCreateEditDialogClosed() -{ - // We must reload the list of list name - loadListsName(); +void ObsListDialog::obsListCreateEditDialogClosed() { + + // The defaultListOlud may have changed in the create dialog. + // The defaultListOlud needs to be updated. + defaultListOlud_ = extractDefaultListOludFromJsonFile(); + + // We must reload the list name + loadListsNameFromJsonFile(); int index = 0; - if ( !selectedObservingListUuid.empty() ) { - index = ui->obsListComboBox->findData ( QString::fromStdString ( selectedObservingListUuid ) ) ; + if (!selectedObservingListUuid.empty()) { + index = ui->obsListComboBox->findData(QString::fromStdString(selectedObservingListUuid)); } - if ( index != -1 ) { - ui->obsListComboBox->setCurrentIndex ( index ); - loadSelectedObservingList ( index ); + + // Reload of the selected observing list. + if (index != -1) { + ui->obsListComboBox->setCurrentIndex(index); + loadSelectedObservingList(index); } - + //TODO remove after qDebug() << "obsListCreateEditDialogClosed() before kill ObsListCreateEditDialog"; @@ -973,38 +1044,59 @@ void ObsListDialog::obsListCreateEditDialogClosed() createEditDialog_instance = Q_NULLPTR; } +/* + * Etract the defaultListOlud from the Json file. +*/ +QString ObsListDialog::extractDefaultListOludFromJsonFile() { + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); + + } else { + try { + QVariantMap map = StelJsonParser::parse(jsonFile.readAll()).toMap(); + jsonFile.close(); + + // Get the default list uuid + QString defaultListOlud = map.value(KEY_DEFAULT_LIST_OLUD).toString(); + return defaultListOlud; + } catch (std::runtime_error &e) { + qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + return ""; + } + } +} + /* * Override of the StelDialog::setVisible((bool) methode * We need to load the default liste when opening the obsListDialog */ -void ObsListDialog::setVisible ( bool v ) -{ - if ( v ) { - StelDialog::setVisible ( true ); +void ObsListDialog::setVisible(bool v) { + if (v) { + StelDialog::setVisible(true); this->loadDefaultList(); } else { - StelDialog::setVisible ( false ); + StelDialog::setVisible(false); } } /* * Sort the obsListTreeView by the column name given in parameter */ -void ObsListDialog::sortObsListTreeViewByColumnName ( QString columnName ) -{ - if ( QString::compare ( columnName,SORTING_BY_NAME ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_NAME, Qt::AscendingOrder ); - } else if ( QString::compare ( columnName,SORTING_BY_TYPE ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_TYPE, Qt::AscendingOrder ); - } else if ( QString::compare ( columnName,SORTING_BY_RA ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_RA, Qt::AscendingOrder ); - } else if ( QString::compare ( columnName,SORTING_BY_DEC ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_DEC, Qt::AscendingOrder ); - } else if ( QString::compare ( columnName,SORTING_BY_MAGNITUDE ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_MAGNITUDE, Qt::AscendingOrder ); - } else if ( QString::compare ( columnName,SORTING_BY_CONSTELLATION ) == 0 ) { - obsListListModel->sort ( COLUMN_NUMBER_CONSTELLATION, Qt::AscendingOrder ); +void ObsListDialog::sortObsListTreeViewByColumnName(QString columnName) { + if (QString::compare(columnName, SORTING_BY_NAME) == 0) { + obsListListModel->sort(COLUMN_NUMBER_NAME, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_TYPE) == 0) { + obsListListModel->sort(COLUMN_NUMBER_TYPE, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_RA) == 0) { + obsListListModel->sort(COLUMN_NUMBER_RA, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_DEC) == 0) { + obsListListModel->sort(COLUMN_NUMBER_DEC, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_MAGNITUDE) == 0) { + obsListListModel->sort(COLUMN_NUMBER_MAGNITUDE, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_CONSTELLATION) == 0) { + obsListListModel->sort(COLUMN_NUMBER_CONSTELLATION, Qt::AscendingOrder); } } diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 0fae274b14e22..a9fc73a6a6db7 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -36,23 +36,24 @@ class ObsListDialog : public StelDialog Q_OBJECT public: - ObsListDialog ( QObject* parent ); - virtual ~ObsListDialog(); + explicit ObsListDialog ( QObject* parent ); + ~ObsListDialog() override; //! Notify that the application style changed - void styleChanged(); + void styleChanged() override; - void setVisible ( bool v ); + void setVisible ( bool v ) override; protected: Ui_obsListDialogForm *ui; //! Initialize the dialog widgets and connect the signals/slots. - virtual void createDialogContent(); + void createDialogContent() override; private: QStandardItemModel * obsListListModel; class StelCore* core; class StelObjectMgr* objectMgr; + class LandscapeMgr* landscapeMgr; class LabelMgr* labelMgr; std::string selectedObservingListUuid; QString observingListJsonPath; @@ -79,31 +80,31 @@ class ObsListDialog : public StelDialog //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow (int number, QString olud, QString name, QString nameI18n, QString type, QString ra, QString dec, QString magnitude, QString constellation ); + void addModelRow (int number, const QString& olud, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, const QString& dec, const QString& magnitude, const QString& constellation ); - //! Load the selected observing list + //! Load the selected observing list from Json file into dialog. //! @param listOlud the olud (id) of the list - void loadObservingList ( QString listOlud ); + void loadSelectedObservingListFromJsonFile (QString listOlud ); - //! Load the lists names to populate the combo box and get the default list olud - void loadListsName(); + //! Load the lists names from Json file to populate the combo box and get the default list olud + void loadListsNameFromJsonFile(); //! Load the default list void loadDefaultList(); //! Load the bookmarks of bookmarks.json file into observing lists file void loadBookmarksInObservingList(); - void saveBookmarks(QHash bookmarksCollection); - bool checkIfBookmarksListExists(QVariantMap allListsMap); + void saveBookmarksInObsListJsonFile(const QHash& bookmarksCollection); + auto checkIfBookmarksListExists(QVariantMap allListsMap) -> bool; //! Load list from JSON file - QVariantList loadListFromJson(QVariantMap map, QString listOlud); + auto loadListFromJson(const QVariantMap& map, QString listOlud) -> QVariantList; //! Populate list names into combo box void populateListNameInComboBox(QVariantMap map); //! Populate data into combo box - void populateDataInComboBox(QVariantMap map, QString defaultListOlud); + void populateDataInComboBox(QVariantMap map, const QString& defaultListOlud); //! Sort the obsListTreeView by the column name given in parameter void sortObsListTreeViewByColumnName(QString columnName); @@ -111,6 +112,9 @@ class ObsListDialog : public StelDialog //! Clear highlights void clearHighlight(); + //! get the defaultListOlud from Json file + QString extractDefaultListOludFromJsonFile(); + public slots: void retranslate(); diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 0045d4a166448..a8e9cb88643ff 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -44,7 +44,7 @@ struct bookmark QString ra; QString dec; bool isVisibleMarker; - QString jd; + double jd; QString location; double fov; @@ -69,7 +69,7 @@ enum ObsListColumns { // à vérifier après la V2 static constexpr char const * JSON_FILE_NAME = "observingList.json"; -static constexpr char const * FILE_VERSION = "1.0"; +static constexpr char const * FILE_VERSION = "2.0"; static constexpr char const * JSON_BOOKMARKS_FILE_NAME = "bookmarks.json"; static constexpr char const * BOOKMARKS_LIST_NAME = "bookmarks list"; @@ -78,6 +78,7 @@ static constexpr char const * SHORT_NAME_VALUE = "Observing list for Stellarium" static constexpr char const * KEY_DEFAULT_LIST_OLUD = "defaultListOlud"; static constexpr char const * KEY_OBSERVING_LISTS = "observingLists"; +static constexpr char const * KEY_CREATION_DATE = "creation date"; static constexpr char const * KEY_BOOKMARKS = "bookmarks"; static constexpr char const * KEY_NAME = "name"; static constexpr char const * KEY_NAME_I18N = "nameI18n"; @@ -86,6 +87,7 @@ static constexpr char const * KEY_RA = "ra"; static constexpr char const * KEY_DEC = "dec"; static constexpr char const * KEY_FOV = "fov"; static constexpr char const * KEY_DESCRIPTION = "description"; +static constexpr char const * KEY_LANDSCAPE_ID = "landscape id"; static constexpr char const * KEY_OBJECTS = "objects"; static constexpr char const * KEY_OBJECTS_TYPE = "objtype"; static constexpr char const * KEY_DESIGNATION = "designation"; diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index 16a61b7fe7460..bf5623ec952f2 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -127,6 +127,36 @@ + + + + + + Description: + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 62 + 20 + + + + + + + + + @@ -135,6 +165,9 @@ 0 + + false + QFrame::StyledPanel @@ -147,7 +180,7 @@ - Right ascension + Add right ascension 3 @@ -160,7 +193,7 @@ - Declination + Add declination 3 @@ -173,7 +206,7 @@ - Fiel Of View + Add field of view 3 @@ -291,57 +324,70 @@ - - + + - + + + QLabel {color : red;} + - Description: + TextLabel + + + + + + -1 + + + + + - + + + Set the list as default + + + 3 + + + Set list as default + + + + + Qt::Horizontal - - QSizePolicy::Fixed - - 67 + 40 20 - - - - - - - - - - QLabel {color : red;} + + + Add landscape + + + 3 - TextLabel + Landscape - - - - -1 - - - @@ -372,23 +418,6 @@ - - - - - - Set the list as default - - - 3 - - - Set list as default - - - - - diff --git a/src/gui/obsListDialog.ui b/src/gui/obsListDialog.ui index 67b4add3cd899..5949a3123de89 100644 --- a/src/gui/obsListDialog.ui +++ b/src/gui/obsListDialog.ui @@ -2,6 +2,9 @@ obsListDialogForm + + true + 0 @@ -300,21 +303,54 @@ - - - Creation date: + + + false - - - - - - true + + + + + + + 35 + 38 + 39 + + + + + + + + + 35 + 38 + 39 + + + + + + + + + 0 + 0 + 0 + + + + + + + + Defined as default list - + Qt::Horizontal @@ -326,6 +362,20 @@ + + + + Creation date: + + + + + + + true + + + From e274a9549c48526ee290fb37a8cb552f84938232 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 13 May 2022 12:40:05 +0200 Subject: [PATCH 14/28] ObservingList V2 --- src/gui/ObsListCreateEditDialog.cpp | 30 ++++++++--------------------- src/gui/ObservingListCommon.hpp | 7 ++++--- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 516e3e9530ff1..6b46be8fc228c 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "NebulaMgr.hpp" #include "StelCore.hpp" @@ -260,6 +262,10 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Object type QString objectType = selectedObject[0]->getType(); + if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ + auto& r_planet = dynamic_cast(*selectedObject[0]); + objectType = r_planet.getPlanetTypeString(); + } // Fov QString objectRaStr = ""; @@ -268,7 +274,8 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { double fov = -1.0; // Ra & Dec - float ra, dec; + float ra = 0.0; + float dec = 0.0; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); @@ -276,9 +283,6 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { if (ui->obsListDecCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); } - //TODO delete after - qDebug() << "ra value" << objectRaStr; - qDebug() << "dec value" << objectDecStr; // Visible flag if (objectName.contains("marker", Qt::CaseInsensitive)) { @@ -375,24 +379,6 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { } /* - * Slot for button obsListAddObjectButton -*/ -void ObsListCreateEditDialog::obsListAddObjectButtonPressed() -{ - const QList& selectedObject = objectMgr->getSelectedObject(); - if ( !selectedObject.isEmpty() ) - { - // No duplicate item in the same list - bool is_already_in_list = false; - QHash::const_iterator i; - for ( i = observingListItemCollection.constBegin(); i != observingListItemCollection.constEnd(); i++ ) - { - if ( i.value().name.compare ( selectedObject[0]->getEnglishName() ) == 0 ) - { - is_already_in_list = true; - break; - } - } * Slot for button obsListRemoveObjectButton */ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() { diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index cb97e1c824d4d..a8e9cb88643ff 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -20,8 +20,6 @@ #ifndef OBSERVINGLISTCOMMON_H #define OBSERVINGLISTCOMMON_H -#include - struct observingListItem { QString name; QString nameI18n; @@ -113,4 +111,7 @@ static constexpr int COLUMN_NUMBER_DEC = 5; static constexpr int COLUMN_NUMBER_MAGNITUDE = 6; static constexpr int COLUMN_NUMBER_CONSTELLATION = 7; -#endif // OBSERVINGLISTCOMMON_H +static constexpr char const * CUSTOM_OBJECT = "CustomObject"; + + +#endif // OBSLISTDIALOG_H From 6aad13733547eedd3cf46f3c2a12037b7aca2ed1 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Thu, 19 May 2022 13:51:26 +0200 Subject: [PATCH 15/28] ObservingList V2 Correction of wrong jd (lost of accuracy) --- src/core/StelObject.hpp | 2 +- src/gui/ObsListCreateEditDialog.cpp | 1 + src/gui/ObsListDialog.cpp | 37 ++++++++++++++++++----------- src/gui/ObsListDialog.hpp | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/core/StelObject.hpp b/src/core/StelObject.hpp index 79c67da45fbf5..11dee11024c91 100644 --- a/src/core/StelObject.hpp +++ b/src/core/StelObject.hpp @@ -267,7 +267,7 @@ class StelObject : public StelRegionObject //! with the circle center assumed to be at getJ2000EquatorialPos(). //! @return radius in degree. This value is the apparent angular size of the object, and is independent of the current FOV. //! @note The default implementation just returns zero. - virtual double getAngularRadius(const StelCore* core) const {Q_UNUSED(core) Q_ASSERT(0); return 0;} + virtual double getAngularRadius(const StelCore* core) const {Q_UNUSED(core); return 0;} //! Return airmass value for the object (for atmosphere-dependent calculations) //! @param core diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 6b46be8fc228c..2003848e0db50 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -256,6 +256,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Object name (designation) QString objectName = selectedObject[0]->getEnglishName(); QString objectNameI18n = selectedObject[0]->getNameI18n(); + StelObjectP object = objectMgr->searchByNameI18n(objectNameI18n); if (selectedObject[0]->getType() == "Nebula") { objectName = GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation(); } diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index e933b6cfe5528..dd9a918fdd370 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -35,6 +35,7 @@ #include "StelUtils.hpp" #include "ObsListDialog.hpp" #include "LabelMgr.hpp" +#include "Planet.hpp" #include "ui_obsListDialog.h" #include @@ -235,7 +236,7 @@ void ObsListDialog::obsListHighLightAllButtonPressed() { QString decStr = item.dec.trimmed(); Vec3d pos; - bool status; + bool status = false; if (!raStr.isEmpty() && !decStr.isEmpty()) { StelUtils::spheToRect(StelUtils::getDecAngle(raStr), StelUtils::getDecAngle(decStr), pos); status = true; @@ -365,7 +366,7 @@ void ObsListDialog::populateListNameInComboBox(QVariantMap map) { void ObsListDialog::populateDataInComboBox(QVariantMap map, const QString& defaultListOlud) { QMap::iterator i; for (i = map.begin(); i != map.end(); ++i) { - QString listUuid = i.key(); + const QString& listUuid = i.key(); if (i.value().canConvert()) { QVariant var = i.value(); QVariantMap data = var.value(); @@ -412,7 +413,7 @@ void ObsListDialog::loadDefaultList() { /* * Load the selected observing list in the combo box, from Json file into dialog. */ -void ObsListDialog::loadSelectedObservingListFromJsonFile(QString listOlud) { +void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlud) { QVariantMap map; QVariantList listOfObjects; QFile jsonFile(observingListJsonPath); @@ -460,7 +461,12 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(QString listOlud) { bool visibleFlag = false; double fov = -1.0; + // TYPE QString objectType = selectedObject[0]->getType(); + if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ + auto& r_planet = dynamic_cast(*selectedObject[0]); + objectType = r_planet.getPlanetTypeString(); + } // RA & DEC QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); @@ -641,8 +647,6 @@ void ObsListDialog::loadBookmarksInObservingList() { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); bookmark item; - QString JDs = ""; - item.name = bookmarkData.value(KEY_NAME).toString(); /// TODO vérifier si nameI18n est utilisé QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); @@ -652,10 +656,10 @@ void ObsListDialog::loadBookmarksInObservingList() { item.nameI18n = ""; } - // Creation date - QString JD = bookmarkData.value(KEY_JD).toString(); - if (!JD.isEmpty()) { - item.jd = JD.toDouble(); + // JDs + QString JDs = bookmarkData.value(KEY_JD).toString(); + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); } else { item.jd = 0.0; } @@ -730,6 +734,8 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHashfindAndSelect(objectName)) { const QList &selectedObject = objectMgr->getSelectedObject(); - obl.insert(QString(KEY_OBJECTS_TYPE), selectedObject[0]->getType()); + QString objectType = selectedObject[0]->getType(); + if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ + auto& r_planet = dynamic_cast(*selectedObject[0]); + objectType = r_planet.getPlanetTypeString(); + } + obl.insert(QString(KEY_OBJECTS_TYPE), objectType); } listOfObjects.push_back(obl); @@ -1061,7 +1070,7 @@ QString ObsListDialog::extractDefaultListOludFromJsonFile() { QString defaultListOlud = map.value(KEY_DEFAULT_LIST_OLUD).toString(); return defaultListOlud; } catch (std::runtime_error &e) { - qWarning() << "[ObservingList] File format is wrong! Error: " << e.what(); + qWarning() << "[ObservingList] File format is wrong! Error: ()()" << e.what(); return ""; } } diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index a9fc73a6a6db7..5b52f4a023629 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -84,7 +84,7 @@ class ObsListDialog : public StelDialog //! Load the selected observing list from Json file into dialog. //! @param listOlud the olud (id) of the list - void loadSelectedObservingListFromJsonFile (QString listOlud ); + void loadSelectedObservingListFromJsonFile (const QString& listOlud ); //! Load the lists names from Json file to populate the combo box and get the default list olud void loadListsNameFromJsonFile(); From de8fc23cdfa3137e34ed10eac2cabe51a4c4b2da Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 23 May 2022 13:53:08 +0200 Subject: [PATCH 16/28] ObservingList V2 Adding JD and Location checkbox in obsListDialog. --- src/gui/obsListDialog.ui | 112 ++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/src/gui/obsListDialog.ui b/src/gui/obsListDialog.ui index 5949a3123de89..ee3d29482c396 100644 --- a/src/gui/obsListDialog.ui +++ b/src/gui/obsListDialog.ui @@ -150,43 +150,7 @@ - - - - Observing list description: - - - - - - - -1 - - - - - - - true - - - - 0 - 0 - - - - - 16777215 - 40 - - - - true - - - - + @@ -300,6 +264,20 @@ + + + + Observing list description: + + + + + + + -1 + + + @@ -378,6 +356,66 @@ + + + + true + + + + 0 + 0 + + + + + 16777215 + 40 + + + + true + + + + + + + + + Use: + + + + + + + Jd + + + + + + + Location + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + From 0569e3bfdbec775fec9c9e92bbd27a08d49c80f5 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Thu, 2 Jun 2022 13:43:34 +0200 Subject: [PATCH 17/28] ObservingList Use new method getObjectType(). --- src/gui/ObsListCreateEditDialog.cpp | 229 +++++-------------------- src/gui/ObsListDialog.cpp | 251 +++++++++++++--------------- src/gui/ObservingListCommon.hpp | 2 + 3 files changed, 162 insertions(+), 320 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 2003848e0db50..679ab494bab70 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -253,52 +253,47 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { const int lastRow = obsListListModel->rowCount(); const QString objectUuid = QUuid::createUuid().toString(); - // Object name (designation) + // Object name (designation) and object name I18n QString objectName = selectedObject[0]->getEnglishName(); QString objectNameI18n = selectedObject[0]->getNameI18n(); StelObjectP object = objectMgr->searchByNameI18n(objectNameI18n); - if (selectedObject[0]->getType() == "Nebula") { + if (selectedObject[0]->getType() == "Nebula" && objectName.isEmpty()) { objectName = GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation(); } - // Object type - QString objectType = selectedObject[0]->getType(); - if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ - auto& r_planet = dynamic_cast(*selectedObject[0]); - objectType = r_planet.getPlanetTypeString(); - } - - // Fov - QString objectRaStr = ""; - QString objectDecStr = ""; - bool visibleFlag = false; - double fov = -1.0; + // Type + QString objectType = selectedObject[0]->getObjectType(); // Ra & Dec float ra = 0.0; float dec = 0.0; + QString objectRaStr = ""; + QString objectDecStr = ""; + bool visibleFlag = false; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); - if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { + if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); } - if (ui->obsListDecCheckBox->isChecked() || objectType == CUSTOM_OBJECT) { + if (ui->obsListDecCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); } + // Fov + double fov = -1.0; + if(ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()){ + fov = GETSTELMODULE(StelMovementMgr)->getCurrentFov(); + } + // Visible flag if (objectName.contains("marker", Qt::CaseInsensitive)) { visibleFlag = true; } - if (objectName.isEmpty()) { - objectName = QString("%1, %2").arg(objectRaStr, objectDecStr); - objectNameI18n = q_("Unnamed object"); - fov = GETSTELMODULE(StelMovementMgr)->getCurrentFov(); - } - + // Magnitude float objectMagnitude = selectedObject[0]->getVMagnitude(core); QString objectMagnitudeStr = QString::number(objectMagnitude); + // Constallation QVariantMap objectMap = selectedObject[0]->getInfoMap(core); QVariant objectConstellationVariant = objectMap["iauConstellation"]; QString objectConstellation("unknown"); @@ -320,6 +315,15 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { Location = QString("%1, %2").arg(loc.name, loc.region); } + // Check if the object name is empty. + if (objectName.isEmpty()) { + objectName = q_("Unnamed object"); + if(objectNameI18n.isEmpty()){ + objectNameI18n = q_("Unnamed object"); + } + } + + // Add objects in row model addModelRow(lastRow, objectUuid, objectName, @@ -334,7 +338,8 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { initItem(item); item.name = objectName; item.nameI18n = objectNameI18n; - // Object Type + + // Type if (!objectType.isEmpty()) { item.type = objectType; } @@ -350,18 +355,16 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; } - //Constellation + // Constellation if (!objectConstellation.isEmpty()) { item.constellation = objectConstellation; } // JD if (!JDs.isEmpty()) { - //item.jd = QString::number(JD, 'f', 6); item.jd = JD; } // Location if (!Location.isEmpty()) { - QHash::iterator i; item.location = Location; } // Visible Flag @@ -369,7 +372,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { item.isVisibleMarker = visibleFlag; } // Fov - if (fov > 0.0 && (ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT)) { + if (fov > 0.0) { item.fov = fov; } observingListItemCollection.insert(objectUuid, item); @@ -452,40 +455,35 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { observingListItem item = i.value(); QVariantMap obl; - // Designation + // Designation (name) obl.insert(QString(KEY_DESIGNATION), item.name); - //TODO delete after - qDebug() << "name: " << item.name; + + // NameI18n + obl.insert(QString(KEY_NAME_I18N), item.nameI18n); // Fov obl.insert(QString(KEY_FOV), item.fov); - //TODO delete after - qDebug() << "fov: " << item.fov; // Jd obl.insert(QString(KEY_JD), item.jd); - //TODO delete after - qDebug() << "jd: " << item.jd; // Location obl.insert(QString(KEY_LOCATION), item.location); - //TODO delete after - qDebug() << "location: " << item.location; // Ra obl.insert(QString(KEY_RA), item.ra); - //TODO delete after - qDebug() << "ra: " << item.ra; // Dec obl.insert(QString(KEY_DEC), item.dec); - //TODO delete after - qDebug() << "dec: " << item.dec; // Object type obl.insert(QString(KEY_OBJECTS_TYPE), item.type); - //TODO delete after - qDebug() << "object type: " << item.type; + + // Magnitude + obl.insert(QString(KEY_MAGNITUDE), item.magnitude); + + // Constellation + obl.insert(QString(KEY_CONSTELLATION), item.constellation); listOfObjects.push_back(obl); } @@ -542,151 +540,6 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); return; } - - /*bool isFileExits = false; - QString listName = ui->nameOfListLineEdit->text(); - if ( observingListJsonPath.isEmpty() || listName.isEmpty() ) { - qWarning() << "[ObservingList Creation/Edition] Error saving observing list"; - return; - } - - - QFile jsonFile ( observingListJsonPath ); - - if(jsonFile.exists()){ - isFileExits = true; - } - - if ( !jsonFile.open ( QIODevice::ReadWrite|QIODevice::Text ) ) { - qWarning() << "[ObservingList Creation/Edition] observing list can not be saved. A file can not be open for - reading and writing:" - << QDir::toNativeSeparators ( observingListJsonPath ); - return; - } - - try { - QVariantMap mapFromJsonFile; - QVariantMap allListsMap; - if ( jsonFile.size() > 0 ) { - mapFromJsonFile = StelJsonParser::parse ( jsonFile.readAll() ).toMap(); - allListsMap = mapFromJsonFile.value ( QString ( KEY_OBSERVING_LISTS ) ).toMap(); - } - - QVariantMap observingListDataList; - - // Description - QString description = ui->descriptionLineEdit->text(); - observingListDataList.insert ( QString ( KEY_DESCRIPTION ), description ); - - // Julian day - QString JDString = ""; - double JD = core->getJD(); - JDString = QString::number ( JD, 'f', 6 ); - - - // No JD modifications in editor mode - QString existingSorting; - if ( !isCreationMode ) { - QString uuidQs = QString::fromStdString ( this->listOlud_ ); - QVariantMap currentList = allListsMap.value ( uuidQs ).toMap(); - QVariant existingJD = currentList.value ( QString ( KEY_JD ) ); - existingSorting = currentList.value(QString(KEY_SORTING)).toString(); - QString existingJDs = existingJD.toString(); - if ( existingJDs.isEmpty() ) { - observingListDataList.insert ( QString ( KEY_JD ), JDString ); - } else { - observingListDataList.insert ( QString ( KEY_JD ), existingJDs ); - } - } else { - observingListDataList.insert ( QString ( KEY_JD ), JDString ); - } - - // Location - QString Location = ""; - StelLocation loc = core->getCurrentLocation(); - if ( loc.name.isEmpty() ) { - Location = QString ( "%1, %2" ).arg ( loc.latitude ).arg ( loc.longitude ); - } else { - Location = QString ( "%1, %2" ).arg ( loc.name ).arg ( loc.region ); - } - observingListDataList.insert ( QString ( KEY_LOCATION ), Location ); - - // Name of the liste - observingListDataList.insert ( QString ( KEY_NAME ), listName ); - - // List of objects - QVariantList listOfObjects; - QHashIterator i ( observingListItemCollection ); - while ( i.hasNext() ) { - i.next(); - - observingListItem item = i.value(); - QVariantMap obl; - QString objectName = item.name; - obl.insert ( QString ( KEY_DESIGNATION ), objectName ); - listOfObjects.push_back ( obl ); - } - - observingListDataList.insert ( QString ( KEY_OBJECTS ), listOfObjects ); - - - if(sorting.isEmpty()){ - observingListDataList.insert ( QString ( KEY_SORTING ), existingSorting ); - }else { - observingListDataList.insert ( QString ( KEY_SORTING ), sorting ); - } - - - QString oblListUuid; - if ( isCreationMode ) { - oblListUuid = QUuid::createUuid().toString(); - } else { - oblListUuid = QString::fromStdString ( listOlud_ ); - } - - if(ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); - } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if(defaultListUuid.isEmpty()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } - }*/ - - // TODO delete after - /*if(!isFileExits && !ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } else if(ui->obsListDefaultListCheckBox->isChecked()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); - } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if(defaultListUuid.isEmpty()){ - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } - } - if ( ui->obsListDefaultListCheckBox->isChecked() ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, oblListUuid ); - } else { - QString defaultListUuid = mapFromJsonFile.value ( KEY_DEFAULT_LIST_UUID ).toString(); - if ( defaultListUuid == oblListUuid ) { - mapFromJsonFile.insert ( KEY_DEFAULT_LIST_UUID, "" ); - } - }*/ - - /*mapFromJsonFile.insert ( KEY_VERSION, FILE_VERSION ); - mapFromJsonFile.insert ( KEY_SHORT_NAME, SHORT_NAME_VALUE ); - - allListsMap.insert ( oblListUuid, observingListDataList ); - mapFromJsonFile.insert ( QString ( KEY_OBSERVING_LISTS ), allListsMap ); - - jsonFile.resize ( 0 ); - StelJsonParser::write ( mapFromJsonFile, &jsonFile ); - jsonFile.flush(); - jsonFile.close(); - } catch ( std::runtime_error &e ) { - qCritical() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); - return; - }*/ } /* @@ -875,7 +728,7 @@ void ObsListCreateEditDialog::loadObservingList() { objectMap = object.value(); QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); - // TODO il faut charger ce qui est dans lee fichier + // TODO il faut charger ce qui est dans le fichier if (objectMgr->findAndSelect(objectName)) { const QList &selectedObject = objectMgr->getSelectedObject(); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index dd9a918fdd370..e771b6dc42cc8 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -46,17 +46,22 @@ using namespace std; ObsListDialog::ObsListDialog(QObject *parent) : StelDialog("Observing list", parent), ui(new Ui_obsListDialogForm()), obsListListModel(new QStandardItemModel(0, ColumnCount)), - core(StelApp::getInstance().getCore()), createEditDialog_instance(Q_NULLPTR) { + core(StelApp::getInstance().getCore()), + createEditDialog_instance(Q_NULLPTR) { objectMgr = GETSTELMODULE (StelObjectMgr); labelMgr = GETSTELMODULE (LabelMgr); landscapeMgr = GETSTELMODULE(LandscapeMgr); observingListJsonPath = - StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + StelFileMgr::findFile("data", + static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + + "/" + QString(JSON_FILE_NAME); bookmarksJsonPath = - StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + StelFileMgr::findFile("data", + static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + + "/" + QString(JSON_BOOKMARKS_FILE_NAME); @@ -177,8 +182,9 @@ void ObsListDialog::setObservingListHeaderNames() { /* * Add row in the obsListListModel */ -void ObsListDialog::addModelRow(int number, const QString& olud, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, - const QString& dec, const QString& magnitude, const QString& constellation) { +void ObsListDialog::addModelRow(int number, const QString &olud, const QString &name, const QString &nameI18n, + const QString &type, const QString &ra, + const QString &dec, const QString &magnitude, const QString &constellation) { QStandardItem *item = Q_NULLPTR; item = new QStandardItem(olud); @@ -230,7 +236,7 @@ void ObsListDialog::obsListHighLightAllButtonPressed() { QString color = hlMgr->getColor().toHtmlColor(); float distance = hlMgr->getMarkersSize(); - for (const auto& item: observingListItemCollection) { + for (const auto &item: observingListItemCollection) { QString name = item.name; QString raStr = item.ra.trimmed(); QString decStr = item.dec.trimmed(); @@ -363,10 +369,10 @@ void ObsListDialog::populateListNameInComboBox(QVariantMap map) { /* * Populate data into combo box */ -void ObsListDialog::populateDataInComboBox(QVariantMap map, const QString& defaultListOlud) { +void ObsListDialog::populateDataInComboBox(QVariantMap map, const QString &defaultListOlud) { QMap::iterator i; for (i = map.begin(); i != map.end(); ++i) { - const QString& listUuid = i.key(); + const QString &listUuid = i.key(); if (i.value().canConvert()) { QVariant var = i.value(); QVariantMap data = var.value(); @@ -403,7 +409,7 @@ void ObsListDialog::loadDefaultList() { } else { // If there is no default list we load the first list in the combo box const int currentIndex = ui->obsListComboBox->currentIndex(); - if(currentIndex != -1){ + if (currentIndex != -1) { ui->obsListComboBox->setCurrentIndex(0); loadSelectedObservingList(0); } @@ -413,7 +419,7 @@ void ObsListDialog::loadDefaultList() { /* * Load the selected observing list in the combo box, from Json file into dialog. */ -void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlud) { +void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlud) { QVariantMap map; QVariantList listOfObjects; QFile jsonFile(observingListJsonPath); @@ -426,7 +432,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlu QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(listOlud).toMap(); // Check or not default list checkbox information - if(listOlud.compare(defaultListOlud_, Qt::CaseSensitive) == 0){ + if (listOlud.compare(defaultListOlud_, Qt::CaseSensitive) == 0) { ui->obsListIsDefaultListCheckBox->setChecked(true); } else { ui->obsListIsDefaultListCheckBox->setChecked(false); @@ -434,7 +440,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlu // Landscape QString landscapeId = observingListMap.value(KEY_LANDSCAPE_ID).toString(); - if(!landscapeId.isEmpty()){ + if (!landscapeId.isEmpty()) { landscapeMgr->setCurrentLandscapeID(landscapeId); } @@ -445,129 +451,109 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlu ui->obsListClearHighlightButton->setEnabled(true); ui->obsListDeleteButton->setEnabled(true); - for (const QVariant& object: listOfObjects) { + for (const QVariant &object: listOfObjects) { QVariantMap objectMap; if (object.canConvert()) { objectMap = object.value(); QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); - if (objectMgr->findAndSelect(objectName)) { + int lastRow = obsListListModel->rowCount(); + QString objectUuid = QUuid::createUuid().toString(); + QString objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); + bool visibleFlag = false; + double fov = -1.0; + + // Type + QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); + + // RA & DEC + QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); + QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + + if (objectMgr->findAndSelect(objectName) && !objectMgr->getSelectedObject().isEmpty()) { const QList &selectedObject = objectMgr->getSelectedObject(); - if (!selectedObject.isEmpty()) { - - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - QString objectNameI18n = selectedObject[0]->getNameI18n(); - bool visibleFlag = false; - double fov = -1.0; - - // TYPE - QString objectType = selectedObject[0]->getType(); - if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ - auto& r_planet = dynamic_cast(*selectedObject[0]); - objectType = r_planet.getPlanetTypeString(); - } - - // RA & DEC - QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); - QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); - - float ra = 0.0; - float dec = 0.0; - StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); - - if(objectRaStr.isEmpty()){ - objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); - } - - if(objectDecStr.isEmpty()){ - objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); - } - - if (objectName.contains("marker", Qt::CaseInsensitive)) { - visibleFlag = true; - } - - float objectMagnitude = selectedObject[0]->getVMagnitude(core); - QString objectMagnitudeStr = QString::number(objectMagnitude); - - QVariantMap objectInfoMap = selectedObject[0]->getInfoMap(core); - QVariant objectConstellationVariant = objectInfoMap["iauConstellation"]; - QString objectConstellation("unknown"); - if (objectConstellationVariant.canConvert()) { - objectConstellation = objectConstellationVariant.value(); - } - - // Julian Day - QString JDs = objectMap.value(QString(KEY_JD)).value(); - - if(JDs.isEmpty()){ - double JD = core->getJD(); - JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace( - "T", " "); - } - - // Location - QString Location = objectMap.value(QString(KEY_LOCATION)).value(); - if(Location.isEmpty()){ - StelLocation loc = core->getCurrentLocation(); - if (loc.name.isEmpty()) { - Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); - } else { - Location = QString("%1, %2").arg(loc.name).arg(loc.region); - } - } - - // FOV - QString fovStr = objectMap.value(QString(KEY_FOV)).value(); - if(!fovStr.isEmpty()){ - fov = fovStr.toDouble(); - } - - - addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, - objectDecStr, objectMagnitudeStr, objectConstellation); - - observingListItem item; - item.name = objectName; - item.nameI18n = objectNameI18n; - if (!objectType.isEmpty()) { - item.type = objectType; - } - if (!objectRaStr.isEmpty()) { - item.ra = objectRaStr; - } - if (!objectDecStr.isEmpty()) { - item.dec = objectDecStr; - } - if (!objectMagnitudeStr.isEmpty()) { - item.magnitude = objectMagnitudeStr; - } - if (!objectConstellation.isEmpty()) { - item.constellation = objectConstellation; - } - if (!JDs.isEmpty()) { - item.jd = JDs.toDouble(); - } - if (!Location.isEmpty()) { - item.location = Location; - } - if (!visibleFlag) { - item.isVisibleMarker = visibleFlag; - } - if (fov > 0.0) { - item.fov = fov; - } - - observingListItemCollection.insert(objectUuid, item); + float ra = 0.0; + float dec = 0.0; + StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); - } else { - qWarning() << "[ObservingList] selected object is empty !"; + if (objectRaStr.isEmpty()) { + objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); } + if (objectDecStr.isEmpty()) { + objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); + } } else { - qWarning() << "[ObservingList] object: " << objectName << " not found !"; + qWarning() << "[ObservingList] object: " << objectName << " not found or empty !"; + } + + // Magnitude + QString objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); + + // Constellation + QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value();; + + // Julian Day + QString JDs = objectMap.value(QString(KEY_JD)).value(); + if (JDs.isEmpty()) { + double JD = core->getJD(); + JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace( + "T", " "); + } + + // Location + QString Location = objectMap.value(QString(KEY_LOCATION)).value(); + if (Location.isEmpty()) { + StelLocation loc = core->getCurrentLocation(); + if (loc.name.isEmpty()) { + Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); + } else { + Location = QString("%1, %2").arg(loc.name).arg(loc.region); + } + } + + // Fov + QString fovStr = objectMap.value(QString(KEY_FOV)).value(); + if (!fovStr.isEmpty()) { + fov = fovStr.toDouble(); } + + addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, + objectDecStr, objectMagnitudeStr, objectConstellation); + + observingListItem item; + item.name = objectName; + item.nameI18n = objectNameI18n; + if (!objectType.isEmpty()) { + item.type = objectType; + } + if (!objectRaStr.isEmpty()) { + item.ra = objectRaStr; + } + if (!objectDecStr.isEmpty()) { + item.dec = objectDecStr; + } + if (!objectMagnitudeStr.isEmpty()) { + item.magnitude = objectMagnitudeStr; + } + if (!objectConstellation.isEmpty()) { + item.constellation = objectConstellation; + } + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); + } + if (!Location.isEmpty()) { + item.location = Location; + } + if (!visibleFlag) { + item.isVisibleMarker = visibleFlag; + } + if (fov > 0.0) { + item.fov = fov; + } + + observingListItemCollection.insert(objectUuid, item); + } else { qCritical() << "[ObservingList] conversion error"; return; @@ -597,7 +583,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString& listOlu /* * Load the list from JSON file QVariantMap map */ -auto ObsListDialog::loadListFromJson(const QVariantMap& map, QString listOlud) -> QVariantList { +auto ObsListDialog::loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList { observingListItemCollection.clear(); QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(listOlud).toMap(); @@ -652,7 +638,7 @@ void ObsListDialog::loadBookmarksInObservingList() { QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); if (!nameI18n.isEmpty()) { item.nameI18n = nameI18n; - } else{ + } else { item.nameI18n = ""; } @@ -681,7 +667,7 @@ void ObsListDialog::loadBookmarksInObservingList() { QString Dec = bookmarkData.value(KEY_DEC).toString(); if (!Dec.isEmpty()) { item.dec = Dec; - }else { + } else { item.dec = ""; } @@ -708,7 +694,7 @@ void ObsListDialog::loadBookmarksInObservingList() { /* * Save the bookmarks into observing list file */ -void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash& bookmarksCollection) { +void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection) { QFile jsonFile(observingListJsonPath); if (!jsonFile.open(QIODevice::ReadWrite | QIODevice::Text)) { @@ -745,7 +731,8 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHashgetJD(); - QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T"," "); + QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", + " "); observingListDataList.insert(QString(KEY_CREATION_DATE), listCreationDate); // Location @@ -793,8 +780,8 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHashfindAndSelect(objectName)) { const QList &selectedObject = objectMgr->getSelectedObject(); QString objectType = selectedObject[0]->getType(); - if(QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0){ - auto& r_planet = dynamic_cast(*selectedObject[0]); + if (QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0) { + auto &r_planet = dynamic_cast(*selectedObject[0]); objectType = r_planet.getPlanetTypeString(); } obl.insert(QString(KEY_OBJECTS_TYPE), objectType); @@ -865,7 +852,7 @@ void ObsListDialog::selectAndGoToObject(QModelIndex index) { observingListItem item = observingListItemCollection.value(itemUuid); - if(item.jd != 0.0){ + if (item.jd != 0.0) { core->setJD(item.jd); } diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index a8e9cb88643ff..1410208d4a270 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -93,6 +93,8 @@ static constexpr char const * KEY_OBJECTS_TYPE = "objtype"; static constexpr char const * KEY_DESIGNATION = "designation"; static constexpr char const * KEY_SORTING = "sorting"; static constexpr char const * KEY_LOCATION = "location"; +static constexpr char const * KEY_MAGNITUDE = "magnitude"; +static constexpr char const * KEY_CONSTELLATION = "constellation"; static constexpr char const * KEY_VERSION = "version"; static constexpr char const * KEY_SHORT_NAME = "shortName"; static constexpr char const * KEY_IS_VISIBLE_MARKER = "isVisibleMarker"; From 6d62fa40accda880e5e32e363ed22c3c02d4ff56 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 17 Jun 2022 15:46:17 +0200 Subject: [PATCH 18/28] ObservingLists-fix --- src/gui/ObsListCreateEditDialog.cpp | 327 ++++++++++++++-------------- src/gui/ObsListCreateEditDialog.hpp | 50 +++-- src/gui/ObsListDialog.cpp | 250 +++++++++++++-------- src/gui/ObsListDialog.hpp | 77 ++++--- src/gui/ObservingListCommon.hpp | 172 +++++++++------ 5 files changed, 511 insertions(+), 365 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 679ab494bab70..8e97585f981d2 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -42,14 +42,17 @@ ObsListCreateEditDialog *ObsListCreateEditDialog::m_instance = nullptr; ObsListCreateEditDialog::ObsListCreateEditDialog(std::string listUuid) : ui(new Ui_obsListCreateEditDialogForm()), - obsListListModel( - new QStandardItemModel(0, ColumnCount)), - core(StelApp::getInstance().getCore()), - listOlud_(std::move(listUuid)), sorting("") { + obsListListModel( + new QStandardItemModel(0, + ColumnCount)), + core(StelApp::getInstance().getCore()), + listOlud_(std::move(listUuid)), sorting("") { objectMgr = GETSTELMODULE(StelObjectMgr); landscapeMgr = GETSTELMODULE(LandscapeMgr); observingListJsonPath = - StelFileMgr::findFile("data", static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + "/" + + StelFileMgr::findFile("data", + static_cast(StelFileMgr::Directory | StelFileMgr::Writable)) + + "/" + QString(JSON_FILE_NAME); } @@ -109,7 +112,7 @@ void ObsListCreateEditDialog::createDialogContent() { ui->obsListCreationEditionTreeView->header()->setStretchLastSection(true); ui->obsListCreationEditionTreeView->hideColumn(ColumnUUID); ui->obsListCreationEditionTreeView->hideColumn(ColumnNameI18n); - ui->obsListCreationEditionTreeView->hideColumn(ColumnJD); + ui->obsListCreationEditionTreeView->hideColumn(ColumnDate); ui->obsListCreationEditionTreeView->hideColumn(ColumnLocation); // Enable the sort for columns ui->obsListCreationEditionTreeView->setSortingEnabled(true); @@ -122,6 +125,7 @@ void ObsListCreateEditDialog::createDialogContent() { ui->closeStelWindow->setHidden(true); ui->obsListErrorMessage->setHidden(true); + ui->obsListLandscapeCheckBox->setChecked(false); // In case of creation the nameOfListLineEdit is empty and button save/close must be disabled // In case on edition the nameOfListLineEdit is not empty and the button save/close must be enable @@ -184,44 +188,52 @@ void ObsListCreateEditDialog::setObservingListHeaderNames() { * Add row in the obsListListModel */ void ObsListCreateEditDialog::addModelRow(int number, - const QString& uuid, - const QString& name, - const QString& nameI18n, - const QString& type, - const QString& ra, - const QString& dec, - const QString& magnitude, - const QString& constellation) { + const QString &uuid, + const QString &name, + const QString &nameI18n, + const QString &objtype, + const QString &ra, + const QString &dec, + const QString &magnitude, + const QString &constellation) { QStandardItem *item = Q_NULLPTR; + // olud item = new QStandardItem(uuid); item->setEditable(false); obsListListModel->setItem(number, ColumnUUID, item); + // name item = new QStandardItem(name); item->setEditable(false); obsListListModel->setItem(number, ColumnName, item); + // nameI18n item = new QStandardItem(nameI18n); item->setEditable(false); obsListListModel->setItem(number, ColumnNameI18n, item); - item = new QStandardItem(type); + // objtype (object type) + item = new QStandardItem(objtype); item->setEditable(false); obsListListModel->setItem(number, ColumnType, item); + // ra item = new QStandardItem(ra); item->setEditable(false); obsListListModel->setItem(number, ColumnRa, item); + // dec item = new QStandardItem(dec); item->setEditable(false); obsListListModel->setItem(number, ColumnDec, item); + // magnitude item = new QStandardItem(magnitude); item->setEditable(false); obsListListModel->setItem(number, ColumnMagnitude, item); + // constellation item = new QStandardItem(constellation); item->setEditable(false); obsListListModel->setItem(number, ColumnConstellation, item); @@ -236,7 +248,9 @@ void ObsListCreateEditDialog::addModelRow(int number, * Save selected object into the list of observed objects. */ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { + const QList &selectedObject = objectMgr->getSelectedObject(); + if (!selectedObject.isEmpty()) { // No duplicate item in the same list @@ -262,6 +276,9 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { } // Type + QString type = selectedObject[0]->getType(); + + // Object Type QString objectType = selectedObject[0]->getObjectType(); // Ra & Dec @@ -280,7 +297,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Fov double fov = -1.0; - if(ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()){ + if (ui->obsListFovCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { fov = GETSTELMODULE(StelMovementMgr)->getCurrentFov(); } @@ -290,8 +307,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { } // Magnitude - float objectMagnitude = selectedObject[0]->getVMagnitude(core); - QString objectMagnitudeStr = QString::number(objectMagnitude); + QString objectMagnitudeStr = util.getMagnitue(selectedObject, core); // Constallation QVariantMap objectMap = selectedObject[0]->getInfoMap(core); @@ -315,10 +331,14 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { Location = QString("%1, %2").arg(loc.name, loc.region); } + // TODO only for test: delete after + // objectName = "Unnamed object"; + // ********************************* + // Check if the object name is empty. if (objectName.isEmpty()) { objectName = q_("Unnamed object"); - if(objectNameI18n.isEmpty()){ + if (objectNameI18n.isEmpty()) { objectNameI18n = q_("Unnamed object"); } } @@ -335,13 +355,17 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { objectConstellation); observingListItem item; - initItem(item); + util.initItem(item); item.name = objectName; item.nameI18n = objectNameI18n; // Type + if (!type.isEmpty()) { + item.type = type; + } + // Object Type if (!objectType.isEmpty()) { - item.type = objectType; + item.objtype = objectType; } // Ra if (!objectRaStr.isEmpty()) { @@ -415,7 +439,7 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { // Creation date double JD = core->getJD(); - QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T"," "); + QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); try { QVariantMap mapFromJsonFile; @@ -440,11 +464,11 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { observingListDataList.insert(QString(KEY_CREATION_DATE), listCreationDate); // Landscape - if(ui->obsListLandscapeCheckBox->isChecked()){ + if (ui->obsListLandscapeCheckBox->isChecked()) { QString landscapeId = landscapeMgr->getCurrentLandscapeID(); - observingListDataList.insert(QString(KEY_LANDSCAPE_ID),landscapeId); + observingListDataList.insert(QString(KEY_LANDSCAPE_ID), landscapeId); } else { - observingListDataList.insert(QString(KEY_LANDSCAPE_ID),""); + observingListDataList.insert(QString(KEY_LANDSCAPE_ID), ""); } // List of objects @@ -476,8 +500,11 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { // Dec obl.insert(QString(KEY_DEC), item.dec); + // Type + obl.insert(QString(KEY_TYPE), item.type); + // Object type - obl.insert(QString(KEY_OBJECTS_TYPE), item.type); + obl.insert(QString(KEY_OBJECTS_TYPE), item.objtype); // Magnitude obl.insert(QString(KEY_MAGNITUDE), item.magnitude); @@ -516,8 +543,9 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { if (defaultListUuid.isEmpty()) { mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); } else { - int compareResult = QString::compare(defaultListUuid, QString::fromStdString(listOlud_), Qt::CaseSensitive); - if(compareResult == 0){ + int compareResult = QString::compare(defaultListUuid, QString::fromStdString(listOlud_), + Qt::CaseSensitive); + if (compareResult == 0) { mapFromJsonFile.insert(KEY_DEFAULT_LIST_OLUD, ""); } } @@ -598,7 +626,8 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { QString listName = ui->nameOfListLineEdit->text(); // TODO il faut faire la comparaison du nom des liste en ignoreCase - bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode ||(listName.compare(currentListName) !=0 &&!isCreationMode)); + bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && + (isCreationMode || (listName.compare(currentListName) != 0 && !isCreationMode)); if (isListAlreadyExists) { QString errorMessage; @@ -678,6 +707,7 @@ void ObsListCreateEditDialog::headerClicked(int index) { * Load the observing list in case of edit mode */ void ObsListCreateEditDialog::loadObservingList() { + QVariantMap map; QFile jsonFile(observingListJsonPath); if (!jsonFile.open(QIODevice::ReadOnly)) { @@ -710,7 +740,7 @@ void ObsListCreateEditDialog::loadObservingList() { // Landscape QString landscape = observingListMap.value(QString(KEY_LANDSCAPE_ID)).value(); - if(!landscape.isEmpty()){ + if (!landscape.isEmpty()) { ui->obsListLandscapeCheckBox->setChecked(true); } @@ -722,128 +752,114 @@ void ObsListCreateEditDialog::loadObservingList() { return; } - for (const QVariant& object: listOfObjects) { + for (const QVariant &object: listOfObjects) { QVariantMap objectMap; if (object.canConvert()) { objectMap = object.value(); + int lastRow = obsListListModel->rowCount(); + QString objectUuid = QUuid::createUuid().toString(); + bool visibleFlag = false; + + // Name QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); - // TODO il faut charger ce qui est dans le fichier - - if (objectMgr->findAndSelect(objectName)) { - const QList &selectedObject = objectMgr->getSelectedObject(); - if (!selectedObject.isEmpty()) { - int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - QString objectNameI18n = selectedObject[0]->getNameI18n(); - QString objectRaStr = ""; - QString objectDecStr = ""; - bool visibleFlag = false; - - // Fov - auto fov = objectMap.value(QString(KEY_FOV)).value(); - - // Object type - QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); - - // Ra & dec - objectRaStr = objectMap.value(QString(KEY_RA)).value(); - objectDecStr = objectMap.value(QString(KEY_DEC)).value(); - - if (objectName.contains("marker", Qt::CaseInsensitive)) { - visibleFlag = true; - } - - // Magnitude - float objectMagnitude = selectedObject[0]->getVMagnitude(core); - QString objectMagnitudeStr = QString::number(objectMagnitude); - - //TODO à modifier - QVariantMap selectedObjectMap = selectedObject[0]->getInfoMap(core); - // ********************************************************* - - QVariant objectConstellationVariant = selectedObjectMap["iauConstellation"]; - QString objectConstellation("unknown"); - if (objectConstellationVariant.canConvert()) { - objectConstellation = objectConstellationVariant.value(); - } - - // Julian Day - QString JDs = objectMap.value(QString(KEY_JD)).value(); - - // Location - QString location = selectedObjectMap.value(QString(KEY_LOCATION)).value();; - - // Add data into model row - addModelRow(lastRow, - objectUuid, - objectName, - objectNameI18n, - objectType, - objectRaStr, - objectDecStr, - objectMagnitudeStr, - objectConstellation); - - - observingListItem item; - initItem(item); - item.name = objectName; - item.nameI18n = objectNameI18n; - - // Object type - if (!objectType.isEmpty()) { - item.type = objectType; - } - - // Ra - if (!objectRaStr.isEmpty()) { - item.ra = objectRaStr; - } - - // Dec - if (!objectDecStr.isEmpty()) { - item.dec = objectDecStr; - } - - // Magnitude - if (!objectMagnitudeStr.isEmpty()) { - item.magnitude = objectMagnitudeStr; - } - - // Constellation - if (!objectConstellation.isEmpty()) { - item.constellation = objectConstellation; - } - - // JD - if (!JDs.isEmpty()) { - item.jd = JDs.toDouble(); - } - - // Location - if (!location.isEmpty()) { - item.location = location; - } - - // Flag - if (!visibleFlag) { - item.isVisibleMarker = visibleFlag; - } - - // Fov - if (fov > 0.0) { - item.fov = fov; - } - observingListItemCollection.insert(objectUuid, item); - - } else { - qWarning() << "[ObservingList Creation/Edition] selected object is empty !"; - } - - } else { - qWarning() << "[ObservingList Creation/Edition] object: " << objectName << " not found !"; + // NameI18n + QString objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); + + // Fov + auto fov = objectMap.value(QString(KEY_FOV)).value(); + + // Object type + QString type = objectMap.value(QString(KEY_TYPE)).value(); + + // Object type + QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); + + // Ra & dec + QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); + QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + + // Magnitude + QString objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); + + // Constellation + QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); + + // Julian Day + QString JDs = objectMap.value(QString(KEY_JD)).value(); + + // Location + QString location = objectMap.value(QString(KEY_LOCATION)).value(); + + + // Add data into model row + addModelRow(lastRow, + objectUuid, + objectName, + objectNameI18n, + objectType, + objectRaStr, + objectDecStr, + objectMagnitudeStr, + objectConstellation); + + + observingListItem item; + util.initItem(item); + item.name = objectName; + item.nameI18n = objectNameI18n; + + // Type + if (!type.isEmpty()) { + item.type = type; } + + // Object type + if (!objectType.isEmpty()) { + item.objtype = objectType; + } + + // Ra + if (!objectRaStr.isEmpty()) { + item.ra = objectRaStr; + } + + // Dec + if (!objectDecStr.isEmpty()) { + item.dec = objectDecStr; + } + + // Magnitude + if (!objectMagnitudeStr.isEmpty()) { + item.magnitude = objectMagnitudeStr; + } + + // Constellation + if (!objectConstellation.isEmpty()) { + item.constellation = objectConstellation; + } + + // JD + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); + } + + // Location + if (!location.isEmpty()) { + item.location = location; + } + + // Flag + if (!visibleFlag) { + item.isVisibleMarker = visibleFlag; + } + + // Fov + if (fov > 0.0) { + item.fov = fov; + } + observingListItemCollection.insert(objectUuid, item); + } else { qCritical() << "[ObservingList Creation/Edition] conversion error"; return; @@ -887,22 +903,3 @@ void ObsListCreateEditDialog::kill() { m_instance = nullptr; } } - -/** - * Init observingListItem. - * @param item - */ -void ObsListCreateEditDialog::initItem(observingListItem &item) { - - item.jd = 0.0; - item.type = ""; - item.ra = ""; - item.dec = ""; - item.name = ""; - item.nameI18n = ""; - item.location = ""; - item.fov = 0.0; - item.constellation = ""; - item.magnitude = ""; - item.isVisibleMarker = false; -} diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 485570ddeefa5..280bee2888cf1 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -30,12 +30,12 @@ class Ui_obsListCreateEditDialogForm; -class ObsListCreateEditDialog : public StelDialog -{ - Q_OBJECT +class ObsListCreateEditDialog : public StelDialog { +Q_OBJECT public: - static auto Instance ( std::string listUuid ) -> ObsListCreateEditDialog *; + static auto Instance(std::string listUuid) -> ObsListCreateEditDialog *; + static void kill(); //! Notify that the application style changed @@ -44,25 +44,30 @@ class ObsListCreateEditDialog : public StelDialog //! called when click on button close in top right corner void close() override; - void setListName ( QList listName ); + void setListName(QList listName); protected: //! Initialize the dialog widgets and connect the signals/slots. void createDialogContent() override; private: - static ObsListCreateEditDialog * m_instance; - Ui_obsListCreateEditDialogForm * ui; + static ObsListCreateEditDialog *m_instance; + Ui_obsListCreateEditDialogForm *ui; //! To know if the dialog is open in creation mode or editionn mode // if true we are in creation mode otherwise in edition mode bool isCreationMode; bool isSaveAs; - QStandardItemModel * obsListListModel; - class StelCore* core; - class StelObjectMgr* objectMgr; - class LandscapeMgr* landscapeMgr; + QStandardItemModel *obsListListModel; + + class StelCore *core; + + class StelObjectMgr *objectMgr; + + class LandscapeMgr *landscapeMgr; + std::string listOlud_; QString observingListJsonPath; + ObservingListUtil util; // Data for observed objects QHash observingListItemCollection; @@ -88,7 +93,8 @@ class ObsListCreateEditDialog : public StelDialog //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow ( int number, const QString& uuid, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, const QString& dec, const QString& magnitude, const QString& constellation ); + void addModelRow(int number, const QString &uuid, const QString &name, const QString &nameI18n, const QString &type, + const QString &ra, const QString &dec, const QString &magnitude, const QString &constellation); //! Save the object informations into json file void saveObservedObjectsInJsonFile(); @@ -97,26 +103,34 @@ class ObsListCreateEditDialog : public StelDialog void loadObservingList(); //Private constructor and destructor - explicit ObsListCreateEditDialog ( std::string listUuid ); - ~ObsListCreateEditDialog() override; - - void initItem(observingListItem &item); + explicit ObsListCreateEditDialog(std::string listUuid); + ~ObsListCreateEditDialog() override; public slots: + void retranslate() override; - + private slots: + void obsListAddObjectButtonPressed(); + void obsListRemoveObjectButtonPressed(); + void obsListExportListButtonPressed(); + void obsListImportListButtonPresssed(); + void obsListSaveButtonPressed(); + void obsListExitButtonPressed(); - void headerClicked ( int index ); + + void headerClicked(int index); + void nameOfListTextChange(); signals: + //To notified that the exit button is clicked void exitButtonClicked(); }; diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index e771b6dc42cc8..66e910a56b79d 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -36,6 +36,7 @@ #include "ObsListDialog.hpp" #include "LabelMgr.hpp" #include "Planet.hpp" +#include "Nebula.hpp" #include "ui_obsListDialog.h" #include @@ -64,6 +65,8 @@ ObsListDialog::ObsListDialog(QObject *parent) : StelDialog("Observing list", par "/" + QString(JSON_BOOKMARKS_FILE_NAME); + currentJd = core->getJD(); + } @@ -106,11 +109,11 @@ void ObsListDialog::createDialogContent() { ui->obsListTreeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setSectionResizeMode(ColumnConstellation, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnDate, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnLocation, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setStretchLastSection(true); ui->obsListTreeView->hideColumn(ColumnUUID); ui->obsListTreeView->hideColumn(ColumnNameI18n); - ui->obsListTreeView->hideColumn(ColumnJD); - ui->obsListTreeView->hideColumn(ColumnLocation); //Enable the sort for columns ui->obsListTreeView->setSortingEnabled(true); @@ -120,6 +123,9 @@ void ObsListDialog::createDialogContent() { ui->obsListClearHighlightButton->setEnabled(false); ui->obsListDeleteButton->setEnabled(false); + ui->obsListJdCheckBox->setChecked(false); + ui->obsListLocationCheckBox->setChecked(false); + // We hide the closeStelWindow to have only two possibilities to close the dialog: // Exit ui->closeStelWindow->setHidden(true); @@ -172,8 +178,8 @@ void ObsListDialog::setObservingListHeaderNames() { q_ ("Declination"), q_ ("Magnitude"), q_ ("Constellation"), - q_ ("Date"), // Hidden column - q_ ("Location") // Hidden column + q_ ("Date"), + q_ ("Location") }; obsListListModel->setHorizontalHeaderLabels(headerStrings); @@ -184,7 +190,8 @@ void ObsListDialog::setObservingListHeaderNames() { */ void ObsListDialog::addModelRow(int number, const QString &olud, const QString &name, const QString &nameI18n, const QString &type, const QString &ra, - const QString &dec, const QString &magnitude, const QString &constellation) { + const QString &dec, const QString &magnitude, const QString &constellation, + const QString &date, const QString &location) { QStandardItem *item = Q_NULLPTR; item = new QStandardItem(olud); @@ -219,6 +226,14 @@ void ObsListDialog::addModelRow(int number, const QString &olud, const QString & item->setEditable(false); obsListListModel->setItem(number, ColumnConstellation, item); + item = new QStandardItem(date); + item->setEditable(false); + obsListListModel->setItem(number, ColumnDate, item); + + item = new QStandardItem(location); + item->setEditable(false); + obsListListModel->setItem(number, ColumnLocation, item); + for (int i = 0; i < ColumnCount; ++i) { ui->obsListTreeView->resizeColumnToContents(i); } @@ -491,16 +506,21 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu QString objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); // Constellation - QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value();; + QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); - // Julian Day + // Julian Day / Date QString JDs = objectMap.value(QString(KEY_JD)).value(); - if (JDs.isEmpty()) { + QString date = ""; + if (JDs.isEmpty() || QString::compare(JDs, "0", Qt::CaseSensitive) == 0) { double JD = core->getJD(); - JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace( + JDs = QString::number(JD, 'f', 6); + } else { + double JD = JDs.toDouble(); + date = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace( "T", " "); } + // Location QString Location = objectMap.value(QString(KEY_LOCATION)).value(); if (Location.isEmpty()) { @@ -519,7 +539,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu } addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, - objectDecStr, objectMagnitudeStr, objectConstellation); + objectDecStr, objectMagnitudeStr, objectConstellation, date, Location); observingListItem item; item.name = objectName; @@ -614,7 +634,7 @@ auto ObsListDialog::loadListFromJson(const QVariantMap &map, QString listOlud) - * For no regression with must take into account the legacy bookmarks.json file */ void ObsListDialog::loadBookmarksInObservingList() { - QHash bookmarksCollection; + QHash bookmarksCollection; QVariantMap map; QFile jsonFile(bookmarksJsonPath); @@ -631,54 +651,122 @@ void ObsListDialog::loadBookmarksInObservingList() { for (auto bookmarkKey: bookmarksMap.keys()) { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); - bookmark item; + observingListItem item; + util.initItem(item); + // Name item.name = bookmarkData.value(KEY_NAME).toString(); - /// TODO vérifier si nameI18n est utilisé - QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); - if (!nameI18n.isEmpty()) { - item.nameI18n = nameI18n; - } else { - item.nameI18n = ""; - } - // JDs - QString JDs = bookmarkData.value(KEY_JD).toString(); - if (!JDs.isEmpty()) { - item.jd = JDs.toDouble(); - } else { - item.jd = 0.0; - } + // We need to select the object to add additional information that is not in the Bookmark file + if (objectMgr->findAndSelect(item.name) && !objectMgr->getSelectedObject().isEmpty()) { + const QList &selectedObject = objectMgr->getSelectedObject(); + + // Ra & Dec - ra and dec are not empty in case of Custom Object + QString raStr = bookmarkData.value(KEY_RA).toString(); + QString decStr = bookmarkData.value(KEY_DEC).toString(); + if (raStr.isEmpty() || decStr.isEmpty()) { + float ra, dec; + StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); + raStr = StelUtils::radToHmsStr(ra, false).trimmed(); + decStr = StelUtils::radToDmsStr(dec, false).trimmed(); + } - QString Location = bookmarkData.value(KEY_LOCATION).toString(); - if (!Location.isEmpty()) { - item.location = Location; - } else { - item.location = ""; - } + if (!raStr.isEmpty()) { + item.ra = raStr; + } else { + item.ra = ""; + } - QString RA = bookmarkData.value(KEY_RA).toString(); - if (!RA.isEmpty()) { - item.ra = RA; - } else { - item.ra = ""; - } + if (!decStr.isEmpty()) { + item.dec = decStr; + } else { + item.dec = ""; + } - QString Dec = bookmarkData.value(KEY_DEC).toString(); - if (!Dec.isEmpty()) { - item.dec = Dec; - } else { - item.dec = ""; - } + // NameI18n + QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); + if (!nameI18n.isEmpty()) { + item.nameI18n = nameI18n; + } else { + item.nameI18n = ""; + } - item.isVisibleMarker = bookmarkData.value(KEY_IS_VISIBLE_MARKER, false).toBool(); - double fov = bookmarkData.value(KEY_FOV).toDouble(); - if (fov > 0.0) { - item.fov = fov; - } + // JDs + QString JDs = bookmarkData.value(KEY_JD).toString(); + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); + } else { + item.jd = 0.0; + } + + // Location + QString location = bookmarkData.value(KEY_LOCATION).toString(); + if (!location.isEmpty()) { + item.location = location; + } else { + item.location = ""; + } + + + // Constallation + QVariantMap objectMap = selectedObject[0]->getInfoMap(core); + QVariant objectConstellationVariant = objectMap["iauConstellation"]; + QString objectConstellation("unknown"); + if (objectConstellationVariant.canConvert()) { + objectConstellation = objectConstellationVariant.value(); + } + if (!objectConstellation.isEmpty()) { + item.constellation = objectConstellation; + } + + // Type + QString type = selectedObject[0]->getType(); + if (!type.isEmpty()) { + item.type = type; + } + + // Object Type + QString objectType = selectedObject[0]->getObjectType(); + if (!objectType.isEmpty()) { + item.objtype = objectType; + } + + // Magnitude + // TODO sortir ce code dans une méthode + /*QString objectMagnitudeStr; + float objectMagnitude = selectedObject[0]->getVMagnitude(core); + const float unknownMagnitude = 99; + if (objectMagnitude == unknownMagnitude) { + if (QString::compare(type, "Nebula", Qt::CaseSensitive) == 0) { + auto &r_nebula = dynamic_cast(*selectedObject[0]); + float mB = r_nebula.getBMagnitude(core); + if (mB == unknownMagnitude) { + objectMagnitudeStr = "–"; + } else { + objectMagnitudeStr = QString::number(mB); + } + } else { + objectMagnitudeStr = "–"; + } + } else { + objectMagnitudeStr = QString::number(objectMagnitude); + }*/ + QString objectMagnitudeStr = util.getMagnitue(selectedObject, core); + if (!objectMagnitudeStr.isEmpty()) { + item.magnitude = objectMagnitudeStr; + } + + // Fov + double fov = bookmarkData.value(KEY_FOV).toDouble(); + if (fov > 0.0) { + item.fov = fov; + } - bookmarksCollection.insert(bookmarkKey, item); + // Visible marker + item.isVisibleMarker = bookmarkData.value(KEY_IS_VISIBLE_MARKER, false).toBool(); + bookmarksCollection.insert(bookmarkKey, item); + } } saveBookmarksInObsListJsonFile(bookmarksCollection); @@ -694,7 +782,7 @@ void ObsListDialog::loadBookmarksInObservingList() { /* * Save the bookmarks into observing list file */ -void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection) { +void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection) { QFile jsonFile(observingListJsonPath); if (!jsonFile.open(QIODevice::ReadWrite | QIODevice::Text)) { @@ -720,8 +808,6 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHashgetCurrentLocation(); - if (loc.name.isEmpty()) { - Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); - } else { - Location = QString("%1, %2").arg(loc.name).arg(loc.region); - } - observingListDataList.insert(QString(KEY_LOCATION), Location); + // Landscape + QString landscapeId = landscapeMgr->getCurrentLandscapeID(); + observingListDataList.insert(QString(KEY_LANDSCAPE_ID), landscapeId); // Name of the liste observingListDataList.insert(QString(KEY_NAME), BOOKMARKS_LIST_NAME); // List of objects QVariantList listOfObjects; - QHashIterator i(bookmarksCollection); + QHashIterator i(bookmarksCollection); while (i.hasNext()) { i.next(); - bookmark item = i.value(); + observingListItem item = i.value(); QVariantMap obl; - // Designation - QString objectName = item.name; - obl.insert(QString(KEY_DESIGNATION), objectName); + // Designation (name) + obl.insert(QString(KEY_DESIGNATION), item.name); + + // NameI18 + obl.insert(QString(KEY_NAME_I18N), item.nameI18n); // Fov obl.insert(QString(KEY_FOV), item.fov); @@ -770,6 +852,12 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHashfindAndSelect(objectName)) { - const QList &selectedObject = objectMgr->getSelectedObject(); - QString objectType = selectedObject[0]->getType(); - if (QString::compare(objectType, "Planet", Qt::CaseSensitive) == 0) { - auto &r_planet = dynamic_cast(*selectedObject[0]); - objectType = r_planet.getPlanetTypeString(); - } - obl.insert(QString(KEY_OBJECTS_TYPE), objectType); - } + obl.insert(QString(KEY_TYPE), item.type); + + // Object type + obl.insert(QString(KEY_OBJECTS_TYPE), item.objtype); listOfObjects.push_back(obl); @@ -852,11 +935,15 @@ void ObsListDialog::selectAndGoToObject(QModelIndex index) { observingListItem item = observingListItemCollection.value(itemUuid); - if (item.jd != 0.0) { + // We use jd if the checkbox JD is checked. + if (ui->obsListJdCheckBox->isChecked() && item.jd != 0.0) { core->setJD(item.jd); + } else { + core->setJD(currentJd); } - if (!item.location.isEmpty()) { + // We use location if the checkbox Location is checked. + if (ui->obsListLocationCheckBox->isChecked() && !item.location.isEmpty()) { StelLocationMgr *locationMgr = &StelApp::getInstance().getLocationMgr(); core->moveObserverTo(locationMgr->locationForString(item.location)); } @@ -973,14 +1060,8 @@ void ObsListDialog::obsListDeleteButtonPressed() { int currentIndex = ui->obsListComboBox->currentIndex(); ui->obsListComboBox->removeItem(currentIndex); - //TODO pas utile car listeName_ est réinitialiséé et rechargée dans loadListsNameFromJsonFile(). - //TODO a supprimer après les tests finaux. - //QString listName = ui->obsListComboBox->itemText(currentIndex); - //listNames_.removeOne(listName); - selectedObservingListUuid = ""; - jsonFile.resize(0); StelJsonParser::write(newMap, &jsonFile); jsonFile.flush(); @@ -1063,7 +1144,6 @@ QString ObsListDialog::extractDefaultListOludFromJsonFile() { } } - /* * Override of the StelDialog::setVisible((bool) methode * We need to load the default liste when opening the obsListDialog diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 5b52f4a023629..a7e98da95dfc4 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -31,30 +31,36 @@ class Ui_obsListDialogForm; -class ObsListDialog : public StelDialog -{ - Q_OBJECT +class ObsListDialog : public StelDialog { +Q_OBJECT public: - explicit ObsListDialog ( QObject* parent ); + explicit ObsListDialog(QObject *parent); + ~ObsListDialog() override; //! Notify that the application style changed void styleChanged() override; - - void setVisible ( bool v ) override; + + void setVisible(bool v) override; protected: Ui_obsListDialogForm *ui; + //! Initialize the dialog widgets and connect the signals/slots. void createDialogContent() override; private: - QStandardItemModel * obsListListModel; - class StelCore* core; - class StelObjectMgr* objectMgr; - class LandscapeMgr* landscapeMgr; - class LabelMgr* labelMgr; + QStandardItemModel *obsListListModel; + + class StelCore *core; + + class StelObjectMgr *objectMgr; + + class LandscapeMgr *landscapeMgr; + + class LabelMgr *labelMgr; + std::string selectedObservingListUuid; QString observingListJsonPath; QString bookmarksJsonPath; @@ -63,13 +69,15 @@ class ObsListDialog : public StelDialog QString defaultListOlud_; QList listName_; QStringList listNamesModel; + double currentJd; + ObservingListUtil util; //! Set header names for observing list table void setObservingListHeaderNames(); - void invokeObsListCreateEditDialog ( std::string listOlud ); + void invokeObsListCreateEditDialog(std::string listOlud); - ObsListCreateEditDialog * createEditDialog_instance; + ObsListCreateEditDialog *createEditDialog_instance; //! Add row in the obsListListModel //! @param number row number @@ -80,35 +88,39 @@ class ObsListDialog : public StelDialog //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow (int number, const QString& olud, const QString& name, const QString& nameI18n, const QString& type, const QString& ra, const QString& dec, const QString& magnitude, const QString& constellation ); + void addModelRow(int number, const QString &olud, const QString &name, const QString &nameI18n, const QString &type, + const QString &ra, const QString &dec, const QString &magnitude, const QString &constellation, + const QString &date, const QString &location); //! Load the selected observing list from Json file into dialog. //! @param listOlud the olud (id) of the list - void loadSelectedObservingListFromJsonFile (const QString& listOlud ); + void loadSelectedObservingListFromJsonFile(const QString &listOlud); //! Load the lists names from Json file to populate the combo box and get the default list olud void loadListsNameFromJsonFile(); - + //! Load the default list void loadDefaultList(); - + //! Load the bookmarks of bookmarks.json file into observing lists file void loadBookmarksInObservingList(); - void saveBookmarksInObsListJsonFile(const QHash& bookmarksCollection); + + void saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection); + auto checkIfBookmarksListExists(QVariantMap allListsMap) -> bool; - + //! Load list from JSON file - auto loadListFromJson(const QVariantMap& map, QString listOlud) -> QVariantList; - + auto loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList; + //! Populate list names into combo box void populateListNameInComboBox(QVariantMap map); - + //! Populate data into combo box - void populateDataInComboBox(QVariantMap map, const QString& defaultListOlud); - + void populateDataInComboBox(QVariantMap map, const QString &defaultListOlud); + //! Sort the obsListTreeView by the column name given in parameter void sortObsListTreeViewByColumnName(QString columnName); - + //! Clear highlights void clearHighlight(); @@ -117,26 +129,33 @@ class ObsListDialog : public StelDialog public slots: + void retranslate(); private slots: + void obsListHighLightAllButtonPressed(); + void obsListClearHighLightButtonPressed(); + void obsListNewListButtonPressed(); + void obsListEditButtonPressed(); + void obsListCreateEditDialogClosed(); + void obsListExitButtonPressed(); + void obsListDeleteButtonPressed(); - - + //! Method called when a list name is selected in the combobox //! @param selectedIndex the index of the list name in the combo box - void loadSelectedObservingList ( int selectedIndex ); + void loadSelectedObservingList(int selectedIndex); //! Select and go to object //! @param index the QModelIndex of the list - void selectAndGoToObject ( QModelIndex index ); + void selectAndGoToObject(QModelIndex index); }; #endif // OBSLISTDIALOG_H diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 1410208d4a270..7e0e42979be31 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -20,91 +20,77 @@ #ifndef OBSERVINGLISTCOMMON_H #define OBSERVINGLISTCOMMON_H +#include "Nebula.hpp" + struct observingListItem { QString name; QString nameI18n; QString type; + QString objtype; QString ra; QString dec; - QString magnitude; //TODO voir si c'est utilisé + QString magnitude; QString constellation; double jd; QString location; double fov; - bool isVisibleMarker; //TODO voir si c'est vraiment utilisé + bool isVisibleMarker; }; -Q_DECLARE_METATYPE ( observingListItem ) - -//TODO certain champ peuvent ne pas servir - penser à les supprimer -// à vérifier après la V2 -struct bookmark -{ - QString name; - QString nameI18n; - QString ra; - QString dec; - bool isVisibleMarker; - double jd; - QString location; - double fov; -}; -Q_DECLARE_METATYPE(bookmark) +Q_DECLARE_METATYPE (observingListItem) enum ObsListColumns { - ColumnUUID, //! UUID of object - ColumnName, //! Name or designation of object - ColumnNameI18n, //! Localized name of object + ColumnUUID, //! UUID of object + ColumnName, //! Name or designation of object + ColumnNameI18n, //! Localized name of object ColumnType, //! Type of the object - ColumnRa, //! Right ascension of the object - ColumnDec, //! Declination of the object - ColumnMagnitude, //! Magnitude of the object + ColumnRa, //! Right ascension of the object + ColumnDec, //! Declination of the object + ColumnMagnitude, //! Magnitude of the object ColumnConstellation, //! Constellation in which the object is located - ColumnJD, //! Date in julian day + ColumnDate, //! Date ColumnLocation, //! Location where the object is observed - ColumnCount //! Total number of columns + ColumnCount //! Total number of columns }; -//TODO certaine clé peuvent ne pas servir - penser à les supprimer -// à vérifier après la V2 - -static constexpr char const * JSON_FILE_NAME = "observingList.json"; -static constexpr char const * FILE_VERSION = "2.0"; - -static constexpr char const * JSON_BOOKMARKS_FILE_NAME = "bookmarks.json"; -static constexpr char const * BOOKMARKS_LIST_NAME = "bookmarks list"; -static constexpr char const * BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version."; -static constexpr char const * SHORT_NAME_VALUE = "Observing list for Stellarium"; - -static constexpr char const * KEY_DEFAULT_LIST_OLUD = "defaultListOlud"; -static constexpr char const * KEY_OBSERVING_LISTS = "observingLists"; -static constexpr char const * KEY_CREATION_DATE = "creation date"; -static constexpr char const * KEY_BOOKMARKS = "bookmarks"; -static constexpr char const * KEY_NAME = "name"; -static constexpr char const * KEY_NAME_I18N = "nameI18n"; -static constexpr char const * KEY_JD = "jd"; -static constexpr char const * KEY_RA = "ra"; -static constexpr char const * KEY_DEC = "dec"; -static constexpr char const * KEY_FOV = "fov"; -static constexpr char const * KEY_DESCRIPTION = "description"; -static constexpr char const * KEY_LANDSCAPE_ID = "landscape id"; -static constexpr char const * KEY_OBJECTS = "objects"; -static constexpr char const * KEY_OBJECTS_TYPE = "objtype"; -static constexpr char const * KEY_DESIGNATION = "designation"; -static constexpr char const * KEY_SORTING = "sorting"; -static constexpr char const * KEY_LOCATION = "location"; -static constexpr char const * KEY_MAGNITUDE = "magnitude"; -static constexpr char const * KEY_CONSTELLATION = "constellation"; -static constexpr char const * KEY_VERSION = "version"; -static constexpr char const * KEY_SHORT_NAME = "shortName"; -static constexpr char const * KEY_IS_VISIBLE_MARKER = "isVisibleMarker"; - -static constexpr char const * SORTING_BY_NAME = "name"; -static constexpr char const * SORTING_BY_TYPE = "type"; -static constexpr char const * SORTING_BY_RA = "right ascension"; -static constexpr char const * SORTING_BY_DEC = "declination"; -static constexpr char const * SORTING_BY_MAGNITUDE = "magnitude"; -static constexpr char const * SORTING_BY_CONSTELLATION = "constellation"; +static constexpr char const *JSON_FILE_NAME = "observingList.json"; +static constexpr char const *FILE_VERSION = "2.0"; + +static constexpr char const *JSON_BOOKMARKS_FILE_NAME = "bookmarks.json"; +static constexpr char const *BOOKMARKS_LIST_NAME = "bookmarks list"; +static constexpr char const *BOOKMARKS_LIST_DESCRIPTION = "Bookmarks of previous Stellarium version."; +static constexpr char const *SHORT_NAME_VALUE = "Observing list for Stellarium"; + +static constexpr char const *KEY_DEFAULT_LIST_OLUD = "defaultListOlud"; +static constexpr char const *KEY_OBSERVING_LISTS = "observingLists"; +static constexpr char const *KEY_CREATION_DATE = "creation date"; +static constexpr char const *KEY_BOOKMARKS = "bookmarks"; +static constexpr char const *KEY_NAME = "name"; +static constexpr char const *KEY_NAME_I18N = "nameI18n"; +static constexpr char const *KEY_JD = "jd"; +static constexpr char const *KEY_RA = "ra"; +static constexpr char const *KEY_DEC = "dec"; +static constexpr char const *KEY_FOV = "fov"; +static constexpr char const *KEY_DESCRIPTION = "description"; +static constexpr char const *KEY_LANDSCAPE_ID = "landscape id"; +static constexpr char const *KEY_OBJECTS = "objects"; +static constexpr char const *KEY_OBJECTS_TYPE = "objtype"; +static constexpr char const *KEY_TYPE = "type"; +static constexpr char const *KEY_DESIGNATION = "designation"; +static constexpr char const *KEY_SORTING = "sorting"; +static constexpr char const *KEY_LOCATION = "location"; +static constexpr char const *KEY_MAGNITUDE = "magnitude"; +static constexpr char const *KEY_CONSTELLATION = "constellation"; +static constexpr char const *KEY_VERSION = "version"; +static constexpr char const *KEY_SHORT_NAME = "shortName"; +static constexpr char const *KEY_IS_VISIBLE_MARKER = "isVisibleMarker"; + +static constexpr char const *SORTING_BY_NAME = "name"; +static constexpr char const *SORTING_BY_TYPE = "type"; +static constexpr char const *SORTING_BY_RA = "right ascension"; +static constexpr char const *SORTING_BY_DEC = "declination"; +static constexpr char const *SORTING_BY_MAGNITUDE = "magnitude"; +static constexpr char const *SORTING_BY_CONSTELLATION = "constellation"; static constexpr int COLUMN_NUMBER_NAME = 1; static constexpr int COLUMN_NUMBER_TYPE = 3; @@ -113,7 +99,57 @@ static constexpr int COLUMN_NUMBER_DEC = 5; static constexpr int COLUMN_NUMBER_MAGNITUDE = 6; static constexpr int COLUMN_NUMBER_CONSTELLATION = 7; -static constexpr char const * CUSTOM_OBJECT = "CustomObject"; +static constexpr char const *CUSTOM_OBJECT = "CustomObject"; + +class ObservingListUtil { +public: + // Init item + void initItem(observingListItem &item) { + + item.jd = 0.0; + item.type = ""; + item.objtype = ""; + item.ra = ""; + item.dec = ""; + item.name = ""; + item.nameI18n = ""; + item.location = ""; + item.fov = 0.0; + item.constellation = ""; + item.magnitude = ""; + item.isVisibleMarker = false; + } + + // Get the magnitude form selected object + QString getMagnitue(const QList &selectedObject, StelCore *core) { + + if (core == nullptr) { + return ""; + } + + QString objectMagnitudeStr; + QString type = selectedObject[0]->getType(); + float objectMagnitude = selectedObject[0]->getVMagnitude(core); + const float unknownMagnitude = 99; + if (objectMagnitude == unknownMagnitude) { + if (QString::compare(type, "Nebula", Qt::CaseSensitive) == 0) { + auto &r_nebula = dynamic_cast(*selectedObject[0]); + float mB = r_nebula.getBMagnitude(core); + if (mB == unknownMagnitude) { + objectMagnitudeStr = "–"; + } else { + objectMagnitudeStr = QString::number(mB); + } + } else { + objectMagnitudeStr = "–"; + } + } else { + objectMagnitudeStr = QString::number(objectMagnitude); + } + + return objectMagnitudeStr; + } +}; -#endif // OBSLISTDIALOG_H +#endif // OBSERVINGLISTCOMMON_H From 6c641dbaf1a4231ad6ea43d61fbf88c810041ffa Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Thu, 4 Aug 2022 12:58:31 +0200 Subject: [PATCH 19/28] Observing List V2 --- src/gui/ObsListCreateEditDialog.cpp | 257 ++++++++++++++++++++++++---- src/gui/ObsListCreateEditDialog.hpp | 9 + src/gui/ObsListDialog.cpp | 34 +--- src/gui/ObservingListCommon.hpp | 2 + 4 files changed, 246 insertions(+), 56 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 8e97585f981d2..2c91ae1ce0a96 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "NebulaMgr.hpp" #include "StelCore.hpp" @@ -103,6 +104,7 @@ void ObsListCreateEditDialog::createDialogContent() { ui->obsListCreationEditionTreeView->setModel(obsListListModel); ui->obsListCreationEditionTreeView->header()->setSectionsMovable(false); ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnName, QHeaderView::ResizeToContents); + ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnNameI18n, QHeaderView::ResizeToContents); ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnType, QHeaderView::ResizeToContents); ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnRa, QHeaderView::ResizeToContents); ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); @@ -111,7 +113,7 @@ void ObsListCreateEditDialog::createDialogContent() { ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); ui->obsListCreationEditionTreeView->header()->setStretchLastSection(true); ui->obsListCreationEditionTreeView->hideColumn(ColumnUUID); - ui->obsListCreationEditionTreeView->hideColumn(ColumnNameI18n); + //ui->obsListCreationEditionTreeView->hideColumn(ColumnNameI18n); ui->obsListCreationEditionTreeView->hideColumn(ColumnDate); ui->obsListCreationEditionTreeView->hideColumn(ColumnLocation); // Enable the sort for columns @@ -124,11 +126,13 @@ void ObsListCreateEditDialog::createDialogContent() { // Save and close and Exit ui->closeStelWindow->setHidden(true); - ui->obsListErrorMessage->setHidden(true); + initErrorMessage(); ui->obsListLandscapeCheckBox->setChecked(false); // In case of creation the nameOfListLineEdit is empty and button save/close must be disabled // In case on edition the nameOfListLineEdit is not empty and the button save/close must be enable + //delete with space -> no list with only white space as name + ui->nameOfListLineEdit->setText(QString(ui->nameOfListLineEdit->text()).remove(QRegExp("([ ]+)$"))); if (ui->nameOfListLineEdit->text().isEmpty()) { ui->obsListSaveButton->setEnabled(false); } else { @@ -139,10 +143,12 @@ void ObsListCreateEditDialog::createDialogContent() { // case of creation mode isCreationMode = true; ui->stelWindowTitle->setText("Observing list creation mode"); + ui->obsListImportListButton->setHidden(false); } else { // case of edit mode isCreationMode = false; ui->stelWindowTitle->setText("Observing list editor mode"); + ui->obsListImportListButton->setHidden(true); loadObservingList(); } } @@ -170,8 +176,8 @@ void ObsListCreateEditDialog::styleChanged() { void ObsListCreateEditDialog::setObservingListHeaderNames() { const QStringList headerStrings = { "UUID", // Hidden column + q_("Object designation"), q_("Object name"), - q_("Object name I18N"), // Hidden column q_("Type"), q_("Right ascension"), q_("Declination"), @@ -248,7 +254,7 @@ void ObsListCreateEditDialog::addModelRow(int number, * Save selected object into the list of observed objects. */ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { - + initErrorMessage(); const QList &selectedObject = objectMgr->getSelectedObject(); if (!selectedObject.isEmpty()) { @@ -323,10 +329,10 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { JDs = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); // Location - QString Location = ""; + QString Location; StelLocation loc = core->getCurrentLocation(); if (loc.name.isEmpty()) { - Location = QString("%1, %2").arg(loc.latitude, loc.longitude); + Location = q_("Location not found"); } else { Location = QString("%1, %2").arg(loc.name, loc.region); } @@ -410,6 +416,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { * Slot for button obsListRemoveObjectButton */ void ObsListCreateEditDialog::obsListRemoveObjectButtonPressed() { + initErrorMessage(); int number = ui->obsListCreationEditionTreeView->currentIndex().row(); QString uuid = obsListListModel->index(number, ColumnUUID).data().toString(); obsListListModel->removeRow(number); @@ -574,6 +581,7 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { * Slot for button obsListExportListButton */ void ObsListCreateEditDialog::obsListExportListButtonPressed() { + initErrorMessage(); QString originalobservingListJsonPath = observingListJsonPath; QString filter = "JSON (*.json)"; @@ -587,35 +595,61 @@ void ObsListCreateEditDialog::obsListExportListButtonPressed() { * Slot for button obsListImportListButton */ void ObsListCreateEditDialog::obsListImportListButtonPresssed() { - QString originalobservingListJsonPath = observingListJsonPath; QString filter = "JSON (*.json)"; - observingListJsonPath = QFileDialog::getOpenFileName(Q_NULLPTR, q_("Import observing list"), QDir::homePath(), - filter); - + QString fileToImportJsonPath = QFileDialog::getOpenFileName(Q_NULLPTR, q_("Import observing list"), + QDir::homePath(), + filter); QVariantMap map; - QFile jsonFile(observingListJsonPath); + QFile jsonFile(fileToImportJsonPath); if (!jsonFile.open(QIODevice::ReadOnly)) { - qWarning() << "[ObservingList Creation/Edition] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); - + qWarning() << "[ObservingList Creation/Edition import] cannot open" + << QDir::toNativeSeparators(jsonFile.fileName()); } else { + try { + initErrorMessage(); map = StelJsonParser::parse(jsonFile.readAll()).toMap(); jsonFile.close(); - QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); - if (observingListMap.size() == 1) { - listOlud_ = observingListMap.keys().at(0).toStdString(); - } else { - // define error message if needed - return; + if (map.contains(KEY_OBSERVING_LISTS)) { // Case of observingList import + qDebug() << "ObservingList import"; + + QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap(); + if (!observingListMap.isEmpty() && observingListMap.size() == 1) { + listOlud_ = observingListMap.keys().at(0).toStdString(); + } else { + qWarning() + << "[ObservingList Creation/Edition import] there is no list or more than one list."; + displayErrorMessage("Error: here is no list or more than one list."); + return; + } + + QString originalobservingListJsonPath = observingListJsonPath; + observingListJsonPath = fileToImportJsonPath; + loadObservingList(); + observingListJsonPath = originalobservingListJsonPath; + } else if (map.contains(KEY_BOOKMARKS)) { // Case of legacy bookmarks import + qDebug() << "Legacy bookmarks import"; + QVariantMap bookmarksListMap = map.value(QString(KEY_BOOKMARKS)).toMap(); + if (!bookmarksListMap.isEmpty()) { + listOlud_ = bookmarksListMap.keys().at(0).toStdString(); + QString originalobservingListJsonPath = observingListJsonPath; + observingListJsonPath = fileToImportJsonPath; + loadBookmarksInObservingList(); + observingListJsonPath = originalobservingListJsonPath; + } else { + qWarning() + << "[ObservingList Creation/Edition import] the file is empty or doesn't contains legacy bookmarks."; + displayErrorMessage("Error: the file is empty or doesn't contains legacy bookmarks."); + return; + } } } catch (std::runtime_error &e) { qWarning() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); + displayErrorMessage("File format is wrong!"); return; } - loadObservingList(); - observingListJsonPath = originalobservingListJsonPath; } } @@ -623,8 +657,12 @@ void ObsListCreateEditDialog::obsListImportListButtonPresssed() { * Slot for button obsListSaveButton */ void ObsListCreateEditDialog::obsListSaveButtonPressed() { + initErrorMessage(); QString listName = ui->nameOfListLineEdit->text(); + //delete with space at the end of the name + listName = QString(listName).remove(QRegExp("([ ]+)$")); + // TODO il faut faire la comparaison du nom des liste en ignoreCase bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode || (listName.compare(currentListName) != 0 && !isCreationMode)); @@ -636,16 +674,12 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { .append(" already exists !"); qWarning() << "[ObservingList Creation/Edition] Error: a list with the name " << ui->nameOfListLineEdit->text() << " already exists !"; - ui->obsListErrorMessage->setHidden(false); - ui->obsListErrorMessage->setText(errorMessage); + std::string errorMessage_str = errorMessage.toStdString(); + displayErrorMessage(errorMessage_str.c_str()); } else if (ui->nameOfListLineEdit->text().isEmpty()) { - QString errorMessage; - errorMessage.append("Error: the list name is empty."); qWarning() << "[ObservingList Creation/Edition] Error: the list name is empty."; - ui->obsListErrorMessage->setHidden(false); - ui->obsListErrorMessage->setText(errorMessage); + displayErrorMessage("Error: the list name is empty."); } else { - ui->obsListErrorMessage->setHidden(true); if (listName.compare(currentListName) != 0 && !isCreationMode) { isSaveAs = true; } else { @@ -661,6 +695,8 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { * Slot for button obsListExitButton */ void ObsListCreateEditDialog::obsListExitButtonPressed() { + ui->obsListErrorMessage->setHidden(true); + ui->obsListErrorMessage->clear(); this->close(); emit exitButtonClicked(); } @@ -875,12 +911,157 @@ void ObsListCreateEditDialog::loadObservingList() { } } +/* +* Load the bookmarks of bookmarks.json file into observing lists file +* For no regression with must take into account the legacy bookmarks.json file +*/ +void ObsListCreateEditDialog::loadBookmarksInObservingList() { + QHash bookmarksCollection; + QVariantMap map; + + QFile jsonFile(observingListJsonPath); + if (!jsonFile.open(QIODevice::ReadOnly)) { + qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(observingListJsonPath); + } else { + + try { + + map = StelJsonParser::parse(jsonFile.readAll()).toMap(); + jsonFile.close(); + QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); + observingListItemCollection.clear(); + + for (auto bookmarkKey: bookmarksMap.keys()) { + + QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); + observingListItem item; + util.initItem(item); + QString objectUuid = QUuid::createUuid().toString(); + int lastRow = obsListListModel->rowCount(); + + // Name + QString objectName = bookmarkData.value(KEY_NAME).toString(); + item.name = objectName; + + // We need to select the object to add additional information that is not in the Bookmark file + if (objectMgr->findAndSelect(item.name) && !objectMgr->getSelectedObject().isEmpty()) { + const QList &selectedObject = objectMgr->getSelectedObject(); + + // Ra & Dec - ra and dec are not empty in case of Custom Object + QString raStr = bookmarkData.value(KEY_RA).toString(); + QString decStr = bookmarkData.value(KEY_DEC).toString(); + if (raStr.isEmpty() || decStr.isEmpty()) { + float ra, dec; + StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); + raStr = StelUtils::radToHmsStr(ra, false).trimmed(); + decStr = StelUtils::radToDmsStr(dec, false).trimmed(); + } + + if (!raStr.isEmpty()) { + item.ra = raStr; + } else { + item.ra = ""; + } + + if (!decStr.isEmpty()) { + item.dec = decStr; + } else { + item.dec = ""; + } + + // NameI18n + QString nameI18n = bookmarkData.value(KEY_NAME_I18N).toString(); + if (!nameI18n.isEmpty()) { + item.nameI18n = nameI18n; + } else { + item.nameI18n = ""; + } + + // JDs + QString JDs = bookmarkData.value(KEY_JD).toString(); + if (!JDs.isEmpty()) { + item.jd = JDs.toDouble(); + } else { + item.jd = 0.0; + } + + // Location + QString location = bookmarkData.value(KEY_LOCATION).toString(); + if (!location.isEmpty()) { + item.location = location; + } else { + item.location = ""; + } + + + // Constallation + QVariantMap objectMap = selectedObject[0]->getInfoMap(core); + QVariant objectConstellationVariant = objectMap["iauConstellation"]; + QString objectConstellation("unknown"); + if (objectConstellationVariant.canConvert()) { + objectConstellation = objectConstellationVariant.value(); + } + if (!objectConstellation.isEmpty()) { + item.constellation = objectConstellation; + } + + // Type + QString type = selectedObject[0]->getType(); + if (!type.isEmpty()) { + item.type = type; + } + + // Object Type + QString objectType = selectedObject[0]->getObjectType(); + if (!objectType.isEmpty()) { + item.objtype = objectType; + } + + // Magnitude + QString objectMagnitudeStr = util.getMagnitue(selectedObject, core); + if (!objectMagnitudeStr.isEmpty()) { + item.magnitude = objectMagnitudeStr; + } + + // Fov + double fov = bookmarkData.value(KEY_FOV).toDouble(); + if (fov > 0.0) { + item.fov = fov; + } + + // Visible marker + item.isVisibleMarker = bookmarkData.value(KEY_IS_VISIBLE_MARKER, false).toBool(); + + // Add data into model row + addModelRow(lastRow, + objectUuid, + objectName, + nameI18n, + objectType, + raStr, + decStr, + objectMagnitudeStr, + objectConstellation); + + observingListItemCollection.insert(objectUuid, item); + } + } + objectMgr->unSelect(); + } catch (std::runtime_error &e) { + qWarning() << "[ObservingList] Load bookmarks in observing list: File format is wrong! Error: " << e.what(); + return; + } + } +} + /* * Called when the text of the nameOfListLineEdit change */ void ObsListCreateEditDialog::nameOfListTextChange() { ui->obsListErrorMessage->setHidden(true); - if (ui->nameOfListLineEdit->text().isEmpty()) { + //delete with space -> no list with only white space as name + QString listeName = QString(ui->nameOfListLineEdit->text()).remove(QRegExp("([ ]+)$")); + if (listeName.isEmpty()) { ui->obsListSaveButton->setEnabled(false); } else { ui->obsListSaveButton->setEnabled(true); @@ -894,6 +1075,24 @@ void ObsListCreateEditDialog::setListName(QList listName) { this->listNames_ = std::move(listName); } +/* + * Initialize error mssage + */ +void ObsListCreateEditDialog::initErrorMessage() { + ui->obsListErrorMessage->setHidden(true); + ui->obsListErrorMessage->clear(); +} + +/* + * Display error message + */ +void ObsListCreateEditDialog::displayErrorMessage(const char *message) { + QString errorMessage; + errorMessage.append(q_(message)); + ui->obsListErrorMessage->setHidden(false); + ui->obsListErrorMessage->setText(errorMessage); +} + /* * Destructor of singleton */ diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 280bee2888cf1..3b54bbd93d221 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -102,6 +102,15 @@ Q_OBJECT //! Load the observing liste in case of edit mode void loadObservingList(); + //! Load bookmark in observing list for import. + void loadBookmarksInObservingList(); + + //! Initialize the error message (obsListErrorMessage). + void initErrorMessage(); + + //! Display the error message. + void displayErrorMessage(const char *message); + //Private constructor and destructor explicit ObsListCreateEditDialog(std::string listUuid); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 66e910a56b79d..51bd558c1b404 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -48,7 +48,7 @@ using namespace std; ObsListDialog::ObsListDialog(QObject *parent) : StelDialog("Observing list", parent), ui(new Ui_obsListDialogForm()), obsListListModel(new QStandardItemModel(0, ColumnCount)), core(StelApp::getInstance().getCore()), - createEditDialog_instance(Q_NULLPTR) { + currentJd(core->getJD()), createEditDialog_instance(Q_NULLPTR) { objectMgr = GETSTELMODULE (StelObjectMgr); labelMgr = GETSTELMODULE (LabelMgr); @@ -65,9 +65,6 @@ ObsListDialog::ObsListDialog(QObject *parent) : StelDialog("Observing list", par "/" + QString(JSON_BOOKMARKS_FILE_NAME); - currentJd = core->getJD(); - - } ObsListDialog::~ObsListDialog() { @@ -104,6 +101,7 @@ void ObsListDialog::createDialogContent() { ui->obsListTreeView->setModel(obsListListModel); ui->obsListTreeView->header()->setSectionsMovable(false); ui->obsListTreeView->header()->setSectionResizeMode(ColumnName, QHeaderView::ResizeToContents); + ui->obsListTreeView->header()->setSectionResizeMode(ColumnNameI18n, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setSectionResizeMode(ColumnType, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setSectionResizeMode(ColumnRa, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); @@ -113,7 +111,7 @@ void ObsListDialog::createDialogContent() { ui->obsListTreeView->header()->setSectionResizeMode(ColumnLocation, QHeaderView::ResizeToContents); ui->obsListTreeView->header()->setStretchLastSection(true); ui->obsListTreeView->hideColumn(ColumnUUID); - ui->obsListTreeView->hideColumn(ColumnNameI18n); + //Enable the sort for columns ui->obsListTreeView->setSortingEnabled(true); @@ -151,7 +149,7 @@ void ObsListDialog::createDialogContent() { * Retranslate dialog */ void ObsListDialog::retranslate() { - if (dialog) { + if (dialog != nullptr) { ui->retranslateUi(dialog); setObservingListHeaderNames(); } @@ -171,8 +169,8 @@ void ObsListDialog::styleChanged() { void ObsListDialog::setObservingListHeaderNames() { const QStringList headerStrings = { "UUID", // Hidden column + q_ ("Object designation"), q_ ("Object name"), - q_ ("Object name I18N"), // Hidden column q_ ("Type"), q_ ("Right ascension"), q_ ("Declination"), @@ -526,7 +524,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu if (Location.isEmpty()) { StelLocation loc = core->getCurrentLocation(); if (loc.name.isEmpty()) { - Location = QString("%1, %2").arg(loc.latitude).arg(loc.longitude); + Location = q_("Location not found"); } else { Location = QString("%1, %2").arg(loc.name).arg(loc.region); } @@ -732,25 +730,6 @@ void ObsListDialog::loadBookmarksInObservingList() { } // Magnitude - // TODO sortir ce code dans une méthode - /*QString objectMagnitudeStr; - float objectMagnitude = selectedObject[0]->getVMagnitude(core); - const float unknownMagnitude = 99; - if (objectMagnitude == unknownMagnitude) { - if (QString::compare(type, "Nebula", Qt::CaseSensitive) == 0) { - auto &r_nebula = dynamic_cast(*selectedObject[0]); - float mB = r_nebula.getBMagnitude(core); - if (mB == unknownMagnitude) { - objectMagnitudeStr = "–"; - } else { - objectMagnitudeStr = QString::number(mB); - } - } else { - objectMagnitudeStr = "–"; - } - } else { - objectMagnitudeStr = QString::number(objectMagnitude); - }*/ QString objectMagnitudeStr = util.getMagnitue(selectedObject, core); if (!objectMagnitudeStr.isEmpty()) { item.magnitude = objectMagnitudeStr; @@ -770,6 +749,7 @@ void ObsListDialog::loadBookmarksInObservingList() { } saveBookmarksInObsListJsonFile(bookmarksCollection); + objectMgr->unSelect(); } catch (std::runtime_error &e) { qWarning() << "[ObservingList] Load bookmarks in observing list: File format is wrong! Error: " << e.what(); diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 7e0e42979be31..0c94d54c9ab14 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -21,6 +21,8 @@ #define OBSERVINGLISTCOMMON_H #include "Nebula.hpp" +#include "StelTranslator.hpp" +#include struct observingListItem { QString name; From e3191c84ffecf6872311979620f456324f3b0c19 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 5 Aug 2022 13:36:11 +0200 Subject: [PATCH 20/28] ObservingLists-fix Visible marker corrections. --- src/gui/ObsListCreateEditDialog.cpp | 19 +++++++++-------- src/gui/ObsListDialog.cpp | 32 +++++++++++++++-------------- src/gui/ObsListDialog.hpp | 4 ++-- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 2c91ae1ce0a96..e66ade89f8dfc 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -294,6 +294,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { QString objectDecStr = ""; bool visibleFlag = false; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); + if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); } @@ -337,10 +338,6 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { Location = QString("%1, %2").arg(loc.name, loc.region); } - // TODO only for test: delete after - // objectName = "Unnamed object"; - // ********************************* - // Check if the object name is empty. if (objectName.isEmpty()) { objectName = q_("Unnamed object"); @@ -519,6 +516,9 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { // Constellation obl.insert(QString(KEY_CONSTELLATION), item.constellation); + // Visible marker + obl.insert(QString(KEY_IS_VISIBLE_MARKER),item.isVisibleMarker); + listOfObjects.push_back(obl); } observingListDataList.insert(QString(KEY_OBJECTS), listOfObjects); @@ -794,7 +794,6 @@ void ObsListCreateEditDialog::loadObservingList() { objectMap = object.value(); int lastRow = obsListListModel->rowCount(); QString objectUuid = QUuid::createUuid().toString(); - bool visibleFlag = false; // Name QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); @@ -827,6 +826,10 @@ void ObsListCreateEditDialog::loadObservingList() { // Location QString location = objectMap.value(QString(KEY_LOCATION)).value(); + // Visible flag + bool visibleFlag = objectMap.value(QString(KEY_IS_VISIBLE_MARKER)).value(); + + // Add data into model row addModelRow(lastRow, @@ -931,7 +934,7 @@ void ObsListCreateEditDialog::loadBookmarksInObservingList() { QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); observingListItemCollection.clear(); - for (auto bookmarkKey: bookmarksMap.keys()) { + for (const auto& bookmarkKey: bookmarksMap.keys()) { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); observingListItem item; @@ -951,7 +954,8 @@ void ObsListCreateEditDialog::loadBookmarksInObservingList() { QString raStr = bookmarkData.value(KEY_RA).toString(); QString decStr = bookmarkData.value(KEY_DEC).toString(); if (raStr.isEmpty() || decStr.isEmpty()) { - float ra, dec; + float ra = 0.0; + float dec = 0.0; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); raStr = StelUtils::radToHmsStr(ra, false).trimmed(); decStr = StelUtils::radToDmsStr(dec, false).trimmed(); @@ -993,7 +997,6 @@ void ObsListCreateEditDialog::loadBookmarksInObservingList() { item.location = ""; } - // Constallation QVariantMap objectMap = selectedObject[0]->getInfoMap(core); QVariant objectConstellationVariant = objectMap["iauConstellation"]; diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 51bd558c1b404..c432124b261e4 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -255,7 +255,7 @@ void ObsListDialog::obsListHighLightAllButtonPressed() { QString decStr = item.dec.trimmed(); Vec3d pos; - bool status = false; + bool status; if (!raStr.isEmpty() && !decStr.isEmpty()) { StelUtils::spheToRect(StelUtils::getDecAngle(raStr), StelUtils::getDecAngle(decStr), pos); status = true; @@ -473,7 +473,6 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu int lastRow = obsListListModel->rowCount(); QString objectUuid = QUuid::createUuid().toString(); QString objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); - bool visibleFlag = false; double fov = -1.0; // Type @@ -536,6 +535,9 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu fov = fovStr.toDouble(); } + // Visible flag + bool visibleFlag = objectMap.value(QString(KEY_IS_VISIBLE_MARKER)).value(); + addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation, date, Location); @@ -646,7 +648,7 @@ void ObsListDialog::loadBookmarksInObservingList() { jsonFile.close(); QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); - for (auto bookmarkKey: bookmarksMap.keys()) { + for (const auto& bookmarkKey: bookmarksMap.keys()) { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); observingListItem item; @@ -663,7 +665,8 @@ void ObsListDialog::loadBookmarksInObservingList() { QString raStr = bookmarkData.value(KEY_RA).toString(); QString decStr = bookmarkData.value(KEY_DEC).toString(); if (raStr.isEmpty() || decStr.isEmpty()) { - float ra, dec; + float ra = 0.0; + float dec = 0.0; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); raStr = StelUtils::radToHmsStr(ra, false).trimmed(); decStr = StelUtils::radToDmsStr(dec, false).trimmed(); @@ -705,7 +708,6 @@ void ObsListDialog::loadBookmarksInObservingList() { item.location = ""; } - // Constallation QVariantMap objectMap = selectedObject[0]->getInfoMap(core); QVariant objectConstellationVariant = objectMap["iauConstellation"]; @@ -850,6 +852,9 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash bool { +auto ObsListDialog::checkIfBookmarksListExists(const QVariantMap& allListsMap) -> bool { for (auto bookmarkKey: allListsMap.keys()) { @@ -961,12 +966,12 @@ void ObsListDialog::selectAndGoToObject(QModelIndex index) { Vec3d winpos; prj->project(pos, winpos); - float xpos = winpos[0]; - float ypos = winpos[1]; - float best_object_value = 1000.f; + double xpos = winpos[0]; + double ypos = winpos[1]; + float best_object_value = 1000.F; for (const auto &obj: candidates) { prj->project(obj->getJ2000EquatorialPos(core), winpos); - float distance = std::sqrt( + double distance = std::sqrt( (xpos - winpos[0]) * (xpos - winpos[0]) + (ypos - winpos[1]) * (ypos - winpos[1])); if (distance < best_object_value) { best_object_value = distance; @@ -974,7 +979,7 @@ void ObsListDialog::selectAndGoToObject(QModelIndex index) { } } - if (sobj) { + if (sobj != nullptr) { status = objectMgr->setSelectedObject(sobj); } } @@ -1094,9 +1099,6 @@ void ObsListDialog::obsListCreateEditDialogClosed() { loadSelectedObservingList(index); } - //TODO remove after - qDebug() << "obsListCreateEditDialogClosed() before kill ObsListCreateEditDialog"; - ObsListCreateEditDialog::kill(); createEditDialog_instance = Q_NULLPTR; } @@ -1140,7 +1142,7 @@ void ObsListDialog::setVisible(bool v) { /* * Sort the obsListTreeView by the column name given in parameter */ -void ObsListDialog::sortObsListTreeViewByColumnName(QString columnName) { +void ObsListDialog::sortObsListTreeViewByColumnName(const QString& columnName) { if (QString::compare(columnName, SORTING_BY_NAME) == 0) { obsListListModel->sort(COLUMN_NUMBER_NAME, Qt::AscendingOrder); } else if (QString::compare(columnName, SORTING_BY_TYPE) == 0) { diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index a7e98da95dfc4..df60051cadee1 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -107,7 +107,7 @@ Q_OBJECT void saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection); - auto checkIfBookmarksListExists(QVariantMap allListsMap) -> bool; + auto checkIfBookmarksListExists(const QVariantMap& allListsMap) -> bool; //! Load list from JSON file auto loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList; @@ -119,7 +119,7 @@ Q_OBJECT void populateDataInComboBox(QVariantMap map, const QString &defaultListOlud); //! Sort the obsListTreeView by the column name given in parameter - void sortObsListTreeViewByColumnName(QString columnName); + void sortObsListTreeViewByColumnName(const QString& columnName); //! Clear highlights void clearHighlight(); From b049e5a954c05d48f9ab731394880eca4e7934de Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Mon, 8 Aug 2022 13:33:32 +0200 Subject: [PATCH 21/28] ObservingLists V2 Adding nameI18N in sort --- src/gui/ObsListCreateEditDialog.cpp | 5 ++++- src/gui/ObsListDialog.cpp | 9 +++++++-- src/gui/ObservingListCommon.hpp | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index e66ade89f8dfc..08b6860c06873 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -333,7 +333,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { QString Location; StelLocation loc = core->getCurrentLocation(); if (loc.name.isEmpty()) { - Location = q_("Location not found"); + Location = ""; } else { Location = QString("%1, %2").arg(loc.name, loc.region); } @@ -717,6 +717,9 @@ void ObsListCreateEditDialog::headerClicked(int index) { case ColumnName: sorting = QString(SORTING_BY_NAME); break; + case ColumnNameI18n: + sorting = QString(SORTING_BY_NAMEI18N); + break; case ColumnType: sorting = QString(SORTING_BY_TYPE); break; diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index c432124b261e4..ccb73d2e6073e 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -459,10 +459,13 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu listOfObjects = loadListFromJson(map, listOlud); + // TODO check if it is possible to have an empty list. If no the delete button must be disabled. + ui->obsListDeleteButton->setEnabled(true); + if (!listOfObjects.isEmpty()) { ui->obsListHighlightAllButton->setEnabled(true); ui->obsListClearHighlightButton->setEnabled(true); - ui->obsListDeleteButton->setEnabled(true); + //ui->obsListDeleteButton->setEnabled(true); for (const QVariant &object: listOfObjects) { QVariantMap objectMap; @@ -582,7 +585,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu } else { ui->obsListHighlightAllButton->setEnabled(false); ui->obsListClearHighlightButton->setEnabled(false); - ui->obsListDeleteButton->setEnabled(false); + //ui->obsListDeleteButton->setEnabled(false); } objectMgr->unSelect(); @@ -1145,6 +1148,8 @@ void ObsListDialog::setVisible(bool v) { void ObsListDialog::sortObsListTreeViewByColumnName(const QString& columnName) { if (QString::compare(columnName, SORTING_BY_NAME) == 0) { obsListListModel->sort(COLUMN_NUMBER_NAME, Qt::AscendingOrder); + } else if (QString::compare(columnName, SORTING_BY_NAMEI18N) == 0) { + obsListListModel->sort(COLUMN_NUMBER_NAMEI18N, Qt::AscendingOrder); } else if (QString::compare(columnName, SORTING_BY_TYPE) == 0) { obsListListModel->sort(COLUMN_NUMBER_TYPE, Qt::AscendingOrder); } else if (QString::compare(columnName, SORTING_BY_RA) == 0) { diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 0c94d54c9ab14..6d8243576d08c 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -88,6 +88,7 @@ static constexpr char const *KEY_SHORT_NAME = "shortName"; static constexpr char const *KEY_IS_VISIBLE_MARKER = "isVisibleMarker"; static constexpr char const *SORTING_BY_NAME = "name"; +static constexpr char const *SORTING_BY_NAMEI18N = "nameI18n"; static constexpr char const *SORTING_BY_TYPE = "type"; static constexpr char const *SORTING_BY_RA = "right ascension"; static constexpr char const *SORTING_BY_DEC = "declination"; @@ -95,6 +96,7 @@ static constexpr char const *SORTING_BY_MAGNITUDE = "magnitude"; static constexpr char const *SORTING_BY_CONSTELLATION = "constellation"; static constexpr int COLUMN_NUMBER_NAME = 1; +static constexpr int COLUMN_NUMBER_NAMEI18N = 2; static constexpr int COLUMN_NUMBER_TYPE = 3; static constexpr int COLUMN_NUMBER_RA = 4; static constexpr int COLUMN_NUMBER_DEC = 5; From a9d78a676156f012495f9f6a838d00aa3d1df00c Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Tue, 9 Aug 2022 13:53:48 +0200 Subject: [PATCH 22/28] ObservingLists V2 Regex correction --- src/gui/ObsListCreateEditDialog.cpp | 6 +++--- src/gui/ObsListDialog.cpp | 6 +++--- src/gui/ObsListDialog.hpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 08b6860c06873..30a2f44ff1470 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "NebulaMgr.hpp" #include "StelCore.hpp" @@ -517,7 +518,7 @@ void ObsListCreateEditDialog::saveObservedObjectsInJsonFile() { obl.insert(QString(KEY_CONSTELLATION), item.constellation); // Visible marker - obl.insert(QString(KEY_IS_VISIBLE_MARKER),item.isVisibleMarker); + obl.insert(QString(KEY_IS_VISIBLE_MARKER), item.isVisibleMarker); listOfObjects.push_back(obl); } @@ -922,7 +923,6 @@ void ObsListCreateEditDialog::loadObservingList() { * For no regression with must take into account the legacy bookmarks.json file */ void ObsListCreateEditDialog::loadBookmarksInObservingList() { - QHash bookmarksCollection; QVariantMap map; QFile jsonFile(observingListJsonPath); @@ -937,7 +937,7 @@ void ObsListCreateEditDialog::loadBookmarksInObservingList() { QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); observingListItemCollection.clear(); - for (const auto& bookmarkKey: bookmarksMap.keys()) { + for (const auto &bookmarkKey: bookmarksMap.keys()) { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); observingListItem item; diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index ccb73d2e6073e..6361d0e08852d 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -651,7 +651,7 @@ void ObsListDialog::loadBookmarksInObservingList() { jsonFile.close(); QVariantMap bookmarksMap = map.value(KEY_BOOKMARKS).toMap(); - for (const auto& bookmarkKey: bookmarksMap.keys()) { + for (const auto &bookmarkKey: bookmarksMap.keys()) { QVariantMap bookmarkData = bookmarksMap.value(bookmarkKey).toMap(); observingListItem item; @@ -895,7 +895,7 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash bool { +auto ObsListDialog::checkIfBookmarksListExists(const QVariantMap &allListsMap) -> bool { for (auto bookmarkKey: allListsMap.keys()) { @@ -1145,7 +1145,7 @@ void ObsListDialog::setVisible(bool v) { /* * Sort the obsListTreeView by the column name given in parameter */ -void ObsListDialog::sortObsListTreeViewByColumnName(const QString& columnName) { +void ObsListDialog::sortObsListTreeViewByColumnName(const QString &columnName) { if (QString::compare(columnName, SORTING_BY_NAME) == 0) { obsListListModel->sort(COLUMN_NUMBER_NAME, Qt::AscendingOrder); } else if (QString::compare(columnName, SORTING_BY_NAMEI18N) == 0) { diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index df60051cadee1..31244737e2eac 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -107,7 +107,7 @@ Q_OBJECT void saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection); - auto checkIfBookmarksListExists(const QVariantMap& allListsMap) -> bool; + auto checkIfBookmarksListExists(const QVariantMap &allListsMap) -> bool; //! Load list from JSON file auto loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList; @@ -119,7 +119,7 @@ Q_OBJECT void populateDataInComboBox(QVariantMap map, const QString &defaultListOlud); //! Sort the obsListTreeView by the column name given in parameter - void sortObsListTreeViewByColumnName(const QString& columnName); + void sortObsListTreeViewByColumnName(const QString &columnName); //! Clear highlights void clearHighlight(); From bca55def8fc3d7b42419e9b2afe70756d12ed0fa Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 10 Aug 2022 13:35:30 +0200 Subject: [PATCH 23/28] ObservingLists V2 Regex modifications and Clang-Tidy corections. --- src/gui/ObsListCreateEditDialog.cpp | 58 +++++++++++++--------------- src/gui/ObsListCreateEditDialog.hpp | 8 ++-- src/gui/ObsListDialog.cpp | 59 ++++++++++++++--------------- src/gui/ObsListDialog.hpp | 4 +- 4 files changed, 60 insertions(+), 69 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 30a2f44ff1470..4cd25e193de5b 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "NebulaMgr.hpp" #include "StelCore.hpp" @@ -114,7 +114,6 @@ void ObsListCreateEditDialog::createDialogContent() { ui->obsListCreationEditionTreeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); ui->obsListCreationEditionTreeView->header()->setStretchLastSection(true); ui->obsListCreationEditionTreeView->hideColumn(ColumnUUID); - //ui->obsListCreationEditionTreeView->hideColumn(ColumnNameI18n); ui->obsListCreationEditionTreeView->hideColumn(ColumnDate); ui->obsListCreationEditionTreeView->hideColumn(ColumnLocation); // Enable the sort for columns @@ -132,8 +131,8 @@ void ObsListCreateEditDialog::createDialogContent() { // In case of creation the nameOfListLineEdit is empty and button save/close must be disabled // In case on edition the nameOfListLineEdit is not empty and the button save/close must be enable - //delete with space -> no list with only white space as name - ui->nameOfListLineEdit->setText(QString(ui->nameOfListLineEdit->text()).remove(QRegExp("([ ]+)$"))); + // delete with space -> no list with only white space as name + ui->nameOfListLineEdit->setText(QString(ui->nameOfListLineEdit->text()).remove(QRegularExpression("([ ]+)$"))); if (ui->nameOfListLineEdit->text().isEmpty()) { ui->obsListSaveButton->setEnabled(false); } else { @@ -195,7 +194,7 @@ void ObsListCreateEditDialog::setObservingListHeaderNames() { * Add row in the obsListListModel */ void ObsListCreateEditDialog::addModelRow(int number, - const QString &uuid, + const QString &olud, const QString &name, const QString &nameI18n, const QString &objtype, @@ -206,7 +205,7 @@ void ObsListCreateEditDialog::addModelRow(int number, QStandardItem *item = Q_NULLPTR; // olud - item = new QStandardItem(uuid); + item = new QStandardItem(olud); item->setEditable(false); obsListListModel->setItem(number, ColumnUUID, item); @@ -272,7 +271,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { if (!is_already_in_list) { const int lastRow = obsListListModel->rowCount(); - const QString objectUuid = QUuid::createUuid().toString(); + const QString objectOlud = QUuid::createUuid().toString(); // Object name (designation) and object name I18n QString objectName = selectedObject[0]->getEnglishName(); @@ -349,7 +348,7 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Add objects in row model addModelRow(lastRow, - objectUuid, + objectOlud, objectName, objectNameI18n, objectType, @@ -403,10 +402,10 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { if (fov > 0.0) { item.fov = fov; } - observingListItemCollection.insert(objectUuid, item); + observingListItemCollection.insert(objectOlud, item); } } else { - qWarning() << "selected object is empty !"; + qWarning() << "Selected object is empty !"; } } @@ -664,7 +663,6 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { //delete with space at the end of the name listName = QString(listName).remove(QRegExp("([ ]+)$")); - // TODO il faut faire la comparaison du nom des liste en ignoreCase bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode || (listName.compare(currentListName) != 0 && !isCreationMode)); @@ -681,11 +679,7 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { qWarning() << "[ObservingList Creation/Edition] Error: the list name is empty."; displayErrorMessage("Error: the list name is empty."); } else { - if (listName.compare(currentListName) != 0 && !isCreationMode) { - isSaveAs = true; - } else { - isSaveAs = false; - } + isSaveAs = listName.compare(currentListName) != 0 && !isCreationMode; saveObservedObjectsInJsonFile(); this->close(); emit exitButtonClicked(); @@ -768,18 +762,18 @@ void ObsListCreateEditDialog::loadObservingList() { QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(keyOlud).toMap(); QVariantList listOfObjects; - QString listName = observingListMap.value(QString(KEY_NAME)).value(); + auto listName = observingListMap.value(QString(KEY_NAME)).value(); // List name currentListName = listName; ui->nameOfListLineEdit->setText(listName); // List description - QString listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); + auto listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); ui->descriptionLineEdit->setText(listDescription); // Landscape - QString landscape = observingListMap.value(QString(KEY_LANDSCAPE_ID)).value(); + auto landscape = observingListMap.value(QString(KEY_LANDSCAPE_ID)).value(); if (!landscape.isEmpty()) { ui->obsListLandscapeCheckBox->setChecked(true); } @@ -797,38 +791,38 @@ void ObsListCreateEditDialog::loadObservingList() { if (object.canConvert()) { objectMap = object.value(); int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); + QString objectOlud = QUuid::createUuid().toString(); // Name - QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); + auto objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); // NameI18n - QString objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); + auto objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); // Fov auto fov = objectMap.value(QString(KEY_FOV)).value(); // Object type - QString type = objectMap.value(QString(KEY_TYPE)).value(); + auto type = objectMap.value(QString(KEY_TYPE)).value(); // Object type - QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); + auto objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); // Ra & dec - QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); - QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + auto objectRaStr = objectMap.value(QString(KEY_RA)).value(); + auto objectDecStr = objectMap.value(QString(KEY_DEC)).value(); // Magnitude - QString objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); + auto objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); // Constellation - QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); + auto objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); // Julian Day - QString JDs = objectMap.value(QString(KEY_JD)).value(); + auto JDs = objectMap.value(QString(KEY_JD)).value(); // Location - QString location = objectMap.value(QString(KEY_LOCATION)).value(); + auto location = objectMap.value(QString(KEY_LOCATION)).value(); // Visible flag bool visibleFlag = objectMap.value(QString(KEY_IS_VISIBLE_MARKER)).value(); @@ -837,7 +831,7 @@ void ObsListCreateEditDialog::loadObservingList() { // Add data into model row addModelRow(lastRow, - objectUuid, + objectOlud, objectName, objectNameI18n, objectType, @@ -901,7 +895,7 @@ void ObsListCreateEditDialog::loadObservingList() { if (fov > 0.0) { item.fov = fov; } - observingListItemCollection.insert(objectUuid, item); + observingListItemCollection.insert(objectOlud, item); } else { qCritical() << "[ObservingList Creation/Edition] conversion error"; diff --git a/src/gui/ObsListCreateEditDialog.hpp b/src/gui/ObsListCreateEditDialog.hpp index 3b54bbd93d221..18b17f361a168 100644 --- a/src/gui/ObsListCreateEditDialog.hpp +++ b/src/gui/ObsListCreateEditDialog.hpp @@ -55,8 +55,8 @@ Q_OBJECT Ui_obsListCreateEditDialogForm *ui; //! To know if the dialog is open in creation mode or editionn mode // if true we are in creation mode otherwise in edition mode - bool isCreationMode; - bool isSaveAs; + bool isCreationMode{}; + bool isSaveAs{}; QStandardItemModel *obsListListModel; class StelCore *core; @@ -86,14 +86,14 @@ Q_OBJECT //! Add row in the obsListListModel //! @param number row number - //! @param uuid id of the record + //! @param olud id of the record //! @param name name or the designation of the object //! @param type type of the object //! @param ra right ascension of the object //! @param dec declination of the object //! @param magnitude magnitude of the object //! @param constellation constellation in which the object is located - void addModelRow(int number, const QString &uuid, const QString &name, const QString &nameI18n, const QString &type, + void addModelRow(int number, const QString &olud, const QString &name, const QString &nameI18n, const QString &type, const QString &ra, const QString &dec, const QString &magnitude, const QString &constellation); //! Save the object informations into json file diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 6361d0e08852d..d02308eb854d6 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -36,7 +36,6 @@ #include "ObsListDialog.hpp" #include "LabelMgr.hpp" #include "Planet.hpp" -#include "Nebula.hpp" #include "ui_obsListDialog.h" #include @@ -132,7 +131,6 @@ void ObsListDialog::createDialogContent() { // For no regression we must take into account the legacy bookmarks file QFile jsonBookmarksFile(bookmarksJsonPath); if (jsonBookmarksFile.exists()) { - qDebug() << "Fichiers bookmarks détecté"; loadBookmarksInObservingList(); } @@ -303,10 +301,9 @@ void ObsListDialog::clearHighlight() { * Slot for button obsListNewListButton */ void ObsListDialog::obsListNewListButtonPressed() { - string listUuid = string(); - invokeObsListCreateEditDialog(listUuid); + string olud = string(); + invokeObsListCreateEditDialog(olud); } - /* * Slot for button obsListEditButton */ @@ -314,7 +311,7 @@ void ObsListDialog::obsListEditButtonPressed() { if (!selectedObservingListUuid.empty()) { invokeObsListCreateEditDialog(selectedObservingListUuid); } else { - qWarning() << "The selected observing list uuid is empty"; + qWarning() << "The selected observing list olud is empty"; } } @@ -369,8 +366,8 @@ void ObsListDialog::populateListNameInComboBox(QVariantMap map) { for (i = map.begin(); i != map.end(); ++i) { if (i.value().canConvert()) { QVariant var = i.value(); - QVariantMap data = var.value(); - QString listName = data.value(KEY_NAME).value(); + auto data = var.value(); + auto listName = data.value(KEY_NAME).value(); listNamesModel.append(listName); listName_.append(listName); } @@ -388,8 +385,8 @@ void ObsListDialog::populateDataInComboBox(QVariantMap map, const QString &defau const QString &listUuid = i.key(); if (i.value().canConvert()) { QVariant var = i.value(); - QVariantMap data = var.value(); - QString listName = data.value(KEY_NAME).value(); + auto data = var.value(); + auto listName = data.value(KEY_NAME).value(); foreach (QString str, listNamesModel) { if (QString::compare(str, listName) == 0) { @@ -471,19 +468,19 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu QVariantMap objectMap; if (object.canConvert()) { objectMap = object.value(); - QString objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); + auto objectName = objectMap.value(QString(KEY_DESIGNATION)).value(); int lastRow = obsListListModel->rowCount(); - QString objectUuid = QUuid::createUuid().toString(); - QString objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); + QString objectOlud = QUuid::createUuid().toString(); + auto objectNameI18n = objectMap.value(QString(KEY_NAME_I18N)).value(); double fov = -1.0; // Type - QString objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); + auto objectType = objectMap.value(QString(KEY_OBJECTS_TYPE)).value(); // RA & DEC - QString objectRaStr = objectMap.value(QString(KEY_RA)).value(); - QString objectDecStr = objectMap.value(QString(KEY_DEC)).value(); + auto objectRaStr = objectMap.value(QString(KEY_RA)).value(); + auto objectDecStr = objectMap.value(QString(KEY_DEC)).value(); if (objectMgr->findAndSelect(objectName) && !objectMgr->getSelectedObject().isEmpty()) { const QList &selectedObject = objectMgr->getSelectedObject(); @@ -503,13 +500,13 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu } // Magnitude - QString objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); + auto objectMagnitudeStr = objectMap.value(QString(KEY_MAGNITUDE)).value(); // Constellation - QString objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); + auto objectConstellation = objectMap.value(QString(KEY_CONSTELLATION)).value(); // Julian Day / Date - QString JDs = objectMap.value(QString(KEY_JD)).value(); + auto JDs = objectMap.value(QString(KEY_JD)).value(); QString date = ""; if (JDs.isEmpty() || QString::compare(JDs, "0", Qt::CaseSensitive) == 0) { double JD = core->getJD(); @@ -522,7 +519,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu // Location - QString Location = objectMap.value(QString(KEY_LOCATION)).value(); + auto Location = objectMap.value(QString(KEY_LOCATION)).value(); if (Location.isEmpty()) { StelLocation loc = core->getCurrentLocation(); if (loc.name.isEmpty()) { @@ -533,7 +530,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu } // Fov - QString fovStr = objectMap.value(QString(KEY_FOV)).value(); + auto fovStr = objectMap.value(QString(KEY_FOV)).value(); if (!fovStr.isEmpty()) { fov = fovStr.toDouble(); } @@ -541,7 +538,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu // Visible flag bool visibleFlag = objectMap.value(QString(KEY_IS_VISIBLE_MARKER)).value(); - addModelRow(lastRow, objectUuid, objectName, objectNameI18n, objectType, objectRaStr, + addModelRow(lastRow, objectOlud, objectName, objectNameI18n, objectType, objectRaStr, objectDecStr, objectMagnitudeStr, objectConstellation, date, Location); observingListItem item; @@ -575,7 +572,7 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu item.fov = fov; } - observingListItemCollection.insert(objectUuid, item); + observingListItemCollection.insert(objectOlud, item); } else { qCritical() << "[ObservingList] conversion error"; @@ -606,17 +603,17 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu /* * Load the list from JSON file QVariantMap map */ -auto ObsListDialog::loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList { +auto ObsListDialog::loadListFromJson(const QVariantMap &map, const QString& listOlud) -> QVariantList { observingListItemCollection.clear(); QVariantMap observingListMap = map.value(QString(KEY_OBSERVING_LISTS)).toMap().value(listOlud).toMap(); QVariantList listOfObjects; - QString listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); + auto listDescription = observingListMap.value(QString(KEY_DESCRIPTION)).value(); ui->obsListDescriptionTextEdit->setPlainText(listDescription); // Displaying the creation date - QString listCreationDate = observingListMap.value(QString(KEY_CREATION_DATE)).value(); + auto listCreationDate = observingListMap.value(QString(KEY_CREATION_DATE)).value(); ui->obsListCreationDateLineEdit->setText(listCreationDate); if (observingListMap.value(QString(KEY_OBJECTS)).canConvert()) { @@ -897,7 +894,7 @@ void ObsListDialog::saveBookmarksInObsListJsonFile(const QHash bool { - for (auto bookmarkKey: allListsMap.keys()) { + for (const auto& bookmarkKey: allListsMap.keys()) { QVariantMap bookmarkData = allListsMap.value(bookmarkKey).toMap(); QString listName = bookmarkData.value(KEY_NAME).toString(); @@ -971,7 +968,7 @@ void ObsListDialog::selectAndGoToObject(QModelIndex index) { prj->project(pos, winpos); double xpos = winpos[0]; double ypos = winpos[1]; - float best_object_value = 1000.F; + double best_object_value = 1000.F; for (const auto &obj: candidates) { prj->project(obj->getJ2000EquatorialPos(core), winpos); double distance = std::sqrt( @@ -1107,13 +1104,12 @@ void ObsListDialog::obsListCreateEditDialogClosed() { } /* - * Etract the defaultListOlud from the Json file. + * Extract the defaultListOlud from the Json file. */ -QString ObsListDialog::extractDefaultListOludFromJsonFile() { +auto ObsListDialog::extractDefaultListOludFromJsonFile() -> QString { QFile jsonFile(observingListJsonPath); if (!jsonFile.open(QIODevice::ReadOnly)) { qWarning() << "[ObservingList] cannot open" << QDir::toNativeSeparators(JSON_FILE_NAME); - } else { try { QVariantMap map = StelJsonParser::parse(jsonFile.readAll()).toMap(); @@ -1127,6 +1123,7 @@ QString ObsListDialog::extractDefaultListOludFromJsonFile() { return ""; } } + return {}; } /* diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 31244737e2eac..c312ed2393b68 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -107,10 +107,10 @@ Q_OBJECT void saveBookmarksInObsListJsonFile(const QHash &bookmarksCollection); - auto checkIfBookmarksListExists(const QVariantMap &allListsMap) -> bool; + static auto checkIfBookmarksListExists(const QVariantMap &allListsMap) -> bool; //! Load list from JSON file - auto loadListFromJson(const QVariantMap &map, QString listOlud) -> QVariantList; + auto loadListFromJson(const QVariantMap &map, const QString& listOlud) -> QVariantList; //! Populate list names into combo box void populateListNameInComboBox(QVariantMap map); From 492782f483a053e1a10ea5a436a475e3d2f72fc2 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 10 Aug 2022 14:27:25 +0200 Subject: [PATCH 24/28] ObservingLists V2 Correction RegExp --- src/gui/ObsListCreateEditDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 4cd25e193de5b..2d5deb511d204 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -661,7 +661,7 @@ void ObsListCreateEditDialog::obsListSaveButtonPressed() { QString listName = ui->nameOfListLineEdit->text(); //delete with space at the end of the name - listName = QString(listName).remove(QRegExp("([ ]+)$")); + listName = QString(listName).remove(QRegularExpression("([ ]+)$")); bool isListAlreadyExists = !this->listNames_.isEmpty() && this->listNames_.contains(listName) && (isCreationMode || (listName.compare(currentListName) != 0 && !isCreationMode)); From 09d11d9476a8a93c590a44f6678a18c9251c5faa Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 10 Aug 2022 18:10:14 +0200 Subject: [PATCH 25/28] Correction RegExp. --- src/gui/ObsListCreateEditDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 2d5deb511d204..c7fce6ad34392 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -1060,7 +1060,7 @@ void ObsListCreateEditDialog::loadBookmarksInObservingList() { void ObsListCreateEditDialog::nameOfListTextChange() { ui->obsListErrorMessage->setHidden(true); //delete with space -> no list with only white space as name - QString listeName = QString(ui->nameOfListLineEdit->text()).remove(QRegExp("([ ]+)$")); + QString listeName = QString(ui->nameOfListLineEdit->text()).remove(QRegularExpression("([ ]+)$")); if (listeName.isEmpty()) { ui->obsListSaveButton->setEnabled(false); } else { From 5bb5495f6734a6e407e94a6981427ee0c610fc13 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Fri, 9 Sep 2022 17:45:57 +0200 Subject: [PATCH 26/28] ObservingLists-fix Ra & Dec checkbox are now Coordinates checkbox. --- src/gui/ObsListCreateEditDialog.cpp | 4 +--- src/gui/ObsListDialog.cpp | 1 - src/gui/obsListCreateEditDialog.ui | 19 +++---------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index c7fce6ad34392..321cc87e9e329 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -295,10 +295,8 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { bool visibleFlag = false; StelUtils::rectToSphe(&ra, &dec, selectedObject[0]->getJ2000EquatorialPos(core)); - if (ui->obsListRaCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { + if (ui->obsListCoordinatesCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { objectRaStr = StelUtils::radToHmsStr(ra, false).trimmed(); - } - if (ui->obsListDecCheckBox->isChecked() || objectType == CUSTOM_OBJECT || objectName.isEmpty()) { objectDecStr = StelUtils::radToDmsStr(dec, false).trimmed(); } diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index d02308eb854d6..f90f1070267da 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -456,7 +456,6 @@ void ObsListDialog::loadSelectedObservingListFromJsonFile(const QString &listOlu listOfObjects = loadListFromJson(map, listOlud); - // TODO check if it is possible to have an empty list. If no the delete button must be disabled. ui->obsListDeleteButton->setEnabled(true); if (!listOfObjects.isEmpty()) { diff --git a/src/gui/obsListCreateEditDialog.ui b/src/gui/obsListCreateEditDialog.ui index bf5623ec952f2..efb9aac2cc3d3 100644 --- a/src/gui/obsListCreateEditDialog.ui +++ b/src/gui/obsListCreateEditDialog.ui @@ -178,28 +178,15 @@ - + - Add right ascension + Add Ra & Dec coordinates 3 - Ra - - - - - - - Add declination - - - 3 - - - Dec + Coordinates (RA and DEC) From 21ecb8e50b6e71c88316f650a049de7e5612a223 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Sat, 10 Sep 2022 13:45:01 +0200 Subject: [PATCH 27/28] ObservingList-fix Magnitude and name correction --- src/gui/ObsListCreateEditDialog.cpp | 5 +++++ src/gui/ObsListDialog.cpp | 2 +- src/gui/ObservingListCommon.hpp | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 321cc87e9e329..37c922590269d 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -276,6 +276,11 @@ void ObsListCreateEditDialog::obsListAddObjectButtonPressed() { // Object name (designation) and object name I18n QString objectName = selectedObject[0]->getEnglishName(); QString objectNameI18n = selectedObject[0]->getNameI18n(); + + if(objectNameI18n.isEmpty()){ + objectNameI18n = dash; + } + StelObjectP object = objectMgr->searchByNameI18n(objectNameI18n); if (selectedObject[0]->getType() == "Nebula" && objectName.isEmpty()) { objectName = GETSTELMODULE(NebulaMgr)->getLatestSelectedDSODesignation(); diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index f90f1070267da..f7290d0ffcb1b 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -688,7 +688,7 @@ void ObsListDialog::loadBookmarksInObservingList() { if (!nameI18n.isEmpty()) { item.nameI18n = nameI18n; } else { - item.nameI18n = ""; + item.nameI18n = dash; } // JDs diff --git a/src/gui/ObservingListCommon.hpp b/src/gui/ObservingListCommon.hpp index 6d8243576d08c..24d1e3dd4045f 100644 --- a/src/gui/ObservingListCommon.hpp +++ b/src/gui/ObservingListCommon.hpp @@ -105,6 +105,8 @@ static constexpr int COLUMN_NUMBER_CONSTELLATION = 7; static constexpr char const *CUSTOM_OBJECT = "CustomObject"; +static const QString dash = QChar(0x2014); + class ObservingListUtil { public: @@ -135,21 +137,20 @@ class ObservingListUtil { QString objectMagnitudeStr; QString type = selectedObject[0]->getType(); float objectMagnitude = selectedObject[0]->getVMagnitude(core); - const float unknownMagnitude = 99; - if (objectMagnitude == unknownMagnitude) { + if (objectMagnitude > 98.f) { if (QString::compare(type, "Nebula", Qt::CaseSensitive) == 0) { auto &r_nebula = dynamic_cast(*selectedObject[0]); float mB = r_nebula.getBMagnitude(core); - if (mB == unknownMagnitude) { - objectMagnitudeStr = "–"; + if (mB > 98.f) { + objectMagnitudeStr = dash; } else { objectMagnitudeStr = QString::number(mB); } } else { - objectMagnitudeStr = "–"; + objectMagnitudeStr = dash; } } else { - objectMagnitudeStr = QString::number(objectMagnitude); + objectMagnitudeStr = QString::number(objectMagnitude, 'f', 2); } return objectMagnitudeStr; From 9ef9bd39f7c9f5bc58b6bb8206e50e77be098bc1 Mon Sep 17 00:00:00 2001 From: Jocelyn Date: Wed, 21 Sep 2022 18:27:22 +0200 Subject: [PATCH 28/28] ObservingList-fix SIGSEGV fix. --- src/gui/ObsListCreateEditDialog.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/ObsListCreateEditDialog.cpp b/src/gui/ObsListCreateEditDialog.cpp index 37c922590269d..36cc55f5f2513 100644 --- a/src/gui/ObsListCreateEditDialog.cpp +++ b/src/gui/ObsListCreateEditDialog.cpp @@ -696,7 +696,6 @@ void ObsListCreateEditDialog::obsListExitButtonPressed() { ui->obsListErrorMessage->setHidden(true); ui->obsListErrorMessage->clear(); this->close(); - emit exitButtonClicked(); } /*