Add files from zip
This commit is contained in:
96
examples/polardemo/Pixmaps.h
Normal file
96
examples/polardemo/Pixmaps.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
static const char* print_xpm[] =
|
||||
{
|
||||
"32 32 12 1",
|
||||
"a c #ffffff",
|
||||
"h c #ffff00",
|
||||
"c c #ffffff",
|
||||
"f c #dcdcdc",
|
||||
"b c #c0c0c0",
|
||||
"j c #a0a0a4",
|
||||
"e c #808080",
|
||||
"g c #808000",
|
||||
"d c #585858",
|
||||
"i c #00ff00",
|
||||
"# c #000000",
|
||||
". c None",
|
||||
"................................",
|
||||
"................................",
|
||||
"...........###..................",
|
||||
"..........#abb###...............",
|
||||
".........#aabbbbb###............",
|
||||
".........#ddaaabbbbb###.........",
|
||||
"........#ddddddaaabbbbb###......",
|
||||
".......#deffddddddaaabbbbb###...",
|
||||
"......#deaaabbbddddddaaabbbbb###",
|
||||
".....#deaaaaaaabbbddddddaaabbbb#",
|
||||
"....#deaaabbbaaaa#ddedddfggaaad#",
|
||||
"...#deaaaaaaaaaa#ddeeeeafgggfdd#",
|
||||
"..#deaaabbbaaaa#ddeeeeabbbbgfdd#",
|
||||
".#deeefaaaaaaa#ddeeeeabbhhbbadd#",
|
||||
"#aabbbeeefaaa#ddeeeeabbbbbbaddd#",
|
||||
"#bbaaabbbeee#ddeeeeabbiibbadddd#",
|
||||
"#bbbbbaaabbbeeeeeeabbbbbbaddddd#",
|
||||
"#bjbbbbbbaaabbbbeabbbbbbadddddd#",
|
||||
"#bjjjjbbbbbbaaaeabbbbbbaddddddd#",
|
||||
"#bjaaajjjbbbbbbaaabbbbadddddddd#",
|
||||
"#bbbbbaaajjjbbbbbbaaaaddddddddd#",
|
||||
"#bjbbbbbbaaajjjbbbbbbddddddddd#.",
|
||||
"#bjjjjbbbbbbaaajjjbbbdddddddd#..",
|
||||
"#bjaaajjjbbbbbbjaajjbddddddd#...",
|
||||
"#bbbbbaaajjjbbbjbbaabdddddd#....",
|
||||
"###bbbbbbaaajjjjbbbbbddddd#.....",
|
||||
"...###bbbbbbaaajbbbbbdddd#......",
|
||||
"......###bbbbbbjbbbbbddd#.......",
|
||||
".........###bbbbbbbbbdd#........",
|
||||
"............###bbbbbbd#.........",
|
||||
"...............###bbb#..........",
|
||||
"..................###..........."
|
||||
};
|
||||
|
||||
|
||||
static const char* zoom_xpm[] =
|
||||
{
|
||||
"32 32 8 1",
|
||||
"# c #000000",
|
||||
"b c #c0c0c0",
|
||||
"a c #ffffff",
|
||||
"e c #585858",
|
||||
"d c #a0a0a4",
|
||||
"c c #0000ff",
|
||||
"f c #00ffff",
|
||||
". c None",
|
||||
"..######################........",
|
||||
".#a#baaaaaaaaaaaaaaaaaa#........",
|
||||
"#aa#baaaaaaaaaaaaaccaca#........",
|
||||
"####baaaaaaaaaaaaaaaaca####.....",
|
||||
"#bbbbaaaaaaaaaaaacccaaa#da#.....",
|
||||
"#aaaaaaaaaaaaaaaacccaca#da#.....",
|
||||
"#aaaaaaaaaaaaaaaaaccaca#da#.....",
|
||||
"#aaaaaaaaaabe###ebaaaaa#da#.....",
|
||||
"#aaaaaaaaa#########aaaa#da#.....",
|
||||
"#aaaaaaaa###dbbbb###aaa#da#.....",
|
||||
"#aaaaaaa###aaaaffb###aa#da#.....",
|
||||
"#aaaaaab##aaccaaafb##ba#da#.....",
|
||||
"#aaaaaae#daaccaccaad#ea#da#.....",
|
||||
"#aaaaaa##aaaaaaccaab##a#da#.....",
|
||||
"#aaaaaa##aacccaaaaab##a#da#.....",
|
||||
"#aaaaaa##aaccccaccab##a#da#.....",
|
||||
"#aaaaaae#daccccaccad#ea#da#.....",
|
||||
"#aaaaaab##aacccaaaa##da#da#.....",
|
||||
"#aaccacd###aaaaaaa###da#da#.....",
|
||||
"#aaaaacad###daaad#####a#da#.....",
|
||||
"#acccaaaad##########da##da#.....",
|
||||
"#acccacaaadde###edd#eda#da#.....",
|
||||
"#aaccacaaaabdddddbdd#eda#a#.....",
|
||||
"#aaaaaaaaaaaaaaaaaadd#eda##.....",
|
||||
"#aaaaaaaaaaaaaaaaaaadd#eda#.....",
|
||||
"#aaaaaaaccacaaaaaaaaadd#eda#....",
|
||||
"#aaaaaaaaaacaaaaaaaaaad##eda#...",
|
||||
"#aaaaaacccaaaaaaaaaaaaa#d#eda#..",
|
||||
"########################dd#eda#.",
|
||||
"...#dddddddddddddddddddddd##eda#",
|
||||
"...#aaaaaaaaaaaaaaaaaaaaaa#.####",
|
||||
"...########################..##."
|
||||
};
|
||||
300
examples/polardemo/Plot.cpp
Normal file
300
examples/polardemo/Plot.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
#include <QwtSeriesData>
|
||||
#include <QwtSymbol>
|
||||
#include <QwtLegend>
|
||||
#include <QwtPolarGrid>
|
||||
#include <QwtPolarCurve>
|
||||
#include <QwtPolarMarker>
|
||||
#include <QwtScaleEngine>
|
||||
|
||||
#include <QPen>
|
||||
|
||||
static const QwtInterval s_radialInterval( 0.0, 10.0 );
|
||||
static const QwtInterval s_azimuthInterval( 0.0, 360.0 );
|
||||
|
||||
namespace
|
||||
{
|
||||
class Data : public QwtSeriesData< QwtPointPolar >
|
||||
{
|
||||
public:
|
||||
Data( const QwtInterval& radialInterval,
|
||||
const QwtInterval& azimuthInterval, size_t size )
|
||||
: m_radialInterval( radialInterval )
|
||||
, m_azimuthInterval( azimuthInterval )
|
||||
, m_size( size )
|
||||
{
|
||||
}
|
||||
|
||||
virtual size_t size() const QWT_OVERRIDE
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
protected:
|
||||
QwtInterval m_radialInterval;
|
||||
QwtInterval m_azimuthInterval;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
class SpiralData : public Data
|
||||
{
|
||||
public:
|
||||
SpiralData( const QwtInterval& radialInterval,
|
||||
const QwtInterval& azimuthInterval, size_t size )
|
||||
: Data( radialInterval, azimuthInterval, size )
|
||||
{
|
||||
}
|
||||
|
||||
virtual QwtPointPolar sample( size_t i ) const QWT_OVERRIDE
|
||||
{
|
||||
const double stepA = 4 * m_azimuthInterval.width() / m_size;
|
||||
const double a = m_azimuthInterval.minValue() + i * stepA;
|
||||
|
||||
const double stepR = m_radialInterval.width() / m_size;
|
||||
const double r = m_radialInterval.minValue() + i * stepR;
|
||||
|
||||
return QwtPointPolar( a, r );
|
||||
}
|
||||
|
||||
virtual QRectF boundingRect() const QWT_OVERRIDE
|
||||
{
|
||||
if ( cachedBoundingRect.width() < 0.0 )
|
||||
cachedBoundingRect = qwtBoundingRect( *this );
|
||||
|
||||
return cachedBoundingRect;
|
||||
}
|
||||
};
|
||||
|
||||
class RoseData : public Data
|
||||
{
|
||||
public:
|
||||
RoseData( const QwtInterval& radialInterval,
|
||||
const QwtInterval& azimuthInterval, size_t size )
|
||||
: Data( radialInterval, azimuthInterval, size )
|
||||
{
|
||||
}
|
||||
|
||||
virtual QwtPointPolar sample( size_t i ) const QWT_OVERRIDE
|
||||
{
|
||||
const double stepA = m_azimuthInterval.width() / m_size;
|
||||
const double a = m_azimuthInterval.minValue() + i * stepA;
|
||||
|
||||
const double d = a / 360.0 * M_PI;
|
||||
const double r = m_radialInterval.maxValue() * qAbs( qSin( 4 * d ) );
|
||||
|
||||
return QwtPointPolar( a, r );
|
||||
}
|
||||
|
||||
virtual QRectF boundingRect() const QWT_OVERRIDE
|
||||
{
|
||||
if ( cachedBoundingRect.width() < 0.0 )
|
||||
cachedBoundingRect = qwtBoundingRect( *this );
|
||||
|
||||
return cachedBoundingRect;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPolarPlot( QwtText( "Polar Plot Demo" ), parent )
|
||||
{
|
||||
setAutoReplot( false );
|
||||
setPlotBackground( Qt::darkBlue );
|
||||
|
||||
// scales
|
||||
setScale( QwtPolar::Azimuth,
|
||||
s_azimuthInterval.minValue(), s_azimuthInterval.maxValue(),
|
||||
s_azimuthInterval.width() / 12 );
|
||||
|
||||
setScaleMaxMinor( QwtPolar::Azimuth, 2 );
|
||||
setScale( QwtPolar::Radius,
|
||||
s_radialInterval.minValue(), s_radialInterval.maxValue() );
|
||||
|
||||
// grids, axes
|
||||
|
||||
m_grid = new QwtPolarGrid();
|
||||
m_grid->setPen( QPen( Qt::white ) );
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
m_grid->showGrid( scaleId );
|
||||
m_grid->showMinorGrid( scaleId );
|
||||
|
||||
QPen minorPen( Qt::gray );
|
||||
#if 0
|
||||
minorPen.setStyle( Qt::DotLine );
|
||||
#endif
|
||||
m_grid->setMinorGridPen( scaleId, minorPen );
|
||||
}
|
||||
m_grid->setAxisPen( QwtPolar::AxisAzimuth, QPen( Qt::black ) );
|
||||
|
||||
m_grid->showAxis( QwtPolar::AxisAzimuth, true );
|
||||
m_grid->showAxis( QwtPolar::AxisLeft, false );
|
||||
m_grid->showAxis( QwtPolar::AxisRight, true );
|
||||
m_grid->showAxis( QwtPolar::AxisTop, true );
|
||||
m_grid->showAxis( QwtPolar::AxisBottom, false );
|
||||
m_grid->showGrid( QwtPolar::Azimuth, true );
|
||||
m_grid->showGrid( QwtPolar::Radius, true );
|
||||
m_grid->attach( this );
|
||||
|
||||
// curves
|
||||
|
||||
for ( int curveId = 0; curveId < PlotSettings::NumCurves; curveId++ )
|
||||
{
|
||||
m_curve[curveId] = createCurve( curveId );
|
||||
m_curve[curveId]->attach( this );
|
||||
}
|
||||
|
||||
// markers
|
||||
QwtPolarMarker* marker = new QwtPolarMarker();
|
||||
marker->setPosition( QwtPointPolar( 57.3, 4.72 ) );
|
||||
marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,
|
||||
QBrush( Qt::white ), QPen( Qt::green ), QSize( 9, 9 ) ) );
|
||||
marker->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );
|
||||
|
||||
QwtText text( "Marker" );
|
||||
text.setColor( Qt::black );
|
||||
QColor bg( Qt::white );
|
||||
bg.setAlpha( 200 );
|
||||
text.setBackgroundBrush( QBrush( bg ) );
|
||||
|
||||
marker->setLabel( text );
|
||||
marker->attach( this );
|
||||
|
||||
QwtLegend* legend = new QwtLegend;
|
||||
insertLegend( legend, QwtPolarPlot::BottomLegend );
|
||||
}
|
||||
|
||||
PlotSettings Plot::settings() const
|
||||
{
|
||||
PlotSettings s;
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
s.flags[PlotSettings::MajorGridBegin + scaleId] =
|
||||
m_grid->isGridVisible( scaleId );
|
||||
s.flags[PlotSettings::MinorGridBegin + scaleId] =
|
||||
m_grid->isMinorGridVisible( scaleId );
|
||||
}
|
||||
for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
|
||||
{
|
||||
s.flags[PlotSettings::AxisBegin + axisId] =
|
||||
m_grid->isAxisVisible( axisId );
|
||||
}
|
||||
|
||||
s.flags[PlotSettings::AutoScaling] =
|
||||
m_grid->testGridAttribute( QwtPolarGrid::AutoScaling );
|
||||
|
||||
s.flags[PlotSettings::Logarithmic] =
|
||||
scaleEngine( QwtPolar::Radius )->transformation();
|
||||
|
||||
const QwtScaleDiv* sd = scaleDiv( QwtPolar::Radius );
|
||||
s.flags[PlotSettings::Inverted] = sd->lowerBound() > sd->upperBound();
|
||||
|
||||
s.flags[PlotSettings::Antialiasing] =
|
||||
m_grid->testRenderHint( QwtPolarItem::RenderAntialiased );
|
||||
|
||||
for ( int curveId = 0; curveId < PlotSettings::NumCurves; curveId++ )
|
||||
{
|
||||
s.flags[PlotSettings::CurveBegin + curveId] =
|
||||
m_curve[curveId]->isVisible();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void Plot::applySettings( const PlotSettings& s )
|
||||
{
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
m_grid->showGrid( scaleId,
|
||||
s.flags[PlotSettings::MajorGridBegin + scaleId] );
|
||||
m_grid->showMinorGrid( scaleId,
|
||||
s.flags[PlotSettings::MinorGridBegin + scaleId] );
|
||||
}
|
||||
|
||||
for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
|
||||
{
|
||||
m_grid->showAxis( axisId,
|
||||
s.flags[PlotSettings::AxisBegin + axisId] );
|
||||
}
|
||||
|
||||
m_grid->setGridAttribute( QwtPolarGrid::AutoScaling,
|
||||
s.flags[PlotSettings::AutoScaling] );
|
||||
|
||||
const QwtInterval interval =
|
||||
scaleDiv( QwtPolar::Radius )->interval().normalized();
|
||||
if ( s.flags[PlotSettings::Inverted] )
|
||||
{
|
||||
setScale( QwtPolar::Radius,
|
||||
interval.maxValue(), interval.minValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setScale( QwtPolar::Radius,
|
||||
interval.minValue(), interval.maxValue() );
|
||||
}
|
||||
|
||||
if ( s.flags[PlotSettings::Logarithmic] )
|
||||
{
|
||||
setScaleEngine( QwtPolar::Radius, new QwtLogScaleEngine() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setScaleEngine( QwtPolar::Radius, new QwtLinearScaleEngine() );
|
||||
}
|
||||
|
||||
m_grid->setRenderHint( QwtPolarItem::RenderAntialiased,
|
||||
s.flags[PlotSettings::Antialiasing] );
|
||||
|
||||
for ( int curveId = 0; curveId < PlotSettings::NumCurves; curveId++ )
|
||||
{
|
||||
m_curve[curveId]->setRenderHint( QwtPolarItem::RenderAntialiased,
|
||||
s.flags[PlotSettings::Antialiasing] );
|
||||
m_curve[curveId]->setVisible(
|
||||
s.flags[PlotSettings::CurveBegin + curveId] );
|
||||
}
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
QwtPolarCurve* Plot::createCurve( int id ) const
|
||||
{
|
||||
const int numPoints = 200;
|
||||
|
||||
QwtPolarCurve* curve = new QwtPolarCurve();
|
||||
curve->setStyle( QwtPolarCurve::Lines );
|
||||
//curve->setLegendAttribute( QwtPolarCurve::LegendShowLine, true );
|
||||
//curve->setLegendAttribute( QwtPolarCurve::LegendShowSymbol, true );
|
||||
|
||||
switch( id )
|
||||
{
|
||||
case PlotSettings::Spiral:
|
||||
{
|
||||
curve->setTitle( "Spiral" );
|
||||
curve->setPen( QPen( Qt::yellow, 2 ) );
|
||||
curve->setSymbol( new QwtSymbol( QwtSymbol::Rect,
|
||||
QBrush( Qt::cyan ), QPen( Qt::white ), QSize( 3, 3 ) ) );
|
||||
curve->setData(
|
||||
new SpiralData( s_radialInterval, s_azimuthInterval, numPoints ) );
|
||||
break;
|
||||
}
|
||||
case PlotSettings::Rose:
|
||||
{
|
||||
curve->setTitle( "Rose" );
|
||||
curve->setPen( QPen( Qt::red, 2 ) );
|
||||
curve->setSymbol( new QwtSymbol( QwtSymbol::Rect,
|
||||
QBrush( Qt::cyan ), QPen( Qt::white ), QSize( 3, 3 ) ) );
|
||||
curve->setData(
|
||||
new RoseData( s_radialInterval, s_azimuthInterval, numPoints ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
return curve;
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
60
examples/polardemo/Plot.h
Normal file
60
examples/polardemo/Plot.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QwtPolarPlot>
|
||||
|
||||
class QwtPolarGrid;
|
||||
class QwtPolarCurve;
|
||||
|
||||
class PlotSettings
|
||||
{
|
||||
public:
|
||||
enum Curve
|
||||
{
|
||||
Spiral,
|
||||
Rose,
|
||||
|
||||
NumCurves
|
||||
};
|
||||
|
||||
enum Flag
|
||||
{
|
||||
MajorGridBegin,
|
||||
MinorGridBegin = MajorGridBegin + QwtPolar::ScaleCount,
|
||||
AxisBegin = MinorGridBegin + QwtPolar::ScaleCount,
|
||||
|
||||
AutoScaling = AxisBegin + QwtPolar::AxesCount,
|
||||
Inverted,
|
||||
Logarithmic,
|
||||
|
||||
Antialiasing,
|
||||
|
||||
CurveBegin,
|
||||
|
||||
NumFlags = CurveBegin + NumCurves
|
||||
};
|
||||
|
||||
bool flags[NumFlags];
|
||||
};
|
||||
|
||||
class Plot : public QwtPolarPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* = NULL );
|
||||
PlotSettings settings() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void applySettings( const PlotSettings& );
|
||||
|
||||
private:
|
||||
QwtPolarCurve* createCurve( int id ) const;
|
||||
|
||||
QwtPolarGrid* m_grid;
|
||||
QwtPolarCurve* m_curve[PlotSettings::NumCurves];
|
||||
};
|
||||
79
examples/polardemo/PlotBox.cpp
Normal file
79
examples/polardemo/PlotBox.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "PlotBox.h"
|
||||
#include "Plot.h"
|
||||
#include "SettingsEditor.h"
|
||||
|
||||
#include <QwtPolarPanner>
|
||||
#include <QwtPolarMagnifier>
|
||||
#include <QwtPolarRenderer>
|
||||
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
PlotBox::PlotBox( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
m_plot = new Plot();
|
||||
|
||||
m_panner = new QwtPolarPanner( m_plot->canvas() );
|
||||
m_panner->setEnabled( false );
|
||||
|
||||
m_zoomer = new QwtPolarMagnifier( m_plot->canvas() );
|
||||
m_zoomer->setEnabled( false );
|
||||
|
||||
SettingsEditor* settingsEditor = new SettingsEditor();
|
||||
settingsEditor->showSettings( m_plot->settings() );
|
||||
connect( settingsEditor, SIGNAL(edited(const PlotSettings&)),
|
||||
m_plot, SLOT(applySettings(const PlotSettings&)) );
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout( this );
|
||||
layout->addWidget( settingsEditor, 0 );
|
||||
layout->addWidget( m_plot, 10 );
|
||||
}
|
||||
|
||||
void PlotBox::printDocument()
|
||||
{
|
||||
QPrinter printer( QPrinter::HighResolution );
|
||||
|
||||
QString docName = m_plot->title().text();
|
||||
if ( !docName.isEmpty() )
|
||||
{
|
||||
docName.replace ( "\n", " -- " );
|
||||
printer.setDocName ( docName );
|
||||
}
|
||||
|
||||
printer.setCreator( "polar plot demo example" );
|
||||
#if QT_VERSION >= 0x050300
|
||||
printer.setPageOrientation( QPageLayout::Landscape );
|
||||
#else
|
||||
printer.setOrientation( QPrinter::Landscape );
|
||||
#endif
|
||||
|
||||
QPrintDialog dialog( &printer );
|
||||
if ( dialog.exec() )
|
||||
{
|
||||
QwtPolarRenderer renderer;
|
||||
renderer.renderTo( m_plot, printer );
|
||||
}
|
||||
}
|
||||
|
||||
void PlotBox::exportDocument()
|
||||
{
|
||||
QString fileName = "polarplot.pdf";
|
||||
|
||||
QwtPolarRenderer renderer;
|
||||
renderer.exportTo( m_plot, "polarplot.pdf" );
|
||||
}
|
||||
|
||||
void PlotBox::enableZoomMode( bool on )
|
||||
{
|
||||
m_panner->setEnabled( on );
|
||||
m_zoomer->setEnabled( on );
|
||||
}
|
||||
|
||||
#include "moc_PlotBox.cpp"
|
||||
30
examples/polardemo/PlotBox.h
Normal file
30
examples/polardemo/PlotBox.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class Plot;
|
||||
class QwtPolarPanner;
|
||||
class QwtPolarMagnifier;
|
||||
|
||||
class PlotBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotBox( QWidget* parent = nullptr );
|
||||
|
||||
private Q_SLOTS:
|
||||
void enableZoomMode( bool on );
|
||||
void printDocument();
|
||||
void exportDocument();
|
||||
|
||||
private:
|
||||
Plot* m_plot;
|
||||
QwtPolarPanner* m_panner;
|
||||
QwtPolarMagnifier* m_zoomer;
|
||||
};
|
||||
155
examples/polardemo/SettingsEditor.cpp
Normal file
155
examples/polardemo/SettingsEditor.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SettingsEditor.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLayout>
|
||||
|
||||
SettingsEditor::SettingsEditor( QWidget* parent )
|
||||
: QFrame( parent )
|
||||
{
|
||||
const int margin = 20;
|
||||
|
||||
QGroupBox* axesBox = new QGroupBox( "Axes", this );
|
||||
QVBoxLayout* axesBoxLayout = new QVBoxLayout( axesBox );
|
||||
axesBoxLayout->setContentsMargins( margin, margin, margin, margin );
|
||||
|
||||
for ( int i = PlotSettings::AxisBegin;
|
||||
i <= PlotSettings::Logarithmic; i++ )
|
||||
{
|
||||
m_checkBox[i] = new QCheckBox( axesBox );
|
||||
axesBoxLayout->addWidget( m_checkBox[i] );
|
||||
}
|
||||
|
||||
QGroupBox* gridBox = new QGroupBox( "Grids", this );
|
||||
QVBoxLayout* gridBoxLayout = new QVBoxLayout( gridBox );
|
||||
gridBoxLayout->setContentsMargins( margin, margin, margin, margin );
|
||||
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
int idx = PlotSettings::MajorGridBegin + scaleId;
|
||||
m_checkBox[idx] = new QCheckBox( gridBox );
|
||||
gridBoxLayout->addWidget( m_checkBox[idx] );
|
||||
|
||||
idx = PlotSettings::MinorGridBegin + scaleId;
|
||||
m_checkBox[idx] = new QCheckBox( gridBox );
|
||||
gridBoxLayout->addWidget( m_checkBox[idx] );
|
||||
}
|
||||
gridBoxLayout->addStretch( 10 );
|
||||
|
||||
QGroupBox* otherBox = new QGroupBox( "Other", this );
|
||||
QVBoxLayout* otherBoxLayout = new QVBoxLayout( otherBox );
|
||||
otherBoxLayout->setContentsMargins( margin, margin, margin, margin );
|
||||
|
||||
for ( int i = PlotSettings::Logarithmic + 1;
|
||||
i < PlotSettings::NumFlags; i++ )
|
||||
{
|
||||
m_checkBox[i] = new QCheckBox( otherBox );
|
||||
otherBoxLayout->addWidget( m_checkBox[i] );
|
||||
}
|
||||
otherBoxLayout->addStretch( 10 );
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->addWidget( axesBox );
|
||||
layout->addWidget( gridBox );
|
||||
layout->addWidget( otherBox );
|
||||
layout->addStretch( 10 );
|
||||
|
||||
for ( int i = 0; i < PlotSettings::NumFlags; i++ )
|
||||
{
|
||||
m_checkBox[i]->setText( label( i ) );
|
||||
connect( m_checkBox[i], SIGNAL(clicked()), this, SLOT(edited()) );
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsEditor::showSettings( const PlotSettings& settings )
|
||||
{
|
||||
blockSignals( true );
|
||||
for ( int i = 0; i < PlotSettings::NumFlags; i++ )
|
||||
m_checkBox[i]->setChecked( settings.flags[i] );
|
||||
|
||||
blockSignals( false );
|
||||
updateEditor();
|
||||
}
|
||||
|
||||
PlotSettings SettingsEditor::settings() const
|
||||
{
|
||||
PlotSettings s;
|
||||
for ( int i = 0; i < PlotSettings::NumFlags; i++ )
|
||||
s.flags[i] = m_checkBox[i]->isChecked();
|
||||
return s;
|
||||
}
|
||||
|
||||
void SettingsEditor::edited()
|
||||
{
|
||||
updateEditor();
|
||||
Q_EMIT edited( settings() );
|
||||
}
|
||||
|
||||
void SettingsEditor::updateEditor()
|
||||
{
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
m_checkBox[PlotSettings::MinorGridBegin + scaleId]->setEnabled(
|
||||
m_checkBox[PlotSettings::MajorGridBegin + scaleId]->isChecked() );
|
||||
}
|
||||
}
|
||||
|
||||
QString SettingsEditor::label( int flag ) const
|
||||
{
|
||||
switch( flag )
|
||||
{
|
||||
case PlotSettings::MajorGridBegin + QwtPolar::ScaleAzimuth:
|
||||
return "Azimuth";
|
||||
|
||||
case PlotSettings::MajorGridBegin + QwtPolar::ScaleRadius:
|
||||
return "Radius";
|
||||
|
||||
case PlotSettings::MinorGridBegin + QwtPolar::ScaleAzimuth:
|
||||
return "Azimuth Minor";
|
||||
|
||||
case PlotSettings::MinorGridBegin + QwtPolar::ScaleRadius:
|
||||
return "Radius Minor";
|
||||
|
||||
case PlotSettings::AxisBegin + QwtPolar::AxisAzimuth:
|
||||
return "Azimuth";
|
||||
|
||||
case PlotSettings::AxisBegin + QwtPolar::AxisLeft:
|
||||
return "Left";
|
||||
|
||||
case PlotSettings::AxisBegin + QwtPolar::AxisRight:
|
||||
return "Right";
|
||||
|
||||
case PlotSettings::AxisBegin + QwtPolar::AxisTop:
|
||||
return "Top";
|
||||
|
||||
case PlotSettings::AxisBegin + QwtPolar::AxisBottom:
|
||||
return "Bottom";
|
||||
|
||||
case PlotSettings::AutoScaling:
|
||||
return "Auto Scaling";
|
||||
|
||||
case PlotSettings::Inverted:
|
||||
return "Inverted";
|
||||
|
||||
case PlotSettings::Logarithmic:
|
||||
return "Logarithmic";
|
||||
|
||||
case PlotSettings::Antialiasing:
|
||||
return "Antialiasing";
|
||||
|
||||
case PlotSettings::CurveBegin + PlotSettings::Spiral:
|
||||
return "Spiral Curve";
|
||||
|
||||
case PlotSettings::CurveBegin + PlotSettings::Rose:
|
||||
return "Rose Curve";
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
#include "moc_SettingsEditor.cpp"
|
||||
34
examples/polardemo/SettingsEditor.h
Normal file
34
examples/polardemo/SettingsEditor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Plot.h"
|
||||
#include <QFrame>
|
||||
|
||||
class QCheckBox;
|
||||
|
||||
class SettingsEditor : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SettingsEditor( QWidget* parent = NULL );
|
||||
|
||||
void showSettings( const PlotSettings& );
|
||||
PlotSettings settings() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void edited( const PlotSettings& );
|
||||
|
||||
private Q_SLOTS:
|
||||
void edited();
|
||||
|
||||
private:
|
||||
void updateEditor();
|
||||
QString label( int flag ) const;
|
||||
|
||||
QCheckBox* m_checkBox[PlotSettings::NumFlags];
|
||||
};
|
||||
73
examples/polardemo/main.cpp
Normal file
73
examples/polardemo/main.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "PlotBox.h"
|
||||
#include "Pixmaps.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace
|
||||
{
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWindow()
|
||||
{
|
||||
PlotBox* plotBox = new PlotBox( this );
|
||||
setCentralWidget( plotBox );
|
||||
|
||||
QToolButton* btnZoom = new QToolButton();
|
||||
|
||||
const QString zoomHelp =
|
||||
"Use the wheel to zoom in/out.\n"
|
||||
"When the plot is zoomed in,\n"
|
||||
"use the left mouse button to move it.";
|
||||
|
||||
btnZoom->setText( "Zoom" );
|
||||
btnZoom->setIcon( QPixmap( zoom_xpm ) );
|
||||
btnZoom->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
btnZoom->setToolTip( zoomHelp );
|
||||
btnZoom->setCheckable( true );
|
||||
connect( btnZoom, SIGNAL(toggled(bool)),
|
||||
plotBox, SLOT(enableZoomMode(bool)) );
|
||||
|
||||
QToolButton* btnPrint = new QToolButton();
|
||||
btnPrint->setText( "Print" );
|
||||
btnPrint->setIcon( QPixmap( print_xpm ) );
|
||||
btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
connect( btnPrint, SIGNAL(clicked()),
|
||||
plotBox, SLOT(printDocument()) );
|
||||
|
||||
QToolButton* btnExport = new QToolButton();
|
||||
btnExport->setText( "Export" );
|
||||
btnExport->setIcon( QPixmap( print_xpm ) );
|
||||
btnExport->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
|
||||
QToolBar* toolBar = new QToolBar();
|
||||
toolBar->addWidget( btnZoom );
|
||||
toolBar->addWidget( btnPrint );
|
||||
toolBar->addWidget( btnExport );
|
||||
|
||||
connect( btnExport, SIGNAL(clicked()),
|
||||
plotBox, SLOT(exportDocument()) );
|
||||
|
||||
addToolBar( toolBar );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
MainWindow window;
|
||||
window.resize( 800, 600 );
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
8
examples/polardemo/polar.css
Normal file
8
examples/polardemo/polar.css
Normal file
@@ -0,0 +1,8 @@
|
||||
QwtPolarPlot
|
||||
{
|
||||
border: 2px solid Blue;
|
||||
border-radius: 5px;
|
||||
background-color: Gray;
|
||||
color: palette(light);
|
||||
padding: 10px;
|
||||
}
|
||||
20
examples/polardemo/polardemo.pro
Normal file
20
examples/polardemo/polardemo.pro
Normal file
@@ -0,0 +1,20 @@
|
||||
######################################################################
|
||||
# Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
# This file may be used under the terms of the 3-clause BSD License
|
||||
######################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = polardemo
|
||||
|
||||
HEADERS = \
|
||||
Pixmaps.h \
|
||||
PlotBox.h \
|
||||
Plot.h \
|
||||
SettingsEditor.h
|
||||
|
||||
SOURCES = \
|
||||
PlotBox.cpp \
|
||||
Plot.cpp \
|
||||
SettingsEditor.cpp \
|
||||
main.cpp
|
||||
Reference in New Issue
Block a user