Qt Virtual Chart Table (QVCT)
CRoutePointDetailView.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"
31 #include "overlays/COverlayUrl.hpp"
38 
39 
40 //------------------------------------------------------------------------------
41 // CONSTRUCTORS / DESTRUCTOR
42 //------------------------------------------------------------------------------
43 
45  : COverlayObjectDetailView( _pqParent )
46 {
48 }
49 
51 {
52  // Create the buttons
53  // ... visible
54  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
55  pqPushButtonVisible->setToolTip( tr("Toggle this waypoint's visibility") );
56  pqPushButtonVisible->setMaximumSize( 36, 34 );
57  pqPushButtonVisible->setEnabled( false );
58  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
59  // ... center
60  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
61  pqPushButtonCenter->setToolTip( tr("Center chart on this waypoint") );
62  pqPushButtonCenter->setMaximumSize( 36, 34 );
63  pqPushButtonCenter->setEnabled( false );
64  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
65  // ... edit
66  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
67  pqPushButtonEdit->setToolTip( tr("Edit this waypoint") );
68  pqPushButtonEdit->setMaximumSize( 36, 34 );
69  pqPushButtonEdit->setEnabled( false );
70  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
71  // ... move
72  pqPushButtonMove = new QPushButton( QIcon( ":icons/32x32/move.png" ), "" );
73  pqPushButtonMove->setToolTip( tr("Change this waypoint's position)") );
74  pqPushButtonMove->setMaximumSize( 36, 34 );
75  pqPushButtonMove->setEnabled( false );
76  pqPushButtonMove->setCheckable( true );
77  QWidget::connect( pqPushButtonMove, SIGNAL( toggled(bool) ), this, SLOT( slotMove(bool) ) );
78  // ... delete
79  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
80  pqPushButtonDelete->setToolTip( tr("Delete this waypoint") );
81  pqPushButtonDelete->setMaximumSize( 36, 34 );
82  pqPushButtonDelete->setEnabled( false );
83  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
84  // ... Add landmark
85  pqPushButtonAddLandmark = new QPushButton( QIcon( ":icons/32x32/landmark_add.png" ), "" );
86  pqPushButtonAddLandmark->setToolTip( tr("Create a new landmark at the waypoint position") );
87  pqPushButtonAddLandmark->setMaximumSize( 36, 34 );
88  pqPushButtonAddLandmark->setEnabled( false );
89  QWidget::connect( pqPushButtonAddLandmark, SIGNAL( clicked() ), this, SLOT( slotAddLandmark() ) );
90 
91  // Create layout
92  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
93 
94  // Add header
95  QFont __qFontHeader;
96  __qFontHeader.setPixelSize( 16 );
97  __qFontHeader.setBold( true );
98  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
99  QLabel* __pqLabelIcon = new QLabel();
100  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/route_point.png" ) );
101  __pqLabelIcon->setToolTip( tr("Waypoint") );
102  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
103  poTextName = new COverlayText();
104  poTextName->setToolTip( tr("Name") );
105  poTextName->setFont( __qFontHeader );
106  poTextName->setWordWrap( true );
107  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
108  pqLabelSymbol = new QLabel();
109  pqLabelSymbol->setMaximumSize( 32, 32 );
110  pqLabelSymbol->setVisible( false );
111  __pqHBoxLayoutHeader->addWidget( pqLabelSymbol );
112  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
113 
114  // Add data
115  QFont __qFontData;
116  QTabWidget* __poTabWidget = new QTabWidget();
117  __poTabWidget->setTabPosition( QTabWidget::South );
118  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
119 
120  // ... position
121  QWidget* __poWidgetPosition = new QWidget();
122  QVBoxLayout* __pqVBoxLayoutPosition = new QVBoxLayout();
123  __qFontData.setPixelSize( 20 );
125  poTextLongitude->setToolTip( tr("Longitude") );
126  poTextLongitude->setFont( __qFontData );
127  poTextLongitude->setIndent( 10 );
128  poTextLongitude->setAlignment( Qt::AlignHCenter );
130  __pqVBoxLayoutPosition->addWidget( poTextLongitude );
132  poTextLatitude->setToolTip( tr("Latitude") );
133  poTextLatitude->setFont( __qFontData );
134  poTextLatitude->setIndent( 10 );
135  poTextLatitude->setAlignment( Qt::AlignHCenter );
137  __pqVBoxLayoutPosition->addWidget( poTextLatitude );
139  poTextElevation->setToolTip( tr("Elevation") );
140  poTextElevation->setFont( __qFontData );
141  poTextElevation->setIndent( 10 );
142  poTextElevation->setAlignment( Qt::AlignHCenter );
144  __pqVBoxLayoutPosition->addWidget( poTextElevation, 1 );
145  __poWidgetPosition->setLayout( __pqVBoxLayoutPosition );
146  __poTabWidget->addTab( __poWidgetPosition, tr("Position") );
147 
148  // ... info
149  QScrollArea* __poScrollAreaInfo = new QScrollArea();
150  __poScrollAreaInfo->setStyleSheet( ".QScrollArea, .QWidget { BACKGROUND-COLOR: rgba(0, 0, 0, 0); BORDER: none; }" );
151  __poScrollAreaInfo->setWidgetResizable( true );
152  QWidget* __poWidgetInfo = new QWidget();
153  QVBoxLayout* __pqVBoxLayoutInfo = new QVBoxLayout();
154  __qFontData.setPixelSize( 12 );
155  __qFontData.setBold( true );
156  poTextType = new COverlayText();
157  poTextType->setToolTip( tr("Type") );
158  poTextType->setFont( __qFontData );
159  poTextType->setIndent( 10 );
161  __pqVBoxLayoutInfo->addWidget( poTextType );
162  __qFontData.setBold( false );
164  poTextDescription->setToolTip( tr("Description") );
165  poTextDescription->setFont( __qFontData );
166  poTextDescription->setIndent( 10 );
167  poTextDescription->setWordWrap( true );
169  __pqVBoxLayoutInfo->addWidget( poTextDescription );
170  __qFontData.setPixelSize( 10 );
171  poTextComment = new COverlayText();
172  poTextComment->setToolTip( tr("Comment") );
173  poTextComment->setFont( __qFontData );
174  poTextComment->setIndent( 10 );
175  poTextComment->setWordWrap( true );
177  __pqVBoxLayoutInfo->addWidget( poTextComment );
178  poUrl = new COverlayUrl();
179  poUrl->setToolTip( tr("URL") );
180  poUrl->setFont( __qFontData );
181  poUrl->setIndent( 10 );
182  poUrl->setWordWrap( true );
183  poUrl->resetText();
184  __pqVBoxLayoutInfo->addWidget( poUrl, 1 );
185  __poWidgetInfo->setLayout( __pqVBoxLayoutInfo );
186  __poScrollAreaInfo->setWidget( __poWidgetInfo );
187  __poTabWidget->addTab( __poScrollAreaInfo, tr("Info") );
188 
189  // ... [end]
190  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
191 
192  // Add separator
193  QFrame* __pqFrameSeparator = new QFrame();
194  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
195  __pqVBoxLayout->addWidget( __pqFrameSeparator );
196 
197  // Add buttons
198  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
199  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
200  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
201  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignHCenter );
202  __pqHBoxLayoutButtons->addWidget( pqPushButtonMove, 0, Qt::AlignHCenter );
203  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
204  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddLandmark, 1, Qt::AlignRight );
205  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
206 
207  // Set the layout
208  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
209 
210 }
211 
212 
213 //------------------------------------------------------------------------------
214 // METHODS: COverlayObjectDetailView (implement/override)
215 //------------------------------------------------------------------------------
216 
218 {
219  if( !poOverlayObject ) return;
220  CMainWindow* __poMainWindow = QVCTRuntime::useMainWindow();
221  CRoutePoint* __poRoutePoint = (CRoutePoint*)poOverlayObject;
222 
223  // ... name
224  poTextName->setText( __poRoutePoint->getName() );
225  QString __qsSymbol = __poRoutePoint->getSymbol();
226  if( __poMainWindow->symbolExists( __qsSymbol ) )
227  {
228  pqLabelSymbol->setPixmap( __poMainWindow->symbolPixmap( __qsSymbol ) );
229  pqLabelSymbol->setVisible( true );
230  }
231  else
232  pqLabelSymbol->setVisible( false );
233 
234  // ... position
235  if( __poRoutePoint->getLongitude() != CDataPosition::UNDEFINED_LONGITUDE
236  && __poRoutePoint->getLatitude() != CDataPosition::UNDEFINED_LATITUDE )
237  {
240  }
241  else
242  {
245  }
246 
247  // ... elevation
248  if( __poRoutePoint->getElevation() != CDataPosition::UNDEFINED_ELEVATION )
250  else
252 
253  // ... info
254  poTextType->setText( __poRoutePoint->getType() );
255  poTextDescription->setText( __poRoutePoint->getDescription() );
256  poTextComment->setText( __poRoutePoint->getComment() );
257  poUrl->setText( __poRoutePoint->getUrl() );
258 }
259 
261 {
263  pqLabelSymbol->setVisible( false );
270  poUrl->resetText();
271 }
272 
274 {
275  if( poOverlayObject )
276  {
277  pqPushButtonVisible->setEnabled( true );
278  pqPushButtonCenter->setEnabled( true );
279  pqPushButtonEdit->setEnabled( true );
280  pqPushButtonMove->setEnabled( true );
281  pqPushButtonDelete->setEnabled( true );
282  pqPushButtonAddLandmark->setEnabled( true );
283  }
284 }
285 
287 {
288  pqPushButtonVisible->setEnabled( false );
289  pqPushButtonCenter->setEnabled( false );
290  pqPushButtonEdit->setEnabled( false );
291  pqPushButtonMove->setEnabled( false );
292  pqPushButtonDelete->setEnabled( false );
293  pqPushButtonAddLandmark->setEnabled( false );
294 }
295 
296 
297 //------------------------------------------------------------------------------
298 // METHODS
299 //------------------------------------------------------------------------------
300 
301 //
302 // SLOTS
303 //
304 
306 {
307  if( !poOverlayObject ) return;
308  CRoutePoint* __poRoutePoint = (CRoutePoint*)poOverlayObject;
309  bool __bVisible = __poRoutePoint->isVisible();
310  __poRoutePoint->toggleVisibility();
311  if( __bVisible != __poRoutePoint->isVisible() )
312  {
313  __poRoutePoint->setCheckState( CRouteOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
314  }
315  __poRoutePoint->useOverlay()->forceRedraw();
317 }
318 
320 {
321  if( !poOverlayObject ) return;
322  CRoutePoint* __poRoutePoint = (CRoutePoint*)poOverlayObject;
323  QVCTRuntime::useChartTable()->setGeoPosition( *__poRoutePoint );
325 }
326 
328 {
329  if( !poOverlayObject ) return;
330  ((CRoutePoint*)poOverlayObject)->showEdit();
332 }
333 
334 void CRoutePointDetailView::slotMove( bool _bEnable )
335 {
336  if( !poOverlayObject ) return;
337  pqPushButtonVisible->setEnabled( !_bEnable );
338  pqPushButtonEdit->setEnabled( !_bEnable );
339  pqPushButtonDelete->setEnabled( !_bEnable );
340  pqPushButtonAddLandmark->setEnabled( !_bEnable );
341  QVCTRuntime::useOverlayListView()->setEnabled( !_bEnable );
344 }
345 
347 {
348  if( !poOverlayObject ) return;
349  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
350  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
351  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
352  CRouteContainer* __poRouteContainer = (CRouteContainer*)((QTreeWidgetItem*)poOverlayObject)->parent();
353  CRoutePoint* __poRoutePoint = (CRoutePoint*)poOverlayObject;
354  __pqMutexDataChange->lock();
355  __poRouteContainer->removeChild( __poRoutePoint );
356  __pqMutexDataChange->unlock();
357  delete __poRoutePoint;
358  QTreeWidgetItem* __pqTreeWidgetItem = __poRouteOverlay->currentItem();
359  if( __pqTreeWidgetItem ) __poRouteOverlay->showDetail( __pqTreeWidgetItem );
360  __poRouteOverlay->forceRedraw();
363 }
364 
366 {
367  if( !poOverlayObject ) return;
368  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
369  CLandmarkContainer* __poLandmarkContainer = __poLandmarkOverlay->pickContainer();
370  if( !__poLandmarkContainer ) return;
371  CRoutePoint* __poRoutePoint = (CRoutePoint*)poOverlayObject;
372  QString __qsName = __poLandmarkContainer->newChildName( __poRoutePoint->getName() );
373  CLandmarkPoint* __poLandmarkPoint = __poLandmarkContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject );
374  if( !__poLandmarkPoint ) return;
375  __poLandmarkPoint->setType( __poRoutePoint->getType() );
376  __poLandmarkPoint->setDescription( __poRoutePoint->getDescription() );
377  __poLandmarkPoint->setComment( __poRoutePoint->getComment() );
378  __poLandmarkPoint->setSymbol( __poRoutePoint->getSymbol() );
379  __poLandmarkPoint->setUrl( __poRoutePoint->getUrl() );
380  __poLandmarkOverlay->setCurrentItem( __poLandmarkPoint );
381  __poLandmarkOverlay->forceRedraw();
382  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
383  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
384  __poPointerPoint->resetPosition();
385  __poPointerOverlay->forceRedraw();
387  __poLandmarkPoint->showEdit();
389 }
void setOverlayPointMove(COverlayPoint *_poOverlayPoint)
Sets the overlay point to be moved (and lock all other actions while it is ongoing)
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.
[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)
void setType(const QString &_rqsType)
Sets this landmark's type.
virtual void showEdit()
Displays this object's edit widget/view.
void setDescription(const QString &_rqsDescription)
Sets this landmark's description.
void setComment(const QString &_rqsComment)
Sets this landmark's comment.
void setSymbol(const QString &_rqsSymbol)
Sets this landmark's symbol.
void setUrl(const QString &_rqsUrl)
Sets this landmark's URL.
[UI] Application main window
Definition: CMainWindow.hpp:36
QPixmap symbolPixmap(const QString &_rqsSymbol)
Returns pixmap matching the given symbol (loaded from the application's symbol directory)
bool symbolExists(const QString &_rqsSymbol)
Returns whether the given symbol exists (in the application's symbol directory)
[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& )
void resetText()
Resets (clears) the underlying QLabel's text.
[UI] Overlay-specific URL label
Definition: COverlayUrl.hpp:36
void setText(const QString &_rqsText)
Definition: COverlayUrl.cpp:51
bool isVisible() const
Returns the point's (marker) visibility status.
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
[UI] Route overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
@ VISIBLE
Route visibility status.
COverlayText * poTextLatitude
[UI:Label] Latitude
void slotAddLandmark()
[UI:Slot] Slot to add new landmark
virtual void disableContent()
Disables the content (controls) of the underlying widget.
QLabel * pqLabelSymbol
[UI:Label] Symbol
COverlayText * poTextElevation
[UI:Label] Elevation
CRoutePointDetailView(QWidget *_pqParent=0)
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonDelete
[UI:Button] Delete
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
COverlayText * poTextComment
[UI:Label] Comment
void slotDelete()
[UI:Slot] Slot to delete (this item/point)
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
COverlayUrl * poUrl
[UI:Label] URL
QPushButton * pqPushButtonMove
[UI:Button] Move (change position)
COverlayText * poTextName
[UI:Label] Name
void slotEdit()
[UI:Slot] Slot to display edit view
void slotPositionCenter()
[UI:Slot] Slot to center chart (on item's position)
virtual void refreshContent()
Refreshes the content of the underlying widget.
virtual void resetContent()
Resets (clears) the content of the underlying widget.
COverlayText * poTextType
[UI:Label] Type
COverlayText * poTextDescription
[UI:Label] Description
QPushButton * pqPushButtonEdit
[UI:Button] Edit
COverlayText * poTextLongitude
[UI:Label] Longitude
QPushButton * pqPushButtonAddLandmark
[UI:Button] Add new landmark
virtual void enableContent()
Enables the content (controls) of the underlying widget.
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
void slotMove(bool _bEnable)
[UI:Slot] Slot to enable/disable move (position change)
[UI] Route overlay point (item) / waypoint
Definition: CRoutePoint.hpp:40
virtual void toggleVisibility()
QString getComment() const
Returns this waypoint's comment.
QString getDescription() const
Returns this waypoint's description.
QString getType() const
Returns this waypoint's type.
QString getUrl() const
Returns this waypoint's URL.
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
Definition: CRoutePoint.hpp:79
QString getSymbol() const
Returns this waypoint's symbol.
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 COverlayListView * useOverlayListView()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
static CLandmarkOverlay * useLandmarkOverlay()