Commit ab753adb authored by Csaba Kertesz's avatar Csaba Kertesz

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);
......
This diff is collapsed.
......@@ -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>
#include <QIcon>
#include <QDialog>
#include <QStandardPaths>
#include <QAction>
#include <QMenu>
#include <QPushButton>
#include <QTcpServer>
#include "config-kstars.h"
#include "clientmanager.h"
#include "driverinfo.h"
#include "guimanager.h"
#include "indilistener.h"
#include "kspaths.h"
#include "kstarsdata.h"
#include "Options.h"
#include "servermanager.h"
#include "ui_indihostconf.h"
#include "auxiliary/ksnotification.h"
#include <basedevice.h>
#ifndef KSTARS_LITE
#include <KMessageBox>
......@@ -29,24 +31,7 @@
#include <KNotifications/KNotification>
#endif
#include "oal/log.h"
#include "oal/scope.h"
#include "ui_indihostconf.h"
#include "servermanager.h"
#include "guimanager.h"
#include "Options.h"
#include "drivermanager.h"
#include "driverinfo.h"
#include "auxiliary/ksnotification.h"
#include "kstars.h"
#include "kstarsdata.h"
#include "ksutils.h"
#include "indilistener.h"
#include "kspaths.h"
#include <config-kstars.h>
#include <QTcpServer>
#define INDI_MAX_TRIES 2
#define ERRMSG_SIZE 1024
......
......@@ -8,21 +8,21 @@
*/
#ifndef DriverManager_H_
#define DriverManager_H_
#pragma once
#include "indicommon.h"
#include "indidbus.h"
#include "ui_drivermanager.h"
#include <QFrame>
#include <QHash>
#include <QStringList>
#include <QDialog>
#include <QFrame>
#include <QIcon>
#include <QString>
#include <lilxml.h>
#include "ui_drivermanager.h"
#include "indidbus.h"
#include "indicommon.h"
class QStringList;
class QTreeWidgetItem;
class QIcon;
class DriverManager;
class ServerManager;
......@@ -184,5 +184,3 @@ class DriverManager : public QDialog
void newCCD();
*/
};
#endif
......@@ -7,39 +7,21 @@
version 2 of the License, or (at your option) any later version.
*/
#include <stdlib.h>
#include <QLineEdit>
#include <QTextEdit>
#include <QFrame>
#include <QCheckBox>
#include <QLabel>
#include <QPushButton>
#include <QLayout>
#include <QSocketNotifier>
#include <QDateTime>
#include <QSplitter>
#include <QLocale>
#include <KMessageBox>
#include <QDebug>
#include <QComboBox>
#include <QDialog>
#include <QTabWidget>
#include <KLed>
#include <KActionCollection>
#include <basedevice.h>
#include "guimanager.h"
#include "clientmanager.h"
#include "deviceinfo.h"
#include "indidevice.h"
#include "kstars.h"
#include "Options.h"
#include "fitsviewer/fitsviewer.h"
#include "kstars.h"
#include "indidevice.h"
#include "guimanager.h"
#include "driverinfo.h"
#include "deviceinfo.h"
#include <KActionCollection>
#include <KMessageBox>
#include "Options.h"
#include <QSplitter>
#include <QTextEdit>
#include <QThread>
extern const char *libindi_strings_context;
......
......@@ -7,33 +7,24 @@
version 2 of the License, or (at your option) any later version.
*/
#ifndef GUIMANAGER_H
#define GUIMANAGER_H
#pragma once
#include <QGridLayout>
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <QTabWidget>
#include <QPointer>
#include <QList>
#include <QWidget>
#include <indibase.h>
#include "clientmanager.h"
class QLabel;
class QHBoxLayout;
class QVBoxLayout;
class QFrame;
class QCloseEvent;
class QHideEvent;
class QPushButton;
class QShowEvent;
class QString;
class QTabWidget;
class QGridLayout;
class QPushButton;
class FITSViewer;
class QVBoxLayout;
class INDI_D;
class ClientManager;
class DeviceInfo;
/**
* @class GUIManager
* GUIManager creates the INDI Control Panel upon receiving a new device. Each device is displayed
......@@ -66,8 +57,8 @@ class GUIManager : public QWidget
private:
/*****************************************************************
* GUI stuff
******************************************************************/
* GUI stuff
******************************************************************/
QVBoxLayout *mainLayout;
QTabWidget *mainTabWidget;
QPushButton *clearB;
......@@ -84,5 +75,3 @@ class GUIManager : public QWidget
void buildDevice(DeviceInfo *di);
void removeDevice(DeviceInfo *di);
};
#endif // GUIMANAGER_H
......@@ -17,62 +17,43 @@
#include "kstars.h"
#include <QApplication>
#include <QDockWidget>
#include <QDebug>
#include <QStatusBar>
#include <QIcon>
#include <QMenu>
#include "config-kstars.h"
#include "version.h"
#ifdef Q_OS_WIN
#include <QProcess>
#endif
#include <KLocalizedString>
#include <KActionCollection>
#include <KToolBar>
#include <KSharedConfig>
#include "Options.h"
#include "fov.h"
#include "kactionmenu.h"
#include "kstarsadaptor.h"
#include "kstarsdata.h"
#include "kstarssplash.h"
#include "kactionmenu.h"
#include "observinglist.h"
#include "Options.h"
#include "skymap.h"
#include "ksutils.h"
#include "simclock.h"
#include "fov.h"
#include "skyqpainter.h"
#include "texturemanager.h"
#include "dialogs/finddialog.h"
#include "dialogs/exportimagedialog.h"
#include "observinglist.h"
//#include "whatsinteresting/wiview.h"
// For profiling only
#include "auxiliary/dms.h"
#include "skyobjects/skypoint.h"
#include "kstarsadaptor.h"
#include <config-kstars.h>
#include <version.h>
#include "skycomponents/starblockfactory.h"
#ifdef HAVE_INDI
#include "ekos/ekosmanager.h"
#include "indi/drivermanager.h"
#include "indi/guimanager.h"
#include "ekos/ekosmanager.h"
#endif
#ifdef HAVE_CFITSIO
#include "fitsviewer/fitsviewer.h"
#endif
KStars *KStars::pinstance = 0;
#include <KActionCollection>
#include <KToolBar>
#ifdef Q_OS_WIN
#include <QProcess>
#endif
KStars *KStars::pinstance = nullptr;
KStars::KStars(bool doSplash, bool clockrun, const QString &startdate)
: KXmlGuiWindow(), colorActionMenu(0), fovActionMenu(0), m_KStarsData(0), m_SkyMap(0), m_TimeStepBox(0),
m_ExportImageDialog(0), m_PrintingWizard(0), m_FindDialog(0), m_AstroCalc(0), m_AltVsTime(0), m_SkyCalendar(0),
m_ScriptBuilder(0), m_PlanetViewer(0), m_WUTDialog(0), /*m_JMoonTool(0),*/ m_MoonPhaseTool(0), m_FlagManager(0),
m_HorizonManager(0), m_EyepieceView(0), m_addDSODialog(0), m_WIView(0), m_ObsConditions(0), m_wiDock(0),
DialogIsObsolete(false), StartClockRunning(clockrun), StartDateString(startdate)
: KXmlGuiWindow(), StartClockRunning(clockrun), StartDateString(startdate)
{
setWindowTitle(i18n("KStars"));
......@@ -250,19 +231,9 @@ KStars *KStars::createInstance(bool doSplash, bool clockrun, const QString &star
KStars::~KStars()
{
releaseResources();
Q_ASSERT(pinstance);
delete m_KStarsData;
pinstance = 0;
#ifdef HAVE_INDI
delete m_EkosManager;
GUIManager::Instance()->close();
#endif
QSqlDatabase::removeDatabase("userdb");
QSqlDatabase::removeDatabase("skydb");
pinstance = nullptr;
#ifdef PROFILE_COORDINATE_CONVERSION
qDebug() << "Spent " << SkyPoint::cpuTime_EqToHz << " seconds in " << SkyPoint::eqToHzCalls
<< " calls to SkyPoint::EquatorialToHorizontal, for an average of "
......@@ -292,6 +263,25 @@ KStars::~KStars()
#endif
}
void KStars::releaseResources()
{
delete m_KStarsData;
m_KStarsData = nullptr;
delete StarBlockFactory::Instance();
TextureManager::Release();
SkyQPainter::releaseImageCache();
FOVManager::releaseCache();
#ifdef HAVE_INDI
delete m_EkosManager;
m_EkosManager = nullptr;
// GUIManager::Instance()->close();
#endif
QSqlDatabase::removeDatabase("userdb");
QSqlDatabase::removeDatabase("skydb");
}
void KStars::clearCachedFindDialog()
{
if (m_FindDialog) // dialog is cached
......
......@@ -14,19 +14,23 @@
* *
***************************************************************************/
#ifndef KSTARS_H_
#define KSTARS_H_
#pragma once
#include <QtDBus/QtDBus>
#include <kxmlguiwindow.h>
#include <config-kstars.h>
#include <QDockWidget>
#include "config-kstars.h"
#include "oal/equipmentwriter.h"
#include "oal/observeradd.h"
#include <kxmlguiwindow.h>
#include <QDockWidget>
#include <QtDBus/qdbusmacros.h>
#ifdef HAVE_CFITSIO
#include <QPointer>
#endif
// forward declaration is enough. We only need pointers
class QDockWidget;
class QPalette;
class KActionMenu;
......@@ -123,9 +127,12 @@ class KStars : public KXmlGuiWindow
/** @return a pointer to the instance of this class */
inline static KStars *Instance() { return pinstance; }
/** Destructor. Synchs config file. Deletes objects. */
/** Destructor. */
virtual ~KStars();
/** Syncs config file. Deletes objects. */
void releaseResources();
/** @return pointer to KStarsData object which contains application data. */
inline KStarsData *data() const { return m_KStarsData; }
......@@ -485,7 +492,7 @@ class KStars : public KXmlGuiWindow
/** action slot: open KStars setup wizard */
void slotWizard();
void updateLocationFromWizard(GeoLocation geo);
void updateLocationFromWizard(const GeoLocation& geo);
WIView *wiView() { return m_WIView; }
......@@ -674,35 +681,35 @@ class KStars : public KXmlGuiWindow
/** Build the KStars main window */
void buildGUI();
KActionMenu *colorActionMenu, *fovActionMenu;
KActionMenu *colorActionMenu { nullptr };
KActionMenu *fovActionMenu { nullptr };
KStarsData *m_KStarsData;
SkyMap *m_SkyMap;
KStarsData *m_KStarsData { nullptr };
SkyMap *m_SkyMap { nullptr };
// Widgets
TimeStepBox *m_TimeStepBox;
TimeStepBox *m_TimeStepBox { nullptr };
// Dialogs & Tools
// File Menu
ExportImageDialog *m_ExportImageDialog;
PrintingWizard *m_PrintingWizard;
ExportImageDialog *m_ExportImageDialog { nullptr };
PrintingWizard *m_PrintingWizard { nullptr };