Commit 3a06498b authored by Csaba Kertesz's avatar Csaba Kertesz

Smart pointer usage to free up resources correctly

parent ab753adb
......@@ -96,7 +96,6 @@ enum BinFileHelper::Errors BinFileHelper::__readHeader()
{
qint16 endian_id, i;
char ASCII_text[125];
dataElement *de = nullptr;
int ret = 0;
// Read the preamble
......@@ -128,17 +127,19 @@ enum BinFileHelper::Errors BinFileHelper::__readHeader()
ret = fread(&nfields, 2, 1, fileHandle);
if (byteswap)
nfields = bswap_16(nfields);
qDeleteAll(fields);
fields.clear();
for (i = 0; i < nfields; ++i)
{
// FIXME: Valgrind shows 176 bytes lost here in 11 blocks. Why? Investigate
de = new dataElement;
dataElement *de = new dataElement;
// Read 16 byte dataElement that describe each field (name[8], size[1], type[1], scale[4])
if (!fread(de, sizeof(dataElement), 1, fileHandle))
{
delete de;
qDeleteAll(fields);
fields.clear();
return ERR_FD_TRUNC;
}
if (byteswap)
......
......@@ -15,14 +15,17 @@
* *
***************************************************************************/
#include <QStandardPaths>
#include "ksuserdb.h"
#include "kstarsdata.h"
#include "artificialhorizoncomponent.h"
#include "version.h"
#include "linelist.h"
#include "kspaths.h"
#include "kstarsdata.h"
#include "linelist.h"
#include "version.h"
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlTableModel>
/*
* TODO (spacetime):
......@@ -1294,7 +1297,7 @@ QList<ArtificialHorizonEntity *> KSUserDB::GetAllHorizons()
points.setTable(regionTable);
points.select();
LineList *skyList = new LineList();
std::shared_ptr<LineList> skyList(new LineList());
ArtificialHorizonEntity *horizon = new ArtificialHorizonEntity;
......@@ -1306,13 +1309,13 @@ QList<ArtificialHorizonEntity *> KSUserDB::GetAllHorizons()
for (int j = 0; j < points.rowCount(); j++)
{
record = points.record(j);
std::shared_ptr<SkyPoint> p(new SkyPoint());
SkyPoint *p = new SkyPoint();
record = points.record(j);
p->setAz(record.value(0).toDouble());
p->setAlt(record.value(1).toDouble());
p->HorizontalToEquatorial(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
skyList->append(p);
skyList->append(std::move(p));
}
points.clear();
......
......@@ -15,27 +15,20 @@
* *
***************************************************************************/
#ifndef KSTARS_KSUSERDB_H
#define KSTARS_KSUSERDB_H
#define KSTARS_USERDB "data/userdb.sqlite"
#pragma once
#include <KLocalizedString>
#include "auxiliary/profileinfo.h"
#ifndef KSTARS_LITE
#include "oal/oal.h"
#endif
#include "skyobjects/skyobject.h"
#include <QStringList>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlTableModel>
#include <QString>
#include <QHash>
#include <QSqlError>
#include <QVariant>
#include <QVariantMap>
#include <QFile>
#include <QXmlStreamReader>
#include "skyobjects/skyobject.h"
#ifndef KSTARS_LITE
#include "oal/oal.h"
#endif
#include "auxiliary/profileinfo.h"
class LineList;
class ArtificialHorizonEntity;
......@@ -354,5 +347,3 @@ class KSUserDB
**/
inline QSqlError LastError();
};
#endif // KSTARS_KSUSERDB_H
......@@ -16,22 +16,11 @@
***************************************************************************/
#include "locationdialog.h"
#include "ui_locationdialog.h"
#include <cstdlib>
#include <cstdio>
#include <QFile>
#include <QTextStream>
#include <QListWidget>
#include <KMessageBox>
#include <KLocalizedString>
#include <QStandardPaths>
#include "kstarsdata.h"
#include "kspaths.h"
#include "kstarsdata.h"
#include <QSqlQuery>
LocationDialogUI::LocationDialogUI(QWidget *parent) : QFrame(parent)
{
......
......@@ -15,43 +15,16 @@
* *
***************************************************************************/
#ifndef LOCATIONDIALOG_H_
#define LOCATIONDIALOG_H_
/** @class LocationDialog
*Dialog for changing the geographic location of the observer. The
*dialog is divided into two sections.
*
*The top section allows the location to be selected from a database
*of 2000 cities. It contains a MapCanvas (showing map of the globe
*with cities overlaid, with a handler for mouse clicks), a QListBox
*containing the names of cities in the database, and three QLineEdit
*widgets, which allow the user to filter the List by the name of the
*City, Province, and Country. In addition, the List
*can be filtered by location, by clicking anywhere in the MapCanvas.
*Doing so will display cities within 2 degrees of the clicked position.
*
*The bottom section allows the location to be specified manually.
*The Longitude, Latitude, City name, Province/State name, and Country name
*are entered into KLineEdits. There is also a QPushButton for adding the
*location to the custom Cities database. If the user selects "Add" without
*filling in all of the manual entry fields, an error message is displayed.
*@short Geographic Location dialog
*@author Jason Harris
*@version 1.0
*/
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QTimer>
#include <QDialog>
#pragma once
#include "geolocation.h"
#include "ui_locationdialog.h"
#include <QDialog>
#include <QList>
class QTimer;
class LocationDialogUI : public QFrame, public Ui::LocationDialog
{
Q_OBJECT
......@@ -59,6 +32,30 @@ class LocationDialogUI : public QFrame, public Ui::LocationDialog
explicit LocationDialogUI(QWidget *parent = 0);
};
/**
* @class LocationDialog
* Dialog for changing the geographic location of the observer. The
* dialog is divided into two sections.
*
* The top section allows the location to be selected from a database
* of 2000 cities. It contains a MapCanvas (showing map of the globe
* with cities overlaid, with a handler for mouse clicks), a QListBox
* containing the names of cities in the database, and three QLineEdit
* widgets, which allow the user to filter the List by the name of the
* City, Province, and Country. In addition, the List
* can be filtered by location, by clicking anywhere in the MapCanvas.
* Doing so will display cities within 2 degrees of the clicked position.
*
* The bottom section allows the location to be specified manually.
* The Longitude, Latitude, City name, Province/State name, and Country name
* are entered into KLineEdits. There is also a QPushButton for adding the
* location to the custom Cities database. If the user selects "Add" without
* filling in all of the manual entry fields, an error message is displayed.
*
* @short Geographic Location dialog
* @author Jason Harris
* @version 1.0
*/
class LocationDialog : public QDialog
{
Q_OBJECT
......@@ -66,15 +63,17 @@ class LocationDialog : public QDialog
public:
typedef enum { CITY_ADD, CITY_UPDATE, CITY_REMOVE } CityOperation;
/**Constructor. Create all widgets, and pack them into QLayouts.
* Connect Signals to Slots. Run initCityList().
*/
/**
* Constructor. Create all widgets, and pack them into QLayouts.
* Connect Signals to Slots. Run initCityList().
*/
explicit LocationDialog(QWidget *parent);
/**Initialize list of cities. Note that the database is not read in here,
* that is done in the KStars constructor. This simply loads the local QListBox
* with the names of the cities from the kstarsData object.
*/
/**
* Initialize list of cities. Note that the database is not read in here,
* that is done in the KStars constructor. This simply loads the local QListBox
* with the names of the cities from the kstarsData object.
*/
void initCityList(void);
/** @return pointer to the highlighted city in the List. */
......@@ -84,66 +83,69 @@ class LocationDialog : public QDialog
QList<GeoLocation *> filteredList() { return filteredCityList; }
/**
* @short Show only cities within 3 degrees of point specified by arguments
* @param longitude the longitude of the search point (int)
* @param latitude the latitude of the search point (int)
*/
* @short Show only cities within 3 degrees of point specified by arguments
* @param longitude the longitude of the search point (int)
* @param latitude the latitude of the search point (int)
*/
void findCitiesNear(int longitude, int latitude);
/** @return the city name of the selected location. */
QString selectedCityName(void) const { return SelectedCity->translatedName(); }
QString selectedCityName() const { return SelectedCity->translatedName(); }
/** @return the province name of the selected location. */
QString selectedProvinceName(void) const { return SelectedCity->translatedProvince(); }
QString selectedProvinceName() const { return SelectedCity->translatedProvince(); }
/** @return the country name of the selected location. */
QString selectedCountryName(void) const { return SelectedCity->translatedCountry(); }
QString selectedCountryName() const { return SelectedCity->translatedCountry(); }
/** @return true if the AddCityBUtton is enabled */
bool addCityEnabled();
public slots:
/**
* When text is entered in the City/Province/Country Filter
* KLineEdits, the List of cities is trimmed to show only cities
* beginning with the entered text. Also, the QMemArray of ID
* numbers is kept in sync with the filtered list.
*/
* When text is entered in the City/Province/Country Filter KLineEdits, the List of cities is
* trimmed to show only cities beginning with the entered text. Also, the QMemArray of ID
* numbers is kept in sync with the filtered list.
*/
void filterCity();
/**
* @short Filter by city / province / country only after a few milliseconds
*/
* @short Filter by city / province / country only after a few milliseconds
*/
void enqueueFilterCity();
/**When the selected city in the QListBox changes, repaint the MapCanvas
* so that the crosshairs icon appears on the newly selected city.
*/
/**
* When the selected city in the QListBox changes, repaint the MapCanvas
* so that the crosshairs icon appears on the newly selected city.
*/
void changeCity();
/**When the "Add new city" QPushButton is clicked, add the manually-entered
* city information to the user's custom city database.
* @return true on success
*/
/**
* When the "Add new city" QPushButton is clicked, add the manually-entered
* city information to the user's custom city database.
* @return true on success
*/
bool addCity();
/**When the "Update City" QPushButton is clicked, update the city
* information in the user's custom city database.
* @return true on success
*/
/**
* When the "Update City" QPushButton is clicked, update the city
* information in the user's custom city database.
* @return true on success
*/
bool updateCity();
/**When the "Remove City" QPushButton is clicked, remove the
* city information from the user's custom city database.
* @return true on success
*/
/**
* When the "Remove City" QPushButton is clicked, remove the
* city information from the user's custom city database.
* @return true on success
*/
bool removeCity();
/**
* @brief updateCity Adds, updates, or removes a city from the user's database.
* @param operation Add, update, or remove city
* @return true on success
*/
* @brief updateCity Adds, updates, or removes a city from the user's database.
* @param operation Add, update, or remove city
* @return true on success
*/
bool updateCity(CityOperation operation);
void clearFields();
......@@ -154,14 +156,13 @@ class LocationDialog : public QDialog
private:
/** Make sure Longitude and Latitude values are valid. */
bool checkLongLat(void);
bool checkLongLat();
bool dataModified, nameModified;
bool dataModified { false };
bool nameModified { false };
LocationDialogUI *ld;
GeoLocation *SelectedCity;
LocationDialogUI *ld { nullptr };
GeoLocation *SelectedCity { nullptr };
QList<GeoLocation *> filteredCityList;
QTimer *timer;
QTimer *timer { nullptr };
};
#endif
......@@ -8,26 +8,19 @@
*/
#include <QPushButton>
#include <QFileDialog>
#include <QCheckBox>
#include <QStringList>
#include <QComboBox>
#include <KConfigDialog>
#include <QSqlTableModel>
#include <QSqlDatabase>
#include <QDesktopServices>
#include "opsekos.h"
#include "Options.h"
#include "kstarsdata.h"
#include "ekosmanager.h"
#include "guide/guide.h"
#include "ksuserdb.h"
#include "ekos/auxiliary/darklibrary.h"
#include "auxiliary/ksnotification.h"
#include "kspaths.h"
#include "kstarsdata.h"
#include "Options.h"
#include "auxiliary/ksnotification.h"
#include "ekos/auxiliary/darklibrary.h"
#include <KConfigDialog>
#include <QSqlRecord>
#include <QSqlTableModel>
OpsEkos::OpsEkos() : QTabWidget(KStars::Instance())
{
......
......@@ -7,15 +7,14 @@
version 2 of the License, or (at your option) any later version.
*/
#ifndef OpsEkos_H_
#define OpsEkos_H_
#pragma once
#include <QSqlDatabase>
#include "ui_opsekos.h"
class KConfigDialog;
class QSqlTableModel;
class KConfigDialog;
/**
* @class OpsEkos
*
......@@ -43,5 +42,3 @@ class OpsEkos : public QTabWidget, public Ui::OpsEkos
KConfigDialog *m_ConfigDialog;
QSqlTableModel *darkFramesModel = nullptr;
};
#endif
......@@ -35,6 +35,7 @@
#include <KMessageBox>
#endif
#include <QSqlQuery>
#include <QtConcurrent>
namespace
......
......@@ -15,22 +15,25 @@
***************************************************************************/
#include "locationdialoglite.h"
#include "kspaths.h"
#include "kstarsdata.h"
#include "kstarslite.h"
#include <QQmlContext>
#include "kspaths.h"
#include <QGeoPositionInfoSource>
#include "Options.h"
#include <QNetworkAccessManager>
#include <QNetworkSession>
#include <QNetworkConfigurationManager>
#include <QUrlQuery>
#include <QNetworkReply>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QNetworkAccessManager>
#include <QNetworkConfigurationManager>
#include <QNetworkReply>
#include <QNetworkSession>
#include <QQmlContext>
#include <QSqlQuery>
#include <QUrlQuery>
LocationDialogLite::LocationDialogLite() : SelectedCity(nullptr), currentGeo(nullptr)
{
......
......@@ -14,16 +14,15 @@
* *
***************************************************************************/
#ifndef LOCATIONDIALOGLITE_H_
#define LOCATIONDIALOGLITE_H_
#pragma once
#include <QStringListModel>
#include <QSqlDatabase>
#include <QGeoPositionInfo>
#include "skyobjects/skyobject.h"
/** @class LocationDialogLite
/**
* @class LocationDialogLite
* A backend of location dialog declared in QML.
*
* @short Backend for location dialog in QML
......@@ -74,23 +73,24 @@ class LocationDialogLite : public QObject
Q_INVOKABLE bool isDuplicate(QString city, QString province, QString country);
/**
* @brief checkLongLat checks whether given longitude and latitude are valid
*/
* @brief checkLongLat checks whether given longitude and latitude are valid
*/
Q_INVOKABLE bool checkLongLat(QString longitude, QString latitude);
/**
* TODO - port dmsBox to QML
* @brief createDms creates dms from string
* @param degree string that should be converted to degree
* @param deg if true, the value is in degrees. Otherwise, it is in hours.
* @param ok
* @return angle in dms
*/
* TODO - port dmsBox to QML
* @brief createDms creates dms from string
* @param degree string that should be converted to degree
* @param deg if true, the value is in degrees. Otherwise, it is in hours.
* @param ok
* @return angle in dms
*/
dms createDms(QString degree, bool deg, bool *ok);
/**
* @short retrieve name of location by latitude and longitude. Name will be sent with sendNameFromCoordinates signal
*/
* @short Retrieve name of location by latitude and longitude. Name will be sent with
* sendNameFromCoordinates signal
*/
Q_INVOKABLE void getNameFromCoordinates(double latitude, double longitude);
public slots:
......@@ -108,23 +108,21 @@ class LocationDialogLite : public QObject
private:
/**
* @short checks whether database with cities is already created. Creates a new otherwise
* @return city database
*/
* @short checks whether database with cities is already created. Creates a new otherwise
* @return city database
*/
QSqlDatabase getDB();
QStringListModel m_cityList;
QHash<QString, GeoLocation *> filteredCityList;
GeoLocation *SelectedCity;
GeoLocation *currentGeo;
GeoLocation *SelectedCity { nullptr };
GeoLocation *currentGeo { nullptr };
QString m_currentLocation;
int m_currLocIndex;
int m_currLocIndex { 0 };
QStringList m_TZList;
QStringList m_DSTRules;
//Retrieve the name of city
QNetworkAccessManager *nam;
QNetworkAccessManager *nam { nullptr };
};
#endif
......@@ -15,6 +15,8 @@
***************************************************************************/
#include "constellationartitem.h"
#include "Options.h"
#include "projections/projector.h"
#include "constellationartcomponent.h"
#include "skynodes/constellationartnode.h"
......
......@@ -13,17 +13,19 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CONSTELLATIONARTITEM_H_
#define CONSTELLATIONARTITEM_H_
#pragma once
#include "skyitem.h"
class RootNode;
class ConstellationArtComponent;
/**
* @class ConstellationArtItem
* This class handles constellation art in SkyMapLite. Each constellation image is represented by ConstellationArtNode.
* @see ConstellationArtNode
*
* @author Artem Fedoskin
* @version 1.0
*/
......@@ -32,29 +34,29 @@ class ConstellationArtItem : public SkyItem
{
public:
/**
* @param artComp - pointer to ConstellationArtComponent instance, that handles constellation art data
* @param rootNode - pointer to the root node
*/
* @param artComp - pointer to ConstellationArtComponent instance, that handles constellation art data
* @param rootNode - pointer to the root node
*/
ConstellationArtItem(ConstellationArtComponent *artComp, RootNode *rootNode = 0);
/**
* @short calls update() of all child ConstellationArtNodes if constellation art is on. Otherwise calls deleteNodes()
*/
* @short calls update() of all child ConstellationArtNodes if constellation art is on. Otherwise
* calls deleteNodes().
*/
void update() override;
/**
* @short deleteNodes deletes constellation art data and ConstellationArtNodes
* @see ConstellationArtComponent::deleteData()
*/
* @short deleteNodes deletes constellation art data and ConstellationArtNodes
* @see ConstellationArtComponent::deleteData()
*/
void deleteNodes();
/**
* @short loadNodes loads constellation art data and creates ConstellationArtNodes