Qt Virtual Chart Table (QVCT)
CRouteContainerDetailView.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 <QFileInfo>
21 #include <QHBoxLayout>
22 #include <QLabel>
23 #include <QPushButton>
24 #include <QScrollArea>
25 #include <QStackedWidget>
26 #include <QVBoxLayout>
27 #include <QWidget>
28 
29 // QVCT
30 #include "QVCTRuntime.hpp"
31 #include "data/CDataPosition.hpp"
33 #include "overlays/COverlayUrl.hpp"
37 
38 
39 //------------------------------------------------------------------------------
40 // CONSTRUCTORS / DESTRUCTOR
41 //------------------------------------------------------------------------------
42 
44  : COverlayObjectDetailView( _pqParent )
45 {
47 }
48 
50 {
51  // Create the buttons
52  // ... visible
53  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
54  pqPushButtonVisible->setMaximumSize( 36, 34 );
55  pqPushButtonVisible->setToolTip( tr("Toggle this route's visibility") );
56  pqPushButtonVisible->setEnabled( false );
57  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
58  // ... center
59  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
60  pqPushButtonCenter->setMaximumSize( 36, 34 );
61  pqPushButtonCenter->setToolTip( tr("Center chart on this route's mean position") );
62  pqPushButtonCenter->setEnabled( false );
63  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
64  // ... edit
65  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
66  pqPushButtonEdit->setMaximumSize( 36, 34 );
67  pqPushButtonEdit->setToolTip( tr("Edit this route") );
68  pqPushButtonEdit->setEnabled( false );
69  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
70  // ... save
71  pqPushButtonSave = new QPushButton( QIcon( ":icons/32x32/save.png" ), "" );
72  pqPushButtonSave->setMaximumSize( 36, 34 );
73  pqPushButtonSave->setToolTip( tr("Save this route to disk") );
74  pqPushButtonSave->setEnabled( false );
75  QWidget::connect( pqPushButtonSave, SIGNAL( clicked() ), this, SLOT( slotSave() ) );
76  // ... delete
77  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
78  pqPushButtonDelete->setMaximumSize( 36, 34 );
79  pqPushButtonDelete->setToolTip( tr("Delete this route") );
80  pqPushButtonDelete->setEnabled( false );
81  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
82  // ... add point
83  pqPushButtonAddPoint = new QPushButton( QIcon( ":icons/32x32/point_add.png" ), "" );
84  pqPushButtonAddPoint->setMaximumSize( 36, 34 );
85  pqPushButtonAddPoint->setToolTip( tr("Add a new waypoint to this route") );
86  pqPushButtonAddPoint->setEnabled( false );
87  QWidget::connect( pqPushButtonAddPoint, SIGNAL( clicked() ), this, SLOT( slotAddPoint() ) );
88 
89  // Create layout
90  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
91 
92  // Add header
93  QFont __qFontHeader;
94  __qFontHeader.setPixelSize( 16 );
95  __qFontHeader.setBold( true );
96  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
97  QLabel* __pqLabelIcon = new QLabel();
98  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/route.png" ) );
99  __pqLabelIcon->setToolTip( tr("Route") );
100  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
101  poTextName = new COverlayText();
102  poTextName->setToolTip( tr("Name") );
103  poTextName->setFont( __qFontHeader );
104  poTextName->setWordWrap( true );
105  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
106  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
107 
108  // Add data
109  QFont __qFontData;
110  QTabWidget* __poTabWidget = new QTabWidget();
111  __poTabWidget->setTabPosition( QTabWidget::South );
112  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
113 
114  // ... summary
115  QWidget* __poWidgetSummary = new QWidget();
116  QVBoxLayout* __pqVBoxLayoutSummary = new QVBoxLayout();
117  __qFontData.setPixelSize( 20 );
118  poTextContent = new COverlayText();
119  poTextContent->setToolTip( tr("Waypoints count") );
120  poTextContent->setFont( __qFontData );
121  poTextContent->setIndent( 10 );
122  poTextContent->setAlignment( Qt::AlignHCenter );
124  __pqVBoxLayoutSummary->addWidget( poTextContent, 0 );
126  poTextLengthRL->setToolTip( tr("Length (rhumb-lines along route)") );
127  poTextLengthRL->setFont( __qFontData );
128  poTextLengthRL->setIndent( 10 );
129  poTextLengthRL->setAlignment( Qt::AlignHCenter );
131  __pqVBoxLayoutSummary->addWidget( poTextLengthRL, 1 );
132  __poWidgetSummary->setLayout( __pqVBoxLayoutSummary );
133  __poTabWidget->addTab( __poWidgetSummary, tr("Summary") );
134 
135  // ... info
136  QScrollArea* __poScrollAreaInfo = new QScrollArea();
137  __poScrollAreaInfo->setStyleSheet( ".QScrollArea, .QWidget { BACKGROUND-COLOR: rgba(0, 0, 0, 0); BORDER: none; }" );
138  __poScrollAreaInfo->setWidgetResizable( true );
139  QWidget* __poWidgetInfo = new QWidget();
140  QVBoxLayout* __pqVBoxLayoutInfo = new QVBoxLayout();
141  __qFontData.setPixelSize( 12 );
142  __qFontData.setBold( true );
143  poTextType = new COverlayText();
144  poTextType->setToolTip( tr("Type") );
145  poTextType->setFont( __qFontData );
146  poTextType->setIndent( 10 );
148  __pqVBoxLayoutInfo->addWidget( poTextType );
149  __qFontData.setBold( false );
151  poTextDescription->setToolTip( tr("Description") );
152  poTextDescription->setFont( __qFontData );
153  poTextDescription->setIndent( 10 );
155  __pqVBoxLayoutInfo->addWidget( poTextDescription );
156  __qFontData.setPixelSize( 10 );
157  poTextComment = new COverlayText();
158  poTextComment->setToolTip( tr("Comment") );
159  poTextComment->setFont( __qFontData );
160  poTextComment->setIndent( 10 );
162  __pqVBoxLayoutInfo->addWidget( poTextComment );
163  poUrl = new COverlayUrl();
164  poUrl->setToolTip( tr("URL") );
165  poUrl->setFont( __qFontData );
166  poUrl->setIndent( 10 );
167  poUrl->resetText();
168  __pqVBoxLayoutInfo->addWidget( poUrl, 1 );
169  __poWidgetInfo->setLayout( __pqVBoxLayoutInfo );
170  __poScrollAreaInfo->setWidget( __poWidgetInfo );
171  __poTabWidget->addTab( __poScrollAreaInfo, tr("Info") );
172 
173  // ... [end]
174  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
175 
176  // Add separator
177  QFrame* __pqFrameSeparator = new QFrame();
178  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
179  __pqVBoxLayout->addWidget( __pqFrameSeparator );
180 
181  // Add buttons
182  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
183  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
184  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
185  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignHCenter );
186  __pqHBoxLayoutButtons->addWidget( pqPushButtonSave, 0, Qt::AlignHCenter );
187  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
188  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddPoint, 1, Qt::AlignRight );
189  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
190 
191  // Set the layout
192  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
193 
194 }
195 
196 
197 //------------------------------------------------------------------------------
198 // METHODS: COverlayObjectDetailView (implement/override)
199 //------------------------------------------------------------------------------
200 
202 {
203  if( !poOverlayObject ) return;
204  CRouteContainer* __poRouteContainer = (CRouteContainer*)poOverlayObject;
205  poTextName->setText( __poRouteContainer->getName() );
206  poTextContent->setText( QString::number( __poRouteContainer->childCount() )+" "+tr("Waypoint(s)") );
207  poTextLengthRL->setText( CUnitDistance::toString( __poRouteContainer->getLengthRL() ) );
208  poTextType->setText( __poRouteContainer->getType() );
209  poTextDescription->setText( __poRouteContainer->getDescription() );
210  poTextComment->setText( __poRouteContainer->getComment() );
211  poUrl->setText( __poRouteContainer->getUrl() );
212 }
213 
215 {
222  poUrl->resetText();
223 }
224 
226 {
227  if( poOverlayObject )
228  {
229  pqPushButtonVisible->setEnabled( true );
230  pqPushButtonCenter->setEnabled( true );
231  pqPushButtonEdit->setEnabled( true );
232  pqPushButtonSave->setEnabled( true );
233  pqPushButtonDelete->setEnabled( true );
234  pqPushButtonAddPoint->setEnabled( true );
235  }
236 }
237 
239 {
240  pqPushButtonVisible->setEnabled( false );
241  pqPushButtonCenter->setEnabled( false );
242  pqPushButtonEdit->setEnabled( false );
243  pqPushButtonSave->setEnabled( false );
244  pqPushButtonDelete->setEnabled( false );
245  pqPushButtonAddPoint->setEnabled( false );
246 }
247 
248 
249 //------------------------------------------------------------------------------
250 // METHODS
251 //------------------------------------------------------------------------------
252 
253 //
254 // SLOTS
255 //
256 
258 {
259  if( !poOverlayObject ) return;
260  CRouteContainer* __poRouteContainer = (CRouteContainer*)poOverlayObject;
261  bool __bVisible = __poRouteContainer->isVisible();
262  __poRouteContainer->toggleVisibility();
263  if( __bVisible != __poRouteContainer->isVisible() )
264  {
265  __poRouteContainer->setCheckState( CRouteOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
266  }
267  __poRouteContainer->useOverlay()->forceRedraw();
269 }
270 
272 {
273  if( !poOverlayObject ) return;
274  CDataPosition __oDataPositionLower, __oDataPositionUpper;
275  int __iCount = COverlayPoint::getPositionBox( poOverlayObject, &__oDataPositionLower, &__oDataPositionUpper );
276  if( __iCount > 1 ) QVCTRuntime::useChartTable()->setScaleArea( __oDataPositionLower, __oDataPositionUpper, 0.9 );
277  else if( __iCount == 1 ) QVCTRuntime::useChartTable()->setGeoPosition( __oDataPositionLower );
279 }
280 
282 {
283  if( !poOverlayObject ) return;
284  ((CRouteContainer*)poOverlayObject)->showEdit();
286 }
287 
289 {
290  if( !poOverlayObject ) return;
291  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::SAVE, tr("Save Route"), tr("GPX Files")+" (*.gpx);;"+tr("QVCT Files")+" (*.qvct)" );
292  if( __qsFilename.isEmpty() ) return;
293  QFileInfo __qFileInfo( __qsFilename );
294  if( __qFileInfo.suffix().isEmpty() ) __qsFilename += ".qvct";
295  QStringList __qsListExtensions; __qsListExtensions << "qvct" << "gpx";
296  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::SAVE, __qsFilename, &__qsListExtensions ) ) return;
298 }
299 
301 {
302  if( !poOverlayObject ) return;
303  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
304  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
305  CRouteOverlay* __poRouteOverlay = (CRouteOverlay*)poOverlayObject->useOverlay();
306  CRouteContainer* __poRouteContainer = (CRouteContainer*)poOverlayObject;
307  __pqMutexDataChange->lock();
308  __poRouteOverlay->removeChild( __poRouteContainer );
309  __pqMutexDataChange->unlock();
310  delete __poRouteContainer;
311  QTreeWidgetItem* __pqTreeWidgetItem = __poRouteOverlay->currentItem();
312  if( __pqTreeWidgetItem ) __poRouteOverlay->showDetail( __pqTreeWidgetItem );
313  __poRouteOverlay->forceRedraw();
316 }
317 
319 {
320  if( !poOverlayObject ) return;
321  QString __qsName = poOverlayObject->newChildName( tr("Waypoint"), 1, true );
322  CRoutePoint* __poRoutePoint = ((CRouteContainer*)poOverlayObject)->addPoint( __qsName );
323  if( !__poRoutePoint ) return;
324  QVCTRuntime::useRouteOverlay()->setCurrentItem( __poRoutePoint );
325  __poRoutePoint->showEdit();
327 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
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]
QString fileDialog(QVCT::EFileOperation _eFileOperation, const QString &_rqsTitle, const QString &_rqsFilter)
Displays a generic dialog to pick a file for the given operation (open/save)
[UI] Generic overlay object's detail view
COverlayObject * poOverlayObject
Overlay object being displayed.
virtual COverlay * useOverlay()=0
Returns this object's (base) overlay.
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.
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.
[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
virtual void resetContent()
Resets (clears) the content of the underlying widget.
void slotSave()
[UI:Slot] Slot to save this container to file
QPushButton * pqPushButtonEdit
[UI:Button] Edit
virtual void disableContent()
Disables the content (controls) of the underlying widget.
COverlayText * poTextContent
[UI:Label] Content (items summary)
virtual void enableContent()
Enables the content (controls) of the underlying widget.
void slotAddPoint()
[UI:Slot] Slot to add new (route) point
CRouteContainerDetailView(QWidget *_pqParent=0)
COverlayText * poTextDescription
[UI:Label] Description
void slotPositionCenter()
[UI:Slot] Slot to center chart (on container's items position)
COverlayUrl * poUrl
[UI:Label] URL
COverlayText * poTextLengthRL
[UI:Label] Length (rhumb-line)
void slotDelete()
[UI:Slot] Slot to delete (this container)
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
COverlayText * poTextComment
[UI:Label] Comment
QPushButton * pqPushButtonDelete
[UI:Button] Delete
COverlayText * poTextName
[UI:Label] Name
QPushButton * pqPushButtonAddPoint
[UI:Button] Add new waypoint
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonSave
[UI:Button] Save
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
virtual void refreshContent()
Refreshes the content of the underlying widget.
void slotEdit()
[UI:Slot] Slot to display edit view
COverlayText * poTextType
[UI:Label] Type
[UI] Route overlay container
virtual void toggleVisibility()
QString getUrl() const
Returns this route's URL.
double getLengthRL()
Returns the route's (rhumb-line) length.
QString getType() const
Returns this route's type.
QString getDescription() const
Returns this route's description.
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
QString getComment() const
Returns this route's comment.
[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.
void save(const QString &_rqsFilename, CRouteContainer *_poRouteContainer=0) const
Save this object's content (container) to the given file (all selected items if no container is given...
[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 QMutex * useMutexDataChange()
static CRouteOverlay * useRouteOverlay()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ SAVE
Definition: QVCT.hpp:42