Qt Virtual Chart Table (QVCT)
CLandmarkContainer.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 <QDomElement> // QtXml module
21 #include <QFileInfo>
22 #include <QFileDialog>
23 #include <QPainter>
24 #include <QPointF>
25 #include <QTreeWidgetItem>
26 
27 // QVCT
28 #include "QVCTRuntime.hpp"
32 
33 
34 //------------------------------------------------------------------------------
35 // CONSTRUCTORS / DESTRUCTOR
36 //------------------------------------------------------------------------------
37 
38 CLandmarkContainer::CLandmarkContainer( const QString& _rqsName )
39  : COverlayContainer( COverlayObject::CONTAINER, _rqsName )
40 {
41  QTreeWidgetItem::setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled );
42  QTreeWidgetItem::setText( CLandmarkOverlay::NAME, qsName );
43  QTreeWidgetItem::setCheckState( CLandmarkOverlay::VISIBLE, Qt::Checked );
44 }
45 
47 {
48  QTreeWidgetItem* __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 0 );
49  while( __pqTreeWidgetItem )
50  {
51  delete (CLandmarkPoint*)__pqTreeWidgetItem;
52  __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 0 );
53  }
54 }
55 
56 
57 //------------------------------------------------------------------------------
58 // METHODS: COverlayObject (implement/override)
59 //------------------------------------------------------------------------------
60 
61 void CLandmarkContainer::unserialize( QDataStream& _rqDataStream )
62 {
63  COverlayObject::unserialize( _rqDataStream );
64  QTreeWidgetItem::setText( CLandmarkOverlay::NAME, qsName );
65 }
66 
67 void CLandmarkContainer::draw( const CChart* _poChart, QPainter* _pqPainter )
68 {
69  if( !bVisible ) return;
70  int __iCount = QTreeWidgetItem::childCount();
71  for( int __i = 0; __i < __iCount; __i++ )
72  ((CLandmarkPoint*)QTreeWidgetItem::child( __i ))->draw( _poChart, _pqPainter );
73 }
74 
76 {
82 }
83 
85 {
86  CLandmarkContainerEditView* __poLandmarkContainerEditView = new CLandmarkContainerEditView( this );
87  if( __poLandmarkContainerEditView->exec() == QDialog::Accepted ) showDetail();
88  delete __poLandmarkContainerEditView;
89 }
90 
91 
92 //------------------------------------------------------------------------------
93 // METHODS: COverlayContainer (implement/override)
94 //------------------------------------------------------------------------------
95 
96 COverlayPoint* CLandmarkContainer::matchScrPosition( const CChart* _poChart, const QPointF& _rqPointFScrPosition ) const
97 {
98  if( !bVisible ) return 0;
99  int __iCount = QTreeWidgetItem::childCount();
100  for( int __i = __iCount-1 ; __i >= 0; __i-- ) // we must go in the reverse order of CLandmarkContainer::draw() to pick the correct (overlapping) item
101  {
102  COverlayPoint* __poOverlayPoint = (COverlayPoint*)QTreeWidgetItem::child( __i );
103  if( __poOverlayPoint->matchScrPosition( _poChart, _rqPointFScrPosition ) )
104  return __poOverlayPoint;
105  }
106  return 0;
107 }
108 
109 
110 //------------------------------------------------------------------------------
111 // METHODS: COverlayVisibility (override)
112 //------------------------------------------------------------------------------
113 
115 {
116  // Toggle global visibility
117  COverlayVisibility::toggleVisibility( false, false );
118  // Set points visibility
119  int __iCount = QTreeWidgetItem::childCount();
120  for( int __i = 0; __i < __iCount; __i++ )
121  {
122  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)QTreeWidgetItem::child( __i );
123  __poLandmarkPoint->setVisibleName( bVisibleName );
124  __poLandmarkPoint->setVisiblePosition( bVisiblePosition );
125  }
126 }
127 
128 
129 //------------------------------------------------------------------------------
130 // METHODS
131 //------------------------------------------------------------------------------
132 
133 //
134 // OTHER
135 //
136 
137 CLandmarkPoint* CLandmarkContainer::addPoint( const QString& _rqsName, const CDataPosition& _roDataPosition )
138 {
139  CLandmarkPoint* __poLandmarkPoint = new CLandmarkPoint( _rqsName, _roDataPosition );
140  __poLandmarkPoint->setVisibility( this->getVisibility() | 1 );
141  QTreeWidgetItem::addChild( __poLandmarkPoint );
142  return __poLandmarkPoint;
143 }
144 
145 int CLandmarkContainer::parseQVCT( const QDomElement& _rqDomElement )
146 {
147  COverlayVisibility::setVisibility( _rqDomElement.attribute( "visibility", "3" ).toInt() );
148  QTreeWidgetItem::setCheckState( CLandmarkOverlay::VISIBLE, bVisible ? Qt::Checked : Qt::Unchecked );
149  int __iCount = 0;
150  for( QDomElement __qDomElement = _rqDomElement.firstChildElement( "Point" );
151  !__qDomElement.isNull();
152  __qDomElement = __qDomElement.nextSiblingElement( "Point" ) )
153  {
154  __iCount++;
155  QString __qsName = __qDomElement.attribute( "name" );
156  if( __qsName.isEmpty() ) __qsName = COverlayObject::newChildName( tr("Landmark"), 1, __iCount );
157  CLandmarkPoint* __poLandmarkPoint = new CLandmarkPoint( __qsName );
158  __poLandmarkPoint->parseQVCT( __qDomElement );
159  addChild( __poLandmarkPoint );
160  }
161  return __iCount;
162 }
163 
164 int CLandmarkContainer::parseGPX( const QDomElement& _rqDomElement )
165 {
166  // GPX format reference: see http://www.topografix.com/GPX/1/1/
167  int __iCount = 0;
168  for( QDomElement __qDomElement = _rqDomElement.firstChildElement( "wpt" );
169  !__qDomElement.isNull();
170  __qDomElement = __qDomElement.nextSiblingElement( "wpt" ) )
171  {
172  __iCount++;
173  QString __qsName = __qDomElement.firstChildElement( "name" ).text();
174  if( __qsName.isEmpty() ) __qsName = COverlayObject::newChildName( tr("Landmark"), 1, __iCount );
175  CLandmarkPoint* __poLandmarkPoint = new CLandmarkPoint( __qsName );
176  __poLandmarkPoint->parseGPX( __qDomElement );
177  addChild( __poLandmarkPoint );
178  }
179  return __iCount;
180 }
181 
182 void CLandmarkContainer::dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter, bool bOnlySelected ) const
183 {
184  // Data
185  _rqXmlStreamWriter.writeStartElement( "Landmarks" );
186  // ... name
187  if( !qsName.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "name", qsName );
188  // ... visibility
189  _rqXmlStreamWriter.writeAttribute( "visibility", QString::number( COverlayVisibility::getVisibility() ) );
190  // ... points
191  int __iCount = QTreeWidgetItem::childCount();
192  for( int __i = 0; __i < __iCount; __i++ )
193  {
194  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)QTreeWidgetItem::child( __i );
195  if( bOnlySelected && !__poLandmarkPoint->isMultiSelected() ) continue;
196  __poLandmarkPoint->dumpQVCT( _rqXmlStreamWriter );
197  }
198  // ... [end]
199  _rqXmlStreamWriter.writeEndElement(); // Landmarks
200 }
201 
202 void CLandmarkContainer::dumpGPX( QXmlStreamWriter & _rqXmlStreamWriter, bool bOnlySelected ) const
203 {
204  // GPX format reference: see http://www.topografix.com/GPX/1/1/
205 
206  // Data
207  // ... points
208  int __iCount = QTreeWidgetItem::childCount();
209  for( int __i = 0; __i < __iCount; __i++ )
210  {
211  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)QTreeWidgetItem::child( __i );
212  if( bOnlySelected && !__poLandmarkPoint->isMultiSelected() ) continue;
213  __poLandmarkPoint->dumpGPX( _rqXmlStreamWriter );
214  }
215 }
216 
218 {
219  int __iCount = 0;
220  for( int __i = QTreeWidgetItem::childCount()-1; __i >= 0; __i-- )
221  {
222  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)QTreeWidgetItem::child( __i );
223  if( __poLandmarkPoint->isMultiSelected() )
224  {
225  __iCount++;
226  QTreeWidgetItem::removeChild( __poLandmarkPoint );
227  delete __poLandmarkPoint;
228  }
229  }
230  return __iCount;
231 }
void setOverlayObjectSelected(COverlayObject *_poOverlayObject)
Sets the currently selected overlay object.
[UI] Chart (view)
Definition: CChart.hpp:44
(Geographical) Position data [long,lat,elev]
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Landmark container's edit view
CLandmarkContainer(const QString &_rqsName)
virtual void toggleVisibility()
int deleteSelection()
Deletes selected items within this container.
virtual COverlayPoint * matchScrPosition(const CChart *_poChart, const QPointF &_rqPointFScrPosition) const
Returns the overlay container's point that (first) matches the given screen position (0 if none is fo...
int parseQVCT(const QDomElement &_rqDomElement)
Retrieves this object's content from the given QVCT source (file)
virtual void draw(const CChart *_poChart, QPainter *_pqPainter)
Draws this object (itself or its content)
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter, bool bOnlySelected=false) const
Stores this object's content to the given QVCT destination (file)
virtual void showEdit()
Displays this object's edit widget/view.
void dumpGPX(QXmlStreamWriter &_rqXmlStreamWriter, bool bOnlySelected=false) const
Stores this object's content to the given GPX destination (file)
virtual void unserialize(QDataStream &_rqDataStream)
Unserializes (restore) this object's data from binary format.
virtual void showDetail()
Displays this object's details (in the appropriate widget/view)
int parseGPX(const QDomElement &_rqDomElement)
Retrieves this object's content from the given GPX source (file)
CLandmarkPoint * addPoint(const QString &_rqsName, const CDataPosition &_roDataPosition=CDataPosition::UNDEFINED)
Add a new landmark (item/point) to this container.
@ NAME
Landmark name.
@ VISIBLE
Landmark visibility status.
[UI] Landmark overlay point (item)
void dumpGPX(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores this object's content to the given GPX destination (file)
void parseGPX(const QDomElement &_rqDomElement)
Retrieves this object's content from the given GPX source (file)
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores this object's content to the given QVCT destination (file)
void parseQVCT(const QDomElement &_rqDomElement)
Retrieves this object's content from the given QVCT source (file)
Generic overlay container.
void switchView(EView eView)
Displays the requested container/item details (switching to the appropriate widget)
@ LANDMARK_CONTAINER
Landmark container.
bool isMultiSelected() const
Returns this item's selection status.
@ LANDMARK
Landmark 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.
virtual void unserialize(QDataStream &_rqDataStream)
Unserializes (restore) this object's data from binary format.
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.
QString qsName
Object name.
Generic overlay point.
virtual bool matchScrPosition(const CChart *_poChart, const QPointF &_rqPointFScrPosition) const
Returns whether this point matches the given screen position.
virtual void setVisiblePosition(bool _bVisiblePosition)
Sets the position's visibility status.
void setVisibility(int _iVisibilityCode)
Sets the global (coded) visibility status.
virtual void toggleVisibility(bool _bIncludeCourse, bool _bIncludeRouting)
Toggle the visibility status.
bool bVisible
Global (marker) visibility status.
bool bVisiblePosition
Position's visibility status.
bool bVisibleName
Name's (tag) visibility status.
int getVisibility() const
Returns the global (coded) visibility status.
virtual void setVisibleName(bool _bVisibleName)
Sets the name's (tag) visibility status.
static CLandmarkContainerDetailView * useLandmarkContainerDetailView()
static COverlayDetailView * useOverlayDetailView()
static COverlayListView * useOverlayListView()
static CChartTable * useChartTable()