[education/kstars] /: "Batch add" option in the Observation Planner

Jasem Mutlaq null at kde.org
Wed Jul 28 11:35:48 BST 2021


Git commit d7f39cd83ce5581021c0cf10227431502df8b652 by Jasem Mutlaq, on behalf of Akarsh Simha.
Committed on 28/07/2021 at 10:35.
Pushed by mutlaqja into branch 'master'.

"Batch add" option in the Observation Planner

M  +2    -0    doc/obsplanner.docbook
M  +6    -1    kstars/catalogsdb/catalogsdb.cpp
M  +3    -1    kstars/catalogsdb/catalogsdb.h
M  +1    -1    kstars/skycomponents/catalogscomponent.cpp
M  +56   -2    kstars/tools/observinglist.cpp
M  +5    -0    kstars/tools/observinglist.h
M  +11   -4    kstars/tools/observinglist.ui

https://invent.kde.org/education/kstars/commit/d7f39cd83ce5581021c0cf10227431502df8b652

diff --git a/doc/obsplanner.docbook b/doc/obsplanner.docbook
index e710b2bc4..54384bdc0 100644
--- a/doc/obsplanner.docbook
+++ b/doc/obsplanner.docbook
@@ -171,6 +171,8 @@ it could be a bit more detailed. Here you can see the same categories of objects
       </para>
     </caption>
   </mediaobject>
+  <para>Another way of adding objects to your observation plan is using the newly introduced <guibutton>Batch Add</guibutton> will open up a text box where you can type many objects to add in one shot to the observation planner. Any objects not in the &kstars; database already will be resolved using SIMBAD Astronomical Database (provided this has been enabled in the Settings) and added to the database. The entire process of adding objects is slow and may take a while, and you can watch the progress in the Status Bar. Any objects that could not be found are then listed in an error message, so you can identify and fix the errors. Usually this may be because SIMBAD expects a different way of specifying the object (⪚ Sim 147 instead of Simeis 147). This new feature allows you to easily scrape data from observing lists on the web &etc; and add them to your workflow in &kstars;.
+  </para>
   <para>This is how the <guilabel>Execution Session</guilabel> Window look. It can be opened by pressing <keycombo action="simul">&Ctrl;<keycap>2</keycap></keycombo>. In it you can also see some information about the selected object and you are able to add observing notes.</para>
   <mediaobject>
     <imageobject>
diff --git a/kstars/catalogsdb/catalogsdb.cpp b/kstars/catalogsdb/catalogsdb.cpp
index 9f6564a13..9244c7941 100644
--- a/kstars/catalogsdb/catalogsdb.cpp
+++ b/kstars/catalogsdb/catalogsdb.cpp
@@ -480,7 +480,8 @@ std::list<CatalogObject> DBManager::fetch_objects(QSqlQuery &query) const
 }
 
 std::list<CatalogObject> DBManager::find_objects_by_name(const QString &name,
-                                                         const int limit)
+                                                         const int limit,
+                                                         const bool exactMatchOnly)
 {
     QMutexLocker _{ &m_mutex };
 
@@ -494,6 +495,10 @@ std::list<CatalogObject> DBManager::find_objects_by_name(const QString &name,
         {
             return objs;
         }
+        if (exactMatchOnly)
+        {
+            return std::list<CatalogObject>();
+        }
     }
 
     m_q_obj_by_name.bindValue(":name", name);
diff --git a/kstars/catalogsdb/catalogsdb.h b/kstars/catalogsdb/catalogsdb.h
index 01f83cf8f..c11bfb62a 100644
--- a/kstars/catalogsdb/catalogsdb.h
+++ b/kstars/catalogsdb/catalogsdb.h
@@ -224,10 +224,12 @@ class DBManager
      *
      * \param limit Upper limit to the quanitity of results. `-1` means "no
      * limit"
+     * \param exactMatchOnly If true, the supplied name must match exactly
      *
      * \return a list of matching objects
      */
-    CatalogObjectList find_objects_by_name(const QString &name, const int limit = -1);
+    CatalogObjectList find_objects_by_name(const QString &name, const int limit = -1,
+                                           const bool exactMatchOnly = false);
 
     /**
      * \brief Find an objects by name in the catalog with \p `catalog_id`.
diff --git a/kstars/skycomponents/catalogscomponent.cpp b/kstars/skycomponents/catalogscomponent.cpp
index 689b8c150..ed6da202a 100644
--- a/kstars/skycomponents/catalogscomponent.cpp
+++ b/kstars/skycomponents/catalogscomponent.cpp
@@ -215,7 +215,7 @@ CatalogObject &CatalogsComponent::insertStaticObject(const CatalogObject &obj)
 
 SkyObject *CatalogsComponent::findByName(const QString &name)
 {
-    auto objects = m_db_manager.find_objects_by_name(name, 1);
+    auto objects = m_db_manager.find_objects_by_name(name, 1, true);
 
     if (objects.size() == 0)
         return nullptr;
diff --git a/kstars/tools/observinglist.cpp b/kstars/tools/observinglist.cpp
index 115e8c20d..ce9391d14 100644
--- a/kstars/tools/observinglist.cpp
+++ b/kstars/tools/observinglist.cpp
@@ -2,7 +2,7 @@
                           observinglist.cpp  -  K Desktop Planetarium
                              -------------------
     begin                : 29 Nov 2004
-    copyright            : (C) 2004-2014 by Jeff Woods, Jason Harris,
+    copyright            : (C) 2004-2020 by Jeff Woods, Jason Harris,
                            Prakash Mohan, Akarsh Simha
     email                : jcwoods at bellsouth.net, jharris at 30doradus.org,
                            prakash.mohan at kdemail.net, akarsh at kde.org
@@ -42,6 +42,7 @@
 #include "dialogs/locationdialog.h"
 #include "oal/execute.h"
 #include "skycomponents/skymapcomposite.h"
+#include "skyobjects/skyobject.h"
 #include "skyobjects/starobject.h"
 #include "tools/altvstime.h"
 #include "tools/eyepiecefield.h"
@@ -74,7 +75,8 @@ ObservingListUI::ObservingListUI(QWidget *p) : QFrame(p)
 // ObservingList
 // ---------------------------------
 ObservingList::ObservingList()
-    : QDialog((QWidget *)KStars::Instance()), LogObject(nullptr), m_CurrentObject(nullptr), isModified(false), m_dl(nullptr)
+    : QDialog((QWidget *)KStars::Instance()), LogObject(nullptr), m_CurrentObject(nullptr), isModified(false), m_dl(nullptr),
+      m_manager{ CatalogsDB::dso_db_path() }
 {
 #ifdef Q_OS_OSX
     setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
@@ -149,6 +151,7 @@ ObservingList::ObservingList()
     connect(ui->SaveButton, SIGNAL(clicked()), this, SLOT(slotSaveSession()));
     connect(ui->SaveAsButton, SIGNAL(clicked()), this, SLOT(slotSaveSessionAs()));
     connect(ui->WizardButton, SIGNAL(clicked()), this, SLOT(slotWizard()));
+    connect(ui->batchAddButton, SIGNAL(clicked()), this, SLOT(slotBatchAdd()));
     connect(ui->SetLocation, SIGNAL(clicked()), this, SLOT(slotLocation()));
     connect(ui->Update, SIGNAL(clicked()), this, SLOT(slotUpdate()));
     connect(ui->DeleteImage, SIGNAL(clicked()), this, SLOT(slotDeleteCurrentImage()));
@@ -778,6 +781,57 @@ void ObservingList::slotFind()
     }
 }
 
+void ObservingList::slotBatchAdd()
+{
+    bool accepted = false;
+    QString items = QInputDialog::getMultiLineText(this,
+                    sessionView ? i18n("Batch add to observing session") : i18n("Batch add to observing wishlist"),
+                    i18n("Specify a list of objects with one object on each line to add. The names must be understood to KStars, or if the internet resolver is enabled in settings, to the CDS Sesame resolver. Objects that are internet resolved will be added to the database."),
+                    QString(),
+                    &accepted);
+    bool resolve = Options::resolveNamesOnline();
+
+    if (accepted && !items.isEmpty())
+    {
+        QStringList failedObjects;
+        QStringList objectNames = items.split("\n");
+        for (QString objectName : objectNames)
+        {
+            objectName = FindDialog::processSearchText(objectName);
+            SkyObject *object = KStarsData::Instance()->objectNamed(objectName);
+            if (!object && resolve)
+            {
+                object = FindDialog::resolveAndAdd(m_manager, objectName);
+            }
+            if (!object)
+            {
+                failedObjects.append(objectName);
+            }
+            else
+            {
+                slotAddObject(object, sessionView);
+            }
+        }
+
+        if (!failedObjects.isEmpty())
+        {
+            QMessageBox msgBox =
+            {
+                QMessageBox::Icon::Warning,
+                i18np("Batch add: %1 object not found", "Batch add: %1 objects not found", failedObjects.size()),
+                i18np("%1 object could not be found in the database or resolved, and hence could not be added. See the details for more.",
+                      "%1 objects could not be found in the database or resolved, and hence could not be added. See the details for more.",
+                      failedObjects.size()),
+                QMessageBox::Ok,
+                this
+            };
+            msgBox.setDetailedText(failedObjects.join("\n"));
+            msgBox.exec();
+        }
+    }
+    Q_ASSERT(false); // Not implemented
+}
+
 void ObservingList::slotEyepieceView()
 {
     KStars::Instance()->slotEyepieceView(currentObject(), getCurrentImagePath());
diff --git a/kstars/tools/observinglist.h b/kstars/tools/observinglist.h
index 85b5786d6..564454afe 100644
--- a/kstars/tools/observinglist.h
+++ b/kstars/tools/observinglist.h
@@ -20,6 +20,7 @@
 #include "ksalmanac.h"
 #include "kstarsdatetime.h"
 #include "ui_observinglist.h"
+#include "catalogsdb.h"
 
 #include <QAbstractTableModel>
 #include <QDialog>
@@ -239,6 +240,9 @@ class ObservingList : public QDialog
             */
     void slotFind();
 
+    /** @short Batch add from a list of objects */
+    void slotBatchAdd();
+
     /** @short Tasks needed when changing the selected object
             *Save the user log of the previous selected object,
             *find the new selected object in the obsList, and
@@ -420,4 +424,5 @@ class ObservingList : public QDialog
     QTimer *m_altitudeUpdater { nullptr };
     std::function<QStandardItem *(const SkyPoint &)> m_altCostHelper;
     bool m_initialWishlistLoad { false };
+    CatalogsDB::DBManager m_manager;
 };
diff --git a/kstars/tools/observinglist.ui b/kstars/tools/observinglist.ui
index 357793807..16929763e 100644
--- a/kstars/tools/observinglist.ui
+++ b/kstars/tools/observinglist.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>605</height>
+    <width>777</width>
+    <height>641</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
@@ -31,7 +31,7 @@
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <widget class="QWidget" name="">
+     <widget class="QWidget" name="layoutWidget">
       <layout class="QVBoxLayout" name="topLayout">
        <property name="spacing">
         <number>3</number>
@@ -349,6 +349,13 @@
            </property>
           </widget>
          </item>
+         <item>
+          <widget class="QPushButton" name="batchAddButton">
+           <property name="text">
+            <string>Batch add</string>
+           </property>
+          </widget>
+         </item>
          <item>
           <spacer name="horizontalSpacer_5">
            <property name="orientation">
@@ -524,7 +531,7 @@
            </layout>
           </widget>
          </widget>
-         <widget class="QWidget" name="">
+         <widget class="QWidget" name="layoutWidget">
           <layout class="QVBoxLayout" name="objectInfoLayout">
            <property name="spacing">
             <number>3</number>


More information about the kde-doc-english mailing list