diff options
author | Georg Zotti <Georg.Zotti@univie.ac.at> | 2023-09-12 14:41:52 +0200 |
---|---|---|
committer | Georg Zotti <Georg.Zotti@univie.ac.at> | 2023-09-12 14:41:52 +0200 |
commit | 39903603cb301b07c01f5edfcd883552bd0d1a5a (patch) | |
tree | f4176617df6872131b4c096ed7df03e05cb025f3 | |
parent | e778e98ecb0f901bd5cd059e9cc395666674b7ce (diff) |
ObsList fixes and improvementsfix/ObsList-Import-Export
- Add last-edited date
- display newly-loaded list (last when loading multiple lists)
- use system time, not simulation time, for list timestamping
- store and load .sol files.
-rw-r--r-- | src/gui/ObsListDialog.cpp | 60 | ||||
-rw-r--r-- | src/gui/ObsListDialog.hpp | 6 | ||||
-rw-r--r-- | src/gui/obsListDialog.ui | 10 |
3 files changed, 50 insertions, 26 deletions
diff --git a/src/gui/ObsListDialog.cpp b/src/gui/ObsListDialog.cpp index 8cb2f6e958..4aa25b665f 100644 --- a/src/gui/ObsListDialog.cpp +++ b/src/gui/ObsListDialog.cpp @@ -141,16 +141,8 @@ void ObsListDialog::createDialogContent() ui->treeView->setModel(itemModel); ui->treeView->header()->setSectionsMovable(false); ui->treeView->hideColumn(ColumnUUID); - ui->treeView->header()->setSectionResizeMode(ColumnDesignation, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnNameI18n, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnType, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnRa, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnDec, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnMagnitude, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnConstellation, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnDate, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnLocation, QHeaderView::ResizeToContents); - ui->treeView->header()->setSectionResizeMode(ColumnLandscapeID, QHeaderView::ResizeToContents); + for (int c=ColumnDesignation; c<=ColumnLandscapeID; c++) + ui->treeView->header()->setSectionResizeMode(c, QHeaderView::ResizeToContents); ui->treeView->header()->setStretchLastSection(true); //Enable the sort for columns ui->treeView->setSortingEnabled(true); @@ -177,14 +169,15 @@ void ObsListDialog::createDialogContent() observingLists = QMap<QString, QVariant>(); // Create one default empty list // Creation date - const double JD = core->getJD(); + const double JD = StelUtils::getJDFromSystem(); const QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); QVariantMap emptyList = { // Name, description, current date for the list, current sorting {KEY_NAME, qc_("new list", "default name for observing list if none is available")}, {KEY_DESCRIPTION, QString()}, {KEY_SORTING, QString()}, - {KEY_CREATION_DATE, listCreationDate }}; + {KEY_CREATION_DATE, listCreationDate }, + {KEY_LAST_EDIT, listCreationDate }}; observingLists.insert(olud, emptyList); jsonMap.insert(KEY_OBSERVING_LISTS, observingLists); @@ -432,6 +425,7 @@ void ObsListDialog::loadSelectedList() ui->listNameLineEdit->setText(currentListName); ui->descriptionLineEdit->setText(observingListMap.value(KEY_DESCRIPTION).toString()); ui->creationDateLineEdit->setText(observingListMap.value(KEY_CREATION_DATE).toString()); + ui->lastEditLineEdit->setText(observingListMap.value(KEY_LAST_EDIT, observingListMap.value(KEY_CREATION_DATE)).toString()); if (observingListMap.value(KEY_OBJECTS).canConvert<QVariantList>()) { @@ -662,7 +656,7 @@ QHash<QString, ObsListDialog::observingListItem> ObsListDialog::loadBookmarksFil /* * Save the bookmarks into observingLists QVariantMap */ -void ObsListDialog::saveBookmarksHashInObservingLists(const QHash<QString, observingListItem> &bookmarksHash) +QString ObsListDialog::saveBookmarksHashInObservingLists(const QHash<QString, observingListItem> &bookmarksHash) { // Creation date double JD = StelUtils::getJDFromSystem(); // Mark with current system time @@ -672,6 +666,7 @@ void ObsListDialog::saveBookmarksHashInObservingLists(const QHash<QString, obser {KEY_NAME, BOOKMARKS_LIST_NAME}, {KEY_DESCRIPTION, BOOKMARKS_LIST_DESCRIPTION}, {KEY_CREATION_DATE, listCreationDate}, + {KEY_LAST_EDIT, listCreationDate}, {KEY_SORTING, SORTING_BY_NAME}}; // Add actual list of (former) bookmark entries @@ -689,6 +684,7 @@ void ObsListDialog::saveBookmarksHashInObservingLists(const QHash<QString, obser QString bookmarkListOlud= (keys.empty() ? QUuid::createUuid().toString() : keys.at(0)); observingLists.insert(bookmarkListOlud, bookmarksObsList); + return bookmarkListOlud; } /* @@ -907,9 +903,9 @@ void ObsListDialog::editListButtonPressed() */ void ObsListDialog::exportListButtonPressed() { - static const QString filter = "JSON (*.json)"; + static const QString filter = "Stellarium Observing List (*.sol)"; QString exportListJsonPath = QFileDialog::getSaveFileName(nullptr, q_("Export observing list as..."), - QDir::homePath() + "/" + JSON_FILE_BASENAME + "_" + currentListName + ".json", filter); + QDir::homePath() + "/" + JSON_FILE_BASENAME + "_" + currentListName + ".sol", filter); QFile jsonFile(exportListJsonPath); if (!jsonFile.open(QIODevice::ReadWrite | QIODevice::Text)) { @@ -941,7 +937,7 @@ void ObsListDialog::exportListButtonPressed() */ void ObsListDialog::importListButtonPressed() { - static const QString filter = "JSON (*.json)"; + static const QString filter = "Stellarium Observing List (*.sol)"; QString fileToImportJsonPath = QFileDialog::getOpenFileName(nullptr, q_("Import observing list"), QDir::homePath(), filter); @@ -983,15 +979,20 @@ void ObsListDialog::importListButtonPressed() QVariantMap importedMap=it.value().toMap(); // This is a map of {{UUID, QMap},...} QString importedName=importedMap.value(KEY_NAME).toString(); QString importedDate=importedMap.value(KEY_CREATION_DATE).toString(); - qDebug() << "Imported Map named:" << importedName << "date" << importedDate << ":" << importedMap; + QString importedLastEditDate=importedMap.value(KEY_LAST_EDIT, importedMap.value(KEY_CREATION_DATE)).toString(); + qDebug() << "Imported Map named:" << importedName << "created" << importedDate << "changed" << importedLastEditDate << ":" << importedMap; QVariantMap existingMap=observingLists.value(it.key()).toMap(); QString existingName=existingMap.value(KEY_NAME).toString(); QString existingDate=existingMap.value(KEY_CREATION_DATE).toString(); - QString message=QString(q_("A list named '%1' and dated %2 would overwrite your existing list '%3', dated %4. Accept?")).arg(importedName, importedDate, existingName, existingDate); + QString existingLastEdit=existingMap.value(KEY_LAST_EDIT, existingMap.value(KEY_CREATION_DATE)).toString(); + QString message=QString(q_("A list named '%1', created %2 and last modified %3 would overwrite your existing list '%4', dated %5/%6. Accept?")).arg(importedName, importedDate, importedLastEditDate, existingName, existingDate, existingLastEdit); overwrite=askConfirmation(message); } if (overwrite) + { observingLists.insert(it.key(), it.value()); + selectedOlud=it.key(); + } } } } @@ -1010,7 +1011,7 @@ void ObsListDialog::importListButtonPressed() { QHash<QString, ObsListDialog::observingListItem> bookmarksHash=loadBookmarksFile(jsonFile); // Put them to the main list. Note that this may create another list named "bookmarks list", however, with a different OLUD than the existing. - saveBookmarksHashInObservingLists(bookmarksHash); + selectedOlud=saveBookmarksHashInObservingLists(bookmarksHash); } } else @@ -1034,6 +1035,10 @@ void ObsListDialog::importListButtonPressed() jsonFile.flush(); jsonFile.close(); tainted=false; + + // Now we have stored to file, but the program is not aware of the new lists! + loadListNames(); // also populate Combobox and make sure at least some defaultOlud exists. + loadSelectedList(); } catch (std::runtime_error &e) { qWarning() << "[ObservingList Creation/Edition] File format is wrong! Error: " << e.what(); messageBox(q_("Error"), q_("File format is wrong!")); @@ -1096,7 +1101,7 @@ void ObsListDialog::addObjectButtonPressed() if (!selectedObject.isEmpty()) { -// TBD: this test should prevent adding duplicate entries, but fails. Maybe for V23.2! +// TBD: this test should prevent adding duplicate entries, but fails. Maybe for V23.4! // // No duplicate item in the same list // bool is_already_in_list = false; // QHash<QString, observingListItem>::iterator i; @@ -1303,6 +1308,8 @@ void ObsListDialog::switchEditMode(bool enableEditMode, bool newList) ui->creationDateLabel->setVisible(!isEditMode); // Creation date: ui->creationDateLineEdit->setVisible(!isEditMode); // + ui->lastEditLabel->setVisible(!isEditMode); // Last edit date: + ui->lastEditLineEdit->setVisible(!isEditMode); // // line with optional store items ui->alsoStoreLabel->setVisible(isEditMode); // Also store @@ -1376,19 +1383,21 @@ void ObsListDialog::setFlagUseFov(bool b) /* * Prepare the currently displayed/edited list for storage - * Returns QVariantList with keys={creation date, description, name, objects, sorting} + * Returns QVariantList with keys={creation date, last edit, description, name, objects, sorting} */ QVariantMap ObsListDialog::prepareCurrentList(QHash<QString, observingListItem> &itemHash) { - // Creation date - const double JD = core->getJD(); - const QString listCreationDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); + // Edit date + const double JD = StelUtils::getJDFromSystem(); + const QString lastEditDate = StelUtils::julianDayToISO8601String(JD + core->getUTCOffset(JD) / 24.).replace("T", " "); QVariantMap currentList = { // Name, description, current date for the list, current sorting {KEY_NAME, currentListName}, {KEY_DESCRIPTION, ui->descriptionLineEdit->text()}, {KEY_SORTING, sorting}, - {KEY_CREATION_DATE, listCreationDate }}; + {KEY_CREATION_DATE, ui->creationDateLineEdit->text()}, + {KEY_LAST_EDIT, lastEditDate } + }; // List of objects QVariantList listOfObjects; @@ -1467,6 +1476,7 @@ const QString ObsListDialog::SHORT_NAME_VALUE = QStringLiteral("Observ const QString ObsListDialog::KEY_DEFAULT_LIST_OLUD = QStringLiteral("defaultListOlud"); const QString ObsListDialog::KEY_OBSERVING_LISTS = QStringLiteral("observingLists"); const QString ObsListDialog::KEY_CREATION_DATE = QStringLiteral("creation date"); +const QString ObsListDialog::KEY_LAST_EDIT = QStringLiteral("last edit"); const QString ObsListDialog::KEY_BOOKMARKS = QStringLiteral("bookmarks"); const QString ObsListDialog::KEY_NAME = QStringLiteral("name"); const QString ObsListDialog::KEY_NAME_I18N = QStringLiteral("nameI18n"); diff --git a/src/gui/ObsListDialog.hpp b/src/gui/ObsListDialog.hpp index 5ff87adb5d..2b2ac36527 100644 --- a/src/gui/ObsListDialog.hpp +++ b/src/gui/ObsListDialog.hpp @@ -50,6 +50,7 @@ //! "observingLists": { //! "{84744f7b-c353-45b0-8394-69af2a1e0917}": { // List OLUD. This is a unique ID //! "creation date": "2022-09-29 20:05:07", +//! "last edit": "2022-11-29 22:15:38", //! "description": "Bookmarks of previous Stellarium version.", //! "name": "bookmarks list", //! "objects": [ // List is stored alphabetized, but given here in contextualized order for clarity. @@ -75,6 +76,7 @@ //! }, // end of list 84744f7b-... //! "{bd40274c-a321-40c1-a6f3-bc8f11026326}": { // List OLUD of next list. //! "creation date": "2022-12-21 11:12:39", +//! "last edit": "2023-07-29 22:23:38", //! "description": "test of unification", //! "name": "mine_edited", //! "objects": [ @@ -292,7 +294,8 @@ private: QVariantMap prepareCurrentList(QHash<QString, observingListItem> &itemHash); //! Put the bookmarks in bookmarksHash into observingLists under the listname "bookmarks list". Does not write JSON! - void saveBookmarksHashInObservingLists(const QHash<QString, observingListItem> &bookmarksHash); + //! @return OLUD of the imported bookmarks list. + QString saveBookmarksHashInObservingLists(const QHash<QString, observingListItem> &bookmarksHash); //! Sort the obsListTreeView by the column name given in parameter void sortObsListTreeViewByColumnName(const QString &columnName); @@ -380,6 +383,7 @@ private: static const QString KEY_DEFAULT_LIST_OLUD; static const QString KEY_OBSERVING_LISTS; static const QString KEY_CREATION_DATE; + static const QString KEY_LAST_EDIT; static const QString KEY_BOOKMARKS; static const QString KEY_NAME; static const QString KEY_NAME_I18N; diff --git a/src/gui/obsListDialog.ui b/src/gui/obsListDialog.ui index aac433a244..f21022225d 100644 --- a/src/gui/obsListDialog.ui +++ b/src/gui/obsListDialog.ui @@ -259,6 +259,16 @@ <item> <widget class="QLineEdit" name="creationDateLineEdit"/> </item> + <item> + <widget class="QLabel" name="lastEditLabel"> + <property name="text"> + <string>Last edit:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lastEditLineEdit"/> + </item> </layout> </item> <item row="3" column="0"> |