summaryrefslogtreecommitdiff
path: root/plugins/Oculars/src/Telescope.cpp
blob: 9fc69d90b76dd5a6486442c30af23805b320cfbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (C) 2009 Timothy Reaves
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
 */

#include "Telescope.hpp"

#include <QDebug>
#include <QSettings>

Telescope::Telescope()
	: m_diameter(0.)
	, m_focalLength(0.)
	, m_hFlipped(false)
	, m_vFlipped(false)
	, m_equatorial(false)
{
}

Telescope::Telescope(const QObject& other)
	: m_name(other.property("name").toString())
	, m_diameter(other.property("diameter").toDouble())
	, m_focalLength(other.property("focalLength").toDouble())
	, m_hFlipped(other.property("hFlipped").toBool())
	, m_vFlipped(other.property("vFlipped").toBool())
	, m_equatorial(other.property("equatorial").toBool())
{
}

Telescope::~Telescope()
{
}

static QMap<int, QString> mapping;
QMap<int, QString> Telescope::propertyMap()
{
	if(mapping.isEmpty()) {
	mapping = {
		    {0, "name"},
		    {1, "diameter"},
		    {2, "focalLength"},
		    {3, "hFlipped"},
		    {4, "vFlipped"},
		    {5, "equatorial"}};
	}
	return mapping;
}

const QString Telescope::name() const
{
	return m_name;
}

void Telescope::setName(QString theValue)
{
	m_name = theValue;
}

double Telescope::focalLength() const
{
	return m_focalLength;
}

void Telescope::setFocalLength(double theValue)
{
	m_focalLength = theValue;
}

double Telescope::diameter() const
{
	return m_diameter;
}

void Telescope::setDiameter(double theValue)
{
	m_diameter = theValue;
}

bool Telescope::isHFlipped() const
{
	return m_hFlipped;
}

void Telescope::setHFlipped(bool flipped)
{
	m_hFlipped = flipped;
}

bool Telescope::isVFlipped() const
{
	return m_vFlipped;
}

void Telescope::setVFlipped(bool flipped)
{
	m_vFlipped = flipped;
}

bool Telescope::isEquatorial() const
{
	return m_equatorial;
}

void Telescope::setEquatorial(bool eq)
{
	m_equatorial = eq;
}

void Telescope::writeToSettings(QSettings * settings, const int index)
{
	QString prefix = "telescope/" + QVariant(index).toString() + "/";
	settings->setValue(prefix + "name", this->name());
	settings->setValue(prefix + "focalLength", this->focalLength());
	settings->setValue(prefix + "diameter", this->diameter());
	settings->setValue(prefix + "hFlip", this->isHFlipped());
	settings->setValue(prefix + "vFlip", this->isVFlipped());
	settings->setValue(prefix + "equatorial", this->isEquatorial());
}

Telescope* Telescope::telescopeFromSettings(QSettings* theSettings, int telescopeIndex)
{
	Telescope* telescope = new Telescope();
	QString prefix = "telescope/" + QVariant(telescopeIndex).toString() + "/";
	
	telescope->setName(theSettings->value(prefix + "name", "").toString());
	telescope->setFocalLength(theSettings->value(prefix + "focalLength", "0").toDouble());
	telescope->setDiameter(theSettings->value(prefix + "diameter", "0").toDouble());
	telescope->setHFlipped(theSettings->value(prefix + "hFlip").toBool());
	telescope->setVFlipped(theSettings->value(prefix + "vFlip").toBool());
	telescope->setEquatorial(theSettings->value(prefix + "equatorial").toBool());
	return telescope;
}

Telescope* Telescope::telescopeModel()
{
	Telescope* model = new Telescope();
	model->setName("My Telescope");
	model->setDiameter(80);
	model->setFocalLength(500);
	model->setHFlipped(true);
	model->setVFlipped(true);
	model->setEquatorial(true);
	return model;
}