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

Memory management clean-up, valgrind suppression file and other fixes

parent 06d85539
......@@ -16,6 +16,7 @@
***************************************************************************/
#include "catalogdb.h"
#include "catalogdata.h"
#include "catalogentrydata.h"
#include "kstars/version.h"
......@@ -23,10 +24,7 @@
#include "starobject.h"
#include "deepskyobject.h"
#include "skycomponent.h"
#include "skyobject.h"
#include <QVariant>
#include <QHash>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QSqlQuery>
......@@ -830,8 +828,10 @@ void CatalogDB::GetAllObjects(const QString &catalog, QList<SkyObject *> &sky_li
QList<QPair<int, QString>> &object_names, CatalogComponent *catalog_ptr,
bool includeCatalogDesignation)
{
qDeleteAll(sky_list);
sky_list.clear();
QString selected_catalog = QString::number(FindCatalog(catalog));
skydb_.open();
QSqlQuery get_query(skydb_);
get_query.prepare("SELECT Epoch, Type, RA, Dec, Magnitude, Prefix, "
......@@ -866,8 +866,8 @@ void CatalogDB::GetAllObjects(const QString &catalog, QList<SkyObject *> &sky_li
float b = get_query.value(9).toFloat();
float PA = get_query.value(10).toFloat();
float flux = get_query.value(11).toFloat();
QString name;
if (!includeCatalogDesignation && !lname.isEmpty())
{
name = lname;
......@@ -912,11 +912,13 @@ void CatalogDB::GetAllObjects(const QString &catalog, QList<SkyObject *> &sky_li
if (iType == 0) // Add a star
{
StarObject *o = new StarObject(RA, Dec, mag, lname);
sky_list.append(o);
}
else // Add a deep-sky object
{
DeepSkyObject *o = new DeepSkyObject(iType, RA, Dec, mag, name, QString(), lname, catPrefix, a, b, -PA);
o->setFlux(flux);
o->setCustomCatalog(catalog_ptr);
......
......@@ -15,37 +15,27 @@
* *
***************************************************************************/
#ifndef CATALOGDB_H
#define CATALOGDB_H
#pragma once
#include <QStandardPaths>
#include <KLocalizedString>
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlError>
#include <QFile>
#include <QDir>
#include "ksparser.h"
#include <KLocalizedString>
#ifndef KSTARS_LITE
#include <KMessageBox>
#endif
#include "ksparser.h"
#include <QString>
#include <QStringList>
#include <QList>
#include <QPair>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlError>
class SkyObject;
class CatalogComponent;
class CatalogData;
class CatalogEntryData;
/* Some notes about the database. (skycomponents.sqlite)
/*
* Some notes about the database. (skycomponents.sqlite)
* 1) The uid for Object Designation is the uid being used by objects in KStars
* hence, the uid is a qint64 i.e. a 64 bit signed integer. Coincidentaly,
* hence, the uid is a qint64 i.e. a 64 bit signed integer. Coincidentally,
* this is the max limit of an int in Sqlite3.
* Hence, the db is compatible with the uid, but doesn't use it as of now.
*/
......@@ -54,196 +44,196 @@ class CatalogDB
{
public:
/**
* @brief Initializes the database and sets up pointers to Catalog DB
* Performs the following actions:
* 1. Checks if database file exists
* 2. Checks if database can be opened
* 3. If DB file is missing, creates new DB
* 4. Sets up pointer to Catalog DB
*
* usage: Call QSqlDatabase::removeDatabase("skydb"); after the object
* of this class is deallocated
* @return bool
**/
* @brief Initializes the database and sets up pointers to Catalog DB
* Performs the following actions:
* 1. Checks if database file exists
* 2. Checks if database can be opened
* 3. If DB file is missing, creates new DB
* 4. Sets up pointer to Catalog DB
*
* usage: Call QSqlDatabase::removeDatabase("skydb"); after the object
* of this class is deallocated
* @return bool
**/
bool Initialize();
/**
* @brief Attempt to close database and remove reference from the DB List
*
**/
* @brief Attempt to close database and remove reference from the DB List
*
**/
~CatalogDB();
/**
* @brief Accessor for list of all available catalogs in db
*
* @return QStringList*
**/
* @brief Accessor for list of all available catalogs in db
*
* @return QStringList*
**/
QStringList *Catalogs();
/**
* @brief Rechecks the database and builds the Catalog listing.
* New listing is directly updated into catalogs (accessed using Catalogs())
*
* @return void
**/
* @brief Rechecks the database and builds the Catalog listing.
* New listing is directly updated into catalogs (accessed using Catalogs())
*
* @return void
**/
void RefreshCatalogList();
/**
* @short Parses the catalog header and returns the catalog name
*
* @p filename the name of the file containing the data to be read
* @return Catalog name or empty string if there is an error
*/
* @short Parses the catalog header and returns the catalog name
*
* @p filename the name of the file containing the data to be read
* @return Catalog name or empty string if there is an error
*/
QString GetCatalogName(const QString &filename);
/**
* @short Add contents of custom catalog to the program database
*
* @p filename the name of the file containing the data to be read
* @return true if catalog was successfully added
*/
* @short Add contents of custom catalog to the program database
*
* @p filename the name of the file containing the data to be read
* @return true if catalog was successfully added
*/
bool AddCatalogContents(const QString &filename);
/**
* @brief returns the id of the row if it matches with certain fuzz.
* Else return -1 if none found
*
* @param ra Right Ascension of new object to be added
* @param dec Declination of new object to be added
* @return int RowUID of the new row
**/
* @brief returns the id of the row if it matches with certain fuzz.
* Else return -1 if none found
*
* @param ra Right Ascension of new object to be added
* @param dec Declination of new object to be added
* @return int RowUID of the new row
**/
int FindFuzzyEntry(const double ra, const double dec, const double magnitude);
/**
* @brief Removes the catalog from the database and refreshes the listing.
*
* @param catalog_name Name of the catalog
* @return void
**/
* @brief Removes the catalog from the database and refreshes the listing.
*
* @param catalog_name Name of the catalog
* @return void
**/
void RemoveCatalog(const QString &catalog_name);
/**
* @brief Creates objects of type SkyObject and assigns them to references
*
* @param catalog Name of the catalog whose objects are needed.
* @param sky_list List of all skyobjects stored in database (assigns)
* @param names List of named objects in database (assigns)
* @param catalog_pointer pointer to the catalogcomponent objects
* (needed for building skyobjects)
* @param includeCatalogDesignation This is useful when using 'fake'
* catalogs to bundle up catalogs. Imagine a "Misc" catalog with a
* bunch of miscellaneous objects. We don't want the designations
* "Misc 1", "Misc 2" etc. So the only proper designations are the
* long name. When this is the case, this flag is set to false,
* and the catalog designation (cat_prefix + cat_id) will not be
* included in the object_names returned.
*
* @return void
**/
* @brief Creates objects of type SkyObject and assigns them to references
*
* @param catalog Name of the catalog whose objects are needed.
* @param sky_list List of all skyobjects stored in database (assigns)
* @param names List of named objects in database (assigns)
* @param catalog_pointer pointer to the catalogcomponent objects
* (needed for building skyobjects)
* @param includeCatalogDesignation This is useful when using 'fake' catalogs to bundle up
* catalogs. Imagine a "Misc" catalog with a bunch of miscellaneous objects. We don't want
* the designations "Misc 1", "Misc 2" etc. So the only proper designations are the
* long name. When this is the case, this flag is set to false, and the catalog designation
* (cat_prefix + cat_id) will not be included in the object_names returned.
*
* @return void
**/
void GetAllObjects(const QString &catalog_name, QList<SkyObject *> &sky_list,
QList<QPair<int, QString>> &object_names, CatalogComponent *catalog_pointer,
bool includeCatalogDesignation = true);
/**
* @brief Get information about the catalog like Prefix etc
*
* @param catalog_name Name of catalog whose details are required
* @param catalog_data Data structure assigned with required data
* @return void
**/
* @brief Get information about the catalog like Prefix etc
*
* @param catalog_name Name of catalog whose details are required
* @param catalog_data Data structure assigned with required data
* @return void
**/
void GetCatalogData(const QString &catalog_name, CatalogData &catalog_data);
/**
* @brief Used to add a cross referenced entry into the database
*
* @note This public method opens and closes the database.
*
* @param catalog_entry Data structure with entry details
* @param catid Category ID in the database
* @return false if adding was unsuccessful
**/
* @brief Used to add a cross referenced entry into the database
*
* @note This public method opens and closes the database.
*
* @param catalog_entry Data structure with entry details
* @param catid Category ID in the database
* @return false if adding was unsuccessful
**/
bool AddEntry(const CatalogEntryData &catalog_entry, int catid);
/**
* @brief Returns database ID of the required catalog.
* Returns -1 if not found.
*
* @param name Name of the class being searched
* @return int
**/
* @brief Returns database ID of the required catalog.
* Returns -1 if not found.
*
* @param name Name of the class being searched
* @return int
**/
int FindCatalog(const QString &catalog_name);
/**
* @brief Add the catalog with given details into the database
*
* @param catalog_data CatalogData object encompassing all catalog info
* @return void
**/
* @brief Add the catalog with given details into the database
*
* @param catalog_data CatalogData object encompassing all catalog info
* @return void
**/
void AddCatalog(const CatalogData &catalog_data);
private:
/**
* @brief Used to add a cross referenced entry into the database
*
* @note This private method is useful when calling the method
* repeatedly on an already-opened DB.
*
* @param catalog_entry Data structure with entry details
* @param catid Category ID in the database
* @return false if adding was unsuccessful
**/
* @brief Used to add a cross referenced entry into the database
*
* @note This private method is useful when calling the method
* repeatedly on an already-opened DB.
*
* @param catalog_entry Data structure with entry details
* @param catid Category ID in the database
* @return false if adding was unsuccessful
**/
bool _AddEntry(const CatalogEntryData &catalog_entry, int catid);
/**
* @brief Database object for the sky object. Assigned and Initialized by
* Initialize()
**/
* @brief Database object for the sky object. Assigned and Initialized by Initialize()
**/
QSqlDatabase skydb_;
/**
* @brief Returns the last error the database encountered
*
* @return QSqlError
**/
* @brief Returns the last error the database encountered
*
* @return QSqlError
**/
QSqlError LastError();
/**
* @brief List of all the catalogs contained in the database.
* This variable is accessed through Catalogs()
**/
* @brief List of all the catalogs contained in the database.
* This variable is accessed through Catalogs()
**/
QStringList catalog_list_;
/**
* @short Add the catalog name and details to the db.
* This does not store the contents. It only adds the catalog info
* to the database. Hence, it is step 1 in AddCatalogContents
*
* @param lines List of lines to use for extraction of details
* @param Columns Stores the read Columns in this list
* @param catalog_name Name retrieved from file header
* @param delimiter Delimeter retrieved from file header
* @return bool
**/
* @short Add the catalog name and details to the db.
* This does not store the contents. It only adds the catalog info
* to the database. Hence, it is step 1 in AddCatalogContents
*
* @param lines List of lines to use for extraction of details
* @param Columns Stores the read Columns in this list
* @param catalog_name Name retrieved from file header
* @param delimiter Delimeter retrieved from file header
* @return bool
**/
bool ParseCatalogInfoToDB(const QStringList &lines, QStringList &columns, QString &catalog_name, char &delimiter);
/**
* @brief Prepares the sequence required by KSParser according to header.
* Information on the sequence is stored inside the header
*
* @param Columns List of the columns names as strings
* @return QList of the format usable by KSParser
**/
* @brief Prepares the sequence required by KSParser according to header.
* Information on the sequence is stored inside the header
*
* @param Columns List of the columns names as strings
* @return QList of the format usable by KSParser
**/
QList<QPair<QString, KSParser::DataTypes>> buildParserSequence(const QStringList &Columns);
/**
* @brief Clears out the DSO table for the given catalog ID
*
* @param catalog_id DB generated catalog ID
* @return void
**/
* @brief Clears out the DSO table for the given catalog ID
*
* @param catalog_id DB generated catalog ID
* @return void
**/
void ClearDSOEntries(int catalog_id);
/**
* @brief Contains setup routines to intitialize a database for catalog storage
*
* @return void
**/
* @brief Contains setup routines to intitialize a database for catalog storage
*
* @return void
**/
void FirstRun();
};
#endif // CATALOGDB_H
......@@ -18,10 +18,11 @@
#include "binfilehelper.h"
#include <QStandardPaths>
#include "byteorder.h"
#include "auxiliary/kspaths.h"
#include <QStandardPaths>
class BinFileHelper;
BinFileHelper::BinFileHelper()
......@@ -33,6 +34,7 @@ BinFileHelper::BinFileHelper()
BinFileHelper::~BinFileHelper()
{
qDeleteAll(fields);
fields.clear();
if (fileHandle)
closeFile();
}
......
......@@ -152,13 +152,18 @@ const QList<FOV *> &FOVManager::readFOVs()
continue;
}
//FIXME: This still shows lost blocks in Valgrind despite the fact memory is always cleared?
m_FOVs.append(new FOV(name, sizeX, sizeY, xoffset, yoffset, rot, shape, color));
}
}
return m_FOVs;
}
void FOVManager::releaseCache()
{
qDeleteAll(m_FOVs);
m_FOVs.clear();
}
FOV::Shape FOV::intToShape(int s)
{
return (s >= FOV::UNKNOWN || s < 0) ? FOV::UNKNOWN : static_cast<FOV::Shape>(s);
......
......@@ -15,24 +15,22 @@
* *
***************************************************************************/
#ifndef FOV_H_
#define FOV_H_
#pragma once
#include <QList>
#include "skypoint.h"
#include <QImage>
#include <QList>
#include <QString>
#include <KLocalizedString>
#include "skypoint.h"
class QPainter;
/** @class FOV
* A simple class encapsulating a Field-of-View symbol
*@author Jason Harris
*@version 1.0
*/
/**
* @class FOV
* A simple class encapsulating a Field-of-View symbol
* @author Jason Harris
* @version 1.0
*/
class FOV
{
public:
......@@ -47,7 +45,7 @@ class FOV
};
static FOV::Shape intToShape(int);
/**Default constructor*/
/** Default constructor */
FOV();
FOV(const QString &name, float a, float b = -1, float xoffset = 0, float yoffset = 0, float rot = 0,
Shape shape = SQUARE, const QString &color = "#FFFFFF");
......@@ -82,16 +80,19 @@ class FOV
inline QString color() const { return m_color; }
void setColor(const QString &c) { m_color = c; }
/** @short draw the FOV symbol on a QPainter
* @param p reference to the target QPainter. The painter should already be started.
* @param zoomFactor is zoom factor as in SkyMap.
*/
/**
* @short draw the FOV symbol on a QPainter
* @param p reference to the target QPainter. The painter should already be started.
* @param zoomFactor is zoom factor as in SkyMap.
*/
void draw(QPainter &p, float zoomFactor);
/** @short draw FOV symbol so it will be inside a rectangle
* @param p reference to the target QPainter. The painter should already be started.
* @param x is X size of rectangle
* @param y is Y size of rectangle
*/
/**
* @short draw FOV symbol so it will be inside a rectangle
* @param p reference to the target QPainter. The painter should already be started.
* @param x is X size of rectangle
* @param y is Y size of rectangle
*/
void draw(QPainter &p, float x, float y);
SkyPoint center() const;
......@@ -107,26 +108,29 @@ class FOV
private:
QString m_name, m_color;
Shape m_shape;
float m_sizeX, m_sizeY;
float m_offsetX, m_offsetY;
float m_rotation;
float m_northPA;
float m_sizeX { 0 }, m_sizeY { 0 };
float m_offsetX { 0 }, m_offsetY { 0 };
float m_rotation { 0 };
float m_northPA { 0 };
SkyPoint m_center;
QImage m_image;
bool m_imageDisplay;
bool m_imageDisplay { false };
};
/** @class FOVManager
* A simple class handling FOVs.
/**
* @class FOVManager
* A simple class handling FOVs.
* @note Should migrate this from file (fov.dat) to using the user sqlite database
*@author Jasem Mutlaq
*@version 1.0
*/
* @author Jasem Mutlaq
* @version 1.0
*/
class FOVManager
{
public:
/** @short Read list of FOVs from "fov.dat" */
static const QList<FOV *> &readFOVs();
/** @short Release the FOV cache */
static void releaseCache();
static void addFOV(FOV *newFOV)
{
Q_ASSERT(newFOV);
......@@ -151,5 +155,3 @@ class FOVManager
static QList<FOV *> m_FOVs;
};
#endif
......@@ -33,6 +33,7 @@
#include <QDebug>
#include <QFileDialog>
#include <QStatusBar>
#include <QTemporaryFile>
#ifndef KSTARS_LITE
#include <KMessageBox>
......
......@@ -8,20 +8,22 @@
*/
#include <basedevice.h>
#include "drivermanager.h"
#include <QRadioButton>
#include <QFile>
#include <QDir>
#include <QTextStream>
#include <QTreeWidget>