Qt Virtual Chart Table (QVCT)
CVesselContainerDevice.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 // C/C++
20 #include <cmath>
21 
22 // QT
23 #include <QDateTime>
24 #include <QDomElement> // QtXml module
25 #include <QPainter>
26 #include <QPointF>
27 #include <QXmlStreamWriter>
28 
29 // QVCT
30 #include "QVCTRuntime.hpp"
31 #include "devices/CDevice.hpp"
35 
36 
37 //------------------------------------------------------------------------------
38 // CONSTRUCTORS / DESTRUCTOR
39 //------------------------------------------------------------------------------
40 
42  : COverlayItem( COverlayObject::SUBITEM1, _rqsName )
43  , poDevice( 0 )
44  , iTTL( 60 )
45 {
46  QTreeWidgetItem::setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
47  QTreeWidgetItem::setText( CVesselOverlay::NAME, getName() );
48 }
49 
50 
51 //------------------------------------------------------------------------------
52 // METHODS: COverlayObject (implement/override)
53 //------------------------------------------------------------------------------
54 
56 {
61 }
62 
64 {
65  CVesselContainerDeviceEditView* __poVesselContainerDeviceEditView = new CVesselContainerDeviceEditView( this );
66  if( __poVesselContainerDeviceEditView->exec() == QDialog::Accepted ) showDetail();
67  delete __poVesselContainerDeviceEditView;
68 }
69 
70 
71 //------------------------------------------------------------------------------
72 // METHODS
73 //------------------------------------------------------------------------------
74 
75 //
76 // SLOTS
77 //
78 
79 void CVesselContainerDevice::slotDestroyed( QObject* _pqObject )
80 {
81  if( !_pqObject || (QObject*)poDevice != _pqObject ) return;
83 }
84 
85 void CVesselContainerDevice::slotDataFix( const CDeviceDataFix& _roDeviceDataFix )
86 {
87  if( _roDeviceDataFix.getSourceName().isEmpty() ) return;
88  CVesselContainer* __poVesselContainer = (CVesselContainer*)QTreeWidgetItem::parent();
89  __poVesselContainer->addPointDynamic( _roDeviceDataFix, COverlayObject::getName() );
90 }
91 
92 //
93 // GETTERS
94 //
95 
97 {
98  return( poDevice && ((CVesselContainer*)QTreeWidgetItem::parent())->isDeviceConnected() );
99 };
100 
101 //
102 // OTHER
103 //
104 
106 {
107  if( !poDevice )
108  {
109  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
110  CDevice* __poDevice = __poDeviceOverlay->pickDevice( COverlayObject::getName() );
111  if( !__poDevice ) return false;
112  poDevice = __poDevice;
113  ((CVesselContainer*)QTreeWidgetItem::parent())->connectDevice();
114  QObject::connect( poDevice, SIGNAL( destroyed(QObject*) ), this, SLOT( slotDestroyed(QObject*) ) );
115  QObject::connect( poDevice, SIGNAL( signalDataFix(const CDeviceDataFix&) ), this, SLOT( slotDataFix(const CDeviceDataFix&) ) );
116  }
117  return true;
118 }
119 
121 {
122  if( !poDevice ) return;
123  QObject::disconnect( poDevice, 0, this, 0 );
124  ((CVesselContainer*)QTreeWidgetItem::parent())->disconnectDevice();
125  poDevice = 0;
126 }
127 
128 void CVesselContainerDevice::parseQVCT( const QDomElement& _rqDomElement )
129 {
130  iTTL = _rqDomElement.attribute( "ttl", "60" ).toInt();
131  if( iTTL < 5 ) iTTL = 5;
132 }
133 
134 void CVesselContainerDevice::dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter ) const
135 {
136 
137  // Data
138  _rqXmlStreamWriter.writeStartElement( "Device" );
139  // ... name
140  if( !getName().isEmpty() ) _rqXmlStreamWriter.writeAttribute( "name", getName() );
141  // ... (vessels) time-to-live
142  _rqXmlStreamWriter.writeAttribute( "ttl", QString::number( iTTL ) );
143  // ... [end]
144  _rqXmlStreamWriter.writeEndElement(); // Device
145 }
Fix data [source,time,position,course,DOPs,...].
QString getSourceName() const
Returns the source name.
[UI] Device overlay container
CDevice * pickDevice(const QString &_rqsName)
Returns the device matching the given name (0 if none is found)
Generic navigation device (GPS, speedometer, compass, etc.)
Definition: CDevice.hpp:43
void switchView(EView eView)
Displays the requested container/item details (switching to the appropriate widget)
@ VESSEL_CONTAINER_DEVICE
Vessel container's device.
Generic overlay item.
@ VESSEL
Vessel overlay.
void switchView(EView eView)
Displays the requested overlay (switching to the appropriate tab)
void setOverlayObject(COverlayObject *_poOverlayObject)
Sets the overlay object to be displayed (and refreshes the underlying widget)
Generic overlay object.
QString getName() const
Returns this object's name.
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Vessel container's device edit view
CDevice * poDevice
Corresponding device's pointer.
int iTTL
(Vessels) Time-to-live (seconds)
void slotDestroyed(QObject *_pqObject)
Slot to handle object destruction.
void slotDataFix(const CDeviceDataFix &_roDeviceDataFix)
Slot to handle fix data (sent by device)
virtual void showDetail()
Displays this object's details (in the appropriate widget/view)
bool connectDevice()
Connects to the actual device.
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores this object's content to the given QVCT destination (file)
bool isDeviceConnected() const
Returns whether the actual device is connected.
virtual void showEdit()
Displays this object's edit widget/view.
CVesselContainerDevice(const QString &_rqsName)
void disconnectDevice()
Dicconnects from the actual device.
void parseQVCT(const QDomElement &_rqDomElement)
Retrieves this object's content from the given QVCT source (file)
[UI] Vessel overlay container / flotilla
void addPointDynamic(const CDeviceDataFix &_roDeviceDataFix, const QString &_rqsDeviceName)
Add a new dynamic vessel (item/point) with the given data fix to this container.
@ NAME
Vessel name.
static COverlayDetailView * useOverlayDetailView()
static CVesselContainerDeviceDetailView * useVesselContainerDeviceDetailView()
static CDeviceOverlay * useDeviceOverlay()
static COverlayListView * useOverlayListView()