Qt Virtual Chart Table (QVCT)
CVesselContainerDetailView.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 <QTabWidget>
27 #include <QVBoxLayout>
28 #include <QWidget>
29 
30 // QVCT
31 #include "QVCTRuntime.hpp"
32 #include "data/CDataPosition.hpp"
34 #include "overlays/COverlayUrl.hpp"
40 
41 
42 //------------------------------------------------------------------------------
43 // CONSTRUCTORS / DESTRUCTOR
44 //------------------------------------------------------------------------------
45 
47  : COverlayObjectDetailView( _pqParent )
48 {
50 }
51 
53 {
54  // Create the buttons
55  // ... visible
56  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
57  pqPushButtonVisible->setMaximumSize( 36, 34 );
58  pqPushButtonVisible->setToolTip( tr("Toggle this flotilla's visibility") );
59  pqPushButtonVisible->setEnabled( false );
60  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
61  // ... center
62  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
63  pqPushButtonCenter->setMaximumSize( 36, 34 );
64  pqPushButtonCenter->setToolTip( tr("Center chart on this flotilla's mean position") );
65  pqPushButtonCenter->setEnabled( false );
66  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
67  // ... edit
68  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
69  pqPushButtonEdit->setMaximumSize( 36, 34 );
70  pqPushButtonEdit->setToolTip( tr("Edit this flotilla") );
71  pqPushButtonEdit->setEnabled( false );
72  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
73  // ... save
74  pqPushButtonSave = new QPushButton( QIcon( ":icons/32x32/save.png" ), "" );
75  pqPushButtonSave->setMaximumSize( 36, 34 );
76  pqPushButtonSave->setToolTip( tr("Save this flotilla to disk") );
77  pqPushButtonSave->setEnabled( false );
78  QWidget::connect( pqPushButtonSave, SIGNAL( clicked() ), this, SLOT( slotSave() ) );
79  // ... delete
80  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
81  pqPushButtonDelete->setMaximumSize( 36, 34 );
82  pqPushButtonDelete->setToolTip( tr("Delete this flotilla") );
83  pqPushButtonDelete->setEnabled( false );
84  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
85  // ... set device
86  pqPushButtonSetDevice = new QPushButton( QIcon( ":icons/32x32/device_add.png" ), "" );
87  pqPushButtonSetDevice->setMaximumSize( 36, 34 );
88  pqPushButtonSetDevice->setToolTip( tr("Set a device for this (dynamic) flotilla") );
89  pqPushButtonSetDevice->setEnabled( false );
90  QWidget::connect( pqPushButtonSetDevice, SIGNAL( clicked() ), this, SLOT( slotSetDevice() ) );
91  // ... add point
92  pqPushButtonAddPoint = new QPushButton( QIcon( ":icons/32x32/vessel_add.png" ), "" );
93  pqPushButtonAddPoint->setMaximumSize( 36, 34 );
94  pqPushButtonAddPoint->setToolTip( tr("Add a new vessel to this flotilla") );
95  pqPushButtonAddPoint->setEnabled( false );
96  QWidget::connect( pqPushButtonAddPoint, SIGNAL( clicked() ), this, SLOT( slotAddPoint() ) );
97 
98  // Create layout
99  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
100 
101  // Add header
102  QFont __qFontHeader;
103  __qFontHeader.setPixelSize( 16 );
104  __qFontHeader.setBold( true );
105  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
106  QLabel* __pqLabelIcon = new QLabel();
107  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/vessel.png" ) );
108  __pqLabelIcon->setToolTip( tr("Flotilla") );
109  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
110  poTextName = new COverlayText();
111  poTextName->setToolTip( tr("Name") );
112  poTextName->setFont( __qFontHeader );
113  poTextName->setWordWrap( true );
114  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
115  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
116 
117  // Add data
118  QFont __qFontData;
119  QTabWidget* __poTabWidget = new QTabWidget();
120  __poTabWidget->setTabPosition( QTabWidget::South );
121  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
122 
123  // ... summary
124  QWidget* __poWidgetSummary = new QWidget();
125  QVBoxLayout* __pqVBoxLayoutSummary = new QVBoxLayout();
126  __qFontData.setPixelSize( 20 );
127  poTextContent = new COverlayText();
128  poTextContent->setToolTip( tr("Vessels count") );
129  poTextContent->setFont( __qFontData );
130  poTextContent->setIndent( 10 );
131  poTextContent->setAlignment( Qt::AlignHCenter );
133  __pqVBoxLayoutSummary->addWidget( poTextContent, 1 );
134  __poWidgetSummary->setLayout( __pqVBoxLayoutSummary );
135  __poTabWidget->addTab( __poWidgetSummary, tr("Summary") );
136 
137  // ... info
138  QScrollArea* __poScrollAreaInfo = new QScrollArea();
139  __poScrollAreaInfo->setStyleSheet( ".QScrollArea, .QWidget { BACKGROUND-COLOR: rgba(0, 0, 0, 0); BORDER: none; }" );
140  __poScrollAreaInfo->setWidgetResizable( true );
141  QWidget* __poWidgetInfo = new QWidget();
142  QVBoxLayout* __pqVBoxLayoutInfo = new QVBoxLayout();
143  __qFontData.setPixelSize( 12 );
144  __qFontData.setBold( true );
145  poTextType = new COverlayText();
146  poTextType->setToolTip( tr("Type") );
147  poTextType->setFont( __qFontData );
148  poTextType->setIndent( 10 );
150  __pqVBoxLayoutInfo->addWidget( poTextType );
151  __qFontData.setBold( false );
153  poTextDescription->setToolTip( tr("Description") );
154  poTextDescription->setFont( __qFontData );
155  poTextDescription->setIndent( 10 );
157  __pqVBoxLayoutInfo->addWidget( poTextDescription );
158  __qFontData.setPixelSize( 10 );
159  poTextComment = new COverlayText();
160  poTextComment->setToolTip( tr("Comment") );
161  poTextComment->setFont( __qFontData );
162  poTextComment->setIndent( 10 );
164  __pqVBoxLayoutInfo->addWidget( poTextComment );
165  poUrl = new COverlayUrl();
166  poUrl->setToolTip( tr("URL") );
167  poUrl->setFont( __qFontData );
168  poUrl->setIndent( 10 );
169  poUrl->resetText();
170  __pqVBoxLayoutInfo->addWidget( poUrl, 1 );
171  __poWidgetInfo->setLayout( __pqVBoxLayoutInfo );
172  __poScrollAreaInfo->setWidget( __poWidgetInfo );
173  __poTabWidget->addTab( __poScrollAreaInfo, tr("Info") );
174 
175  // ... [end]
176  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
177 
178  // Add separator
179  QFrame* __pqFrameSeparator = new QFrame();
180  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
181  __pqVBoxLayout->addWidget( __pqFrameSeparator );
182 
183  // Add buttons
184  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
185  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
186  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
187  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignHCenter );
188  __pqHBoxLayoutButtons->addWidget( pqPushButtonSave, 0, Qt::AlignHCenter );
189  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
190  __pqHBoxLayoutButtons->addWidget( pqPushButtonSetDevice, 1, Qt::AlignRight );
191  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddPoint, 0, Qt::AlignRight );
192  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
193 
194  // Set the layout
195  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
196 
197 }
198 
199 
200 //------------------------------------------------------------------------------
201 // METHODS: COverlayObjectDetailView (implement/override)
202 //------------------------------------------------------------------------------
203 
205 {
206  if( !poOverlayObject ) return;
207  CVesselContainer* __poVesselContainer = (CVesselContainer*)poOverlayObject;
208  poTextName->setText( __poVesselContainer->getName() );
209  poTextContent->setText( QString::number( __poVesselContainer->childCount() - ( __poVesselContainer->isDynamic() ? 1 : 0 ) )+" "+tr("Vessel(s)") );
210  poTextType->setText( __poVesselContainer->getType() );
211  poTextDescription->setText( __poVesselContainer->getDescription() );
212  poTextComment->setText( __poVesselContainer->getComment() );
213  poUrl->setText( __poVesselContainer->getUrl() );
214 
215  // ... buttons
216  bool __bDynamic = __poVesselContainer->isDynamic();
217  pqPushButtonSetDevice->setEnabled( !__bDynamic );
218  pqPushButtonAddPoint->setEnabled( !__bDynamic );
219 }
220 
222 {
228  poUrl->resetText();
229 }
230 
232 {
233  if( poOverlayObject )
234  {
235  pqPushButtonVisible->setEnabled( true );
236  pqPushButtonCenter->setEnabled( true );
237  pqPushButtonEdit->setEnabled( true );
238  pqPushButtonSave->setEnabled( true );
239  pqPushButtonDelete->setEnabled( true );
240  }
241 }
242 
244 {
245  pqPushButtonVisible->setEnabled( false );
246  pqPushButtonCenter->setEnabled( false );
247  pqPushButtonEdit->setEnabled( false );
248  pqPushButtonSave->setEnabled( false );
249  pqPushButtonDelete->setEnabled( false );
250  pqPushButtonSetDevice->setEnabled( false );
251  pqPushButtonAddPoint->setEnabled( false );
252 }
253 
254 
255 //------------------------------------------------------------------------------
256 // METHODS
257 //------------------------------------------------------------------------------
258 
259 //
260 // SLOTS
261 //
262 
264 {
265  if( !poOverlayObject ) return;
266  CVesselContainer* __poVesselContainer = (CVesselContainer*)poOverlayObject;
267  bool __bVisible = __poVesselContainer->isVisible();
268  __poVesselContainer->toggleVisibility();
269  if( __bVisible != __poVesselContainer->isVisible() )
270  {
271  __poVesselContainer->setCheckState( CVesselOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
272  }
273  __poVesselContainer->useOverlay()->forceRedraw();
275 }
276 
278 {
279  if( !poOverlayObject ) return;
280  CDataPosition __oDataPositionLower, __oDataPositionUpper;
281  int __iCount = COverlayPoint::getPositionBox( poOverlayObject, &__oDataPositionLower, &__oDataPositionUpper );
282  if( __iCount > 1 ) QVCTRuntime::useChartTable()->setScaleArea( __oDataPositionLower, __oDataPositionUpper, 0.9 );
283  else if( __iCount == 1 ) QVCTRuntime::useChartTable()->setGeoPosition( __oDataPositionLower );
285 }
286 
288 {
289  if( !poOverlayObject ) return;
290  ((CVesselContainer*)poOverlayObject)->showEdit();
292 }
293 
295 {
296  if( !poOverlayObject ) return;
297  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::SAVE, tr("Save Vessel"), tr("QVCT Files")+" (*.qvct)" );
298  if( __qsFilename.isEmpty() ) return;
299  QFileInfo __qFileInfo( __qsFilename );
300  if( __qFileInfo.suffix().isEmpty() ) __qsFilename += ".qvct";
301  QStringList __qsListExtensions; __qsListExtensions << "qvct";
302  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::SAVE, __qsFilename, &__qsListExtensions ) ) return;
304 }
305 
307 {
308  if( !poOverlayObject ) return;
309  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
310  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
311  CVesselOverlay* __poVesselOverlay = (CVesselOverlay*)poOverlayObject->useOverlay();
312  CVesselContainer* __poVesselContainer = (CVesselContainer*)poOverlayObject;
313  __pqMutexDataChange->lock();
314  __poVesselOverlay->removeChild( __poVesselContainer );
315  __pqMutexDataChange->unlock();
316  delete __poVesselContainer;
317  QTreeWidgetItem* __pqTreeWidgetItem = __poVesselOverlay->currentItem();
318  if( __pqTreeWidgetItem ) __poVesselOverlay->showDetail( __pqTreeWidgetItem );
319  __poVesselOverlay->forceRedraw();
322 }
323 
325 {
326  if( !poOverlayObject ) return;
327  if( !QVCTRuntime::useMainWindow()->deleteConfirm( tr("Defined vessel(s)") ) ) return;
328  CVesselContainerDevice* __poVesselContainerDevice = 0;
329  CVesselContainerDeviceCreateView* __poVesselContainerDeviceCreateView = new CVesselContainerDeviceCreateView( &__poVesselContainerDevice );
330  __poVesselContainerDeviceCreateView->exec();
331  if( __poVesselContainerDevice )
332  {
333  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
334  __pqMutexDataChange->lock();
335  ((CVesselContainer*)poOverlayObject)->setDevice( __poVesselContainerDevice );
336  __pqMutexDataChange->unlock();
337  QVCTRuntime::useVesselOverlay()->setCurrentItem( __poVesselContainerDevice );
338  __poVesselContainerDevice->showEdit();
342  }
343  delete __poVesselContainerDeviceCreateView;
344 }
345 
347 {
348  if( !poOverlayObject ) return;
349  QString __qsName = poOverlayObject->newChildName( tr("Vessel"), 1, true );
350  CVesselPoint* __poVesselPoint = ((CVesselContainer*)poOverlayObject)->addPoint( __qsName );
351  if( !__poVesselPoint ) return;
352  QVCTRuntime::useVesselOverlay()->setCurrentItem( __poVesselPoint );
353  __poVesselPoint->showEdit();
355 }
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
QPushButton * pqPushButtonSetDevice
[UI:Button] Set device (dynamic flotilla)
virtual void disableContent()
Disables the content (controls) of the underlying widget.
void slotPositionCenter()
[UI:Slot] Slot to center chart (on container's items position)
COverlayText * poTextComment
[UI:Label] Comment
virtual void resetContent()
Resets (clears) the content of the underlying widget.
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
virtual void refreshContent()
Refreshes the content of the underlying widget.
COverlayText * poTextType
[UI:Label] Type
void slotSave()
[UI:Slot] Slot to save this container to file
void slotAddPoint()
[UI:Slot] Slot to add new (vessel) point
QPushButton * pqPushButtonAddPoint
[UI:Button] Add new vessel
void slotDelete()
[UI:Slot] Slot to delete (this container)
QPushButton * pqPushButtonSave
[UI:Button] Save
virtual void enableContent()
Enables the content (controls) of the underlying widget.
void constructLayout()
Constructs the layout of the user-interface.
CVesselContainerDetailView(QWidget *_pqParent=0)
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotSetDevice()
[UI:Slot] Slot to set device (dynamic flotilla)
COverlayText * poTextContent
[UI:Label] Content (items summary)
QPushButton * pqPushButtonEdit
[UI:Button] Edit
COverlayText * poTextName
[UI:Label] Name
COverlayText * poTextDescription
[UI:Label] Description
COverlayUrl * poUrl
[UI:Label] URL
void slotEdit()
[UI:Slot] Slot to display edit view
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
[UI] Generic overlay object's pick (select) view
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Vessel overlay container / flotilla
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
bool isDynamic()
Returns this flotilla's dynamic status.
QString getUrl() const
Returns this flotilla's URL.
QString getComment() const
Returns this flotilla's comment.
QString getType() const
Returns this flotilla's type.
virtual void toggleVisibility()
QString getDescription() const
Returns this flotilla's description.
[UI] Vessel overlay container
void save(const QString &_rqsFilename, CVesselContainer *_poVesselContainer=0) const
Save this object's content (container) to the given file (all selected items if no container is given...
@ VISIBLE
Vessel visibility status.
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
[UI] Vessel overlay point (item) / vessel
virtual void showEdit()
Displays this object's edit widget/view.
static CVesselOverlay * useVesselOverlay()
static QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ SAVE
Definition: QVCT.hpp:42