Add files from zip
This commit is contained in:
103
playground/svgmap/Plot.cpp
Normal file
103
playground/svgmap/Plot.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
#include <QwtPlotGraphicItem>
|
||||
#include <QwtPlotLayout>
|
||||
#include <QwtPlotPanner>
|
||||
#include <QwtPlotMagnifier>
|
||||
#include <QwtGraphic>
|
||||
|
||||
#define DEBUG_SCALE 0
|
||||
|
||||
#if DEBUG_SCALE
|
||||
#include <QwtPlotGrid>
|
||||
#endif
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QFileDialog>
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPlot( parent )
|
||||
, m_mapItem( NULL )
|
||||
, m_mapRect( 0.0, 0.0, 100.0, 100.0 ) // something
|
||||
{
|
||||
#if DEBUG_SCALE
|
||||
QwtPlotGrid* grid = new QwtPlotGrid();
|
||||
grid->attach( this );
|
||||
#else
|
||||
/*
|
||||
m_mapRect is only a reference for zooming, but
|
||||
the ranges are nothing useful for the user. So we
|
||||
hide the axes.
|
||||
*/
|
||||
plotLayout()->setCanvasMargin( 0 );
|
||||
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
|
||||
setAxisVisible( axisPos, false );
|
||||
#endif
|
||||
|
||||
/*
|
||||
Navigation:
|
||||
|
||||
Left Mouse Button: Panning
|
||||
Mouse Wheel: Zooming In/Out
|
||||
Right Mouse Button: Reset to initial
|
||||
*/
|
||||
|
||||
( void )new QwtPlotPanner( canvas() );
|
||||
( void )new QwtPlotMagnifier( canvas() );
|
||||
|
||||
canvas()->setFocusPolicy( Qt::WheelFocus );
|
||||
setCanvasBackground( Qt::white );
|
||||
|
||||
rescale();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
|
||||
void Plot::loadSVG()
|
||||
{
|
||||
QString dir;
|
||||
const QString fileName = QFileDialog::getOpenFileName( NULL,
|
||||
"Load a Scaleable Vector Graphic (SVG) Map",
|
||||
dir, "SVG Files (*.svg)" );
|
||||
|
||||
if ( !fileName.isEmpty() )
|
||||
loadSVG( fileName );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Plot::loadSVG( const QString& fileName )
|
||||
{
|
||||
if ( m_mapItem == NULL )
|
||||
{
|
||||
m_mapItem = new QwtPlotGraphicItem();
|
||||
m_mapItem->attach( this );
|
||||
}
|
||||
|
||||
QwtGraphic graphic;
|
||||
|
||||
QSvgRenderer renderer;
|
||||
if ( renderer.load( fileName ) )
|
||||
{
|
||||
QPainter p( &graphic );
|
||||
renderer.render( &p );
|
||||
}
|
||||
|
||||
m_mapItem->setGraphic( m_mapRect, graphic );
|
||||
|
||||
rescale();
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::rescale()
|
||||
{
|
||||
setAxisScale( QwtAxis::XBottom, m_mapRect.left(), m_mapRect.right() );
|
||||
setAxisScale( QwtAxis::YLeft, m_mapRect.top(), m_mapRect.bottom() );
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
33
playground/svgmap/Plot.h
Normal file
33
playground/svgmap/Plot.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QwtPlot>
|
||||
#include <QRect>
|
||||
|
||||
class QwtPlotGraphicItem;
|
||||
|
||||
class Plot : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
void loadSVG();
|
||||
#endif
|
||||
|
||||
void loadSVG( const QString& );
|
||||
|
||||
private:
|
||||
void rescale();
|
||||
|
||||
QwtPlotGraphicItem* m_mapItem;
|
||||
const QRectF m_mapRect;
|
||||
};
|
||||
345
playground/svgmap/Schlosspark_Nymphenburg.svg
Normal file
345
playground/svgmap/Schlosspark_Nymphenburg.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 92 KiB |
65
playground/svgmap/main.cpp
Normal file
65
playground/svgmap/main.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWindow( const QString& fileName )
|
||||
{
|
||||
Plot* plot = new Plot( this );
|
||||
if ( !fileName.isEmpty() )
|
||||
plot->loadSVG( fileName );
|
||||
|
||||
setCentralWidget( plot );
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
|
||||
QToolButton* btnLoad = new QToolButton();
|
||||
btnLoad->setText( "Load SVG" );
|
||||
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
|
||||
QToolBar* toolBar = new QToolBar();
|
||||
toolBar->addWidget( btnLoad );
|
||||
addToolBar( toolBar );
|
||||
|
||||
connect( btnLoad, SIGNAL(clicked()), plot, SLOT(loadSVG()) );
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
QString fileName;
|
||||
if ( argc > 1 )
|
||||
{
|
||||
fileName = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
// see: https://commons.wikimedia.org/wiki/File:Schlosspark_Nymphenburg.svg
|
||||
fileName = ":/svg/Schlosspark_Nymphenburg.svg";
|
||||
}
|
||||
|
||||
MainWindow window( fileName );
|
||||
window.resize( 600, 600 );
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
25
playground/svgmap/svgmap.pro
Normal file
25
playground/svgmap/svgmap.pro
Normal file
@@ -0,0 +1,25 @@
|
||||
######################################################################
|
||||
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
# This file may be used under the terms of the 3-clause BSD License
|
||||
######################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
!qtHaveModule(svg) {
|
||||
error("Qt has been built without SVG support !")
|
||||
}
|
||||
}
|
||||
|
||||
TARGET = svgmap
|
||||
QT += svg
|
||||
|
||||
RESOURCES += \
|
||||
svgmap.qrc
|
||||
|
||||
HEADERS = \
|
||||
Plot.h
|
||||
|
||||
SOURCES = \
|
||||
Plot.cpp \
|
||||
main.cpp
|
||||
5
playground/svgmap/svgmap.qrc
Normal file
5
playground/svgmap/svgmap.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/svg">
|
||||
<file>Schlosspark_Nymphenburg.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user