Qt Virtual Chart Table (QVCT)
CVesselTarget.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // C/C++
20 #include <cmath>
21 
22 // QT
23 #include <QDateTime>
24 #include <QDockWidget>
25 #include <QWidget>
26 
27 // QVCT
28 #include "QVCTRuntime.hpp"
33 
34 
35 //------------------------------------------------------------------------------
36 // CONSTRUCTORS / DESTRUCTOR
37 //------------------------------------------------------------------------------
38 
39 CVesselTarget::CVesselTarget( QWidget* _pqParent )
40  : CVesselWidget( tr("Target Course"), _pqParent )
41  , bContentDisplayed( false )
42 {
43  QDockWidget::setObjectName( "VesselTarget" ); // required to save main window's state
44  QDockWidget::setAllowedAreas( Qt::AllDockWidgetAreas );
46  QObject::connect( this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT( slotLocationChanged(Qt::DockWidgetArea) ) );
47  QObject::connect( this, SIGNAL(topLevelChanged(bool)), this, SLOT( slotTopLevelChanged(bool) ) );
48 }
49 
51 {
52  // Add data
53  // ... target
55  poTextBearing->setToolTip( tr("Bearing") );
56  poTextBearing->setAlignment( Qt::AlignCenter );
58  pqBoxLayout->addWidget( poTextBearing );
60  poTextDistance->setToolTip( tr("Distance") );
61  poTextDistance->setAlignment( Qt::AlignCenter );
63  pqBoxLayout->addWidget( poTextDistance );
64  poTextEte = new COverlayText();
65  poTextEte->setToolTip( tr("Estimated Time En-Route (ETE)") );
66  poTextEte->setAlignment( Qt::AlignCenter );
68  pqBoxLayout->addWidget( poTextEte );
69  poTextEta = new COverlayText();
70  poTextEta->setToolTip( tr("Estimated Time of Arrival (ETA)") );
71  poTextEta->setAlignment( Qt::AlignCenter );
73  pqBoxLayout->addWidget( poTextEta );
74 }
75 
76 
77 //------------------------------------------------------------------------------
78 // METHODS: CVesselWidget (implement/override)
79 //------------------------------------------------------------------------------
80 
81 void CVesselTarget::setFont( QFont _qFont )
82 {
83  poTextBearing->setFont( _qFont );
84  poTextDistance->setFont( _qFont );
85  poTextEte->setFont( _qFont );
86  poTextEta->setFont( _qFont );
87 }
88 
90 {
91  if( !poVesselPoint || !QWidget::isVisible() ) return;
93  if( __poPointerPoint->CDataPosition::operator==( CDataPosition::UNDEFINED ) )
94  {
96  return;
97  }
98 
99  // ... target
102  {
103  bContentDisplayed = true;
104  // ... bearing
105  double __fdBearingTarget = CDataPosition::bearingRL( *poVesselPoint, *__poPointerPoint );
107  // ... distance
108  double __fdDistance = CDataPosition::distanceRL( *poVesselPoint, *__poPointerPoint );
110  // ... ETE/ETA
111  bool __bTimeValid = false;
112  do // processing-breaking loop
113  {
114  double __fdBearingCourse = poVesselPoint->GroundCourse.getBearing();
115  if( __fdBearingCourse == CDataCourse::UNDEFINED_BEARING ) break;
116  double __fdSpeed = poVesselPoint->GroundCourse.getSpeed();
117  if( __fdSpeed == CDataCourse::UNDEFINED_SPEED ) break;
118  double __fdSpeedCosine = __fdSpeed * cos( ( __fdBearingCourse - __fdBearingTarget ) * QVCT::DEG2RAD );
119  if( __fdSpeedCosine <= 0 ) break; // we can't get any ETE/ETA if we're moving away from the target (or not moving at all)
120  double __fdDuration = __fdDistance / __fdSpeedCosine;
121  if( __fdDuration > 86400 ) break; // if the ETE is more than 24 hours, let's assume it's not worth displaying it
122  QDateTime __qDateTime = QDateTime::currentDateTime();
123  double __fdTime = __qDateTime.toUTC().toTime_t()+__qDateTime.time().msec()/1000.0;
124  __bTimeValid = true;
127  }
128  while( false ); // processing-breaking loop
129  if( !__bTimeValid )
130  {
131  poTextEte->resetText();
132  poTextEta->resetText();
133  }
134  }
135  else
136  resetContent();
137 }
138 
140 {
141  bContentDisplayed = false;
144  poTextEte->resetText();
145  poTextEta->resetText();
146 }
CDataCourse GroundCourse
Ground course.
CDataCourseValidity GroundCourseValidity
Ground course validity.
bool isValidSpeed() const
Returns the horizontal speed's (global) validity status.
bool isValidBearing() const
Returns the bearing's (global) validity status.
static constexpr double UNDEFINED_BEARING
Specific value for an undefined bearing.
Definition: CDataCourse.hpp:42
static constexpr double UNDEFINED_SPEED
Specific value for an undefined speed.
Definition: CDataCourse.hpp:44
double getBearing() const
Returns this course's bearing, in degrees.
double getSpeed() const
Returns this course's horizontal speed, in meters per second.
bool isValidPosition() const
Returns the position's (global) validity status.
double getLongitude() const
Returns this position's longitude, in degrees.
static constexpr double UNDEFINED_LATITUDE
Specific value for an undefined latitude.
static double bearingRL(const CDataPosition &_roPosition1, const CDataPosition &_roPosition2)
Returns the rhumb-line (constant) bearing between two points, in degrees.
static double distanceRL(const CDataPosition &_roPosition1, const CDataPosition &_roPosition2)
Returns the rhumb-line distance between two points, in meters.
double getLatitude() const
Returns this position's latitude, in degrees.
static const CDataPosition UNDEFINED
Specific value for an undefined position.
static constexpr double UNDEFINED_LONGITUDE
Specific value for an undefined longitude.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
void resetText()
Resets (clears) the underlying QLabel's text.
CPointerPoint * usePointerTarget()
Returns the pointer point corresponding to the target.
[UI] Pointer overlay point (item)
static QString toString(double _fdValue, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static QString toString(double _fdValue, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static QString toString(double _fdValue, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitTime.cpp:79
void constructLayout()
Constructs the layout of the user-interface.
COverlayText * poTextBearing
[UI:Label] Bearing
COverlayText * poTextEte
[UI:Label] Estimated Time En-Route (ETE)
COverlayText * poTextDistance
[UI:Label] Distance
virtual void resetContent()
Resets (clears) the content of the underlying widget.
COverlayText * poTextEta
[UI:Label] Estimated Time of Arrival (ETA)
bool bContentDisplayed
Flag to track whether content data are currently displayed.
CVesselTarget(QWidget *_pqParent=0)
virtual void setFont(QFont _qFont)
Sets the font for the content of the underlying widget.
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Generic vessel (dock) widget
CVesselPoint * poVesselPoint
Overlay course being displayed.
void slotTopLevelChanged(bool _bTopLevel)
Slot to handle floating change.
void slotLocationChanged(Qt::DockWidgetArea _qDockWidgetArea)
Slot to handle dock area change.
QBoxLayout * pqBoxLayout
[UI:Layout] Layout
static CPointerOverlay * usePointerOverlay()
static constexpr double DEG2RAD
Definition: QVCT.hpp:46