Commit da7c8a6b authored by Csaba Kertesz's avatar Csaba Kertesz
Browse files

Fix the custom sky object removal

parent 9c7bebf8
......@@ -25,9 +25,10 @@
#include "deepskyobject.h"
#include "skycomponent.h"
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlTableModel>
#include <catalog_debug.h>
......@@ -397,7 +398,40 @@ bool CatalogDB::_AddEntry(const CatalogEntryData &catalog_entry, int catid)
return retVal;
}
bool CatalogDB::RemoveCustomEntry(const QString &entry_long_name)
bool CatalogDB::CheckCustomEntry(const QString &entry_long_name, int catid)
{
if (!skydb_.open())
{
qCWarning(KSTARS_CATALOG) << "Failed to open database to remove catalog entry!";
qCWarning(KSTARS_CATALOG) << LastError();
return false;
}
QSqlQuery query_od(skydb_);
query_od.prepare("SELECT LongName FROM ObjectDesignation WHERE LongName = :long_name AND id_Catalog = :catid;");
query_od.bindValue(":long_name", entry_long_name);
query_od.bindValue(":catid", catid);
if (!query_od.exec())
{
qWarning() << "Query exec failed:";
qWarning() << query_od.lastQuery();
qWarning() << skydb_.lastError();
skydb_.close();
return false;
}
query_od.next();
QSqlRecord result = query_od.record();
if (result.count() != 1 || result.value(0).toString().isEmpty())
{
skydb_.close();
return false;
}
skydb_.close();
return true;
}
bool CatalogDB::RemoveCustomEntry(const QString &entry_long_name, int catid)
{
if (!skydb_.open())
{
......@@ -407,13 +441,15 @@ bool CatalogDB::RemoveCustomEntry(const QString &entry_long_name)
}
QSqlQuery remove_od(skydb_);
remove_od.prepare("DELETE FROM ObjectDesignation WHERE LongName = :long_name;");
remove_od.prepare("DELETE FROM ObjectDesignation WHERE LongName = :long_name AND id_Catalog = :catid;");
remove_od.bindValue(":long_name", entry_long_name);
remove_od.bindValue(":catid", catid);
if (!remove_od.exec())
{
qWarning() << "Query exec failed:";
qWarning() << remove_od.lastQuery();
qWarning() << skydb_.lastError();
skydb_.close();
return false;
}
skydb_.close();
......
......@@ -152,14 +152,27 @@ class CatalogDB
**/
bool AddEntry(const CatalogEntryData &catalog_entry, int catid);
/**
* @brief Check an entry in the database
*
* @note This public method opens and closes the database.
*
* @param entry_long_name Long name of the entry
* @param catid Category ID in the database
* @return True if successful otherwise false
**/
bool CheckCustomEntry(const QString &entry_long_name, int catid);
/**
* @brief Remove an entry from the database
*
* @note This public method opens and closes the database.
*
* @param entry_long_name Long name of the entry
* @param catid Category ID in the database
* @return True if successful otherwise false
**/
bool RemoveCustomEntry(const QString &entry_long_name);
bool RemoveCustomEntry(const QString &entry_long_name, int catid);
/**
* @brief Returns database ID of the required catalog.
......
......@@ -15,8 +15,7 @@
* *
***************************************************************************/
#ifndef CATALOGENTRYDATA_H
#define CATALOGENTRYDATA_H
#pragma once
#include <QString>
......@@ -72,5 +71,3 @@ class CatalogEntryData
float minor_axis;
float flux;
};
#endif // CATALOGENTRYDATA_H
......@@ -355,9 +355,9 @@ void FindDialog::finishProcessing(SkyObject *selObj, bool resolve)
{
if (!selObj && resolve)
{
CatalogEntryData cedata;
cedata = NameResolver::resolveName(processSearchText());
CatalogEntryData cedata = NameResolver::resolveName(processSearchText());
DeepSkyObject *dso = nullptr;
if (!std::isnan(cedata.ra) && !std::isnan(cedata.dec))
{
dso = KStarsData::Instance()->skyComposite()->internetResolvedComponent()->addObject(cedata);
......
......@@ -72,7 +72,7 @@ void SyncedCatalogComponent::draw( SkyPainter *skyp ) {
}
*/
DeepSkyObject *SyncedCatalogComponent::addObject(CatalogEntryData catalogEntry)
DeepSkyObject *SyncedCatalogComponent::addObject(CatalogEntryData &catalogEntry)
{
if (std::isnan(catalogEntry.major_axis))
catalogEntry.major_axis = 0.0;
......@@ -118,12 +118,18 @@ DeepSkyObject *SyncedCatalogComponent::addObject(CatalogEntryData catalogEntry)
bool SyncedCatalogComponent::hasObject(SkyObject &object)
{
QString name;
if (object.hasLongName())
{
if (objectNames()[object.type()].contains(object.longname()))
return true;
} else
if (objectNames()[object.type()].contains(object.name()))
name = object.longname();
} else {
name = object.name();
}
CatalogDB *db = KStarsData::Instance()->catalogdb();
if (db->CheckCustomEntry(name, m_catId))
{
return true;
}
......@@ -157,7 +163,7 @@ bool SyncedCatalogComponent::removeObject(SkyObject &object)
{
CatalogDB *db = KStarsData::Instance()->catalogdb();
if (!db->RemoveCustomEntry(name))
if (!db->RemoveCustomEntry(name, m_catId))
{
qWarning() << "Can't find SkyObject " << name << " in the CatalogDB";
return false;
......
......@@ -52,7 +52,7 @@ class SyncedCatalogComponent : public CatalogComponent
*
* @return 0 upon failure, a valid SkyObject pointer otherwise.
*/
DeepSkyObject *addObject(CatalogEntryData catalogEntry);
DeepSkyObject *addObject(CatalogEntryData &catalogEntry);
/**
* @short Whether an object is in the database
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment