~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.0/examples/svgmap/plot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qfiledialog.h>
2
 
#include <qwt_plot_svgitem.h>
3
 
#include <qwt_plot_grid.h>
4
 
#include <qwt_plot_layout.h>
5
 
#include <qwt_plot_canvas.h>
6
 
#include <qwt_plot_panner.h>
7
 
#include <qwt_plot_magnifier.h>
8
 
#include "plot.h"
9
 
 
10
 
Plot::Plot(QWidget *parent):
11
 
    QwtPlot(parent),
12
 
    d_mapItem(NULL),
13
 
    d_mapRect(0.0, 0.0, 100.0, 100.0) // something
14
 
{   
15
 
#if 1
16
 
    /*
17
 
       d_mapRect is only a reference for zooming, but
18
 
       the ranges are nothing useful for the user. So we
19
 
       hide the axes.
20
 
     */
21
 
    plotLayout()->setCanvasMargin(0);
22
 
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
23
 
        enableAxis(axis, false);
24
 
#else
25
 
    QwtPlotGrid *grid = new QwtPlotGrid();
26
 
    grid->attach(this);
27
 
#endif
28
 
 
29
 
    /*
30
 
      Navigation:
31
 
      
32
 
      Left Mouse Button: Panning
33
 
      Mouse Wheel:       Zooming In/Out
34
 
      Right Mouse Button: Reset to initial 
35
 
    */
36
 
 
37
 
    (void)new QwtPlotPanner(canvas());
38
 
    (void)new QwtPlotMagnifier(canvas());
39
 
 
40
 
#if QT_VERSION >= 0x040000
41
 
    using namespace Qt;
42
 
#endif
43
 
    canvas()->setFocusPolicy(WheelFocus);
44
 
    rescale();
45
 
}
46
 
 
47
 
void Plot::loadSVG()
48
 
{
49
 
    QString dir;
50
 
#if 0
51
 
    dir = "/dw/svg";
52
 
#endif
53
 
#if QT_VERSION >= 0x040000
54
 
    const QString fileName = QFileDialog::getOpenFileName( NULL,
55
 
        "Load a Scaleable Vector Graphic (SVG) Map",
56
 
        dir, "SVG Files (*.svg)");
57
 
#else
58
 
    const QString fileName = QFileDialog::getOpenFileName( 
59
 
        dir, "SVG Files (*.svg)", NULL, NULL, 
60
 
        "Load a Scaleable Vector Graphic (SVG) Map" );
61
 
#endif
62
 
    if ( !fileName.isEmpty() )
63
 
    {
64
 
        if ( d_mapItem == NULL )
65
 
        {
66
 
            d_mapItem = new QwtPlotSvgItem();
67
 
            d_mapItem->attach(this);
68
 
        }
69
 
 
70
 
        d_mapItem->loadFile(d_mapRect, fileName);
71
 
        rescale();
72
 
 
73
 
        replot();
74
 
    }
75
 
}
76
 
 
77
 
void Plot::rescale()
78
 
{
79
 
    setAxisScale(QwtPlot::xBottom,
80
 
        d_mapRect.left(), d_mapRect.right());
81
 
    setAxisScale(QwtPlot::yLeft,
82
 
        d_mapRect.top(), d_mapRect.bottom());
83
 
}