Add files from zip
This commit is contained in:
69
examples/legends/MainWindow.cpp
Normal file
69
examples/legends/MainWindow.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************
|
||||
* 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 "Panel.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QwtPlotRenderer>
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QLayout>
|
||||
|
||||
MainWindow::MainWindow( QWidget* parent )
|
||||
: QMainWindow( parent )
|
||||
{
|
||||
m_plot = new Plot();
|
||||
|
||||
Settings settings;
|
||||
settings.legend.isEnabled = true;
|
||||
settings.legend.position = QwtPlot::BottomLegend;
|
||||
|
||||
settings.legendItem.isEnabled = false;
|
||||
settings.legendItem.numColumns = 1;
|
||||
settings.legendItem.alignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||
settings.legendItem.backgroundMode = 0;
|
||||
settings.legendItem.size = m_plot->canvas()->font().pointSize();
|
||||
|
||||
settings.curve.numCurves = 4;
|
||||
settings.curve.title = "Curve";
|
||||
|
||||
m_panel = new Panel();
|
||||
m_panel->setSettings( settings );
|
||||
|
||||
QWidget* box = new QWidget( this );
|
||||
QHBoxLayout* layout = new QHBoxLayout( box );
|
||||
layout->addWidget( m_plot, 10 );
|
||||
layout->addWidget( m_panel );
|
||||
|
||||
setCentralWidget( box );
|
||||
|
||||
QToolBar* toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton* btnExport = new QToolButton( toolBar );
|
||||
btnExport->setText( "Export" );
|
||||
toolBar->addWidget( btnExport );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
updatePlot();
|
||||
|
||||
connect( m_panel, SIGNAL(edited()), SLOT(updatePlot()) );
|
||||
connect( btnExport, SIGNAL(clicked()), SLOT(exportPlot()) );
|
||||
}
|
||||
|
||||
void MainWindow::updatePlot()
|
||||
{
|
||||
m_plot->applySettings( m_panel->settings() );
|
||||
}
|
||||
|
||||
void MainWindow::exportPlot()
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
renderer.exportTo( m_plot, "legends.pdf" );
|
||||
}
|
||||
|
||||
#include "moc_MainWindow.cpp"
|
||||
27
examples/legends/MainWindow.h
Normal file
27
examples/legends/MainWindow.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class Plot;
|
||||
class Panel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget* parent = 0 );
|
||||
|
||||
private Q_SLOTS:
|
||||
void updatePlot();
|
||||
void exportPlot();
|
||||
|
||||
private:
|
||||
Plot* m_plot;
|
||||
Panel* m_panel;
|
||||
};
|
||||
225
examples/legends/Panel.cpp
Normal file
225
examples/legends/Panel.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <QwtPlot>
|
||||
#include <QwtPlotLegendItem>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
Panel::Panel( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
// create widgets
|
||||
|
||||
m_legend.checkBox = new QCheckBox( "Enabled" );
|
||||
|
||||
m_legend.positionBox = new QComboBox();
|
||||
m_legend.positionBox->addItem( "Left", QwtPlot::LeftLegend );
|
||||
m_legend.positionBox->addItem( "Right", QwtPlot::RightLegend );
|
||||
m_legend.positionBox->addItem( "Bottom", QwtPlot::BottomLegend );
|
||||
m_legend.positionBox->addItem( "Top", QwtPlot::TopLegend );
|
||||
m_legend.positionBox->addItem( "External", QwtPlot::TopLegend + 1 );
|
||||
|
||||
m_legendItem.checkBox = new QCheckBox( "Enabled" );
|
||||
|
||||
m_legendItem.numColumnsBox = new QSpinBox();
|
||||
m_legendItem.numColumnsBox->setRange( 0, 10 );
|
||||
m_legendItem.numColumnsBox->setSpecialValueText( "Unlimited" );
|
||||
|
||||
m_legendItem.hAlignmentBox = new QComboBox();
|
||||
m_legendItem.hAlignmentBox->addItem( "Left", Qt::AlignLeft );
|
||||
m_legendItem.hAlignmentBox->addItem( "Centered", Qt::AlignHCenter );
|
||||
m_legendItem.hAlignmentBox->addItem( "Right", Qt::AlignRight );
|
||||
|
||||
m_legendItem.vAlignmentBox = new QComboBox();
|
||||
m_legendItem.vAlignmentBox->addItem( "Top", Qt::AlignTop );
|
||||
m_legendItem.vAlignmentBox->addItem( "Centered", Qt::AlignVCenter );
|
||||
m_legendItem.vAlignmentBox->addItem( "Bottom", Qt::AlignBottom );
|
||||
|
||||
m_legendItem.backgroundBox = new QComboBox();
|
||||
m_legendItem.backgroundBox->addItem( "Legend",
|
||||
QwtPlotLegendItem::LegendBackground );
|
||||
m_legendItem.backgroundBox->addItem( "Items",
|
||||
QwtPlotLegendItem::ItemBackground );
|
||||
|
||||
m_legendItem.sizeBox = new QSpinBox();
|
||||
m_legendItem.sizeBox->setRange( 8, 22 );
|
||||
|
||||
m_curve.numCurves = new QSpinBox();
|
||||
m_curve.numCurves->setRange( 0, 99 );
|
||||
|
||||
m_curve.title = new QLineEdit();
|
||||
|
||||
// layout
|
||||
|
||||
QGroupBox* legendBox = new QGroupBox( "Legend" );
|
||||
QGridLayout* legendBoxLayout = new QGridLayout( legendBox );
|
||||
|
||||
int row = 0;
|
||||
legendBoxLayout->addWidget( m_legend.checkBox, row, 0, 1, -1 );
|
||||
|
||||
row++;
|
||||
legendBoxLayout->addWidget( new QLabel( "Position" ), row, 0 );
|
||||
legendBoxLayout->addWidget( m_legend.positionBox, row, 1 );
|
||||
|
||||
|
||||
QGroupBox* legendItemBox = new QGroupBox( "Legend Item" );
|
||||
QGridLayout* legendItemBoxLayout = new QGridLayout( legendItemBox );
|
||||
|
||||
row = 0;
|
||||
legendItemBoxLayout->addWidget( m_legendItem.checkBox, row, 0, 1, -1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Columns" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( m_legendItem.numColumnsBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Horizontal" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( m_legendItem.hAlignmentBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Vertical" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( m_legendItem.vAlignmentBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Background" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( m_legendItem.backgroundBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Size" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( m_legendItem.sizeBox, row, 1 );
|
||||
|
||||
QGroupBox* curveBox = new QGroupBox( "Curves" );
|
||||
QGridLayout* curveBoxLayout = new QGridLayout( curveBox );
|
||||
|
||||
row = 0;
|
||||
curveBoxLayout->addWidget( new QLabel( "Number" ), row, 0 );
|
||||
curveBoxLayout->addWidget( m_curve.numCurves, row, 1 );
|
||||
|
||||
row++;
|
||||
curveBoxLayout->addWidget( new QLabel( "Title" ), row, 0 );
|
||||
curveBoxLayout->addWidget( m_curve.title, row, 1 );
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->addWidget( legendBox );
|
||||
layout->addWidget( legendItemBox );
|
||||
layout->addWidget( curveBox );
|
||||
layout->addStretch( 10 );
|
||||
|
||||
connect( m_legend.checkBox,
|
||||
SIGNAL(stateChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legend.positionBox,
|
||||
SIGNAL(currentIndexChanged(int)), SIGNAL(edited()) );
|
||||
|
||||
connect( m_legendItem.checkBox,
|
||||
SIGNAL(stateChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legendItem.numColumnsBox,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legendItem.hAlignmentBox,
|
||||
SIGNAL(currentIndexChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legendItem.vAlignmentBox,
|
||||
SIGNAL(currentIndexChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legendItem.backgroundBox,
|
||||
SIGNAL(currentIndexChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_curve.numCurves,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_legendItem.sizeBox,
|
||||
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
|
||||
connect( m_curve.title,
|
||||
SIGNAL(textEdited(const QString&)), SIGNAL(edited()) );
|
||||
}
|
||||
|
||||
void Panel::setSettings( const Settings& settings)
|
||||
{
|
||||
blockSignals( true );
|
||||
|
||||
m_legend.checkBox->setCheckState(
|
||||
settings.legend.isEnabled ? Qt::Checked : Qt::Unchecked );
|
||||
m_legend.positionBox->setCurrentIndex( settings.legend.position );
|
||||
|
||||
m_legendItem.checkBox->setCheckState(
|
||||
settings.legendItem.isEnabled ? Qt::Checked : Qt::Unchecked );
|
||||
|
||||
m_legendItem.numColumnsBox->setValue( settings.legendItem.numColumns );
|
||||
|
||||
int align = settings.legendItem.alignment;
|
||||
|
||||
if ( align & Qt::AlignLeft )
|
||||
m_legendItem.hAlignmentBox->setCurrentIndex( 0 );
|
||||
else if ( align & Qt::AlignRight )
|
||||
m_legendItem.hAlignmentBox->setCurrentIndex( 2 );
|
||||
else
|
||||
m_legendItem.hAlignmentBox->setCurrentIndex( 1 );
|
||||
|
||||
if ( align & Qt::AlignTop )
|
||||
m_legendItem.vAlignmentBox->setCurrentIndex( 0 );
|
||||
else if ( align & Qt::AlignBottom )
|
||||
m_legendItem.vAlignmentBox->setCurrentIndex( 2 );
|
||||
else
|
||||
m_legendItem.vAlignmentBox->setCurrentIndex( 1 );
|
||||
|
||||
m_legendItem.backgroundBox->setCurrentIndex(
|
||||
settings.legendItem.backgroundMode );
|
||||
|
||||
m_legendItem.sizeBox->setValue( settings.legendItem.size );
|
||||
|
||||
m_curve.numCurves->setValue( settings.curve.numCurves );
|
||||
m_curve.title->setText( settings.curve.title );
|
||||
|
||||
blockSignals( false );
|
||||
}
|
||||
|
||||
Settings Panel::settings() const
|
||||
{
|
||||
Settings s;
|
||||
|
||||
s.legend.isEnabled =
|
||||
m_legend.checkBox->checkState() == Qt::Checked;
|
||||
s.legend.position = m_legend.positionBox->currentIndex();
|
||||
|
||||
s.legendItem.isEnabled =
|
||||
m_legendItem.checkBox->checkState() == Qt::Checked;
|
||||
s.legendItem.numColumns = m_legendItem.numColumnsBox->value();
|
||||
|
||||
int align = 0;
|
||||
|
||||
int hIndex = m_legendItem.hAlignmentBox->currentIndex();
|
||||
if ( hIndex == 0 )
|
||||
align |= Qt::AlignLeft;
|
||||
else if ( hIndex == 2 )
|
||||
align |= Qt::AlignRight;
|
||||
else
|
||||
align |= Qt::AlignHCenter;
|
||||
|
||||
int vIndex = m_legendItem.vAlignmentBox->currentIndex();
|
||||
if ( vIndex == 0 )
|
||||
align |= Qt::AlignTop;
|
||||
else if ( vIndex == 2 )
|
||||
align |= Qt::AlignBottom;
|
||||
else
|
||||
align |= Qt::AlignVCenter;
|
||||
|
||||
s.legendItem.alignment = align;
|
||||
|
||||
s.legendItem.backgroundMode =
|
||||
m_legendItem.backgroundBox->currentIndex();
|
||||
s.legendItem.size = m_legendItem.sizeBox->value();
|
||||
|
||||
s.curve.numCurves = m_curve.numCurves->value();
|
||||
s.curve.title = m_curve.title->text();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#include "moc_Panel.cpp"
|
||||
54
examples/legends/Panel.h
Normal file
54
examples/legends/Panel.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Settings.h"
|
||||
#include <QWidget>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QSpinBox;
|
||||
class QLineEdit;
|
||||
|
||||
class Panel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Panel( QWidget* parent = NULL );
|
||||
|
||||
void setSettings( const Settings&);
|
||||
Settings settings() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void edited();
|
||||
|
||||
private:
|
||||
struct
|
||||
{
|
||||
QCheckBox* checkBox;
|
||||
QComboBox* positionBox;
|
||||
|
||||
} m_legend;
|
||||
|
||||
struct
|
||||
{
|
||||
QCheckBox* checkBox;
|
||||
QSpinBox* numColumnsBox;
|
||||
QComboBox* hAlignmentBox;
|
||||
QComboBox* vAlignmentBox;
|
||||
QComboBox* backgroundBox;
|
||||
QSpinBox* sizeBox;
|
||||
|
||||
} m_legendItem;
|
||||
|
||||
struct
|
||||
{
|
||||
QSpinBox* numCurves;
|
||||
QLineEdit* title;
|
||||
|
||||
} m_curve;
|
||||
};
|
||||
272
examples/legends/Plot.cpp
Normal file
272
examples/legends/Plot.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
/*****************************************************************************
|
||||
* 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 "Settings.h"
|
||||
|
||||
#include <QwtPlotCurve>
|
||||
#include <QwtPlotLegendItem>
|
||||
#include <QwtLegend>
|
||||
#include <QwtPlotCanvas>
|
||||
#include <QwtPlotGrid>
|
||||
#include <QwtPlotLayout>
|
||||
#include <QwtMath>
|
||||
|
||||
#include <QPen>
|
||||
|
||||
namespace
|
||||
{
|
||||
class LegendItem : public QwtPlotLegendItem
|
||||
{
|
||||
public:
|
||||
LegendItem()
|
||||
{
|
||||
setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
|
||||
const QColor c1( Qt::white );
|
||||
|
||||
setTextPen( c1 );
|
||||
setBorderPen( c1 );
|
||||
|
||||
QColor c2( Qt::gray );
|
||||
c2.setAlpha( 200 );
|
||||
|
||||
setBackgroundBrush( c2 );
|
||||
}
|
||||
};
|
||||
|
||||
class Curve : public QwtPlotCurve
|
||||
{
|
||||
public:
|
||||
Curve( int index ):
|
||||
m_index( index )
|
||||
{
|
||||
setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
initData();
|
||||
}
|
||||
|
||||
void setCurveTitle( const QString& title )
|
||||
{
|
||||
QString txt("%1 %2");
|
||||
setTitle( QString( "%1 %2" ).arg( title ).arg( m_index ) );
|
||||
}
|
||||
|
||||
void initData()
|
||||
{
|
||||
QVector< QPointF > points;
|
||||
|
||||
double y = qwtRand() % 1000;
|
||||
|
||||
for ( double x = 0.0; x <= 1000.0; x += 100.0 )
|
||||
{
|
||||
double off = qwtRand() % 200 - 100;
|
||||
if ( y + off > 980.0 || y + off < 20.0 )
|
||||
off = -off;
|
||||
|
||||
y += off;
|
||||
|
||||
points += QPointF( x, y );
|
||||
}
|
||||
|
||||
setSamples( points );
|
||||
}
|
||||
|
||||
private:
|
||||
const int m_index;
|
||||
};
|
||||
}
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPlot( parent )
|
||||
, m_externalLegend( NULL )
|
||||
, m_legendItem( NULL )
|
||||
, m_isDirty( false )
|
||||
{
|
||||
QwtPlotCanvas* canvas = new QwtPlotCanvas();
|
||||
canvas->setFocusIndicator( QwtPlotCanvas::CanvasFocusIndicator );
|
||||
canvas->setFocusPolicy( Qt::StrongFocus );
|
||||
canvas->setPalette( Qt::black );
|
||||
setCanvas( canvas );
|
||||
|
||||
setAutoReplot( false );
|
||||
|
||||
setTitle( "Legend Test" );
|
||||
setFooter( "Footer" );
|
||||
|
||||
// grid
|
||||
QwtPlotGrid* grid = new QwtPlotGrid;
|
||||
grid->enableXMin( true );
|
||||
grid->setMajorPen( Qt::gray, 0, Qt::DotLine );
|
||||
grid->setMinorPen( Qt::darkGray, 0, Qt::DotLine );
|
||||
grid->attach( this );
|
||||
|
||||
// axis
|
||||
setAxisScale( QwtAxis::YLeft, 0.0, 1000.0 );
|
||||
setAxisScale( QwtAxis::XBottom, 0.0, 1000.0 );
|
||||
}
|
||||
|
||||
Plot::~Plot()
|
||||
{
|
||||
delete m_externalLegend;
|
||||
}
|
||||
|
||||
void Plot::insertCurve()
|
||||
{
|
||||
static int counter = 1;
|
||||
|
||||
const char* colors[] =
|
||||
{
|
||||
"LightSalmon",
|
||||
"SteelBlue",
|
||||
"Yellow",
|
||||
"Fuchsia",
|
||||
"PaleGreen",
|
||||
"PaleTurquoise",
|
||||
"Cornsilk",
|
||||
"HotPink",
|
||||
"Peru",
|
||||
"Maroon"
|
||||
};
|
||||
const int numColors = sizeof( colors ) / sizeof( colors[0] );
|
||||
|
||||
QwtPlotCurve* curve = new Curve( counter++ );
|
||||
curve->setPen( QColor( colors[ counter % numColors ] ), 2 );
|
||||
curve->attach( this );
|
||||
}
|
||||
|
||||
void Plot::applySettings( const Settings& settings )
|
||||
{
|
||||
m_isDirty = false;
|
||||
setAutoReplot( true );
|
||||
|
||||
if ( settings.legend.isEnabled )
|
||||
{
|
||||
if ( settings.legend.position > QwtPlot::TopLegend )
|
||||
{
|
||||
if ( legend() )
|
||||
{
|
||||
// remove legend controlled by the plot
|
||||
insertLegend( NULL );
|
||||
}
|
||||
|
||||
if ( m_externalLegend == NULL )
|
||||
{
|
||||
m_externalLegend = new QwtLegend();
|
||||
m_externalLegend->setWindowTitle("Plot Legend");
|
||||
|
||||
connect(
|
||||
this,
|
||||
SIGNAL(legendDataChanged(const QVariant&,const QList<QwtLegendData>&)),
|
||||
m_externalLegend,
|
||||
SLOT(updateLegend(const QVariant&,const QList<QwtLegendData>&)) );
|
||||
|
||||
m_externalLegend->show();
|
||||
|
||||
// populate the new legend
|
||||
updateLegend();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_externalLegend;
|
||||
m_externalLegend = NULL;
|
||||
|
||||
if ( legend() == NULL ||
|
||||
plotLayout()->legendPosition() != settings.legend.position )
|
||||
{
|
||||
insertLegend( new QwtLegend(),
|
||||
QwtPlot::LegendPosition( settings.legend.position ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
insertLegend( NULL );
|
||||
|
||||
delete m_externalLegend;
|
||||
m_externalLegend = NULL;
|
||||
}
|
||||
|
||||
if ( settings.legendItem.isEnabled )
|
||||
{
|
||||
if ( m_legendItem == NULL )
|
||||
{
|
||||
m_legendItem = new LegendItem();
|
||||
m_legendItem->attach( this );
|
||||
}
|
||||
|
||||
m_legendItem->setMaxColumns( settings.legendItem.numColumns );
|
||||
m_legendItem->setAlignmentInCanvas( Qt::Alignment( settings.legendItem.alignment ) );
|
||||
m_legendItem->setBackgroundMode(
|
||||
QwtPlotLegendItem::BackgroundMode( settings.legendItem.backgroundMode ) );
|
||||
if ( settings.legendItem.backgroundMode ==
|
||||
QwtPlotLegendItem::ItemBackground )
|
||||
{
|
||||
m_legendItem->setBorderRadius( 4 );
|
||||
m_legendItem->setMargin( 0 );
|
||||
m_legendItem->setSpacing( 4 );
|
||||
m_legendItem->setItemMargin( 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_legendItem->setBorderRadius( 8 );
|
||||
m_legendItem->setMargin( 4 );
|
||||
m_legendItem->setSpacing( 2 );
|
||||
m_legendItem->setItemMargin( 0 );
|
||||
}
|
||||
|
||||
QFont font = m_legendItem->font();
|
||||
font.setPointSize( settings.legendItem.size );
|
||||
m_legendItem->setFont( font );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_legendItem;
|
||||
m_legendItem = NULL;
|
||||
}
|
||||
|
||||
QwtPlotItemList curveList = itemList( QwtPlotItem::Rtti_PlotCurve );
|
||||
if ( curveList.size() != settings.curve.numCurves )
|
||||
{
|
||||
while ( curveList.size() > settings.curve.numCurves )
|
||||
{
|
||||
QwtPlotItem* curve = curveList.takeFirst();
|
||||
delete curve;
|
||||
}
|
||||
|
||||
for ( int i = curveList.size(); i < settings.curve.numCurves; i++ )
|
||||
insertCurve();
|
||||
}
|
||||
|
||||
curveList = itemList( QwtPlotItem::Rtti_PlotCurve );
|
||||
for ( int i = 0; i < curveList.count(); i++ )
|
||||
{
|
||||
Curve* curve = static_cast< Curve* >( curveList[i] );
|
||||
curve->setCurveTitle( settings.curve.title );
|
||||
|
||||
int sz = 0.5 * settings.legendItem.size;
|
||||
curve->setLegendIconSize( QSize( sz, sz ) );
|
||||
}
|
||||
|
||||
setAutoReplot( false );
|
||||
if ( m_isDirty )
|
||||
{
|
||||
m_isDirty = false;
|
||||
replot();
|
||||
}
|
||||
}
|
||||
|
||||
void Plot::replot()
|
||||
{
|
||||
if ( autoReplot() )
|
||||
{
|
||||
m_isDirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
QwtPlot::replot();
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
34
examples/legends/Plot.h
Normal file
34
examples/legends/Plot.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* 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>
|
||||
|
||||
class Settings;
|
||||
class QwtPlotLegendItem;
|
||||
class QwtLegend;
|
||||
|
||||
class Plot : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* parent = NULL );
|
||||
virtual ~Plot();
|
||||
|
||||
public Q_SLOTS:
|
||||
void applySettings( const Settings& );
|
||||
|
||||
public:
|
||||
virtual void replot() QWT_OVERRIDE;
|
||||
|
||||
private:
|
||||
void insertCurve();
|
||||
|
||||
QwtLegend* m_externalLegend;
|
||||
QwtPlotLegendItem* m_legendItem;
|
||||
bool m_isDirty;
|
||||
};
|
||||
49
examples/legends/Settings.h
Normal file
49
examples/legends/Settings.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
Settings()
|
||||
{
|
||||
legend.isEnabled = false;
|
||||
legend.position = 0;
|
||||
|
||||
legendItem.isEnabled = false;
|
||||
legendItem.numColumns = 0;
|
||||
legendItem.alignment = 0;
|
||||
legendItem.backgroundMode = 0;
|
||||
legendItem.size = 12;
|
||||
|
||||
curve.numCurves = 0;
|
||||
curve.title = "Curve";
|
||||
}
|
||||
|
||||
struct
|
||||
{
|
||||
bool isEnabled;
|
||||
int position;
|
||||
} legend;
|
||||
|
||||
struct
|
||||
{
|
||||
bool isEnabled;
|
||||
int numColumns;
|
||||
int alignment;
|
||||
int backgroundMode;
|
||||
int size;
|
||||
|
||||
} legendItem;
|
||||
|
||||
struct
|
||||
{
|
||||
int numCurves;
|
||||
QString title;
|
||||
} curve;
|
||||
};
|
||||
20
examples/legends/legends.pro
Normal file
20
examples/legends/legends.pro
Normal file
@@ -0,0 +1,20 @@
|
||||
######################################################################
|
||||
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
# This file may be used under the terms of the 3-clause BSD License
|
||||
######################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = legends
|
||||
|
||||
HEADERS = \
|
||||
MainWindow.h \
|
||||
Panel.h \
|
||||
Settings.h \
|
||||
Plot.h
|
||||
|
||||
SOURCES = \
|
||||
MainWindow.cpp \
|
||||
Panel.cpp \
|
||||
Plot.cpp \
|
||||
main.cpp
|
||||
19
examples/legends/main.cpp
Normal file
19
examples/legends/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
app.setStyle( "Windows" );
|
||||
|
||||
MainWindow window;
|
||||
window.resize( 700, 500 );
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user