Kstars

log.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Prakash Mohan <prakash.mohan@kdemail.net>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "log.h"
8
9#include "kstars.h"
10#include "kstarsdata.h"
11#include "kstarsdatetime.h"
12#include "ksutils.h"
13#include "observinglist.h"
14#include "skymap.h"
15#include "skycomponents/constellationboundarylines.h"
16#include "skycomponents/skymapcomposite.h"
17#include "skyobjects/skyobject.h"
18#include "skyobjects/starobject.h"
19
20#include "kstars_debug.h"
21
22OAL::Log::~Log()
23{
24 //qDeleteAll(m_targetList);
25 qDeleteAll(m_observerList);
26 qDeleteAll(m_eyepieceList);
27 qDeleteAll(m_lensList);
28 qDeleteAll(m_filterList);
29 qDeleteAll(m_siteList);
30 qDeleteAll(m_sessionList);
31 qDeleteAll(m_scopeList);
32 qDeleteAll(m_dslrLensList);
33 qDeleteAll(m_observationList);
34}
35
36void OAL::Log::writeBegin()
37{
38 output = "";
39 //m_targetList = KSUtils::makeVanillaPointerList(KStarsData::Instance()->observingList()->sessionList());
40 m_targetList = KStarsData::Instance()->observingList()->sessionList();
41 writer = new QXmlStreamWriter(&output);
42 writer->setAutoFormatting(true);
43 writer->writeStartDocument();
44 writer->writeNamespace("http://observation.sourceforge.net/openastronomylog", "oal");
45 writer->writeNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
46 writer->writeNamespace("http://observation.sourceforge.net/openastronomylog oal20.xsd", "schemaLocation");
47 writer->writeStartElement("oal:observations");
48 writer->writeAttribute("version", "2.0");
49}
50
51QString OAL::Log::writeLog(bool _native)
52{
53 native = _native;
54 writeBegin();
55 if (native)
56 writeGeoDate();
57 writeObservers();
58 writeSites();
59 writeSessions();
60 writeTargets();
61 writeScopes();
62 writeDSLRLenses();
63 writeEyepieces();
64 writeLenses();
65 writeFilters();
66 writeImagers();
67 writeObservations();
68 writeEnd();
69 return output;
70}
71
72void OAL::Log::writeEnd()
73{
74 writer->writeEndDocument();
75 delete writer;
76}
77
78void OAL::Log::writeObservers()
79{
80 writer->writeStartElement("observers");
81 foreach (OAL::Observer *o, m_observerList)
82 writeObserver(o);
83 writer->writeEndElement();
84}
85
86void OAL::Log::writeSites()
87{
88 writer->writeStartElement("sites");
89 foreach (OAL::Site *o, m_siteList)
90 writeSite(o);
91 writer->writeEndElement();
92}
93
94void OAL::Log::writeSessions()
95{
96 writer->writeStartElement("sessions");
97 foreach (OAL::Session *o, m_sessionList)
98 writeSession(o);
99 writer->writeEndElement();
100}
101
102void OAL::Log::writeTargets()
103{
104 writer->writeStartElement("targets");
105 //foreach (SkyObject *o, m_targetList)
106 for (auto &o : m_targetList)
107 {
108 writeTarget(o.data());
109 }
110 writer->writeEndElement();
111}
112
113void OAL::Log::writeScopes()
114{
115 writer->writeStartElement("scopes");
116 foreach (OAL::Scope *o, m_scopeList)
117 writeScope(o);
118 writer->writeEndElement();
119}
120
121void OAL::Log::writeDSLRLenses()
122{
123 writer->writeStartElement("dslrlenses");
124 for (const auto &o : m_dslrLensList)
125 writeDSLRLenses(o);
126 writer->writeEndElement();
127}
128
129void OAL::Log::writeEyepieces()
130{
131 writer->writeStartElement("eyepieces");
132 foreach (OAL::Eyepiece *o, m_eyepieceList)
133 writeEyepiece(o);
134 writer->writeEndElement();
135}
136
137void OAL::Log::writeLenses()
138{
139 writer->writeStartElement("lenses");
140 foreach (OAL::Lens *o, m_lensList)
141 writeLens(o);
142 writer->writeEndElement();
143}
144
145void OAL::Log::writeFilters()
146{
147 writer->writeStartElement("filters");
148 foreach (OAL::Filter *o, m_filterList)
149 writeFilter(o);
150 writer->writeEndElement();
151}
152
153void OAL::Log::writeImagers()
154{
155 writer->writeStartElement("imagers");
156 writer->writeEndElement();
157}
158
159void OAL::Log::writeObservations()
160{
161 foreach (OAL::Observation *o, m_observationList)
162 writeObservation(o);
163}
164
165void OAL::Log::writeTarget(SkyObject *o)
166{
167 writer->writeStartElement("target");
168 writer->writeAttribute("id", o->name().remove(' '));
169 QString typeString;
170 if (native)
171 writer->writeAttribute("type", o->typeName());
172 else
173 {
174 switch (o->type())
175 {
176 case 0:
177 typeString = "oal:starTargetType";
178 break;
179 case 1:
180 typeString = "oal:starTargetType";
181 break;
182 case 2:
183 typeString = "oal:PlanetTargetType";
184 break;
185 case 3:
186 typeString = "oal:deepSkyOC";
187 break;
188 case 4:
189 typeString = "oal:deepSkyGC";
190 break;
191 case 5:
192 typeString = "oal:deepSkyGN";
193 break;
194 case 6:
195 typeString = "oal:deepSkyPN";
196 break;
197 case 8:
198 typeString = "oal:deepSkyGX";
199 break;
200 case 9:
201 typeString = "oal:CometTargetType";
202 break;
203 case 12:
204 typeString = "oal:MoonTargetType";
205 break;
206 case 13:
207 typeString = "oal:deepSkyAS";
208 break;
209 case 14:
210 typeString = "oal:deepSkyCG";
211 break;
212 case 15:
213 typeString = "oal:deepSkyDN";
214 break;
215 case 16:
216 typeString = "oal:deepSkyQS";
217 break;
218 case 17:
219 typeString = "oal:deepSkyMS";
220 break;
221 default:
222 typeString = "oal:deepSkyNA";
223 break;
224 }
225 writer->writeAttribute("xsi:type", typeString);
226 }
227 writer->writeStartElement("datasource");
228 writer->writeCDATA("KStars");
229 writer->writeEndElement();
230 writer->writeStartElement("name");
231 QString name = o->name();
232 if (name == "star")
233 {
234 if (((StarObject *)o)->getHDIndex() != 0)
235 name = QString("HD %1").arg(((StarObject *)o)->getHDIndex());
236 }
237 writer->writeCDATA(name);
238 writer->writeEndElement();
239 writer->writeStartElement("position");
240 writer->writeStartElement("ra");
241 writer->writeAttribute("unit", "rad");
242 writer->writeCharacters(QString::number(o->ra().radians()));
243 writer->writeEndElement();
244 writer->writeStartElement("dec");
245 writer->writeAttribute("unit", "rad");
246 writer->writeCharacters(QString::number(o->dec().radians()));
247 writer->writeEndElement();
248 writer->writeEndElement();
249 if (native && !KStarsData::Instance()->observingList()->getTime(o).isEmpty())
250 {
251 writer->writeStartElement("time");
252 writer->writeCDATA(KStarsData::Instance()->observingList()->getTime(o));
253 writer->writeEndElement();
254 }
255 writer->writeStartElement("constellation");
256 writer->writeCDATA(KStarsData::Instance()
257 ->skyComposite()
258 ->constellationBoundary()
259 ->constellationName(o));
260 writer->writeEndElement();
261 writer->writeStartElement("notes");
262 writer->writeCDATA(KStarsData::Instance()->getUserData(o->name()).userLog);
263 writer->writeEndElement();
264 writer->writeEndElement();
265}
266
267void OAL::Log::writeObserver(OAL::Observer *o)
268{
269 writer->writeStartElement("observer");
270 writer->writeAttribute("id", o->id());
271 writer->writeStartElement("name");
272 writer->writeCDATA(o->name());
273 writer->writeEndElement();
274 writer->writeStartElement("surname");
275 writer->writeCDATA(o->surname());
276 writer->writeEndElement();
277 writer->writeStartElement("contact");
278 writer->writeCDATA(o->contact());
279 writer->writeEndElement();
280 writer->writeEndElement();
281}
282
283void OAL::Log::writeSite(OAL::Site *s)
284{
285 writer->writeStartElement("site");
286 writer->writeAttribute("id", s->id());
287 writer->writeStartElement("name");
288 writer->writeCDATA(s->name());
289 writer->writeEndElement();
290 writer->writeStartElement("latitude");
291 writer->writeAttribute("unit", s->latUnit());
292 writer->writeCharacters(QString::number(s->latitude()));
293 writer->writeStartElement("longitude");
294 writer->writeAttribute("unit", s->lonUnit());
295 writer->writeCharacters(QString::number(s->longitude()));
296 writer->writeEndElement();
297 writer->writeEndElement();
298}
299
300void OAL::Log::writeSession(OAL::Session *s)
301{
302 writer->writeStartElement("session");
303 writer->writeAttribute("id", s->id());
304 writer->writeStartElement("begin");
305 writer->writeCharacters(s->begin().date().toString("yyyy-MM-dd") + 'T' + s->begin().time().toString("hh:mm:ss"));
306 writer->writeEndElement();
307 writer->writeStartElement("end");
308 writer->writeCharacters(s->end().date().toString("yyyy-MM-dd") + 'T' + s->end().time().toString("hh:mm:ss"));
309 writer->writeEndElement();
310 writer->writeStartElement("site");
311 writer->writeCharacters(s->site());
312 writer->writeEndElement();
313 writer->writeStartElement("weather");
314 writer->writeCDATA(s->weather());
315 writer->writeEndElement();
316 writer->writeStartElement("equipment");
317 writer->writeCDATA(s->equipment());
318 writer->writeEndElement();
319 writer->writeStartElement("comments");
320 writer->writeCDATA(s->comments());
321 writer->writeEndElement();
322 writer->writeEndElement();
323}
324
325void OAL::Log::writeScope(OAL::Scope *s)
326{
327 writer->writeStartElement("scope");
328 writer->writeAttribute("id", s->id());
329 writer->writeStartElement("model");
330 writer->writeCDATA(s->model());
331 writer->writeEndElement();
332 writer->writeStartElement("type");
333 writer->writeCDATA(s->type().at(0));
334 writer->writeEndElement();
335 writer->writeStartElement("vendor");
336 writer->writeCDATA(s->vendor());
337 writer->writeEndElement();
338 writer->writeStartElement("aperture");
339 writer->writeCharacters(QString::number(s->aperture()));
340 writer->writeEndElement();
341 writer->writeStartElement("focalLength");
342 writer->writeCharacters(QString::number(s->focalLength()));
343 writer->writeEndElement();
344 writer->writeEndElement();
345 writer->writeEndElement();
346}
347
348void OAL::Log::writeDSLRLenses(OAL::DSLRLens *s)
349{
350 writer->writeStartElement("dslrlens");
351 writer->writeAttribute("id", s->id());
352 writer->writeStartElement("model");
353 writer->writeCDATA(s->model());
354 writer->writeEndElement();
355 writer->writeStartElement("vendor");
356 writer->writeCDATA(s->vendor());
357 writer->writeEndElement();
358 writer->writeStartElement("focalLength");
359 writer->writeCharacters(QString::number(s->focalLength()));
360 writer->writeEndElement();
361 writer->writeStartElement("focalRatio");
362 writer->writeCharacters(QString::number(s->focalRatio()));
363 writer->writeEndElement();
364 writer->writeEndElement();
365}
366
367void OAL::Log::writeEyepiece(OAL::Eyepiece *ep)
368{
369 writer->writeStartElement("eyepiece");
370 writer->writeAttribute("id", ep->id());
371 writer->writeStartElement("model");
372 writer->writeCDATA(ep->model());
373 writer->writeEndElement();
374 writer->writeStartElement("vendor");
375 writer->writeCDATA(ep->vendor());
376 writer->writeEndElement();
377 writer->writeStartElement("focalLength");
378 writer->writeCharacters(QString::number(ep->focalLength()));
379 writer->writeEndElement();
380 writer->writeStartElement("apparantFOV");
381 writer->writeAttribute("unit", ep->fovUnit());
382 writer->writeCharacters(QString::number(ep->appFov()));
383 writer->writeEndElement();
384 writer->writeEndElement();
385}
386
387void OAL::Log::writeLens(OAL::Lens *l)
388{
389 writer->writeStartElement("lens");
390 writer->writeAttribute("id", l->id());
391 writer->writeStartElement("model");
392 writer->writeCDATA(l->model());
393 writer->writeEndElement();
394 writer->writeStartElement("vendor");
395 writer->writeCDATA(l->vendor());
396 writer->writeEndElement();
397 writer->writeStartElement("factor");
398 writer->writeCharacters(QString::number(l->factor()));
399 writer->writeEndElement();
400 writer->writeEndElement();
401}
402
403void OAL::Log::writeFilter(OAL::Filter *f)
404{
405 writer->writeStartElement("filter");
406 writer->writeAttribute("id", f->id());
407
408 // Model
409 writer->writeStartElement("model");
410 writer->writeCDATA(f->model());
411 writer->writeEndElement();
412 // Vendor
413 writer->writeStartElement("vendor");
414 writer->writeCDATA(f->vendor());
415 writer->writeEndElement();
416 // Type
417 writer->writeStartElement("type");
418 writer->writeCDATA(f->type());
419 writer->writeEndElement();
420 // Color
421 writer->writeStartElement("color");
422 writer->writeCDATA(f->color());
423 writer->writeEndElement();
424 // Offset
425 writer->writeStartElement("offset");
426 writer->writeCDATA(QString::number(f->offset()));
427 writer->writeEndElement();
428 // Exposure
429 writer->writeStartElement("exposure");
430 writer->writeCDATA(QString::number(f->exposure()));
431 writer->writeEndElement();
432 // AutoFocus
433 writer->writeStartElement("autofocus");
434 writer->writeCDATA(QString::number(f->useAutoFocus() ? 1 : 0));
435 writer->writeEndElement();
436 // Locked Filter
437 writer->writeStartElement("lockedfilter");
438 writer->writeCDATA(f->lockedFilter());
439 writer->writeEndElement();
440
441 writer->writeEndElement();
442}
443
444void OAL::Log::writeObservation(OAL::Observation *o)
445{
446 writer->writeStartElement("observation");
447 writer->writeStartElement("observer");
448 writer->writeCharacters(o->observer());
449 writer->writeEndElement();
450 writer->writeStartElement("site");
451 writer->writeCharacters(o->site());
452 writer->writeEndElement();
453 writer->writeStartElement("session");
454 writer->writeCharacters(o->session());
455 writer->writeEndElement();
456 writer->writeStartElement("target");
457 writer->writeCharacters(o->target().remove(' '));
458 writer->writeEndElement();
459 writer->writeStartElement("begin");
460 writer->writeCharacters(o->begin().date().toString("yyyy-MM-dd") + 'T' + o->begin().time().toString("hh:mm:ss"));
461 writer->writeEndElement();
462 writer->writeStartElement("faintestStar");
463 writer->writeCharacters(QString::number(o->faintestStar()));
464 writer->writeEndElement();
465 writer->writeStartElement("seeing");
466 writer->writeCharacters(QString::number(o->seeing()));
467 writer->writeEndElement();
468 writer->writeStartElement("scope");
469 writer->writeCharacters(o->scope());
470 writer->writeEndElement();
471 writer->writeStartElement("eyepiece");
472 writer->writeCharacters(o->eyepiece());
473 writer->writeEndElement();
474 writer->writeStartElement("lens");
475 writer->writeCharacters(o->lens());
476 writer->writeEndElement();
477 writer->writeStartElement("filter");
478 writer->writeCharacters(o->filter());
479 writer->writeEndElement();
480 writer->writeStartElement("result");
481 writer->writeAttribute("xsi:type", "oal:findingsType");
482 writer->writeAttribute("lang", o->lang());
483 writer->writeStartElement("description");
484 writer->writeCDATA(o->result());
485 writer->writeEndElement();
486 writer->writeEndElement();
487 writer->writeEndElement();
488}
489
490void OAL::Log::writeGeoDate()
491{
492 writer->writeStartElement("geodate");
493 writer->writeStartElement("name");
494 writer->writeCDATA(KStarsData::Instance()->observingList()->geoLocation()->name());
495 writer->writeEndElement();
496 writer->writeStartElement("province");
497 writer->writeCDATA(KStarsData::Instance()->observingList()->geoLocation()->province());
498 writer->writeEndElement();
499 writer->writeStartElement("country");
500 writer->writeCDATA(KStarsData::Instance()->observingList()->geoLocation()->country());
501 writer->writeEndElement();
502 writer->writeStartElement("date");
503 writer->writeCDATA(KStarsData::Instance()->observingList()->dateTime().date().toString("ddMMyyyy"));
504 writer->writeEndElement();
505 writer->writeEndElement();
506}
507
508void OAL::Log::readBegin(QString input)
509{
510 reader = new QXmlStreamReader(input);
511 while (!reader->atEnd())
512 {
513 reader->readNext();
514 if (reader->isStartElement())
515 {
516 // if( reader->name() == "oal:observations" && reader->attributes().value("version") == "2.0" )
517 readLog();
518 }
519 }
520}
521
522void OAL::Log::readUnknownElement()
523{
524 while (!reader->atEnd())
525 {
526 reader->readNext();
527
528 if (reader->isEndElement())
529 break;
530
531 if (reader->isStartElement())
532 readUnknownElement();
533 }
534}
535
536void OAL::Log::readLog()
537{
538 while (!reader->atEnd())
539 {
540 reader->readNext();
541
542 if (reader->isEndElement())
543 break;
544
545 if (reader->isStartElement())
546 {
547 if (reader->name().toString() == "targets")
548 readTargets();
549 else if (reader->name().toString() == "sites")
550 readSites();
551 else if (reader->name().toString() == "sessions")
552 readSessions();
553 else if (reader->name().toString() == "observation")
554 readObservation(reader->attributes().value("id").toString());
555 else if (reader->name().toString() == "geodate")
556 readGeoDate();
557 else
558 readUnknownElement();
559 }
560 }
561}
562
563void OAL::Log::readTargets()
564{
565 while (!reader->atEnd())
566 {
567 reader->readNext();
568
569 if (reader->isEndElement())
570 break;
571
572 if (reader->isStartElement())
573 {
574 if (reader->name().toString() == "target")
575 readTarget();
576 else
577 readUnknownElement();
578 }
579 }
580}
581
582void OAL::Log::readObservers()
583{
584 KStars::Instance()->data()->userdb()->GetAllObservers(m_observerList);
585}
586
587void OAL::Log::readSites()
588{
589 while (!reader->atEnd())
590 {
591 reader->readNext();
592
593 if (reader->isEndElement())
594 break;
595
596 if (reader->isStartElement())
597 {
598 if (reader->name().toString() == "site")
599 readSite(reader->attributes().value("id").toString());
600 else
601 readUnknownElement();
602 }
603 }
604}
605
606void OAL::Log::readSessions()
607{
608 while (!reader->atEnd())
609 {
610 reader->readNext();
611
612 if (reader->isEndElement())
613 break;
614
615 if (reader->isStartElement())
616 {
617 if (reader->name().toString() == "session")
618 readSession(reader->attributes().value("id").toString(), reader->attributes().value("lang").toString());
619 else
620 readUnknownElement();
621 }
622 }
623}
624
625void OAL::Log::readScopes()
626{
627 KStars::Instance()->data()->userdb()->GetAllScopes(m_scopeList);
628}
629
630void OAL::Log::readDSLRLenses()
631{
632 KStars::Instance()->data()->userdb()->GetAllDSLRLenses(m_dslrLensList);
633}
634
635void OAL::Log::readEyepieces()
636{
637 KStars::Instance()->data()->userdb()->GetAllEyepieces(m_eyepieceList);
638}
639
640void OAL::Log::readLenses()
641{
642 KStars::Instance()->data()->userdb()->GetAllLenses(m_lensList);
643}
644
645void OAL::Log::readFilters()
646{
647 KStars::Instance()->data()->userdb()->GetAllFilters(m_filterList);
648}
649
650void OAL::Log::readTarget()
651{
652 SkyObject *o = nullptr;
653 SkyPoint pos;
654 bool posOK = false;
655 QString name, time, notes;
656 while (!reader->atEnd())
657 {
658 reader->readNext();
659
660 if (reader->isEndElement())
661 break;
662
663 if (reader->isStartElement())
664 {
665 if (reader->name().toString() == "name")
666 {
667 name = reader->readElementText();
668 if (name != "star")
669 {
670 o = KStarsData::Instance()->objectNamed(name);
671 if (!o)
672 o = KStarsData::Instance()
673 ->skyComposite()
674 ->findStarByGenetiveName(name);
675 if (o)
676 targetList().append(QSharedPointer<SkyObject>(o->clone()));
677 }
678 }
679 else if (!o && reader->name().toString() == "position")
680 {
681 pos = readPosition(posOK);
682 if (posOK)
683 {
684 double maxrd = 0.5;
685 while (!o && maxrd <= 2.0)
686 {
687 o = KStarsData::Instance()->skyComposite()->starNearest(&pos,
688 maxrd);
689 if (!o)
690 maxrd += 0.5;
691 }
692
693 if (o)
694 targetList().append(QSharedPointer<SkyObject>(o->clone()));
695 }
696 }
697 else if (reader->name().toString() == "time")
698 {
699 time = reader->readElementText();
700 if (o)
701 TimeHash.insert(o->name(), QTime::fromString(time, "h:mm:ss AP"));
702 }
703 else if (reader->name().toString() == "notes")
704 {
705 notes = reader->readElementText();
706 if (o)
707 {
708 KStarsData::Instance()->updateUserLog(o->name(), notes);
709 }
710 }
711 // else if( reader->name() == "datasource" )
712 // qDebug() << reader->readElementText();
713 // else if( reader->name() == "position" )
714 // readPosition();
715 // else if( reader->name() == "constellation" )
716 // qDebug() << reader->readElementText();
717 else
718 readUnknownElement();
719 }
720 }
721}
722
723void OAL::Log::readSite(const QString &id)
724{
725 QString name, latUnit, lonUnit, lat, lon;
726 while (!reader->atEnd())
727 {
728 reader->readNext();
729
730 if (reader->isEndElement())
731 break;
732
733 if (reader->isStartElement())
734 {
735 if (reader->name().toString() == "name")
736 {
737 name = reader->readElementText();
738 }
739 else if (reader->name().toString() == "latitude")
740 {
741 lat = reader->readElementText();
742 latUnit = reader->attributes().value("unit").toString();
743 }
744 else if (reader->name().toString() == "longitude")
745 {
746 lon = reader->readElementText();
747 lonUnit = reader->attributes().value("unit").toString();
748 }
749 else
750 readUnknownElement();
751 }
752 }
753 OAL::Site *o = new OAL::Site(id, name, lat.toDouble(), latUnit, lon.toDouble(), lonUnit);
754 m_siteList.append(o);
755}
756
757void OAL::Log::readSession(const QString &id, const QString &lang)
758{
759 QString site, weather, equipment, comments, begin, end;
760 KStarsDateTime beginDT, endDT;
761 while (!reader->atEnd())
762 {
763 reader->readNext();
764
765 if (reader->isEndElement())
766 break;
767
768 if (reader->isStartElement())
769 {
770 if (reader->name().toString() == "site")
771 {
772 site = reader->readElementText();
773 }
774 else if (reader->name().toString() == "begin")
775 {
776 begin = reader->readElementText();
777 beginDT.fromString(begin);
778 }
779 else if (reader->name().toString() == "end")
780 {
781 end = reader->readElementText();
782 endDT.fromString(begin);
783 }
784 else if (reader->name().toString() == "weather")
785 {
786 weather = reader->readElementText();
787 }
788 else if (reader->name().toString() == "equipment")
789 {
790 equipment = reader->readElementText();
791 }
792 else if (reader->name().toString() == "comments")
793 {
794 comments = reader->readElementText();
795 }
796 else
797 readUnknownElement();
798 }
799 }
800 OAL::Session *o = new OAL::Session(id, site, beginDT, endDT, weather, equipment, comments, lang);
801 m_sessionList.append(o);
802}
803
804SkyPoint OAL::Log::readPosition(bool &OK)
805{
806 SkyPoint p;
807 bool RAOK = false, DEOK = false;
808 while (!reader->atEnd())
809 {
810 reader->readNext();
811
812 if (reader->isEndElement())
813 break;
814
815 if (reader->isStartElement())
816 {
817 if (reader->name().toString() == "ra")
818 {
819 qDebug() << reader->readElementText() << reader->attributes().value("unit");
820 dms ra;
821 if (reader->attributes().value("unit").toString() == "rad")
822 ra.setRadians(reader->readElementText().toDouble(&RAOK));
823 else
824 ra.setD(reader->readElementText().toDouble(&RAOK));
825
826 p.setRA(ra);
827 }
828 else if (reader->name().toString() == "dec")
829 {
830 qDebug() << reader->readElementText() << reader->attributes().value("unit");
831 dms de;
832 if (reader->attributes().value("unit").toString() == "rad")
833 de.setRadians(reader->readElementText().toDouble(&DEOK));
834 else
835 de.setD(reader->readElementText().toDouble(&DEOK));
836
837 p.setDec(de);
838 }
839 else
840 readUnknownElement();
841 }
842 }
843
844 OK = RAOK && DEOK;
845
846 return p;
847}
848
849void OAL::Log::readObservation(const QString &id)
850{
851 QString observer, site, session, target, faintestStar, seeing, scope, eyepiece, lens, filter, result, lang;
853 while (!reader->atEnd())
854 {
855 reader->readNext();
856 if (reader->isEndElement())
857 break;
858 if (reader->isStartElement())
859 {
860 if (reader->name().toString() == "observer")
861 observer = reader->readElementText();
862 else if (reader->name().toString() == "site")
863 site = reader->readElementText();
864 else if (reader->name().toString() == "session")
865 session = reader->readElementText();
866 else if (reader->name().toString() == "target")
867 target = reader->readElementText();
868 else if (reader->name().toString() == "begin")
869 begin.fromString(reader->readElementText());
870 else if (reader->name().toString() == "faintestStar")
871 faintestStar = reader->readElementText();
872 else if (reader->name().toString() == "seeing")
873 seeing = reader->readElementText();
874 else if (reader->name().toString() == "scope")
875 scope = reader->readElementText();
876 else if (reader->name().toString() == "eyepiece")
877 eyepiece = reader->readElementText();
878 else if (reader->name().toString() == "lens")
879 lens = reader->readElementText();
880 else if (reader->name().toString() == "filter")
881 filter = reader->readElementText();
882 else if (reader->name().toString() == "result")
883 {
884 lang = reader->attributes().value("lang").toString();
885 result = readResult();
886 }
887 else
888 readUnknownElement();
889 }
890 }
891 OAL::Observation *o = new OAL::Observation(id, observer, site, session, target, begin, faintestStar.toDouble(),
892 seeing.toDouble(), scope, eyepiece, lens, filter, result, lang);
893 m_observationList.append(o);
894}
895
896QString OAL::Log::readResult()
897{
898 QString result;
899 while (!reader->atEnd())
900 {
901 reader->readNext();
902
903 if (reader->isEndElement())
904 break;
905 if (reader->isStartElement())
906 {
907 if (reader->name().toString() == "description")
908 result = reader->readElementText();
909 else
910 readUnknownElement();
911 }
912 }
913 return result;
914}
915
916void OAL::Log::readGeoDate()
917{
918 QString name, province, country, date;
919 while (!reader->atEnd())
920 {
921 reader->readNext();
922
923 if (reader->isEndElement())
924 break;
925
926 if (reader->isStartElement())
927 {
928 if (reader->name().toString() == "name")
929 name = reader->readElementText();
930 else if (reader->name().toString() == "province")
931 province = reader->readElementText();
932 else if (reader->name().toString() == "country")
933 country = reader->readElementText();
934 else if (reader->name().toString() == "date")
935 {
936 date = reader->readElementText();
937 }
938 else
939 readUnknownElement();
940 }
941 }
942 geo = KStarsData::Instance()->locationNamed(name, province, country);
943 if (geo == nullptr)
944 {
945 qCWarning(KSTARS) << "Location " << name << ", " << province << ", " << country
946 << " not found in KStars. Using current location.";
947 geo = KStarsData::Instance()->geo();
948 }
949 dt.setDate(QDate::fromString(date, "ddMMyyyy"));
950}
951
952OAL::Observer *OAL::Log::findObserverByName(const QString &name)
953{
954 foreach (OAL::Observer *obs, *observerList())
955 {
956 if (QString(obs->name() + ' ' + obs->surname()) == name)
957 return obs;
958 }
959 return nullptr;
960}
961
962OAL::Observer *OAL::Log::findObserverById(const QString &id)
963{
964 foreach (OAL::Observer *obs, *observerList())
965 {
966 if (obs->id() == id)
967 return obs;
968 }
969 return nullptr;
970}
971
972OAL::Session *OAL::Log::findSessionByName(const QString &id)
973{
974 foreach (OAL::Session *s, *sessionList())
975 {
976 if (s->id() == id)
977 return s;
978 }
979 return nullptr;
980}
981
982OAL::Site *OAL::Log::findSiteById(const QString &id)
983{
984 foreach (OAL::Site *s, *siteList())
985 {
986 if (s->id() == id)
987 return s;
988 }
989 return nullptr;
990}
991
992OAL::Site *OAL::Log::findSiteByName(const QString &name)
993{
994 foreach (OAL::Site *s, *siteList())
995 {
996 if (s->name() == name)
997 return s;
998 }
999 return nullptr;
1000}
1001
1002OAL::Scope *OAL::Log::findScopeById(const QString &id)
1003{
1004 foreach (OAL::Scope *s, *scopeList())
1005 {
1006 if (s->id() == id)
1007 return s;
1008 }
1009 return nullptr;
1010}
1011
1012OAL::Eyepiece *OAL::Log::findEyepieceById(const QString &id)
1013{
1014 foreach (OAL::Eyepiece *e, *eyepieceList())
1015 {
1016 if (e->id() == id)
1017 return e;
1018 }
1019 return nullptr;
1020}
1021
1022OAL::Lens *OAL::Log::findLensById(const QString &id)
1023{
1024 foreach (OAL::Lens *l, *lensList())
1025 {
1026 if (l->id() == id)
1027 return l;
1028 }
1029 return nullptr;
1030}
1031
1032OAL::Filter *OAL::Log::findFilterById(const QString &id)
1033{
1034 foreach (OAL::Filter *f, *filterList())
1035 {
1036 if (f->id() == id)
1037 return f;
1038 }
1039 return nullptr;
1040}
1041
1042OAL::Scope *OAL::Log::findScopeByName(const QString &name)
1043{
1044 foreach (OAL::Scope *s, *scopeList())
1045 {
1046 if (s->name() == name)
1047 return s;
1048 }
1049 return nullptr;
1050}
1051
1052OAL::DSLRLens *OAL::Log::findDSLRLensByName(const QString &name)
1053{
1054 for (const auto &s : *dslrLensList())
1055 {
1056 if (s->name() == name)
1057 return s;
1058 }
1059 return nullptr;
1060}
1061
1062OAL::DSLRLens *OAL::Log::findDSLRLensById(const QString &id)
1063{
1064 for (const auto &s : *dslrLensList())
1065 {
1066 if (s->id() == id)
1067 return s;
1068 }
1069 return nullptr;
1070}
1071
1072OAL::Eyepiece *OAL::Log::findEyepieceByName(const QString &name)
1073{
1074 foreach (OAL::Eyepiece *e, *eyepieceList())
1075 {
1076 if (e->name() == name)
1077 return e;
1078 }
1079 return nullptr;
1080}
1081
1082OAL::Filter *OAL::Log::findFilterByName(const QString &name)
1083{
1084 foreach (OAL::Filter *f, *filterList())
1085 {
1086 if (f->name() == name)
1087 return f;
1088 }
1089 return nullptr;
1090}
1091
1092OAL::Lens *OAL::Log::findLensByName(const QString &name)
1093{
1094 foreach (OAL::Lens *l, *lensList())
1095 {
1096 if (l->name() == name)
1097 return l;
1098 }
1099 return nullptr;
1100}
1101
1102OAL::Observation *OAL::Log::findObservationByName(const QString &id)
1103{
1104 foreach (OAL::Observation *o, *observationList())
1105 {
1106 if (o->id() == id)
1107 return o;
1108 }
1109 return nullptr;
1110}
1111
1112void OAL::Log::readAll()
1113{
1114 readObservers();
1115 readScopes();
1116 readEyepieces();
1117 readLenses();
1118 readFilters();
1119}
bool GetAllScopes(QList< OAL::Scope * > &m_scopeList)
updates the scope list with all scopes from database List is cleared and then filled with content.
bool GetAllObservers(QList< OAL::Observer * > &observer_list)
Updates the passed reference of observer_list with all observers The original content of the list is ...
Definition ksuserdb.cpp:713
bool GetAllLenses(QList< OAL::Lens * > &m_lensList)
Populate the reference passed with all lenses.
bool GetAllFilters(QList< OAL::Filter * > &m_filterList)
Populate the reference passed with all filters.
bool GetAllDSLRLenses(QList< OAL::DSLRLens * > &dslrlens_list)
updates the dslr list with all DSLR lenses from database List is cleared and then filled with content...
bool GetAllEyepieces(QList< OAL::Eyepiece * > &m_eyepieceList)
Populate the reference passed with all eyepieces.
KSUserDB * userdb()
Definition kstarsdata.h:217
SkyObject * objectNamed(const QString &name)
Find object by name.
std::pair< bool, QString > updateUserLog(const QString &name, const QString &newLog)
Update the user log of the object with the name to contain newLog (find and replace).
GeoLocation * geo()
Definition kstarsdata.h:232
SkyMapComposite * skyComposite()
Definition kstarsdata.h:168
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsDateTime fromString(const QString &s)
static KStars * Instance()
Definition kstars.h:121
KStarsData * data() const
Definition kstars.h:133
Information on DSLR lens used in astrophotography.
Definition dslrlens.h:18
Information of user filters.
Definition filter.h:48
Information of lens utilized in the observation.
Definition lens.h:18
Information on observation session details.
Definition observation.h:29
FIXME: why not just use a QHash?
Definition observer.h:20
Information on telescope used in observation.
Definition scope.h:18
Information on session details.
Definition session.h:19
Information on site of observation.
Definition site.h:20
QList< QSharedPointer< SkyObject > > & sessionList()
SkyObject * starNearest(SkyPoint *p, double &maxrad)
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
virtual SkyObject * clone() const
Create copy of object.
Definition skyobject.cpp:50
virtual QString name(void) const
Definition skyobject.h:146
static QString typeName(const int t)
int type(void) const
Definition skyobject.h:189
The sky coordinates of a point in the sky.
Definition skypoint.h:45
const CachingDms & dec() const
Definition skypoint.h:269
void setDec(dms d)
Sets Dec, the current Declination.
Definition skypoint.h:169
void setRA(dms &r)
Sets RA, the current Right Ascension.
Definition skypoint.h:144
const CachingDms & ra() const
Definition skypoint.h:263
This is a subclass of SkyObject.
Definition starobject.h:33
QString name(void) const override
If star is unnamed return "star" otherwise return the name.
Definition starobject.h:130
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
double radians() const
Express the angle in radians.
Definition dms.h:325
virtual void setRadians(const double &Rad)
Set angle according to the argument, in radians.
Definition dms.h:333
virtual void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition dms.h:179
char * toString(const EngineQuery &query)
GeoCoordinates geo(const QVariant &location)
QString name(StandardAction id)
const QList< QKeySequence > & begin()
const QList< QKeySequence > & end()
KI18NLOCALEDATA_EXPORT KCountry country(const char *ianaId)
KEDUVOCDOCUMENT_EXPORT QStringList comments(const QString &language=QString())
QDate fromString(QStringView string, QStringView format, QCalendar cal)
QString toString(QStringView format, QCalendar cal) const const
QDate date() const const
QTime time() const const
QString arg(Args &&... args) const const
const QChar at(qsizetype position) const const
QString & insert(qsizetype position, QChar ch)
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
double toDouble(bool *ok) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QTime fromString(QStringView string, QStringView format)
QString toString(QStringView format) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.