Released version 6.1.3
This commit is contained in:
commit
a94503cb82
49 changed files with 276310 additions and 0 deletions
129
playground/curvetracker/curvetracker.cpp
Normal file
129
playground/curvetracker/curvetracker.cpp
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#include "curvetracker.h"
|
||||
#include <qwt_picker_machine.h>
|
||||
#include <qwt_series_data.h>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
|
||||
struct compareX
|
||||
{
|
||||
inline bool operator()( const double x, const QPointF &pos ) const
|
||||
{
|
||||
return ( x < pos.x() );
|
||||
}
|
||||
};
|
||||
|
||||
CurveTracker::CurveTracker( QWidget *canvas ):
|
||||
QwtPlotPicker( canvas )
|
||||
{
|
||||
setTrackerMode( QwtPlotPicker::ActiveOnly );
|
||||
setRubberBand( VLineRubberBand );
|
||||
|
||||
setStateMachine( new QwtPickerDragPointMachine() );
|
||||
}
|
||||
|
||||
QRect CurveTracker::trackerRect( const QFont &font ) const
|
||||
{
|
||||
QRect r = QwtPlotPicker::trackerRect( font );
|
||||
|
||||
// align r to the first curve
|
||||
|
||||
const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
|
||||
if ( curves.size() > 0 )
|
||||
{
|
||||
QPointF pos = invTransform( trackerPosition() );
|
||||
|
||||
const QLineF line = curveLineAt(
|
||||
static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() );
|
||||
if ( !line.isNull() )
|
||||
{
|
||||
const double curveY = line.pointAt(
|
||||
( pos.x() - line.p1().x() ) / line.dx() ).y();
|
||||
|
||||
pos.setY( curveY );
|
||||
pos = transform( pos );
|
||||
|
||||
r.moveBottom( pos.y() );
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
QwtText CurveTracker::trackerTextF( const QPointF &pos ) const
|
||||
{
|
||||
QwtText trackerText;
|
||||
|
||||
trackerText.setColor( Qt::black );
|
||||
|
||||
QColor c( "#333333" );
|
||||
trackerText.setBorderPen( QPen( c, 2 ) );
|
||||
c.setAlpha( 200 );
|
||||
trackerText.setBackgroundBrush( c );
|
||||
|
||||
QString info;
|
||||
|
||||
const QwtPlotItemList curves =
|
||||
plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
|
||||
|
||||
for ( int i = 0; i < curves.size(); i++ )
|
||||
{
|
||||
const QString curveInfo = curveInfoAt(
|
||||
static_cast<const QwtPlotCurve *>( curves[i] ), pos );
|
||||
|
||||
if ( !curveInfo.isEmpty() )
|
||||
{
|
||||
if ( !info.isEmpty() )
|
||||
info += "<br>";
|
||||
|
||||
info += curveInfo;
|
||||
}
|
||||
}
|
||||
|
||||
trackerText.setText( info );
|
||||
return trackerText;
|
||||
}
|
||||
|
||||
QString CurveTracker::curveInfoAt(
|
||||
const QwtPlotCurve *curve, const QPointF &pos ) const
|
||||
{
|
||||
const QLineF line = curveLineAt( curve, pos.x() );
|
||||
if ( line.isNull() )
|
||||
return QString::null;
|
||||
|
||||
const double y = line.pointAt(
|
||||
( pos.x() - line.p1().x() ) / line.dx() ).y();
|
||||
|
||||
QString info( "<font color=""%1"">%2</font>" );
|
||||
return info.arg( curve->pen().color().name() ).arg( y );
|
||||
}
|
||||
|
||||
QLineF CurveTracker::curveLineAt(
|
||||
const QwtPlotCurve *curve, double x ) const
|
||||
{
|
||||
QLineF line;
|
||||
|
||||
if ( curve->dataSize() >= 2 )
|
||||
{
|
||||
const QRectF br = curve->boundingRect();
|
||||
if ( ( br.width() > 0 ) && ( x >= br.left() ) && ( x <= br.right() ) )
|
||||
{
|
||||
int index = qwtUpperSampleIndex<QPointF>(
|
||||
*curve->data(), x, compareX() );
|
||||
|
||||
if ( index == -1 &&
|
||||
x == curve->sample( curve->dataSize() - 1 ).x() )
|
||||
{
|
||||
// the last sample is excluded from qwtUpperSampleIndex
|
||||
index = curve->dataSize() - 1;
|
||||
}
|
||||
|
||||
if ( index > 0 )
|
||||
{
|
||||
line.setP1( curve->sample( index - 1 ) );
|
||||
line.setP2( curve->sample( index ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
22
playground/curvetracker/curvetracker.h
Normal file
22
playground/curvetracker/curvetracker.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef _CURVE_TRACKER_H_
|
||||
#define _CURVE_TRACKER_H_
|
||||
|
||||
#include <qwt_plot_picker.h>
|
||||
|
||||
class QwtPlotCurve;
|
||||
|
||||
class CurveTracker: public QwtPlotPicker
|
||||
{
|
||||
public:
|
||||
CurveTracker( QWidget * );
|
||||
|
||||
protected:
|
||||
virtual QwtText trackerTextF( const QPointF & ) const;
|
||||
virtual QRect trackerRect( const QFont & ) const;
|
||||
|
||||
private:
|
||||
QString curveInfoAt( const QwtPlotCurve *, const QPointF & ) const;
|
||||
QLineF curveLineAt( const QwtPlotCurve *, double x ) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
22
playground/curvetracker/curvetracker.pro
Normal file
22
playground/curvetracker/curvetracker.pro
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = curvetracker
|
||||
|
||||
HEADERS = \
|
||||
curvetracker.h \
|
||||
plot.h
|
||||
|
||||
SOURCES = \
|
||||
curvetracker.cpp \
|
||||
plot.cpp \
|
||||
main.cpp
|
||||
|
||||
13
playground/curvetracker/main.cpp
Normal file
13
playground/curvetracker/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <qapplication.h>
|
||||
#include "plot.h"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
Plot plot;
|
||||
plot.resize( 600, 400 );
|
||||
plot.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
107
playground/curvetracker/plot.cpp
Normal file
107
playground/curvetracker/plot.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#include "plot.h"
|
||||
#include "curvetracker.h"
|
||||
#include <qwt_picker_machine.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_plot_textlabel.h>
|
||||
#include <qwt_plot_zoneitem.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qwt_symbol.h>
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent)
|
||||
{
|
||||
setPalette( Qt::black );
|
||||
|
||||
// we want to have the axis scales like a frame around the
|
||||
// canvas
|
||||
plotLayout()->setAlignCanvasToScales( true );
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
axisWidget( axis )->setMargin( 0 );
|
||||
|
||||
QwtPlotCanvas *canvas = new QwtPlotCanvas();
|
||||
canvas->setAutoFillBackground( false );
|
||||
canvas->setFrameStyle( QFrame::NoFrame );
|
||||
setCanvas( canvas );
|
||||
|
||||
setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
|
||||
|
||||
// a title
|
||||
QwtText title( "Picker Demo" );
|
||||
title.setColor( Qt::white );
|
||||
title.setRenderFlags( Qt::AlignHCenter | Qt::AlignTop );
|
||||
|
||||
QFont font;
|
||||
font.setBold( true );
|
||||
title.setFont( font );
|
||||
|
||||
QwtPlotTextLabel *titleItem = new QwtPlotTextLabel();
|
||||
titleItem->setText( title );
|
||||
titleItem->attach( this );
|
||||
|
||||
#if 1
|
||||
// section
|
||||
|
||||
//QColor c( "PaleVioletRed" );
|
||||
|
||||
QwtPlotZoneItem* zone = new QwtPlotZoneItem();
|
||||
zone->setPen( Qt::darkGray );
|
||||
zone->setBrush( QColor( "#834358" ) );
|
||||
zone->setOrientation( Qt::Horizontal );
|
||||
zone->setInterval( 3.8, 5.7 );
|
||||
zone->attach( this );
|
||||
|
||||
#else
|
||||
// grid
|
||||
|
||||
QwtPlotGrid *grid = new QwtPlotGrid();
|
||||
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
|
||||
grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
|
||||
grid->attach( this );
|
||||
#endif
|
||||
|
||||
// curves
|
||||
|
||||
QPolygonF points1;
|
||||
points1 << QPointF( 0.2, 4.4 ) << QPointF( 1.2, 3.0 )
|
||||
<< QPointF( 2.7, 4.5 ) << QPointF( 3.5, 6.8 )
|
||||
<< QPointF( 4.7, 7.9 ) << QPointF( 5.8, 7.1 );
|
||||
|
||||
insertCurve( "Curve 1", "DarkOrange", points1 );
|
||||
|
||||
QPolygonF points2;
|
||||
points2 << QPointF( 0.4, 8.7 ) << QPointF( 1.4, 7.8 )
|
||||
<< QPointF( 2.3, 5.5 ) << QPointF( 3.3, 4.1 )
|
||||
<< QPointF( 4.4, 5.2 ) << QPointF( 5.6, 5.7 );
|
||||
|
||||
insertCurve( "Curve 2", "DodgerBlue", points2 );
|
||||
|
||||
CurveTracker* tracker = new CurveTracker( this->canvas() );
|
||||
|
||||
// for the demo we want the tracker to be active without
|
||||
// having to click on the canvas
|
||||
tracker->setStateMachine( new QwtPickerTrackerMachine() );
|
||||
tracker->setRubberBandPen( QPen( "MediumOrchid" ) );
|
||||
}
|
||||
|
||||
void Plot::insertCurve( const QString &title,
|
||||
const QColor &color, const QPolygonF &points )
|
||||
{
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setTitle( title );
|
||||
curve->setPen( color, 2 ),
|
||||
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
|
||||
|
||||
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
|
||||
QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
|
||||
curve->setSymbol( symbol );
|
||||
|
||||
curve->setSamples( points );
|
||||
|
||||
curve->attach( this );
|
||||
}
|
||||
|
||||
|
||||
21
playground/curvetracker/plot.h
Normal file
21
playground/curvetracker/plot.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class QPolygonF;
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget * = NULL );
|
||||
|
||||
private:
|
||||
void insertCurve( const QString &title,
|
||||
const QColor &, const QPolygonF & );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
72
playground/graphicscale/canvas.cpp
Normal file
72
playground/graphicscale/canvas.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include "canvas.h"
|
||||
#include <qwt_graphic.h>
|
||||
#include <qsvgrenderer.h>
|
||||
|
||||
Canvas::Canvas( Mode mode, QWidget *parent ):
|
||||
QWidget( parent ),
|
||||
d_mode( mode )
|
||||
{
|
||||
const int m = 10;
|
||||
setContentsMargins( m, m, m, m );
|
||||
|
||||
if ( d_mode == Svg )
|
||||
d_renderer = new QSvgRenderer( this );
|
||||
else
|
||||
d_graphic = new QwtGraphic();
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
if ( d_mode == VectorGraphic )
|
||||
delete d_graphic;
|
||||
}
|
||||
|
||||
void Canvas::setSvg( const QByteArray &data )
|
||||
{
|
||||
if ( d_mode == VectorGraphic )
|
||||
{
|
||||
d_graphic->reset();
|
||||
|
||||
QSvgRenderer renderer;
|
||||
renderer.load( data );
|
||||
|
||||
QPainter p( d_graphic );
|
||||
renderer.render( &p, renderer.viewBoxF() );
|
||||
p.end();
|
||||
}
|
||||
else
|
||||
{
|
||||
d_renderer->load( data );
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void Canvas::paintEvent( QPaintEvent * )
|
||||
{
|
||||
QPainter painter( this );
|
||||
|
||||
painter.save();
|
||||
|
||||
painter.setPen( Qt::black );
|
||||
painter.setBrush( Qt::white );
|
||||
painter.drawRect( contentsRect().adjusted( 0, 0, -1, -1 ) );
|
||||
|
||||
painter.restore();
|
||||
|
||||
painter.setPen( Qt::NoPen );
|
||||
painter.setBrush( Qt::NoBrush );
|
||||
render( &painter, contentsRect() );
|
||||
}
|
||||
|
||||
void Canvas::render( QPainter *painter, const QRect &rect ) const
|
||||
{
|
||||
if ( d_mode == Svg )
|
||||
{
|
||||
d_renderer->render( painter, rect );
|
||||
}
|
||||
else
|
||||
{
|
||||
d_graphic->render( painter, rect );
|
||||
}
|
||||
}
|
||||
33
playground/graphicscale/canvas.h
Normal file
33
playground/graphicscale/canvas.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include <qwidget.h>
|
||||
|
||||
class QByteArray;
|
||||
class QSvgRenderer;
|
||||
class QwtGraphic;
|
||||
|
||||
class Canvas: public QWidget
|
||||
{
|
||||
public:
|
||||
enum Mode
|
||||
{
|
||||
Svg,
|
||||
VectorGraphic
|
||||
};
|
||||
|
||||
Canvas( Mode, QWidget *parent = NULL );
|
||||
virtual ~Canvas();
|
||||
|
||||
void setSvg( const QByteArray & );
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent * );
|
||||
|
||||
private:
|
||||
void render( QPainter *, const QRect & ) const;
|
||||
|
||||
const Mode d_mode;
|
||||
union
|
||||
{
|
||||
QSvgRenderer *d_renderer;
|
||||
QwtGraphic *d_graphic;
|
||||
};
|
||||
};
|
||||
23
playground/graphicscale/graphicscale.pro
Normal file
23
playground/graphicscale/graphicscale.pro
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = graphicscale
|
||||
QT += svg
|
||||
|
||||
HEADERS = \
|
||||
canvas.h \
|
||||
mainwindow.h
|
||||
|
||||
SOURCES = \
|
||||
canvas.cpp \
|
||||
mainwindow.cpp \
|
||||
main.cpp
|
||||
|
||||
13
playground/graphicscale/main.cpp
Normal file
13
playground/graphicscale/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow w;
|
||||
w.resize( 600, 400 );
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
109
playground/graphicscale/mainwindow.cpp
Normal file
109
playground/graphicscale/mainwindow.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#include "mainwindow.h"
|
||||
#include "canvas.h"
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qlayout.h>
|
||||
#include <qlabel.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qbuffer.h>
|
||||
#include <qpainter.h>
|
||||
#include <qsvggenerator.h>
|
||||
#include <qstatusbar.h>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
QWidget *w = new QWidget( this );
|
||||
|
||||
d_canvas[0] = new Canvas( Canvas::Svg, this );
|
||||
d_canvas[0]->setAutoFillBackground( true );
|
||||
d_canvas[0]->setPalette( Qt::gray );
|
||||
|
||||
d_canvas[1] = new Canvas( Canvas::VectorGraphic, this );
|
||||
d_canvas[1]->setAutoFillBackground( true );
|
||||
d_canvas[1]->setPalette( Qt::gray );
|
||||
|
||||
QVBoxLayout *vBox1 = new QVBoxLayout();
|
||||
vBox1->setContentsMargins( 0, 0, 0, 0 );
|
||||
vBox1->setSpacing( 5 );
|
||||
vBox1->addWidget( new QLabel( "SVG" ), 0, Qt::AlignCenter );
|
||||
vBox1->addWidget( d_canvas[0], 10 );
|
||||
|
||||
QVBoxLayout *vBox2 = new QVBoxLayout();
|
||||
vBox2->setContentsMargins( 0, 0, 0, 0 );
|
||||
vBox2->setSpacing( 5 );
|
||||
vBox2->addWidget( new QLabel( "Vector Graphic" ), 0, Qt::AlignCenter );
|
||||
vBox2->addWidget( d_canvas[1], 10 );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout( w );
|
||||
layout->addLayout( vBox1 );
|
||||
layout->addLayout( vBox2 );
|
||||
|
||||
setCentralWidget( w );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton *btnLoad = new QToolButton( toolBar );
|
||||
|
||||
btnLoad->setText( "Load SVG" );
|
||||
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnLoad );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
connect( btnLoad, SIGNAL( clicked() ), this, SLOT( loadSVG() ) );
|
||||
|
||||
#if 0
|
||||
QPainterPath path;
|
||||
path.addRect( QRectF( 1.0, 1.0, 2.0, 2.0 ) );
|
||||
loadPath( path );
|
||||
#endif
|
||||
};
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::loadSVG()
|
||||
{
|
||||
QString dir = "/home1/uwe/qwt/qwt/tests/svg";
|
||||
const QString fileName = QFileDialog::getOpenFileName( NULL,
|
||||
"Load a Scaleable Vector Graphic (SVG) Document",
|
||||
dir, "SVG Files (*.svg)" );
|
||||
|
||||
if ( !fileName.isEmpty() )
|
||||
loadSVG( fileName );
|
||||
|
||||
statusBar()->showMessage( fileName );
|
||||
}
|
||||
|
||||
void MainWindow::loadSVG( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
|
||||
return;
|
||||
|
||||
const QByteArray document = file.readAll();
|
||||
file.close();
|
||||
|
||||
d_canvas[0]->setSvg( document );
|
||||
d_canvas[1]->setSvg( document );
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadPath( const QPainterPath &path )
|
||||
{
|
||||
QBuffer buf;
|
||||
|
||||
QSvgGenerator generator;
|
||||
generator.setOutputDevice( &buf );
|
||||
|
||||
QPainter painter( &generator );
|
||||
painter.setRenderHint( QPainter::Antialiasing, false );
|
||||
painter.setPen( QPen( Qt::blue, 0 ) );
|
||||
painter.setBrush( Qt::darkCyan );
|
||||
painter.drawPath( path );
|
||||
painter.end();
|
||||
|
||||
d_canvas[0]->setSvg( buf.data() );
|
||||
d_canvas[1]->setSvg( buf.data() );
|
||||
}
|
||||
22
playground/graphicscale/mainwindow.h
Normal file
22
playground/graphicscale/mainwindow.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <qmainwindow.h>
|
||||
|
||||
class Canvas;
|
||||
class QPainterPath;
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
virtual ~MainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadSVG();
|
||||
|
||||
private:
|
||||
void loadSVG( const QString & );
|
||||
void loadPath( const QPainterPath & );
|
||||
|
||||
Canvas *d_canvas[2];
|
||||
};
|
||||
70
playground/playground.pri
Normal file
70
playground/playground.pri
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
###################################################################
|
||||
|
||||
QWT_ROOT = $${PWD}/..
|
||||
include( $${QWT_ROOT}/qwtconfig.pri )
|
||||
include( $${QWT_ROOT}/qwtbuild.pri )
|
||||
include( $${QWT_ROOT}/qwtfunctions.pri )
|
||||
|
||||
QWT_OUT_ROOT = $${OUT_PWD}/../..
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
INCLUDEPATH += $${QWT_ROOT}/src
|
||||
DEPENDPATH += $${QWT_ROOT}/src
|
||||
|
||||
!debug_and_release {
|
||||
|
||||
DESTDIR = $${QWT_OUT_ROOT}/playground/bin
|
||||
}
|
||||
else {
|
||||
CONFIG(debug, debug|release) {
|
||||
|
||||
DESTDIR = $${QWT_OUT_ROOT}/playground/bin_debug
|
||||
}
|
||||
else {
|
||||
|
||||
DESTDIR = $${QWT_OUT_ROOT}/playground/bin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QMAKE_RPATHDIR *= $${QWT_ROOT}/lib
|
||||
qwtAddLibrary($${QWT_OUT_ROOT}/lib, qwt)
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
|
||||
QT += printsupport
|
||||
QT += concurrent
|
||||
}
|
||||
|
||||
contains(QWT_CONFIG, QwtOpenGL ) {
|
||||
|
||||
QT += opengl
|
||||
}
|
||||
else {
|
||||
|
||||
DEFINES += QWT_NO_OPENGL
|
||||
}
|
||||
|
||||
contains(QWT_CONFIG, QwtSvg) {
|
||||
|
||||
QT += svg
|
||||
}
|
||||
else {
|
||||
|
||||
DEFINES += QWT_NO_SVG
|
||||
}
|
||||
|
||||
|
||||
win32 {
|
||||
contains(QWT_CONFIG, QwtDll) {
|
||||
DEFINES += QT_DLL QWT_DLL
|
||||
}
|
||||
}
|
||||
32
playground/playground.pro
Normal file
32
playground/playground.pro
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../qwtconfig.pri )
|
||||
|
||||
TEMPLATE = subdirs
|
||||
|
||||
contains(QWT_CONFIG, QwtPlot) {
|
||||
|
||||
SUBDIRS += \
|
||||
plotmatrix \
|
||||
timescale \
|
||||
scaleengine \
|
||||
graphicscale \
|
||||
rescaler \
|
||||
shapes \
|
||||
curvetracker \
|
||||
symbols
|
||||
|
||||
contains(QWT_CONFIG, QwtSvg) {
|
||||
|
||||
SUBDIRS += \
|
||||
svgmap
|
||||
}
|
||||
|
||||
}
|
||||
66
playground/plotmatrix/main.cpp
Normal file
66
playground/plotmatrix/main.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "plotmatrix.h"
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qapplication.h>
|
||||
#include <qpen.h>
|
||||
#include <qmath.h>
|
||||
|
||||
class MainWindow: public PlotMatrix
|
||||
{
|
||||
public:
|
||||
MainWindow();
|
||||
};
|
||||
|
||||
MainWindow::MainWindow():
|
||||
PlotMatrix( 3, 4 )
|
||||
{
|
||||
enableAxis( QwtPlot::yLeft );
|
||||
enableAxis( QwtPlot::yRight );
|
||||
enableAxis( QwtPlot::xBottom );
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
const double v = qPow( 10.0, row );
|
||||
setAxisScale( QwtPlot::yLeft, row, -v, v );
|
||||
setAxisScale( QwtPlot::yRight, row, -v, v );
|
||||
}
|
||||
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
const double v = qPow( 10.0, col );
|
||||
setAxisScale( QwtPlot::xBottom, col, -v, v );
|
||||
setAxisScale( QwtPlot::xTop, col, -v, v );
|
||||
}
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *plot = plotAt( row, col );
|
||||
plot->setCanvasBackground( QColor( Qt::darkGray ) );
|
||||
|
||||
QwtPlotGrid *grid = new QwtPlotGrid();
|
||||
grid->enableXMin( true );
|
||||
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
|
||||
grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
|
||||
grid->attach( plot );
|
||||
}
|
||||
}
|
||||
|
||||
plotAt( 1, 0 )->axisWidget( QwtPlot::yLeft )->setLabelRotation( 45 );
|
||||
plotAt( 1, numColumns() - 1 )->axisWidget( QwtPlot::yRight )->setLabelRotation( -45 );
|
||||
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow mainWindow;
|
||||
|
||||
mainWindow.resize( 800, 600 );
|
||||
mainWindow.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
428
playground/plotmatrix/plotmatrix.cpp
Normal file
428
playground/plotmatrix/plotmatrix.cpp
Normal file
|
|
@ -0,0 +1,428 @@
|
|||
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
// vim: expandtab
|
||||
|
||||
#include <qlayout.h>
|
||||
#include <qpen.h>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
#include "plotmatrix.h"
|
||||
|
||||
static void enablePlotAxis( QwtPlot *plot, int axis, bool on )
|
||||
{
|
||||
// when false we still enable the axis to have an effect
|
||||
// of the minimal extent active. Instead we hide all visible
|
||||
// parts and margins/spacings.
|
||||
|
||||
plot->enableAxis( axis, true );
|
||||
|
||||
QwtScaleDraw *sd = plot->axisScaleDraw( axis );
|
||||
sd->enableComponent( QwtScaleDraw::Backbone, on );
|
||||
sd->enableComponent( QwtScaleDraw::Ticks, on );
|
||||
sd->enableComponent( QwtScaleDraw::Labels, on );
|
||||
|
||||
QwtScaleWidget* sw = plot->axisWidget( axis );
|
||||
sw->setMargin( on ? 4 : 0 );
|
||||
sw->setSpacing( on ? 20 : 0 );
|
||||
}
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
public:
|
||||
Plot( QWidget *parent = NULL ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
QwtPlotCanvas *canvas = new QwtPlotCanvas();
|
||||
canvas->setLineWidth( 1 );
|
||||
canvas->setFrameStyle( QFrame::Box | QFrame::Plain );
|
||||
|
||||
setCanvas( canvas );
|
||||
}
|
||||
|
||||
virtual QSize sizeHint() const
|
||||
{
|
||||
return minimumSizeHint();
|
||||
}
|
||||
};
|
||||
|
||||
class PlotMatrix::PrivateData
|
||||
{
|
||||
public:
|
||||
PrivateData():
|
||||
inScaleSync( false )
|
||||
{
|
||||
isAxisEnabled[QwtPlot::xBottom] = true;
|
||||
isAxisEnabled[QwtPlot::xTop] = false;
|
||||
isAxisEnabled[QwtPlot::yLeft] = true;
|
||||
isAxisEnabled[QwtPlot::yRight] = false;
|
||||
}
|
||||
|
||||
bool isAxisEnabled[QwtPlot::axisCnt];
|
||||
QVector<QwtPlot *> plotWidgets;
|
||||
mutable bool inScaleSync;
|
||||
};
|
||||
|
||||
PlotMatrix::PlotMatrix( int numRows, int numColumns, QWidget *parent ):
|
||||
QFrame( parent )
|
||||
{
|
||||
d_data = new PrivateData();
|
||||
d_data->plotWidgets.resize( numRows * numColumns );
|
||||
|
||||
QGridLayout *layout = new QGridLayout( this );
|
||||
layout->setSpacing( 5 );
|
||||
|
||||
for ( int row = 0; row < numRows; row++ )
|
||||
{
|
||||
for ( int col = 0; col < numColumns; col++ )
|
||||
{
|
||||
QwtPlot *plot = new Plot( this );
|
||||
layout->addWidget( plot, row, col );
|
||||
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
{
|
||||
connect( plot->axisWidget( axis ),
|
||||
SIGNAL( scaleDivChanged() ), SLOT( scaleDivChanged() ) );
|
||||
}
|
||||
d_data->plotWidgets[row * numColumns + col] = plot;
|
||||
}
|
||||
}
|
||||
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
PlotMatrix::~PlotMatrix()
|
||||
{
|
||||
delete d_data;
|
||||
}
|
||||
|
||||
int PlotMatrix::numRows() const
|
||||
{
|
||||
const QGridLayout *l = qobject_cast<const QGridLayout *>( layout() );
|
||||
if ( l )
|
||||
return l->rowCount();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PlotMatrix::numColumns() const
|
||||
{
|
||||
const QGridLayout *l = qobject_cast<const QGridLayout *>( layout() );
|
||||
if ( l )
|
||||
return l->columnCount();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QwtPlot* PlotMatrix::plotAt( int row, int column )
|
||||
{
|
||||
const int index = row * numColumns() + column;
|
||||
if ( index < d_data->plotWidgets.size() )
|
||||
return d_data->plotWidgets[index];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const QwtPlot* PlotMatrix::plotAt( int row, int column ) const
|
||||
{
|
||||
const int index = row * numColumns() + column;
|
||||
if ( index < d_data->plotWidgets.size() )
|
||||
return d_data->plotWidgets[index];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PlotMatrix::enableAxis( int axis, bool tf )
|
||||
{
|
||||
if ( axis >= 0 && axis < QwtPlot::axisCnt )
|
||||
{
|
||||
if ( tf != d_data->isAxisEnabled[axis] )
|
||||
{
|
||||
d_data->isAxisEnabled[axis] = tf;
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PlotMatrix::axisEnabled( int axis ) const
|
||||
{
|
||||
if ( axis >= 0 && axis < QwtPlot::axisCnt )
|
||||
return d_data->isAxisEnabled[axis];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PlotMatrix::setAxisScale( int axis, int rowOrColumn,
|
||||
double min, double max, double step )
|
||||
{
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
|
||||
col = rowOrColumn;
|
||||
else
|
||||
row = rowOrColumn;
|
||||
|
||||
QwtPlot *plt = plotAt( row, col );
|
||||
if ( plt )
|
||||
{
|
||||
plt->setAxisScale( axis, min, max, step );
|
||||
plt->updateAxes();
|
||||
}
|
||||
}
|
||||
|
||||
void PlotMatrix::scaleDivChanged()
|
||||
{
|
||||
if ( d_data->inScaleSync )
|
||||
return;
|
||||
|
||||
d_data->inScaleSync = true;
|
||||
|
||||
QwtPlot *plt = NULL;
|
||||
int axisId = -1;
|
||||
int rowOrColumn = -1;
|
||||
|
||||
// find the changed axis
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, col );
|
||||
if ( p )
|
||||
{
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
{
|
||||
if ( p->axisWidget( axis ) == sender() )
|
||||
{
|
||||
plt = p;
|
||||
axisId = axis;
|
||||
if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
|
||||
rowOrColumn = col;
|
||||
else
|
||||
rowOrColumn = row;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( plt )
|
||||
{
|
||||
const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId );
|
||||
|
||||
// synchronize the axes
|
||||
if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
|
||||
{
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, rowOrColumn );
|
||||
if ( p != plt )
|
||||
{
|
||||
p->setAxisScaleDiv( axisId, scaleDiv );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, col );
|
||||
if ( p != plt )
|
||||
{
|
||||
p->setAxisScaleDiv( axisId, scaleDiv );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
d_data->inScaleSync = false;
|
||||
}
|
||||
|
||||
void PlotMatrix::updateLayout()
|
||||
{
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, col );
|
||||
if ( p )
|
||||
{
|
||||
bool showAxis[QwtPlot::axisCnt];
|
||||
showAxis[QwtPlot::xBottom] =
|
||||
axisEnabled( QwtPlot::xBottom ) && row == numRows() - 1;
|
||||
showAxis[QwtPlot::xTop] =
|
||||
axisEnabled( QwtPlot::xTop ) && row == 0;
|
||||
showAxis[QwtPlot::yLeft] =
|
||||
axisEnabled( QwtPlot::yLeft ) && col == 0;
|
||||
showAxis[QwtPlot::yRight] =
|
||||
axisEnabled( QwtPlot::yRight ) && col == numColumns() - 1;
|
||||
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
{
|
||||
enablePlotAxis( p, axis, showAxis[axis] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
alignAxes( row, QwtPlot::xTop );
|
||||
alignAxes( row, QwtPlot::xBottom );
|
||||
|
||||
alignScaleBorder( row, QwtPlot::yLeft );
|
||||
alignScaleBorder( row, QwtPlot::yRight );
|
||||
}
|
||||
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
alignAxes( col, QwtPlot::yLeft );
|
||||
alignAxes( col, QwtPlot::yRight );
|
||||
|
||||
alignScaleBorder( col, QwtPlot::xBottom );
|
||||
alignScaleBorder( col, QwtPlot::xTop );
|
||||
}
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, col );
|
||||
if ( p )
|
||||
p->replot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlotMatrix::alignAxes( int rowOrColumn, int axis )
|
||||
{
|
||||
if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
|
||||
{
|
||||
double maxExtent = 0;
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, rowOrColumn );
|
||||
if ( p )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = p->axisWidget( axis );
|
||||
|
||||
QwtScaleDraw *sd = scaleWidget->scaleDraw();
|
||||
sd->setMinimumExtent( 0.0 );
|
||||
|
||||
const double extent = sd->extent( scaleWidget->font() );
|
||||
if ( extent > maxExtent )
|
||||
maxExtent = extent;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int row = 0; row < numRows(); row++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, rowOrColumn );
|
||||
if ( p )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = p->axisWidget( axis );
|
||||
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double maxExtent = 0;
|
||||
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, col );
|
||||
if ( p )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = p->axisWidget( axis );
|
||||
|
||||
QwtScaleDraw *sd = scaleWidget->scaleDraw();
|
||||
sd->setMinimumExtent( 0.0 );
|
||||
|
||||
const double extent = sd->extent( scaleWidget->font() );
|
||||
if ( extent > maxExtent )
|
||||
maxExtent = extent;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int col = 0; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, col );
|
||||
if ( p )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = p->axisWidget( axis );
|
||||
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlotMatrix::alignScaleBorder( int rowOrColumn, int axis )
|
||||
{
|
||||
int startDist = 0;
|
||||
int endDist = 0;
|
||||
|
||||
if ( axis == QwtPlot::yLeft )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, 0 );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
|
||||
|
||||
for ( int col = 1; col < numColumns(); col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, col );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
|
||||
}
|
||||
}
|
||||
else if ( axis == QwtPlot::yRight )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, numColumns() - 1 );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
|
||||
|
||||
for ( int col = 0; col < numColumns() - 1; col++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, col );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
|
||||
}
|
||||
}
|
||||
if ( axis == QwtPlot::xTop )
|
||||
{
|
||||
QwtPlot *p = plotAt( rowOrColumn, 0 );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
|
||||
|
||||
for ( int row = 1; row < numRows(); row++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, rowOrColumn );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
|
||||
}
|
||||
}
|
||||
else if ( axis == QwtPlot::xBottom )
|
||||
{
|
||||
QwtPlot *p = plotAt( numRows() - 1, rowOrColumn );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
|
||||
|
||||
for ( int row = 0; row < numRows() - 1; row++ )
|
||||
{
|
||||
QwtPlot *p = plotAt( row, rowOrColumn );
|
||||
if ( p )
|
||||
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
|
||||
}
|
||||
}
|
||||
}
|
||||
41
playground/plotmatrix/plotmatrix.h
Normal file
41
playground/plotmatrix/plotmatrix.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef _PLOT_MATRIX_H_
|
||||
#define _PLOT_MATRIX_H_
|
||||
|
||||
#include <qframe.h>
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class PlotMatrix: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotMatrix( int rows, int columns, QWidget * parent = NULL );
|
||||
virtual ~PlotMatrix();
|
||||
|
||||
int numRows() const;
|
||||
int numColumns() const;
|
||||
|
||||
QwtPlot* plotAt( int row, int column );
|
||||
const QwtPlot* plotAt( int row, int column ) const;
|
||||
|
||||
void enableAxis( int axisId, bool tf = true );
|
||||
bool axisEnabled( int axisId ) const;
|
||||
|
||||
void setAxisScale( int axisId, int rowOrColumn,
|
||||
double min, double max, double step = 0 );
|
||||
|
||||
protected:
|
||||
void updateLayout();
|
||||
|
||||
private Q_SLOTS:
|
||||
void scaleDivChanged();
|
||||
|
||||
private:
|
||||
void alignAxes( int rowOrColumn, int axis );
|
||||
void alignScaleBorder( int rowOrColumn, int axis );
|
||||
|
||||
class PrivateData;
|
||||
PrivateData *d_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
19
playground/plotmatrix/plotmatrix.pro
Normal file
19
playground/plotmatrix/plotmatrix.pro
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = plotmatrix
|
||||
|
||||
HEADERS = \
|
||||
plotmatrix.h
|
||||
|
||||
SOURCES = \
|
||||
plotmatrix.cpp \
|
||||
main.cpp
|
||||
15
playground/rescaler/main.cpp
Normal file
15
playground/rescaler/main.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow mainWindow;
|
||||
|
||||
mainWindow.resize( 800, 600 );
|
||||
mainWindow.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
146
playground/rescaler/mainwindow.cpp
Normal file
146
playground/rescaler/mainwindow.cpp
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#include <cstdlib>
|
||||
#include <qgroupbox.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qlayout.h>
|
||||
#include <qstatusbar.h>
|
||||
#include <qlabel.h>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_rescaler.h>
|
||||
#include <qwt_scale_div.h>
|
||||
#include "plot.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
QFrame *w = new QFrame( this );
|
||||
|
||||
QWidget *panel = createPanel( w );
|
||||
panel->setFixedWidth( 2 * panel->sizeHint().width() );
|
||||
d_plot = createPlot( w );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout( w );
|
||||
layout->setMargin( 0 );
|
||||
layout->addWidget( panel, 0 );
|
||||
layout->addWidget( d_plot, 10 );
|
||||
|
||||
setCentralWidget( w );
|
||||
|
||||
setRescaleMode( 0 );
|
||||
|
||||
( void )statusBar();
|
||||
}
|
||||
|
||||
QWidget *MainWindow::createPanel( QWidget *parent )
|
||||
{
|
||||
QGroupBox *panel = new QGroupBox( "Navigation Panel", parent );
|
||||
|
||||
QComboBox *rescaleBox = new QComboBox( panel );
|
||||
rescaleBox->setEditable( false );
|
||||
rescaleBox->insertItem( KeepScales, "None" );
|
||||
rescaleBox->insertItem( Fixed, "Fixed" );
|
||||
rescaleBox->insertItem( Expanding, "Expanding" );
|
||||
rescaleBox->insertItem( Fitting, "Fitting" );
|
||||
|
||||
connect( rescaleBox, SIGNAL( activated( int ) ), SLOT( setRescaleMode( int ) ) );
|
||||
|
||||
d_rescaleInfo = new QLabel( panel );
|
||||
d_rescaleInfo->setSizePolicy(
|
||||
QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||
d_rescaleInfo->setWordWrap( true );
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout( panel );
|
||||
layout->addWidget( rescaleBox );
|
||||
layout->addWidget( d_rescaleInfo );
|
||||
layout->addStretch( 10 );
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
Plot *MainWindow::createPlot( QWidget *parent )
|
||||
{
|
||||
Plot *plot = new Plot( parent, QwtInterval( 0.0, 1000.0 ) );
|
||||
plot->replot();
|
||||
|
||||
d_rescaler = new QwtPlotRescaler( plot->canvas() );
|
||||
d_rescaler->setReferenceAxis( QwtPlot::xBottom );
|
||||
d_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
|
||||
d_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
|
||||
d_rescaler->setAspectRatio( QwtPlot::xTop, 0.0 );
|
||||
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
d_rescaler->setIntervalHint( axis, QwtInterval( 0.0, 1000.0 ) );
|
||||
|
||||
connect( plot, SIGNAL( resized( double, double ) ),
|
||||
SLOT( showRatio( double, double ) ) );
|
||||
return plot;
|
||||
}
|
||||
|
||||
void MainWindow::setRescaleMode( int mode )
|
||||
{
|
||||
bool doEnable = true;
|
||||
QString info;
|
||||
QRectF rectOfInterest;
|
||||
QwtPlotRescaler::ExpandingDirection direction = QwtPlotRescaler::ExpandUp;
|
||||
|
||||
switch( mode )
|
||||
{
|
||||
case KeepScales:
|
||||
{
|
||||
doEnable = false;
|
||||
info = "All scales remain unchanged, when the plot is resized";
|
||||
break;
|
||||
}
|
||||
case Fixed:
|
||||
{
|
||||
d_rescaler->setRescalePolicy( QwtPlotRescaler::Fixed );
|
||||
info = "The scale of the bottom axis remains unchanged, "
|
||||
"when the plot is resized. All other scales are changed, "
|
||||
"so that a pixel on screen means the same distance for"
|
||||
"all scales.";
|
||||
break;
|
||||
}
|
||||
case Expanding:
|
||||
{
|
||||
d_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
|
||||
info = "The scales of all axis are shrinked/expanded, when "
|
||||
"resizing the plot, keeping the distance that is represented "
|
||||
"by one pixel.";
|
||||
d_rescaleInfo->setText( "Expanding" );
|
||||
break;
|
||||
}
|
||||
case Fitting:
|
||||
{
|
||||
d_rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
|
||||
const QwtInterval xIntv =
|
||||
d_rescaler->intervalHint( QwtPlot::xBottom );
|
||||
const QwtInterval yIntv =
|
||||
d_rescaler->intervalHint( QwtPlot::yLeft );
|
||||
|
||||
rectOfInterest = QRectF( xIntv.minValue(), yIntv.minValue(),
|
||||
xIntv.width(), yIntv.width() );
|
||||
direction = QwtPlotRescaler::ExpandBoth;
|
||||
|
||||
info = "Fitting";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
d_plot->setRectOfInterest( rectOfInterest );
|
||||
|
||||
d_rescaleInfo->setText( info );
|
||||
d_rescaler->setEnabled( doEnable );
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
d_rescaler->setExpandingDirection( direction );
|
||||
|
||||
if ( doEnable )
|
||||
d_rescaler->rescale();
|
||||
else
|
||||
d_plot->replot();
|
||||
}
|
||||
|
||||
void MainWindow::showRatio( double xRatio, double yRatio )
|
||||
{
|
||||
const QString msg = QString( "%1, %2" ).arg( xRatio ).arg( yRatio );
|
||||
statusBar()->showMessage( msg );
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue