Qt Virtual Chart Table (QVCT)
CTrackPointDetailView.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 // QT
20 #include <QHBoxLayout>
21 #include <QLabel>
22 #include <QPushButton>
23 #include <QScrollArea>
24 #include <QStackedWidget>
25 #include <QVBoxLayout>
26 #include <QWidget>
27 
28 // QVCT
29 #include "QVCTRuntime.hpp"
40 
41 
42 //------------------------------------------------------------------------------
43 // CONSTRUCTORS / DESTRUCTOR
44 //------------------------------------------------------------------------------
45 
47  : COverlayObjectDetailView( _pqParent )
48 {
50 }
51 
53 {
54  // Create the buttons
55  // ... center
56  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
57  pqPushButtonCenter->setToolTip( tr("Center chart on this point") );
58  pqPushButtonCenter->setMaximumSize( 36, 34 );
59  pqPushButtonCenter->setEnabled( false );
60  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
61  // ... delete
62  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
63  pqPushButtonDelete->setToolTip( tr("Delete this point") );
64  pqPushButtonDelete->setMaximumSize( 36, 34 );
65  pqPushButtonDelete->setEnabled( false );
66  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
67  // ... Add landmark
68  pqPushButtonAddLandmark = new QPushButton( QIcon( ":icons/32x32/landmark_add.png" ), "" );
69  pqPushButtonAddLandmark->setToolTip( tr("Create a new landmark at the point position") );
70  pqPushButtonAddLandmark->setMaximumSize( 36, 34 );
71  pqPushButtonAddLandmark->setEnabled( false );
72  QWidget::connect( pqPushButtonAddLandmark, SIGNAL( clicked() ), this, SLOT( slotAddLandmark() ) );
73  // ... Add (route) waypoint
74  pqPushButtonAddRoute = new QPushButton( QIcon( ":icons/32x32/route_add.png" ), "" );
75  pqPushButtonAddRoute->setToolTip( tr("Create a new (route) waypoint at the point position") );
76  pqPushButtonAddRoute->setMaximumSize( 36, 34 );
77  pqPushButtonAddRoute->setEnabled( false );
78  QWidget::connect( pqPushButtonAddRoute, SIGNAL( clicked() ), this, SLOT( slotAddRoute() ) );
79 
80  // Create layout
81  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
82 
83  // Add header
84  QFont __qFontHeader;
85  __qFontHeader.setPixelSize( 16 );
86  __qFontHeader.setBold( true );
87  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
88  QLabel* __pqLabelIcon = new QLabel();
89  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/track_point.png" ) );
90  __pqLabelIcon->setToolTip( tr("Point") );
91  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
92  poTextName = new COverlayText();
93  poTextName->setToolTip( tr("Name") );
94  poTextName->setFont( __qFontHeader );
95  poTextName->setWordWrap( true );
96  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
97  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
98 
99  // Add data
100  QFont __qFontData;
101  QTabWidget* __poTabWidget = new QTabWidget();
102  __poTabWidget->setTabPosition( QTabWidget::South );
103  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
104 
105  // ... position
106  QWidget* __poWidgetPosition = new QWidget();
107  QVBoxLayout* __pqVBoxLayoutPosition = new QVBoxLayout();
108  __qFontData.setPixelSize( 20 );
110  poTextLongitude->setToolTip( tr("Longitude") );
111  poTextLongitude->setFont( __qFontData );
112  poTextLongitude->setIndent( 10 );
113  poTextLongitude->setAlignment( Qt::AlignHCenter );
115  __pqVBoxLayoutPosition->addWidget( poTextLongitude );
117  poTextLatitude->setToolTip( tr("Latitude") );
118  poTextLatitude->setFont( __qFontData );
119  poTextLatitude->setIndent( 10 );
120  poTextLatitude->setAlignment( Qt::AlignHCenter );
122  __pqVBoxLayoutPosition->addWidget( poTextLatitude );
124  poTextElevation->setToolTip( tr("Elevation") );
125  poTextElevation->setFont( __qFontData );
126  poTextElevation->setIndent( 10 );
127  poTextElevation->setAlignment( Qt::AlignHCenter );
129  __pqVBoxLayoutPosition->addWidget( poTextElevation, 1 );
130  __poWidgetPosition->setLayout( __pqVBoxLayoutPosition );
131  __poTabWidget->addTab( __poWidgetPosition, tr("Position") );
132 
133  // ... date/time
134  QWidget* __poWidgetTime = new QWidget();
135  QVBoxLayout* __pqVBoxLayoutTime = new QVBoxLayout();
136  poTextDate = new COverlayText();
137  poTextDate->setToolTip( tr("Date") );
138  poTextDate->setFont( __qFontData );
139  poTextDate->setIndent( 10 );
140  poTextDate->setAlignment( Qt::AlignHCenter );
142  __pqVBoxLayoutTime->addWidget( poTextDate );
143  poTextTime = new COverlayText();
144  poTextTime->setToolTip( tr("Time") );
145  poTextTime->setFont( __qFontData );
146  poTextTime->setIndent( 10 );
147  poTextTime->setAlignment( Qt::AlignHCenter );
149  __pqVBoxLayoutTime->addWidget( poTextTime );
150  poTextTime2 = new COverlayText();
151  poTextTime2->setToolTip( tr("Time (alternate timezone)") );
152  poTextTime2->setFont( __qFontData );
153  poTextTime2->setIndent( 10 );
154  poTextTime2->setAlignment( Qt::AlignHCenter );
156  __pqVBoxLayoutTime->addWidget( poTextTime2, 1 );
157  __poWidgetTime->setLayout( __pqVBoxLayoutTime );
158  __poTabWidget->addTab( __poWidgetTime, tr("Time") );
159 
160  // ... precision
161  QWidget* __poWidgetPrecision = new QWidget();
162  QVBoxLayout* __pqVBoxLayoutPrecision = new QVBoxLayout();
163  poTextFixType = new COverlayText();
164  poTextFixType->setToolTip( tr("Fix Type") );
165  poTextFixType->setFont( __qFontData );
166  poTextFixType->setIndent( 10 );
167  poTextFixType->setAlignment( Qt::AlignHCenter );
169  __pqVBoxLayoutPrecision->addWidget( poTextFixType );
171  poTextSatellite->setToolTip( tr("Satellites Used") );
172  poTextSatellite->setFont( __qFontData );
173  poTextSatellite->setIndent( 10 );
174  poTextSatellite->setAlignment( Qt::AlignHCenter );
176  __pqVBoxLayoutPrecision->addWidget( poTextSatellite );
177  poTextDop = new COverlayText();
178  poTextDop->setToolTip( tr("HDOP / VDOP") );
179  poTextDop->setFont( __qFontData );
180  poTextDop->setIndent( 10 );
181  poTextDop->setAlignment( Qt::AlignHCenter );
182  poTextDop->resetText();
183  __pqVBoxLayoutPrecision->addWidget( poTextDop, 1 );
184  __poWidgetPrecision->setLayout( __pqVBoxLayoutPrecision );
185  __poTabWidget->addTab( __poWidgetPrecision, tr("Precision") );
186 
187  // ... [end]
188  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
189 
190  // Add separator
191  QFrame* __pqFrameSeparator = new QFrame();
192  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
193  __pqVBoxLayout->addWidget( __pqFrameSeparator );
194 
195  // Add buttons
196  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
197  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
198  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
199  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddLandmark, 1, Qt::AlignRight );
200  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddRoute, 0, Qt::AlignRight );
201  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
202 
203  // Set the layout
204  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
205 
206 }
207 
208 
209 //------------------------------------------------------------------------------
210 // METHODS: COverlayObjectDetailView (implement/override)
211 //------------------------------------------------------------------------------
212 
214 {
215  if( !poOverlayObject ) return;
216  CTrackPoint* __poTrackPoint = (CTrackPoint*)poOverlayObject;
217 
218  // ... name
219  poTextName->setText( __poTrackPoint->getName() );
220 
221  // ... position
222  if( __poTrackPoint->getLongitude() != CDataPosition::UNDEFINED_LONGITUDE
223  && __poTrackPoint->getLatitude() != CDataPosition::UNDEFINED_LATITUDE )
224  {
227  }
228  else
229  {
232  }
233 
234  // ... elevation
235  if( __poTrackPoint->getElevation() != CDataPosition::UNDEFINED_ELEVATION )
237  else
239 
240  // ... time
241  if( __poTrackPoint->getTime() != CDataTime::UNDEFINED_TIME )
242  {
243  double __fdTime = __poTrackPoint->getTime();
244  poTextDate->setText( CUnitDate::toString( __fdTime ) );
245  poTextTime->setText( CUnitTime::toString( __fdTime ) );
246  poTextTime2->setText( "("+CUnitTime::toString( __fdTime, true )+")" );
247  }
248  else
249  {
253  }
254 
255  // ... precision
256  poTextFixType->setText( __poTrackPoint->getFixType() );
257  if( __poTrackPoint->getSatelliteCount() )
258  poTextSatellite->setText( QString::number( __poTrackPoint->getSatelliteCount() ) );
259  else
262  poTextDop->setText( ( __poTrackPoint->getDopHorizontal() != CDeviceDataDop::UNDEFINED_VALUE ? QString::number( __poTrackPoint->getDopHorizontal(), 'f', 1 ) : poTextDop->emptyString() )
263  +" / "
264  +( __poTrackPoint->getDopVertical() != CDeviceDataDop::UNDEFINED_VALUE ? QString::number( __poTrackPoint->getDopVertical(), 'f', 1 ) : poTextDop->emptyString() ) );
265  else
266  poTextDop->resetText();
267 }
268 
270 {
280  poTextDop->resetText();
281 }
282 
284 {
285  if( poOverlayObject )
286  {
287  pqPushButtonCenter->setEnabled( true );
288  pqPushButtonDelete->setEnabled( true );
289  pqPushButtonAddLandmark->setEnabled( true );
290  pqPushButtonAddRoute->setEnabled( true );
291  }
292 }
293 
295 {
296  pqPushButtonCenter->setEnabled( false );
297  pqPushButtonDelete->setEnabled( false );
298  pqPushButtonAddLandmark->setEnabled( false );
299  pqPushButtonAddRoute->setEnabled( false );
300 }
301 
302 
303 //------------------------------------------------------------------------------
304 // METHODS
305 //------------------------------------------------------------------------------
306 
307 //
308 // SLOTS
309 //
310 
312 {
313  if( !poOverlayObject ) return;
314  CTrackPoint* __poTrackPoint = (CTrackPoint*)poOverlayObject;
315  QVCTRuntime::useChartTable()->setGeoPosition( *__poTrackPoint );
317 }
318 
320 {
321  if( !poOverlayObject ) return;
322  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
323  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
324  CTrackOverlay* __poTrackOverlay = QVCTRuntime::useTrackOverlay();
325  CTrackContainer* __poTrackContainer = (CTrackContainer*)((QTreeWidgetItem*)poOverlayObject)->parent();
326  CTrackPoint* __poTrackPoint = (CTrackPoint*)poOverlayObject;
327  __pqMutexDataChange->lock();
328  __poTrackContainer->removeChild( __poTrackPoint );
329  __pqMutexDataChange->unlock();
330  delete __poTrackPoint;
331  QTreeWidgetItem* __pqTreeWidgetItem = __poTrackOverlay->currentItem();
332  if( __pqTreeWidgetItem ) __poTrackOverlay->showDetail( __pqTreeWidgetItem );
333  __poTrackOverlay->forceRedraw();
336 }
337 
339 {
340  if( !poOverlayObject ) return;
341  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
342  CLandmarkContainer* __poLandmarkContainer = __poLandmarkOverlay->pickContainer();
343  if( !__poLandmarkContainer ) return;
344  QString __qsName = __poLandmarkContainer->newChildName( poOverlayObject->getName() );
345  CLandmarkPoint* __poLandmarkPoint = __poLandmarkContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject );
346  if( !__poLandmarkPoint ) return;
347  __poLandmarkOverlay->setCurrentItem( __poLandmarkPoint );
348  __poLandmarkOverlay->forceRedraw();
349  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
350  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
351  __poPointerPoint->resetPosition();
352  __poPointerOverlay->forceRedraw();
354  __poLandmarkPoint->showEdit();
356 }
357 
359 {
360  if( !poOverlayObject ) return;
361  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
362  CRouteContainer* __poRouteContainer = __poRouteOverlay->pickContainer();
363  if( !__poRouteContainer ) return;
364  QString __qsName = __poRouteContainer->newChildName( poOverlayObject->getName() );
365  CRoutePoint* __poRoutePoint = __poRouteContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject, true );
366  if( !__poRoutePoint ) return;
367  __poRouteOverlay->setCurrentItem( __poRoutePoint );
368  __poRouteOverlay->forceRedraw();
369  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
370  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
371  __poPointerPoint->resetPosition();
372  __poPointerOverlay->forceRedraw();
374  __poRoutePoint->showEdit();
376 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
void updateChart()
Update the (current) chart content (on screen)
void setGeoPosition(const CDataPosition &_roGeoPosition, bool _bSkipCurrent=false)
Sets the reference chart (geographical) position.
double getLongitude() const
Returns this position's longitude, in degrees.
static constexpr double UNDEFINED_LATITUDE
Specific value for an undefined latitude.
void resetPosition()
Resets all coordinates (to an undefined position)
double getElevation() const
Returns this position's elevation, in meters.
double getLatitude() const
Returns this position's latitude, in degrees.
static constexpr double UNDEFINED_LONGITUDE
Specific value for an undefined longitude.
static constexpr double UNDEFINED_ELEVATION
Specific value for an undefined elevation.
double getTime() const
Returns this time's time, in seconds from Unix epoch.
Definition: CDataTime.hpp:89
static constexpr double UNDEFINED_TIME
Specific value for an undefined time.
Definition: CDataTime.hpp:44
static const double UNDEFINED_VALUE
Specific value for an undefined component.
[UI] Landmark overlay container
CLandmarkPoint * addPoint(const QString &_rqsName, const CDataPosition &_roDataPosition=CDataPosition::UNDEFINED)
Add a new landmark (item/point) to this container.
[UI] Landmark overlay container
CLandmarkContainer * pickContainer()
Pick (select) a container among the available ones (0 if none is selected)
[UI] Landmark overlay point (item)
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Generic overlay object's detail view
COverlayObject * poOverlayObject
Overlay object being displayed.
QString getName() const
Returns this object's name.
QString newChildName(const QString &_rqsName, int _iZeroPrefix=0, bool _bForceSuffix=false) const
Returns a valid (non-duplicate) name for a new sibling of this object.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
const QString & emptyString()
Returns the string corresponding to undefined (empty) content ("n/a" in English)
void resetText()
Resets (clears) the underlying QLabel's text.
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
Definition: COverlay.hpp:115
[UI] Pointer overlay
CPointerPoint * usePointerPoint()
Returns the pointer point corresponding to the mouse pointer.
[UI] Pointer overlay point (item)
[UI] Route overlay container
CRoutePoint * addPoint(const QString &_rqsName, const CDataPosition &_roDataPosition=CDataPosition::UNDEFINED, bool _bMinimizeLength=false)
Add a new route (item/point) to this container.
[UI] Route overlay container
CRouteContainer * pickContainer()
Pick (select) a route (container) among the available ones (0 if none is selected)
[UI] Route overlay point (item) / waypoint
Definition: CRoutePoint.hpp:40
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Track overlay container
[UI] Track overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
COverlayText * poTextDate
[UI:Label] Date
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
COverlayText * poTextElevation
[UI:Label] Elevation
COverlayText * poTextSatellite
[UI:Label] Satellite
CTrackPointDetailView(QWidget *_pqParent=0)
virtual void disableContent()
Disables the content (controls) of the underlying widget.
void slotAddRoute()
[UI:Slot] Slot to add new (route) waypoint
virtual void enableContent()
Enables the content (controls) of the underlying widget.
QPushButton * pqPushButtonAddRoute
[UI:Button] Add new (route) waypoint
COverlayText * poTextTime
[UI:Label] Time
QPushButton * pqPushButtonAddLandmark
[UI:Button] Add new landmark
COverlayText * poTextName
[UI:Label] Name
COverlayText * poTextLatitude
[UI:Label] Latitude
COverlayText * poTextDop
[UI:Label] DOP
COverlayText * poTextFixType
[UI:Label] Fix type
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotAddLandmark()
[UI:Slot] Slot to add new landmark
COverlayText * poTextLongitude
[UI:Label] Longitude
virtual void resetContent()
Resets (clears) the content of the underlying widget.
void slotPositionCenter()
[UI:Slot] Slot to center chart (on item's position)
virtual void refreshContent()
Refreshes the content of the underlying widget.
COverlayText * poTextTime2
[UI:Label] Time (alternate timezone)
void slotDelete()
[UI:Slot] Slot to delete (this item/point)
[UI] Track overlay point (item)
Definition: CTrackPoint.hpp:40
double getDopHorizontal()
Sets this track point's horizontal Dilution-of-Precision (HDOP)
int getSatelliteCount()
Sets this track point's satellite count.
double getDopVertical()
Sets this track point's vertical Dilution-of-Precision (VDOP)
QString getFixType()
Sets this track point's fix type.
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitDate.cpp:71
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, EType _eType, 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
static CPointerOverlay * usePointerOverlay()
static QMutex * useMutexDataChange()
static CRouteOverlay * useRouteOverlay()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
static CLandmarkOverlay * useLandmarkOverlay()
static CTrackOverlay * useTrackOverlay()