Kstars

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

KDE's Doxygen guidelines are available online.