Qt Virtual Chart Table (QVCT)
CLandmarkPointDetailView.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 landmark'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 landmark") );
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 landmark") );
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 landmark'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 landmark") );
81  pqPushButtonDelete->setMaximumSize( 36, 34 );
82  pqPushButtonDelete->setEnabled( false );
83  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
84  // ... Add route
85  pqPushButtonAddRoute = new QPushButton( QIcon( ":icons/32x32/route_add.png" ), "" );
86  pqPushButtonAddRoute->setToolTip( tr("Create a new (route) waypoint at the landmark position") );
87  pqPushButtonAddRoute->setMaximumSize( 36, 34 );
88  pqPushButtonAddRoute->setEnabled( false );
89  QWidget::connect( pqPushButtonAddRoute, SIGNAL( clicked() ), this, SLOT( slotAddRoute() ) );
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/landmark_point.png" ) );
101  __pqLabelIcon->setToolTip( tr("Landmark") );
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( pqPushButtonAddRoute, 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  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
222 
223  // ... name
224  poTextName->setText( __poLandmarkPoint->getName() );
225  QString __qsSymbol = __poLandmarkPoint->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( __poLandmarkPoint->getLongitude() != CDataPosition::UNDEFINED_LONGITUDE
236  && __poLandmarkPoint->getLatitude() != CDataPosition::UNDEFINED_LATITUDE )
237  {
240  }
241  else
242  {
245  }
246 
247  // ... elevation
248  if( __poLandmarkPoint->getElevation() != CDataPosition::UNDEFINED_ELEVATION )
249  poTextElevation->setText( CUnitElevation::toString( __poLandmarkPoint->getElevation() ) );
250  else
252 
253  // ... info
254  poTextType->setText( __poLandmarkPoint->getType() );
255  poTextDescription->setText( __poLandmarkPoint->getDescription() );
256  poTextComment->setText( __poLandmarkPoint->getComment() );
257  poUrl->setText( __poLandmarkPoint->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  pqPushButtonAddRoute->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  pqPushButtonAddRoute->setEnabled( false );
294 }
295 
296 
297 //------------------------------------------------------------------------------
298 // METHODS
299 //------------------------------------------------------------------------------
300 
301 //
302 // SLOTS
303 //
304 
306 {
307  if( !poOverlayObject ) return;
308  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
309  bool __bVisible = __poLandmarkPoint->isVisible();
310  __poLandmarkPoint->toggleVisibility();
311  if( __bVisible != __poLandmarkPoint->isVisible() )
312  {
313  __poLandmarkPoint->setCheckState( CLandmarkOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
314  }
315  __poLandmarkPoint->useOverlay()->forceRedraw();
317 }
318 
320 {
321  if( !poOverlayObject ) return;
322  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
323  QVCTRuntime::useChartTable()->setGeoPosition( *__poLandmarkPoint );
325 }
326 
328 {
329  if( !poOverlayObject ) return;
330  ((CLandmarkPoint*)poOverlayObject)->showEdit();
332 }
333 
335 {
336  if( !poOverlayObject ) return;
337  pqPushButtonVisible->setEnabled( !_bEnable );
338  pqPushButtonEdit->setEnabled( !_bEnable );
339  pqPushButtonDelete->setEnabled( !_bEnable );
340  pqPushButtonAddRoute->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  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
352  CLandmarkContainer* __poLandmarkContainer = (CLandmarkContainer*)((QTreeWidgetItem*)poOverlayObject)->parent();
353  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
354  __pqMutexDataChange->lock();
355  __poLandmarkContainer->removeChild( __poLandmarkPoint );
356  __pqMutexDataChange->unlock();
357  delete __poLandmarkPoint;
358  QTreeWidgetItem* __pqTreeWidgetItem = __poLandmarkOverlay->currentItem();
359  if( __pqTreeWidgetItem ) __poLandmarkOverlay->showDetail( __pqTreeWidgetItem );
360  __poLandmarkOverlay->forceRedraw();
363 }
364 
366 {
367  if( !poOverlayObject ) return;
368  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
369  CRouteContainer* __poRouteContainer = __poRouteOverlay->pickContainer();
370  if( !__poRouteContainer ) return;
371  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
372  QString __qsName = __poRouteContainer->newChildName( __poLandmarkPoint->getName() );
373  CRoutePoint* __poRoutePoint = __poRouteContainer->addPoint( __qsName, *(CPointerPoint*)poOverlayObject, true );
374  if( !__poRoutePoint ) return;
375  __poRoutePoint->setType( __poLandmarkPoint->getType() );
376  __poRoutePoint->setDescription( __poLandmarkPoint->getDescription() );
377  __poRoutePoint->setComment( __poLandmarkPoint->getComment() );
378  __poRoutePoint->setSymbol( __poLandmarkPoint->getSymbol() );
379  __poRoutePoint->setUrl( __poLandmarkPoint->getUrl() );
380  __poRouteOverlay->setCurrentItem( __poRoutePoint );
381  __poRouteOverlay->forceRedraw();
382  CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay();
383  CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint();
384  __poPointerPoint->resetPosition();
385  __poPointerOverlay->forceRedraw();
387  __poRoutePoint->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
[UI] Landmark overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
@ VISIBLE
Landmark visibility status.
CLandmarkPointDetailView(QWidget *_pqParent=0)
COverlayText * poTextComment
[UI:Label] Comment
void constructLayout()
Constructs the layout of the user-interface.
virtual void enableContent()
Enables the content (controls) of the underlying widget.
void slotPositionCenter()
[UI:Slot] Slot to center chart (on item's position)
QPushButton * pqPushButtonAddRoute
[UI:Button] Add new (route) waypoint
virtual void disableContent()
Disables the content (controls) of the underlying widget.
COverlayText * poTextLatitude
[UI:Label] Latitude
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
COverlayText * poTextElevation
[UI:Label] Elevation
COverlayText * poTextDescription
[UI:Label] Description
QPushButton * pqPushButtonEdit
[UI:Button] Edit
void slotMove(bool _bEnable)
[UI:Slot] Slot to enable/disable move (position change)
QLabel * pqLabelSymbol
[UI:Label] Symbol
COverlayText * poTextType
[UI:Label] Type
QPushButton * pqPushButtonDelete
[UI:Button] Delete
virtual void refreshContent()
Refreshes the content of the underlying widget.
void slotAddRoute()
[UI:Slot] Slot to add new (route) waypoint
COverlayText * poTextLongitude
[UI:Label] Longitude
COverlayText * poTextName
[UI:Label] Name
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
QPushButton * pqPushButtonMove
[UI:Button] Move (change position)
void slotDelete()
[UI:Slot] Slot to delete (this item/point)
COverlayUrl * poUrl
[UI:Label] URL
void slotEdit()
[UI:Slot] Slot to display edit view
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
virtual void resetContent()
Resets (clears) the content of the underlying widget.
[UI] Landmark overlay point (item)
QString getSymbol() const
Returns this landmark's symbol.
QString getComment() const
Returns this landmark's comment.
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
virtual void toggleVisibility()
QString getType() const
Returns this landmark's type.
QString getUrl() const
Returns this landmark's URL.
QString getDescription() const
Returns this landmark's description.
[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
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
void setSymbol(const QString &_rqsSymbol)
Sets this waypoint's symbol.
void setUrl(const QString &_rqsUrl)
Sets this waypoint's URL.
void setType(const QString &_rqsType)
Sets this waypoint's type.
void setDescription(const QString &_rqsDescription)
Sets this waypoint's description.
virtual void showEdit()
Displays this object's edit widget/view.
void setComment(const QString &_rqsComment)
Sets this waypoint's comment.
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()