Qt Virtual Chart Table (QVCT)
CPointerPointDetailView.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 <QPushButton>
22 #include <QStackedWidget>
23 #include <QVBoxLayout>
24 #include <QWidget>
25 
26 // QVCT
27 #include "QVCTRuntime.hpp"
35 
36 
37 //------------------------------------------------------------------------------
38 // CONSTRUCTORS / DESTRUCTOR
39 //------------------------------------------------------------------------------
40 
42  : COverlayObjectDetailView( _pqParent )
43 {
45 }
46 
48 {
49  // Create the buttons
50  // ... visible
51  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
52  pqPushButtonVisible->setToolTip( tr("Toggle the pointer visibility") );
53  pqPushButtonVisible->setMaximumSize( 36, 34 );
54  pqPushButtonVisible->setEnabled( false );
55  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
56  // ... center
57  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
58  pqPushButtonCenter->setToolTip( tr("Center chart on the pointer position") );
59  pqPushButtonCenter->setMaximumSize( 36, 34 );
60  pqPushButtonCenter->setEnabled( false );
61  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
62  // ... delete
63  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
64  pqPushButtonDelete->setToolTip( tr("Delete the last pointer path's position") );
65  pqPushButtonDelete->setMaximumSize( 36, 34 );
66  pqPushButtonDelete->setEnabled( false );
67  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
68  // ... Add landmark
69  pqPushButtonAddLandmark = new QPushButton( QIcon( ":icons/32x32/landmark_add.png" ), "" );
70  pqPushButtonAddLandmark->setToolTip( tr("Create new landmark(s) at the pointer (path) positions") );
71  pqPushButtonAddLandmark->setMaximumSize( 36, 34 );
72  pqPushButtonAddLandmark->setEnabled( false );
73  QWidget::connect( pqPushButtonAddLandmark, SIGNAL( clicked() ), this, SLOT( slotAddLandmark() ) );
74  // ... Add route
75  pqPushButtonAddRoute = new QPushButton( QIcon( ":icons/32x32/route_add.png" ), "" );
76  pqPushButtonAddRoute->setToolTip( tr("Create new (route) waypoint(s) at the pointer (path) position(s)") );
77  pqPushButtonAddRoute->setMaximumSize( 36, 34 );
78  pqPushButtonAddRoute->setEnabled( false );
79  QWidget::connect( pqPushButtonAddRoute, SIGNAL( clicked() ), this, SLOT( slotAddRoute() ) );
80 
81  // Create layout
82  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
83 
84  // Add header
85  QFont __qFontHeader;
86  __qFontHeader.setPixelSize( 16 );
87  __qFontHeader.setBold( true );
88  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
89  QLabel* __pqLabelIcon = new QLabel();
90  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/pointer.png" ) );
91  __pqLabelIcon->setToolTip( tr("Pointer") );
92  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
93  COverlayText* __poTextName = new COverlayText( tr("Pointer") );
94  __poTextName->setToolTip( tr("Name") );
95  __poTextName->setFont( __qFontHeader );
96  __poTextName->setWordWrap( true );
97  __pqHBoxLayoutHeader->addWidget( __poTextName, 1 );
98  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
99 
100  // Add data
101  QFont __qFontData;
102  QTabWidget* __poTabWidget = new QTabWidget();
103  __poTabWidget->setTabPosition( QTabWidget::South );
104  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
105 
106  // ... position
107  __qFontData.setPixelSize( 20 );
108  QWidget* __poWidgetPosition = new QWidget();
109  QVBoxLayout* __pqVBoxLayoutPosition = new QVBoxLayout();
111  poTextLongitude->setToolTip( tr("Longitude") );
112  poTextLongitude->setFont( __qFontData );
113  poTextLongitude->setIndent( 10 );
114  poTextLongitude->setAlignment( Qt::AlignHCenter );
116  __pqVBoxLayoutPosition->addWidget( poTextLongitude );
118  poTextLatitude->setToolTip( tr("Latitude") );
119  poTextLatitude->setFont( __qFontData );
120  poTextLatitude->setIndent( 10 );
121  poTextLatitude->setAlignment( Qt::AlignHCenter );
123  __pqVBoxLayoutPosition->addWidget( poTextLatitude );
125  poTextElevation->setToolTip( tr("Elevation") );
126  poTextElevation->setFont( __qFontData );
127  poTextElevation->setIndent( 10 );
128  poTextElevation->setAlignment( Qt::AlignHCenter );
130  __pqVBoxLayoutPosition->addWidget( poTextElevation, 1 );
131  __poWidgetPosition->setLayout( __pqVBoxLayoutPosition );
132  __poTabWidget->addTab( __poWidgetPosition, tr("Position") );
133 
134  // ... path
135  QWidget* __poWidgetPath = new QWidget();
136  QVBoxLayout* __pqVBoxLayoutPath = new QVBoxLayout();
138  poTextPathSegments->setToolTip( tr("Segments") );
139  poTextPathSegments->setFont( __qFontData );
140  poTextPathSegments->setIndent( 10 );
141  poTextPathSegments->setAlignment( Qt::AlignHCenter );
143  __pqVBoxLayoutPath->addWidget( poTextPathSegments );
145  poTextPathLengthRL->setToolTip( tr("Length (rhumb-line along segments)") );
146  poTextPathLengthRL->setFont( __qFontData );
147  poTextPathLengthRL->setIndent( 10 );
148  poTextPathLengthRL->setAlignment( Qt::AlignHCenter );
150  __pqVBoxLayoutPath->addWidget( poTextPathLengthRL );
152  poTextPathLengthGC->setToolTip( tr("Length (great-circle equivalent)") );
153  poTextPathLengthGC->setFont( __qFontData );
154  poTextPathLengthGC->setIndent( 10 );
155  poTextPathLengthGC->setAlignment( Qt::AlignHCenter );
157  __pqVBoxLayoutPath->addWidget( poTextPathLengthGC, 1 );
158  __poWidgetPath->setLayout( __pqVBoxLayoutPath );
159  __poTabWidget->addTab( __poWidgetPath, tr("Path") );
160 
161  // ... [end]
162  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
163 
164  // Add separator
165  QFrame* __pqFrameSeparator = new QFrame();
166  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
167  __pqVBoxLayout->addWidget( __pqFrameSeparator );
168 
169  // Add buttons
170  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
171  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
172  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
173  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
174  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddLandmark, 1, Qt::AlignRight );
175  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddRoute, 0, Qt::AlignRight );
176  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
177 
178  // Set the layout
179  QWidget::setLayout( __pqVBoxLayout );
180 
181 }
182 
183 
184 //------------------------------------------------------------------------------
185 // METHODS: COverlayObjectDetailView (implement/override)
186 //------------------------------------------------------------------------------
187 
189 {
190  if( !poOverlayObject ) return;
191  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
192  CPointerPoint* __poPointerPoint = (CPointerPoint*)poOverlayObject;
193 
194  // ... position
197 
198  // ... elevation
199  if( __poPointerPoint->getElevation() != CDataPosition::UNDEFINED_ELEVATION )
201  else
203 
204  // ... path
205  if( __poPointerOverlay->hasPath() )
206  {
207  poTextPathSegments->setText( QString::number( __poPointerOverlay->getPathSegments() )+" "+tr("segment(s)") );
209  poTextPathLengthGC->setText( "("+CUnitDistance::toString( __poPointerOverlay->getPathLengthGC() )+")", true );
210  }
211  else
212  {
216  }
217 
218  // ... buttons
220 }
221 
223 {
230 }
231 
233 {
234  if( poOverlayObject )
235  {
236  pqPushButtonVisible->setEnabled( true );
237  pqPushButtonCenter->setEnabled( true );
238  pqPushButtonAddLandmark->setEnabled( true );
239  pqPushButtonAddRoute->setEnabled( true );
240  }
241 }
242 
244 {
245  pqPushButtonVisible->setEnabled( false );
246  pqPushButtonCenter->setEnabled( false );
247  pqPushButtonDelete->setEnabled( false );
248  pqPushButtonAddLandmark->setEnabled( false );
249  pqPushButtonAddRoute->setEnabled( false );
250 }
251 
252 
253 //------------------------------------------------------------------------------
254 // METHODS
255 //------------------------------------------------------------------------------
256 
257 //
258 // SLOTS
259 //
260 
262 {
263  if( !poOverlayObject ) return;
264  CPointerPoint* __poPointerPoint = (CPointerPoint*)poOverlayObject;
265  __poPointerPoint->toggleVisibility();
266  __poPointerPoint->useOverlay()->forceRedraw();
268 }
269 
271 {
272  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
273  if( __poPointerOverlay->hasPath() )
274  {
275  CDataPosition _oDataPositionLower, _oDataPositionUpper;
276  int __iCount = COverlayPoint::getPositionBox( __poPointerOverlay, &_oDataPositionLower, &_oDataPositionUpper, 1 );
277  if( __iCount > 1 ) QVCTRuntime::useChartTable()->setScaleArea( _oDataPositionLower, _oDataPositionUpper, 0.9 );
278  else if( __iCount == 1 ) QVCTRuntime::useChartTable()->setGeoPosition( _oDataPositionLower );
279  if( __iCount ) return;
280  }
281  if( !poOverlayObject ) return;
282  CPointerPoint* __poPointerPoint = (CPointerPoint*)poOverlayObject;
283  QVCTRuntime::useChartTable()->setGeoPosition( *__poPointerPoint );
285 }
286 
288 {
289  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
290  if( !__poPointerOverlay->hasPath() ) return;
291  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
292  __pqMutexDataChange->lock();
293  CPointerPoint* __poPointerPoint = (CPointerPoint*)__poPointerOverlay->takeChild( __poPointerOverlay->childCount()-1 );
294  delete __poPointerPoint;
295  __poPointerPoint = __poPointerOverlay->usePointerPoint();
296  __poPointerPoint->setPosition( *(CPointerPoint*)__poPointerOverlay->child( __poPointerOverlay->childCount()-1 ) );
297  __poPointerPoint->showDetail();
298  __poPointerOverlay->forceRedraw();
300  __pqMutexDataChange->unlock();
301 }
302 
304 {
305  if( !poOverlayObject ) return;
306  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
307  CLandmarkContainer* __poLandmarkContainer = __poLandmarkOverlay->pickContainer();
308  if( !__poLandmarkContainer ) return;
309  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
310  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
311  CLandmarkPoint* __poLandmarkPoint = 0;
312  if( __poPointerOverlay->hasPath() )
313  {
314  int __iCount = __poPointerOverlay->childCount();
315  for( int __i = 2; __i < __iCount; __i++ )
316  {
317  QString __qsName = __poLandmarkContainer->newChildName( tr("Landmark"), 1, true );
318  __poLandmarkContainer->addPoint( __qsName, *(CPointerPoint*)__poPointerOverlay->child( __i ) );
319  }
320  __poLandmarkOverlay->setCurrentItem( __poLandmarkContainer );
321  }
322  else
323  {
324  QString __qsName = __poLandmarkContainer->newChildName( tr("Landmark"), 1, true );
325  __poLandmarkPoint = __poLandmarkContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject );
326  if( __poLandmarkPoint ) __poLandmarkOverlay->setCurrentItem( __poLandmarkPoint );
327  }
328  __poLandmarkOverlay->forceRedraw();
329  __poPointerPoint->resetPosition();
330  __poPointerOverlay->clearPath();
331  __poPointerOverlay->forceRedraw();
333  if( __poLandmarkPoint ) __poLandmarkPoint->showEdit();
334 }
335 
337 {
338  if( !poOverlayObject ) return;
339  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
340  CRouteContainer* __poRouteContainer = __poRouteOverlay->pickContainer();
341  if( !__poRouteContainer ) return;
342  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
343  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
344  CRoutePoint* __poRoutePoint = 0;
345  if( __poPointerOverlay->hasPath() )
346  {
347  int __iCount = __poPointerOverlay->childCount();
348  for( int __i = 2; __i < __iCount; __i++ )
349  {
350  QString __qsName = __poRouteContainer->newChildName( tr("Waypoint"), 1, true );
351  __poRouteContainer->addPoint( __qsName, *(CPointerPoint*)__poPointerOverlay->child( __i ) );
352  }
353  __poRouteOverlay->setCurrentItem( __poRouteContainer );
354  }
355  else
356  {
357  QString __qsName = __poRouteContainer->newChildName( tr("Waypoint"), 1, true );
358  __poRoutePoint = __poRouteContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject, true );
359  if( __poRoutePoint ) __poRouteOverlay->setCurrentItem( __poRoutePoint );
360  }
361  __poRouteOverlay->forceRedraw();
362  __poPointerPoint->resetPosition();
363  __poPointerOverlay->clearPath();
364  __poPointerOverlay->forceRedraw();
366  if( __poRoutePoint ) __poRoutePoint->showEdit();
367 }
void setScaleArea(const CDataPosition &_roGeoPosition1, const CDataPosition &_roGeoPosition2, double _fdScaleCorrection=1.0)
Sets the reference scale factor to display the given (geographical) area (defined by its opposite cor...
void updateChart()
Update the (current) chart content (on screen)
void setGeoPosition(const CDataPosition &_roGeoPosition, bool _bSkipCurrent=false)
Sets the reference chart (geographical) position.
(Geographical) Position data [long,lat,elev]
double getLongitude() const
Returns this position's longitude, in degrees.
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.
void setPosition(double _fdLongitude, double _fdLatitude, double _fdElevation=UNDEFINED_ELEVATION)
Sets new coordinates.
static constexpr double UNDEFINED_ELEVATION
Specific value for an undefined elevation.
[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 newChildName(const QString &_rqsName, int _iZeroPrefix=0, bool _bForceSuffix=false) const
Returns a valid (non-duplicate) name for a new sibling of this object.
static int getPositionBox(const QTreeWidgetItem *_pqTreeWidgetItem, CDataPosition *_poDataPositionLower, CDataPosition *_poDataPositionUpper, int _iIndexMin=0, int _iIndexMax=-1)
Returns the minimal geographical positions box containing the points in the given overlay/container.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
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
double getPathLengthRL()
Returns the pointer path (rhumb-line) length along its segments.
bool hasPath() const
Returns whether a pointer path has been defined.
int getPathSegments() const
Returns the quantity of segments along the pointer path (0 if no path is defined)
double getPathLengthGC()
Returns the equivalent (great-circle) length between the first and last position of the pointer path.
void clearPath()
Clears the pointer path.
CPointerPoint * usePointerPoint()
Returns the pointer point corresponding to the mouse pointer.
COverlayText * poTextPathLengthGC
[UI:Label] Path (great-circle) length
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
void slotDelete()
[UI:Slot] Slot to delete last path's point
virtual void resetContent()
Resets (clears) the content of the underlying widget.
void slotAddLandmark()
[UI:Slot] Slot to add new landmark
QPushButton * pqPushButtonAddLandmark
[UI:Button] Add new landmark
virtual void refreshContent()
Refreshes the content of the underlying widget.
QPushButton * pqPushButtonAddRoute
[UI:Button] Add new (route) waypoint
virtual void disableContent()
Disables the content (controls) of the underlying widget.
COverlayText * poTextLongitude
[UI:Label] Longitude
void constructLayout()
Constructs the layout of the user-interface.
virtual void enableContent()
Enables the content (controls) of the underlying widget.
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotPositionCenter()
[UI:Slot] Slot to center chart (on item's position)
void slotAddRoute()
[UI:Slot] Slot to add new (route) waypoint
CPointerPointDetailView(QWidget *_pqParent=0)
COverlayText * poTextLatitude
[UI:Label] Latitude
COverlayText * poTextPathSegments
[UI:Label] Path segments count
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
COverlayText * poTextPathLengthRL
[UI:Label] Path (rhumb-line) length
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
COverlayText * poTextElevation
[UI:Label] Elevation
[UI] Pointer overlay point (item)
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
virtual void toggleVisibility()
virtual void showDetail()
Displays this object's details (in the appropriate widget/view)
[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.
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, EType _eType, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static CPointerOverlay * usePointerOverlay()
static QMutex * useMutexDataChange()
static CRouteOverlay * useRouteOverlay()
static CChartTable * useChartTable()
static CLandmarkOverlay * useLandmarkOverlay()