23 #include <QDomElement>
30 #include <QXmlStreamWriter>
45 : QWidget( _pqParent )
46 , poChartGDALRaster( 0 )
47 , poChartGDALElevation( 0 )
48 , bShowElevation( false )
52 QPalette __qPalette( QWidget::palette() );
53 __qPalette.setColor( QPalette::Background, Qt::black );
54 QWidget::setPalette( __qPalette );
55 QWidget::setAutoFillBackground(
true);
56 QWidget::setCursor( QCursor( QPixmap(
":cursors/crosshair.png" ), 15, 15 ) );
87 qRectFDrawArea = QRectF( 0, 0, QWidget::width(), QWidget::height() );
102 qRectFDrawArea = QRectF( 0, 0, QWidget::width(), QWidget::height() );
156 double __fdZoomWidth =
qRectFDrawArea.width() / (double)__qRectDatGeometry.width();
157 double __fdZoomHeight =
qRectFDrawArea.height() / (double)__qRectDatGeometry.height();
158 return( __fdZoomWidth < __fdZoomHeight ? __fdZoomWidth : __fdZoomHeight );
165 CDataPosition __oGeoPosition( ( __fdLongitude1 + __fdLongitude2 ) / 2.0, ( __fdLatitude1 + __fdLatitude1 ) / 2.0 );
167 double __fdLatitudeMaxCos;
168 if( __fdLatitude1 * __fdLatitude2 < 0 ) __fdLatitudeMaxCos = 0;
169 else if( fabs( __fdLatitude1 ) < fabs( __fdLatitude2 ) ) __fdLatitudeMaxCos = __fdLatitude1;
170 else __fdLatitudeMaxCos = __fdLatitude2;
171 double __fdZoomWidth =
qRectFDrawArea.width() / ( fabs( ( __fdLongitude2 - __fdLongitude1 ) * cos( __fdLatitudeMaxCos *
QVCT::DEG2RAD ) ) * 111120.0 / __fdResolution );
172 double __fdZoomHeight =
qRectFDrawArea.height() / ( fabs( __fdLatitude2 - __fdLatitude1 ) * 111120.0 / __fdResolution );
173 return( __fdZoomWidth < __fdZoomHeight ? __fdZoomWidth : __fdZoomHeight );
189 return __oGeoPosition;
206 static const QPointF __qPointFCrosshairA1(5,0), __qPointFCrosshairA2(15,0);
207 static const QPointF __qPointFCrosshairB1(0,5), __qPointFCrosshairB2(0,15);
208 static const QPointF __qPointFCrosshairC1(-5,0), __qPointFCrosshairC2(-15,0);
209 static const QPointF __qPointFCrosshairD1(0,-5), __qPointFCrosshairD2(0,-15);
213 __qPainter.begin(
this );
214 __qPainter.setRenderHints( QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing );
222 __qPointFDatPosition,
230 __qPainter.setOpacity( 1.0 );
239 __qPen.setColor( QColor( 0, 0, 0, 128 ) );
240 __qPen.setWidth( 1 );
241 __qPainter.setPen( __qPen );
243 __qPainter.drawPoint( __qPointF );
244 __qPainter.setPen( __qPen );
245 __qPainter.drawLine( __qPointF + __qPointFCrosshairA1, __qPointF + __qPointFCrosshairA2 );
246 __qPainter.drawLine( __qPointF + __qPointFCrosshairB1, __qPointF + __qPointFCrosshairB2 );
247 __qPainter.drawLine( __qPointF + __qPointFCrosshairC1, __qPointF + __qPointFCrosshairC2 );
248 __qPainter.drawLine( __qPointF + __qPointFCrosshairD1, __qPointF + __qPointFCrosshairD2 );
257 __qPainter.begin( _pqPrinter );
258 __qPainter.setRenderHints( QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing );
265 __qPointFDatPosition,
286 if( _rqDomElement.hasAttribute(
"longitude" ) && _rqDomElement.hasAttribute(
"longitude" ) )
289 CDataPosition __oGeoPosition( _rqDomElement.attribute(
"longitude" ).toDouble(),
290 _rqDomElement.attribute(
"latitude" ).toDouble() );
293 if( _rqDomElement.hasAttribute(
"zoom" ) )
296 fdZoom = _rqDomElement.attribute(
"zoom" ).toDouble();
298 if( _rqDomElement.hasAttribute(
"dem" ) )
300 QString __qsFilename = _rqDomElement.attribute(
"dem" );
311 _rqXmlStreamWriter.writeStartElement(
"Chart" );
317 _rqXmlStreamWriter.writeAttribute(
"longitude", QString::number( __oDataPosition.
getLongitude() ) );
318 _rqXmlStreamWriter.writeAttribute(
"latitude", QString::number( __oDataPosition.
getLatitude() ) );
321 _rqXmlStreamWriter.writeAttribute(
"zoom", QString::number(
fdZoom ) );
322 _rqXmlStreamWriter.writeEndElement();
GDAL-based (elevation) chart.
double getElevation(const QPointF &_rqPointFDatPosition) const
Returns the elevation at the given chart pixel position.
GDAL-based (raster) chart.
QPointF getDatPosition() const
Returns the last drawn chart (GDAL dataset) center pixel position.
QRect getDatGeometry() const
Returns the chart (GDAL dataset) geometry (size)
void draw(QPainter *_pqPainter, const QPointF &_rqPointFDatPosition, double _fdZoom)
Draws chart, centered on given chart (GDAL dataset) point [px] and zoomed according to given factor.
CDataPosition toGeoPosition(const QPointF &_rqPointFDatPosition) const
Converts the given chart pixel position to geographical position.
void move(const QPointF &_rqPointFDatPosition, double _fdZoom)
Moves the chart, centered on given chart (GDAL dataset) point [px] and zoomed according to given fact...
QVCT::EStatus getStatus() const
Returns the chart internal status (after constructing object)
double getResolution(const QPointF &_rqPointFDatPosition) const
Returns the resolution at given chart (GDAL dataset) point [px], in meters per pixel [m/px].
QPointF toDatPosition(const CDataPosition &_roGeoPosition) const
Converts the given (geographical) position [long,lat,elev] to chart (GDAL dataset) point [px].
QString getFileName() const
Returns the chart (GDAL dataset) file name.
double getZoom() const
Returns the last drawn chart (GDAL dataset) zoom factor.
bool hasElevation() const
Returns whether this chart has been associated elevation model data.
QString getFileName() const
Returns the underlying chart (GDAL dataset) file name.
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)
double getZoomFit() const
Returns the zoom factor allowing to view the entire chart.
void print(QPrinter *_pqPrinter)
Prints the chart.
void draw()
Draws the chart (on screen)
CChartGDALElevation * poChartGDALElevation
GDAL data elevation model (dataset)
double fdZoom
Current zoom factor.
double getResolution() const
Returns the resolution of the chart at its current position, in meters per pixel [m/px].
void move(const QPointF &_rqPointFDrawPositionOffset)
Move the current (center) chart position by specified offset (in the draw area)
QPointF qPointFDatPosition
Current (center) position in the GDAL dataset.
bool bZoomLock
Zoom lock status.
void setGeoPosition(const CDataPosition &_roGeoPosition)
Sets the current (center) position (geographical coordinates) of the chart.
virtual void paintEvent(QPaintEvent *_pqPaintEvent)
QVCT::EStatus getStatus() const
Returns the internal status of the object.
CDataPosition getGeoPosition() const
Returns the current (center) position (geographical coordinates) of the chart.
CChart(const QString &_rqsFileName, QWidget *_pqParent=0)
bool bPositionLock
Position lock status.
void resetDrawArea()
Resets the viewport draw area (to the widget's area)
QPointF toDrawPosition(const CDataPosition &_roGeoPosition) const
Converts the given (geographical) position [long,lat,elev] to chart draw point [px].
CDataPosition toGeoPosition(const QPointF &_rqPointFDrawPosition) const
Converts the given chart draw position to geographical position.
CChartGDALRaster * poChartGDALRaster
GDAL chart (dataset)
void showElevation(bool _bShow)
Sets the elevation model show status.
QRectF qRectFDrawArea
Viewport draw area.
bool bShowElevation
Elevation model show status.
double getZoomArea(const CDataPosition &_roGeoPosition1, const CDataPosition &_roGeoPosition2) const
Returns the zoom factor allowing to view the given geographical area (defined by its opposite corners...
QPointF getDrawPositionCenter() const
Returns the viewport draw area's center position.
void addElevation(const QString &_rqsFileName)
Add elevation model data to chart.
CDataPosition getGeoPositionCenter() const
Returns the center position (geographical coordinates) of the chart.
(Geographical) Position data [long,lat,elev]
double getLongitude() const
Returns this position's longitude, in degrees.
double getLatitude() const
Returns this position's latitude, in degrees.
void setElevation(double _fdElevation)
Sets the elevation, in meters.
void fileError(QVCT::EFileOperation _eFileOperation, const QString &_rqsFilename)
Displays a generic error message for an invalid file name and operation (open/save)
void draw(const CChart *_poChart, QPainter *_pqPainter)
Draws this overlay.
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
static CPointerOverlay * usePointerOverlay()
static CVesselOverlay * useVesselOverlay()
static CRouteOverlay * useRouteOverlay()
static CMainWindow * useMainWindow()
static CSettings * useSettings()
static CLandmarkOverlay * useLandmarkOverlay()
static CTrackOverlay * useTrackOverlay()
static constexpr double DEG2RAD