Qt Virtual Chart Table (QVCT)
CTrackSubContainerDetailView.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"
34 
35 
36 //------------------------------------------------------------------------------
37 // CONSTRUCTORS / DESTRUCTOR
38 //------------------------------------------------------------------------------
39 
41  : COverlayObjectDetailView( _pqParent )
42 {
44 }
45 
47 {
48  // Create the buttons
49  // ... visible
50  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
51  pqPushButtonVisible->setMaximumSize( 36, 34 );
52  pqPushButtonVisible->setToolTip( tr("Toggle this segment's visibility") );
53  pqPushButtonVisible->setEnabled( false );
54  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
55  // ... center
56  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
57  pqPushButtonCenter->setMaximumSize( 36, 34 );
58  pqPushButtonCenter->setToolTip( tr("Center chart on this segment's mean position") );
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->setMaximumSize( 36, 34 );
64  pqPushButtonDelete->setToolTip( tr("Delete this segment") );
65  pqPushButtonDelete->setEnabled( false );
66  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
67 
68  // Create layout
69  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
70 
71  // Add header
72  QFont __qFontHeader;
73  __qFontHeader.setPixelSize( 16 );
74  __qFontHeader.setBold( true );
75  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
76  QLabel* __pqLabelIcon = new QLabel();
77  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/track.png" ) );
78  __pqLabelIcon->setToolTip( tr("Segment") );
79  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
80  poTextName = new COverlayText();
81  poTextName->setToolTip( tr("Name") );
82  poTextName->setFont( __qFontHeader );
83  poTextName->setWordWrap( true );
84  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
85  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
86 
87  // Add data
88  QFont __qFontData;
89  QTabWidget* __poTabWidget = new QTabWidget();
90  __poTabWidget->setTabPosition( QTabWidget::South );
91  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
92 
93  // ... summary
94  QWidget* __poWidgetSummary = new QWidget();
95  QVBoxLayout* __pqVBoxLayoutSummary = new QVBoxLayout();
96  __qFontData.setPixelSize( 20 );
98  poTextContent->setToolTip( tr("Points count") );
99  poTextContent->setFont( __qFontData );
100  poTextContent->setIndent( 10 );
101  poTextContent->setAlignment( Qt::AlignHCenter );
103  __pqVBoxLayoutSummary->addWidget( poTextContent, 0 );
105  poTextLengthRL->setToolTip( tr("Length (rhumb-lines along segment)") );
106  poTextLengthRL->setFont( __qFontData );
107  poTextLengthRL->setIndent( 10 );
108  poTextLengthRL->setAlignment( Qt::AlignHCenter );
110  __pqVBoxLayoutSummary->addWidget( poTextLengthRL, 0 );
112  poTextTimeElapsed->setToolTip( tr("Elapsed time") );
113  poTextTimeElapsed->setFont( __qFontData );
114  poTextTimeElapsed->setIndent( 10 );
115  poTextTimeElapsed->setAlignment( Qt::AlignHCenter );
117  __pqVBoxLayoutSummary->addWidget( poTextTimeElapsed, 1 );
118  __poWidgetSummary->setLayout( __pqVBoxLayoutSummary );
119  __poTabWidget->addTab( __poWidgetSummary, tr("Summary") );
120 
121  // ... [end]
122  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
123 
124  // Add separator
125  QFrame* __pqFrameSeparator = new QFrame();
126  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
127  __pqVBoxLayout->addWidget( __pqFrameSeparator );
128 
129  // Add buttons
130  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
131  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
132  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
133  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
134  __pqHBoxLayoutButtons->addWidget( new QLabel(), 1, Qt::AlignRight );
135  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
136 
137  // Set the layout
138  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
139 
140 }
141 
142 
143 //------------------------------------------------------------------------------
144 // METHODS: COverlayObjectDetailView (implement/override)
145 //------------------------------------------------------------------------------
146 
148 {
149  if( !poOverlayObject ) return;
150  CTrackSubContainer* __poTrackSubContainer = (CTrackSubContainer*)poOverlayObject;
151  poTextName->setText( __poTrackSubContainer->getName() );
152  poTextContent->setText( QString::number( __poTrackSubContainer->childCount() )+" "+tr("Point(s)") );
153  poTextLengthRL->setText( CUnitDistance::toString( __poTrackSubContainer->getLengthRL() ) );
154  poTextTimeElapsed->setText( CUnitTimeDelta::toString( __poTrackSubContainer->getTimeElapsed() ) );
155 }
156 
158 {
163 }
164 
166 {
167  if( poOverlayObject )
168  {
169  pqPushButtonVisible->setEnabled( true );
170  pqPushButtonCenter->setEnabled( true );
171  pqPushButtonDelete->setEnabled( true );
172  }
173 }
174 
176 {
177  pqPushButtonVisible->setEnabled( false );
178  pqPushButtonCenter->setEnabled( false );
179  pqPushButtonDelete->setEnabled( false );
180 }
181 
182 
183 //------------------------------------------------------------------------------
184 // METHODS
185 //------------------------------------------------------------------------------
186 
187 //
188 // SLOTS
189 //
190 
192 {
193  if( !poOverlayObject ) return;
194  CTrackSubContainer* __poTrackSubContainer = (CTrackSubContainer*)poOverlayObject;
195  bool __bVisible = __poTrackSubContainer->isVisible();
196  __poTrackSubContainer->toggleVisibility();
197  if( __bVisible != __poTrackSubContainer->isVisible() )
198  {
199  __poTrackSubContainer->setCheckState( CTrackOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
200  }
201  __poTrackSubContainer->useOverlay()->forceRedraw();
203 }
204 
206 {
207  if( !poOverlayObject ) return;
208  CDataPosition __oDataPositionLower, __oDataPositionUpper;
209  int __iCount = COverlayPoint::getPositionBox( poOverlayObject, &__oDataPositionLower, &__oDataPositionUpper );
210  if( __iCount > 1 ) QVCTRuntime::useChartTable()->setScaleArea( __oDataPositionLower, __oDataPositionUpper, 0.9 );
211  else if( __iCount == 1 ) QVCTRuntime::useChartTable()->setGeoPosition( __oDataPositionLower );
213 }
214 
216 {
217  if( !poOverlayObject ) return;
218  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
219  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
220  CTrackOverlay* __poTrackOverlay = (CTrackOverlay*)poOverlayObject->useOverlay();
221  CTrackContainer* __poTrackContainer = (CTrackContainer*)poOverlayObject->QTreeWidgetItem::parent();
222  CTrackSubContainer* __poTrackSubContainer = (CTrackSubContainer*)poOverlayObject;
223  __pqMutexDataChange->lock();
224  __poTrackContainer->removeChild( __poTrackSubContainer );
225  __pqMutexDataChange->unlock();
226  delete __poTrackSubContainer;
227  QTreeWidgetItem* __pqTreeWidgetItem = __poTrackOverlay->currentItem();
228  if( __pqTreeWidgetItem ) __poTrackOverlay->showDetail( __pqTreeWidgetItem );
229  __poTrackOverlay->forceRedraw();
232 }
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]
[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.
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.
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] Track overlay container
[UI] Track overlay container
@ VISIBLE
Track visibility status.
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
virtual void disableContent()
Disables the content (controls) of the underlying widget.
QPushButton * pqPushButtonDelete
[UI:Button] Delete
COverlayText * poTextLengthRL
[UI:Label] Length (rhumb-line)
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
COverlayText * poTextContent
[UI:Label] Content (items summary)
void slotPositionCenter()
[UI:Slot] Slot to center chart (on sub-container's items position)
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
COverlayText * poTextTimeElapsed
[UI:Label] Elapsed time
void slotDelete()
[UI:Slot] Slot to delete (this sub-container)
virtual void enableContent()
Enables the content (controls) of the underlying widget.
virtual void refreshContent()
Refreshes the content of the underlying widget.
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
void constructLayout()
Constructs the layout of the user-interface.
CTrackSubContainerDetailView(QWidget *_pqParent=0)
COverlayText * poTextName
[UI:Label] Name
virtual void resetContent()
Resets (clears) the content of the underlying widget.
[UI] Track overlay sub-container
double getLengthRL()
Returns the track's (rhumb-line) length.
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
double getTimeElapsed()
Returns the track's elapsed time.
virtual void toggleVisibility()
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 QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()