Qt Virtual Chart Table (QVCT)
CChartTable.hpp
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 #ifndef QVCT_CCHARTTABLE_HPP
19 #define QVCT_CCHARTTABLE_HPP
20 
21 // QT
22 #include <QDomElement> // QtXml module
23 #include <QGestureEvent>
24 #include <QKeyEvent>
25 #include <QMouseEvent>
26 #include <QWheelEvent>
27 #include <QTabWidget>
28 #include <QTimer>
29 #include <QWidget>
30 #include <QXmlStreamWriter>
31 
32 // QVCT
33 #include "data/CDataPosition.hpp"
36 class CChart;
37 class CChartControl;
38 
39 
41 
54 class CChartTable: public QTabWidget
55 {
56  Q_OBJECT
57  friend class CChartControl;
58 
59  //------------------------------------------------------------------------------
60  // FIELDS
61  //------------------------------------------------------------------------------
62 
63 private:
66 
68 
70 
72 
74 
76  int iDpi;
77 
79  // (used when switching tabs and synchronizing the chart controls)
81 
83  QPointF qPointFMouse;
87  bool bMouseDrag;
88 
93 
95 
98 
101 
103 
105 
107 
109 
111 
113 
115 
116 
117  //------------------------------------------------------------------------------
118  // CONSTRUCTORS / DESTRUCTOR
119  //------------------------------------------------------------------------------
120 
121 public:
122  CChartTable( QWidget* _pqParent = 0 );
123  virtual ~CChartTable() {};
124 
125 private:
127  void constructLayout();
128 
129 
130  //------------------------------------------------------------------------------
131  // METHODS: QWidget (override)
132  //------------------------------------------------------------------------------
133 
134 public:
135  virtual QSize sizeHint() const;
136 
137 
138  //------------------------------------------------------------------------------
139  // METHODS: QTabWidget (override)
140  //------------------------------------------------------------------------------
141 
142 private:
143  virtual void clear();
144  virtual bool eventFilter( QObject* _pqObject, QEvent* _pqEvent );
145 
146 
147  //------------------------------------------------------------------------------
148  // METHODS
149  //------------------------------------------------------------------------------
150 
151  // SLOTS
152 private slots:
154  void slotLoad();
156  void slotSave();
158  void slotLoadChart();
160  void slotPrintChart();
162  void slotAddElevation();
164 
165  void slotChangeTab( int _iTabIndex );
167  void slotCloseTab();
169 
170  void slotCloseTab( int _iTabIndex );
172  void slotScaleActual();
174  void slotScaleFit();
176  void slotPointerTarget( bool _bEnable );
178  void slotPointerPath( bool _bEnable );
180  void slotPointerPathSingle( bool _bEnable );
181 
183  void slotVesselPointDestroyed( QObject* _pqObject );
184 
185  // HANDLERS
186 private:
188 
189  bool handlerKeyEvent( QKeyEvent* _pqKeyEvent );
191 
192  bool handlerMouseEvent( QMouseEvent* _pqMouseEvent );
194 
195  bool handlerWheelEvent( QWheelEvent* _pqWheelEvent );
197 
198  bool handlerGestureEvent( QGestureEvent* _pqGestureEvent );
199 
200  // SETTERS
201 public:
205  void setGeoPosition( const CDataPosition& _roGeoPosition, bool _bSkipCurrent = false );
207 
210  void showGeoPosition( const CDataPosition& _roGeoPosition );
212  void stepScrPosition( bool _bHorizontal, bool _bIncrease, bool _bBigStep = true );
214  void dragScrPosition( const QPointF& _rqPointFScrPositionOffset );
216  void setPositionHome();
218  void lockPosition( bool _bLock );
220  void setScale( double _fdScale, bool _bSkipCurrent = false, bool _bUpdateControl = true );
222  void stepScale( bool _bIncrease, bool _bBigStep = true );
224  void setScaleActual();
226  void setScaleFit();
228  void setScaleArea( const CDataPosition& _roGeoPosition1, const CDataPosition& _roGeoPosition2, double _fdScaleCorrection = 1.0 );
230  void lockScale( bool _bLock );
231 
232 private:
234  void setZoom( double _fdZoom, bool _bSkipCurrent = false, bool _bUpdateControl = true );
235 
236 public:
238  void enablePointerTarget( bool _bEnable );
240 
242  bool setPointerTarget( const CDataPosition& _roGeoPosition );
244  void enablePointerPath( bool _bEnable );
246  void enablePointerPathSingle( bool _bEnable );
248 
250  bool extendPointerPath( const CDataPosition& _roGeoPosition );
252  void setOverlayObjectSelected( COverlayObject* _poOverlayObject );
254  void setOverlayPointMove( COverlayPoint* _poOverlayPoint );
256  void setVesselPointSynchronize( CVesselPoint* _poVesselPoint );
259 
260  // GETTERS
261 public:
263  bool isProjectModified() const { return bProjectModified; };
267  double getScale() const { return fdScaleReference; };
274 
275  // USERS
276 public:
278  CChart* useChart() { return (CChart*)currentWidget(); };
279 
280  // OTHER
281 public:
283 
284  void synchronizeVesselPoint();
285 
286 public:
288  void load( const QString& _rqsFilename );
290  void save( const QString& _rqsFilename ) const;
292  int parseQVCT( const QDomElement& _rqDomElement );
294  void dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter ) const;
295 
296 public:
298  CChart* loadChart( const QString& _rqsFilename );
300 
301  void updateChart();
303  bool addElevation( const QString& _rqsFilename );
305  bool hasElevation();
307  void showElevation( bool _bShow );
308 
309 private:
311  double toZoom( double _fdScale, const CChart* _poChart = 0 );
313  double toScale( double _fdZoom, const CChart* _poChart = 0 );
314 
315 };
316 
317 #endif // QVCT_CCHARTTABLE_HPP
[UI] Chart control user-interface
[UI] Virtual "chart table" (view)
Definition: CChartTable.hpp:55
double fdGestureZoomReference
Reference zoom for pinch gesture.
Definition: CChartTable.hpp:92
int parseQVCT(const QDomElement &_rqDomElement)
Retrieves this object's content from the given QVCT source (file)
double fdGestureTimeLast
Keep track of when a gesture event last occured.
Definition: CChartTable.hpp:90
virtual bool eventFilter(QObject *_pqObject, QEvent *_pqEvent)
void slotLoad()
[UI:Slot] Slot to load a full project's content from file
int iDpi
Resolution, in Dots-per-Inch (DPI)
Definition: CChartTable.hpp:76
void slotSave()
[UI:Slot] Slot to save the full project's content to file
void setOverlayPointMove(COverlayPoint *_poOverlayPoint)
Sets the overlay point to be moved (and lock all other actions while it is ongoing)
double toZoom(double _fdScale, const CChart *_poChart=0)
Converts the given scale factor to zoom factor (for the current position and - by default - the curre...
bool extendPointerPath(const CDataPosition &_roGeoPosition)
Extends the pointer path; returns true if is was actually extended, false otherwise.
void enablePointerTarget(bool _bEnable)
Enables/disables pointer target.
double fdScaleReference
Reference scale factor (shared by all "locked" maps)
Definition: CChartTable.hpp:73
QPointF qPointFMouse
Mouse position (saved dragging purposes)
Definition: CChartTable.hpp:83
COverlayObject * poOverlayObjectSelected
Currently selected overlay object.
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
bool handlerKeyEvent(QKeyEvent *_pqKeyEvent)
Key events handler.
void showElevation(bool _bShow)
Display elevation data (instead of raster data) of the currently selected chart (if any)
void setPositionHome()
Sets the reference chart (geographical) position to the current chart's center position.
void slotVesselPointDestroyed(QObject *_pqObject)
[APP:Slot] Slot to handle vessel point destruction
void setVesselPointSynchronize(CVesselPoint *_poVesselPoint)
Sets the vessel point used to synchronize the chart reference (geographical) position.
bool bProjectModified
Flag to track project changes (and trigger user confirmation before discarding unsaved data)
Definition: CChartTable.hpp:65
double toScale(double _fdZoom, const CChart *_poChart=0)
Converts the given zoom factor to scale factor (for the current position and - by default - the curre...
bool handlerMouseEvent(QMouseEvent *_pqMouseEvent)
Mouse events handler.
void slotChangeTab(int _iTabIndex)
[UI:Slot] Slot to handle active tab change
bool isProjectModified() const
Returns whether the project has been modified (data have changed since last saved)
CVesselPoint * getVesselPointSynchronize() const
Returns the vessel defined to synchronize the chart reference (geographical) position.
void setZoom(double _fdZoom, bool _bSkipCurrent=false, bool _bUpdateControl=true)
Sets the reference zoom factor.
void lockScale(bool _bLock)
Sets the scale lock/unlock status.
void constructLayout()
Constructs the layout of the user-interface.
Definition: CChartTable.cpp:81
CChartTable(QWidget *_pqParent=0)
Definition: CChartTable.cpp:57
CVesselPoint * poVesselPointSynchronize
Vessel point to synchronize to.
void setScale(double _fdScale, bool _bSkipCurrent=false, bool _bUpdateControl=true)
Sets the reference scale factor.
void slotPointerTarget(bool _bEnable)
[UI:Slot] Slot to enable/disable pointer target
bool bIgnoreUpdate
Flag that disables position, scale and pointer updates.
Definition: CChartTable.hpp:80
bool bMousePressed
Mouse-pressed status.
Definition: CChartTable.hpp:85
void lockPosition(bool _bLock)
Sets the position lock/unlock status.
void setScaleFit()
Sets the reference scale factor to match the current chart's "fit" scale (entire chart visible)
void synchronizeVesselPoint()
Synchronize the reference chart (geographical) position with the designed vessel.
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...
virtual QSize sizeHint() const
Definition: CChartTable.cpp:97
void slotLoadChart()
[UI:Slot] Slot to load a new chart
void stepScale(bool _bIncrease, bool _bBigStep=true)
Discretely increases/decreases the reference scale factor.
CDataPosition oGeoPositionReference
Reference chart (geographical) position (shared by all "locked" maps)
Definition: CChartTable.hpp:69
bool bMouseDrag
Mouse-drag status.
Definition: CChartTable.hpp:87
COverlayPoint * poOverlayPointMove
Overlay point being moved (non-0 only when a move is being performed)
void stepScrPosition(bool _bHorizontal, bool _bIncrease, bool _bBigStep=true)
Discretely move the reference chart (geographical) position.
bool bPointerPathSingle
Pointer single-segment path status.
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores this object's content to the given QVCT destination (file)
bool bPointerPath
Pointer path status.
Definition: CChartTable.hpp:99
COverlayObject * getOverlayObjectSelected() const
Returns the currently selected overlay object.
bool handlerGestureEvent(QGestureEvent *_pqGestureEvent)
Gesture events handler.
CChart * useChart()
Returns the currently displayed chart.
virtual ~CChartTable()
void updateChart()
Update the (current) chart content (on screen)
bool setPointerTarget(const CDataPosition &_roGeoPosition)
Sets the pointer target's position; returns true if is was actually set, false otherwise.
void slotCloseTab()
[UI:Slot] Slot to close the current tab
void slotScaleFit()
[UI:Slot] Slot to trigger scaling to "fit" scale
void showGeoPosition(const CDataPosition &_roGeoPosition)
Shows the given (geographical) position on chart.
void slotPointerPathSingle(bool _bEnable)
[UI:Slot] Slot to enable/disable single measurement (pointer path)
virtual void clear()
CDataPosition getGeoPosition() const
Returns the reference chart (geographical) position.
double getScale() const
Returns the reference scale factor.
void slotPointerPath(bool _bEnable)
[UI:Slot] Slot to enable/disable ongoing measurements (pointer path)
void load(const QString &_rqsFilename)
Load a full project's content from the given file.
void slotAddElevation()
[UI:Slot] Slot to add elevation data to the currently displayed chart
void enablePointerPathSingle(bool _bEnable)
Enables/disables single measurement (pointer path)
void slotScaleActual()
[UI:Slot] Slot to trigger scaling to "actual" scale
void dragScrPosition(const QPointF &_rqPointFScrPositionOffset)
Moves the reference chart (geographical) position according to the given screen offset.
bool handlerWheelEvent(QWheelEvent *_pqWheelEvent)
Wheel events handler.
bool bPointerTarget
Pointer target status.
Definition: CChartTable.hpp:96
CChart * loadChart(const QString &_rqsFilename)
Load the given chart from file.
void setScaleActual()
Sets the reference scale factor to match the current chart's "actual" scale (1:1 zoom)
void setGeoPosition(const CDataPosition &_roGeoPosition, bool _bSkipCurrent=false)
Sets the reference chart (geographical) position.
void slotPrintChart()
[UI:Slot] Slot to print the currently displayed chart
bool hasElevation()
Returns whether the currently selected chart has been associated elevation data (if any)
void setOverlayObjectSelected(COverlayObject *_poOverlayObject)
Sets the currently selected overlay object.
bool addElevation(const QString &_rqsFilename)
Add elevation data to the currently displayed chart (if any)
COverlayPoint * getOverlayPointMove() const
Returns the overlay point currently being moved (0 if none)
void enablePointerPath(bool _bEnable)
Enables/disables ongoing measurements (pointer path)
void save(const QString &_rqsFilename) const
Save the full project's content to the given file.
void resetVesselPointSynchronize()
Resets (clears) the vessel point used to synchronize the chart reference (geographical) position.
[UI] Chart (view)
Definition: CChart.hpp:44
(Geographical) Position data [long,lat,elev]
Generic overlay object.
Generic overlay point.
[UI] Vessel overlay point (item) / vessel