Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
24
examples/legends/legends.pro
Normal file
24
examples/legends/legends.pro
Normal file
|
@ -0,0 +1,24 @@
|
|||
################################################################
|
||||
# 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}/../examples.pri )
|
||||
|
||||
TARGET = legends
|
||||
|
||||
HEADERS = \
|
||||
mainwindow.h \
|
||||
panel.h \
|
||||
settings.h \
|
||||
plot.h
|
||||
|
||||
SOURCES = \
|
||||
mainwindow.cpp \
|
||||
panel.cpp \
|
||||
plot.cpp \
|
||||
main.cpp
|
14
examples/legends/main.cpp
Normal file
14
examples/legends/main.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
a.setStyle( "Windows" );
|
||||
|
||||
MainWindow w;
|
||||
w.resize( 700, 500 );
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
61
examples/legends/mainwindow.cpp
Normal file
61
examples/legends/mainwindow.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qlayout.h>
|
||||
#include <qwt_plot_renderer.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include "plot.h"
|
||||
#include "panel.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
d_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 = d_plot->canvas()->font().pointSize();
|
||||
|
||||
settings.curve.numCurves = 4;
|
||||
settings.curve.title = "Curve";
|
||||
|
||||
d_panel = new Panel();
|
||||
d_panel->setSettings( settings );
|
||||
|
||||
QWidget *box = new QWidget( this );
|
||||
QHBoxLayout *layout = new QHBoxLayout( box );
|
||||
layout->addWidget( d_plot, 10 );
|
||||
layout->addWidget( d_panel );
|
||||
|
||||
setCentralWidget( box );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton *btnExport = new QToolButton( toolBar );
|
||||
btnExport->setText( "Export" );
|
||||
toolBar->addWidget( btnExport );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
updatePlot();
|
||||
|
||||
connect( d_panel, SIGNAL( edited() ), SLOT( updatePlot() ) );
|
||||
connect( btnExport, SIGNAL( clicked() ), SLOT( exportPlot() ) );
|
||||
}
|
||||
|
||||
void MainWindow::updatePlot()
|
||||
{
|
||||
d_plot->applySettings( d_panel->settings() );
|
||||
}
|
||||
|
||||
void MainWindow::exportPlot()
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
renderer.exportTo( d_plot, "legends.pdf" );
|
||||
}
|
20
examples/legends/mainwindow.h
Normal file
20
examples/legends/mainwindow.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <qmainwindow.h>
|
||||
|
||||
class Plot;
|
||||
class Panel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget *parent = 0 );
|
||||
|
||||
private Q_SLOTS:
|
||||
void updatePlot();
|
||||
void exportPlot();
|
||||
|
||||
private:
|
||||
Plot *d_plot;
|
||||
Panel *d_panel;
|
||||
};
|
216
examples/legends/panel.cpp
Normal file
216
examples/legends/panel.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
#include "panel.h"
|
||||
#include "settings.h"
|
||||
#include <qcheckbox.h>
|
||||
#include <qspinbox.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qgroupbox.h>
|
||||
#include <qlayout.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_legenditem.h>
|
||||
|
||||
Panel::Panel( QWidget *parent ):
|
||||
QWidget( parent )
|
||||
{
|
||||
// create widgets
|
||||
|
||||
d_legend.checkBox = new QCheckBox( "Enabled" );
|
||||
|
||||
d_legend.positionBox = new QComboBox();
|
||||
d_legend.positionBox->addItem( "Left", QwtPlot::LeftLegend );
|
||||
d_legend.positionBox->addItem( "Right", QwtPlot::RightLegend );
|
||||
d_legend.positionBox->addItem( "Bottom", QwtPlot::BottomLegend );
|
||||
d_legend.positionBox->addItem( "Top", QwtPlot::TopLegend );
|
||||
d_legend.positionBox->addItem( "External", QwtPlot::TopLegend + 1 );
|
||||
|
||||
d_legendItem.checkBox = new QCheckBox( "Enabled" );
|
||||
|
||||
d_legendItem.numColumnsBox = new QSpinBox();
|
||||
d_legendItem.numColumnsBox->setRange( 0, 10 );
|
||||
d_legendItem.numColumnsBox->setSpecialValueText( "Unlimited" );
|
||||
|
||||
d_legendItem.hAlignmentBox = new QComboBox();
|
||||
d_legendItem.hAlignmentBox->addItem( "Left", Qt::AlignLeft );
|
||||
d_legendItem.hAlignmentBox->addItem( "Centered", Qt::AlignHCenter );
|
||||
d_legendItem.hAlignmentBox->addItem( "Right", Qt::AlignRight );
|
||||
|
||||
d_legendItem.vAlignmentBox = new QComboBox();
|
||||
d_legendItem.vAlignmentBox->addItem( "Top", Qt::AlignTop );
|
||||
d_legendItem.vAlignmentBox->addItem( "Centered", Qt::AlignVCenter );
|
||||
d_legendItem.vAlignmentBox->addItem( "Bottom", Qt::AlignBottom );
|
||||
|
||||
d_legendItem.backgroundBox = new QComboBox();
|
||||
d_legendItem.backgroundBox->addItem( "Legend",
|
||||
QwtPlotLegendItem::LegendBackground );
|
||||
d_legendItem.backgroundBox->addItem( "Items",
|
||||
QwtPlotLegendItem::ItemBackground );
|
||||
|
||||
d_legendItem.sizeBox = new QSpinBox();
|
||||
d_legendItem.sizeBox->setRange( 8, 22 );
|
||||
|
||||
d_curve.numCurves = new QSpinBox();
|
||||
d_curve.numCurves->setRange( 0, 99 );
|
||||
|
||||
d_curve.title = new QLineEdit();
|
||||
|
||||
// layout
|
||||
|
||||
QGroupBox *legendBox = new QGroupBox( "Legend" );
|
||||
QGridLayout *legendBoxLayout = new QGridLayout( legendBox );
|
||||
|
||||
int row = 0;
|
||||
legendBoxLayout->addWidget( d_legend.checkBox, row, 0, 1, -1 );
|
||||
|
||||
row++;
|
||||
legendBoxLayout->addWidget( new QLabel( "Position" ), row, 0 );
|
||||
legendBoxLayout->addWidget( d_legend.positionBox, row, 1 );
|
||||
|
||||
|
||||
QGroupBox *legendItemBox = new QGroupBox( "Legend Item" );
|
||||
QGridLayout *legendItemBoxLayout = new QGridLayout( legendItemBox );
|
||||
|
||||
row = 0;
|
||||
legendItemBoxLayout->addWidget( d_legendItem.checkBox, row, 0, 1, -1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Columns" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( d_legendItem.numColumnsBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Horizontal" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( d_legendItem.hAlignmentBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Vertical" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( d_legendItem.vAlignmentBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Background" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( d_legendItem.backgroundBox, row, 1 );
|
||||
|
||||
row++;
|
||||
legendItemBoxLayout->addWidget( new QLabel( "Size" ), row, 0 );
|
||||
legendItemBoxLayout->addWidget( d_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( d_curve.numCurves, row, 1 );
|
||||
|
||||
row++;
|
||||
curveBoxLayout->addWidget( new QLabel( "Title" ), row, 0 );
|
||||
curveBoxLayout->addWidget( d_curve.title, row, 1 );
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout( this );
|
||||
layout->addWidget( legendBox );
|
||||
layout->addWidget( legendItemBox );
|
||||
layout->addWidget( curveBox );
|
||||
layout->addStretch( 10 );
|
||||
|
||||
connect( d_legend.checkBox,
|
||||
SIGNAL( stateChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legend.positionBox,
|
||||
SIGNAL( currentIndexChanged( int ) ), SIGNAL( edited() ) );
|
||||
|
||||
connect( d_legendItem.checkBox,
|
||||
SIGNAL( stateChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legendItem.numColumnsBox,
|
||||
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legendItem.hAlignmentBox,
|
||||
SIGNAL( currentIndexChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legendItem.vAlignmentBox,
|
||||
SIGNAL( currentIndexChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legendItem.backgroundBox,
|
||||
SIGNAL( currentIndexChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_curve.numCurves,
|
||||
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_legendItem.sizeBox,
|
||||
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
|
||||
connect( d_curve.title,
|
||||
SIGNAL( textEdited( const QString & ) ), SIGNAL( edited() ) );
|
||||
}
|
||||
|
||||
void Panel::setSettings( const Settings &settings)
|
||||
{
|
||||
blockSignals( true );
|
||||
|
||||
d_legend.checkBox->setCheckState(
|
||||
settings.legend.isEnabled ? Qt::Checked : Qt::Unchecked );
|
||||
d_legend.positionBox->setCurrentIndex( settings.legend.position );
|
||||
|
||||
d_legendItem.checkBox->setCheckState(
|
||||
settings.legendItem.isEnabled ? Qt::Checked : Qt::Unchecked );
|
||||
|
||||
d_legendItem.numColumnsBox->setValue( settings.legendItem.numColumns );
|
||||
|
||||
int align = settings.legendItem.alignment;
|
||||
|
||||
if ( align & Qt::AlignLeft )
|
||||
d_legendItem.hAlignmentBox->setCurrentIndex( 0 );
|
||||
else if ( align & Qt::AlignRight )
|
||||
d_legendItem.hAlignmentBox->setCurrentIndex( 2 );
|
||||
else
|
||||
d_legendItem.hAlignmentBox->setCurrentIndex( 1 );
|
||||
|
||||
if ( align & Qt::AlignTop )
|
||||
d_legendItem.vAlignmentBox->setCurrentIndex( 0 );
|
||||
else if ( align & Qt::AlignBottom )
|
||||
d_legendItem.vAlignmentBox->setCurrentIndex( 2 );
|
||||
else
|
||||
d_legendItem.vAlignmentBox->setCurrentIndex( 1 );
|
||||
|
||||
d_legendItem.backgroundBox->setCurrentIndex(
|
||||
settings.legendItem.backgroundMode );
|
||||
|
||||
d_legendItem.sizeBox->setValue( settings.legendItem.size );
|
||||
|
||||
d_curve.numCurves->setValue( settings.curve.numCurves );
|
||||
d_curve.title->setText( settings.curve.title );
|
||||
|
||||
blockSignals( false );
|
||||
}
|
||||
|
||||
Settings Panel::settings() const
|
||||
{
|
||||
Settings s;
|
||||
|
||||
s.legend.isEnabled =
|
||||
d_legend.checkBox->checkState() == Qt::Checked;
|
||||
s.legend.position = d_legend.positionBox->currentIndex();
|
||||
|
||||
s.legendItem.isEnabled =
|
||||
d_legendItem.checkBox->checkState() == Qt::Checked;
|
||||
s.legendItem.numColumns = d_legendItem.numColumnsBox->value();
|
||||
|
||||
int align = 0;
|
||||
|
||||
int hIndex = d_legendItem.hAlignmentBox->currentIndex();
|
||||
if ( hIndex == 0 )
|
||||
align |= Qt::AlignLeft;
|
||||
else if ( hIndex == 2 )
|
||||
align |= Qt::AlignRight;
|
||||
else
|
||||
align |= Qt::AlignHCenter;
|
||||
|
||||
int vIndex = d_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 =
|
||||
d_legendItem.backgroundBox->currentIndex();
|
||||
s.legendItem.size = d_legendItem.sizeBox->value();
|
||||
|
||||
s.curve.numCurves = d_curve.numCurves->value();
|
||||
s.curve.title = d_curve.title->text();
|
||||
|
||||
return s;
|
||||
}
|
52
examples/legends/panel.h
Normal file
52
examples/legends/panel.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef _PANEL_
|
||||
#define _PANEL_
|
||||
|
||||
#include "settings.h"
|
||||
#include <qwidget.h>
|
||||
|
||||
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;
|
||||
|
||||
} d_legend;
|
||||
|
||||
struct
|
||||
{
|
||||
QCheckBox *checkBox;
|
||||
QSpinBox *numColumnsBox;
|
||||
QComboBox *hAlignmentBox;
|
||||
QComboBox *vAlignmentBox;
|
||||
QComboBox *backgroundBox;
|
||||
QSpinBox *sizeBox;
|
||||
|
||||
} d_legendItem;
|
||||
|
||||
struct
|
||||
{
|
||||
QSpinBox *numCurves;
|
||||
QLineEdit *title;
|
||||
|
||||
} d_curve;
|
||||
};
|
||||
|
||||
#endif
|
263
examples/legends/plot.cpp
Normal file
263
examples/legends/plot.cpp
Normal file
|
@ -0,0 +1,263 @@
|
|||
#include "plot.h"
|
||||
#include "settings.h"
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_legenditem.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
|
||||
class LegendItem: public QwtPlotLegendItem
|
||||
{
|
||||
public:
|
||||
LegendItem()
|
||||
{
|
||||
setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
|
||||
QColor color( Qt::white );
|
||||
|
||||
setTextPen( color );
|
||||
#if 1
|
||||
setBorderPen( color );
|
||||
|
||||
QColor c( Qt::gray );
|
||||
c.setAlpha( 200 );
|
||||
|
||||
setBackgroundBrush( c );
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
class Curve: public QwtPlotCurve
|
||||
{
|
||||
public:
|
||||
Curve( int index ):
|
||||
d_index( index )
|
||||
{
|
||||
setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
initData();
|
||||
}
|
||||
|
||||
void setCurveTitle( const QString &title )
|
||||
{
|
||||
QString txt("%1 %2");
|
||||
setTitle( QString( "%1 %2" ).arg( title ).arg( d_index ) );
|
||||
}
|
||||
|
||||
void initData()
|
||||
{
|
||||
QVector<QPointF> points;
|
||||
|
||||
double y = qrand() % 1000;
|
||||
|
||||
for ( double x = 0.0; x <= 1000.0; x += 100.0 )
|
||||
{
|
||||
double off = qrand() % 200 - 100;
|
||||
if ( y + off > 980.0 || y + off < 20.0 )
|
||||
off = -off;
|
||||
|
||||
y += off;
|
||||
|
||||
points += QPointF( x, y );
|
||||
}
|
||||
|
||||
setSamples( points );
|
||||
}
|
||||
|
||||
private:
|
||||
const int d_index;
|
||||
};
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent ),
|
||||
d_externalLegend( NULL ),
|
||||
d_legendItem( NULL ),
|
||||
d_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( QwtPlot::yLeft, 0.0, 1000.0 );
|
||||
setAxisScale( QwtPlot::xBottom, 0.0, 1000.0 );
|
||||
}
|
||||
|
||||
Plot::~Plot()
|
||||
{
|
||||
delete d_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 )
|
||||
{
|
||||
d_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 ( d_externalLegend == NULL )
|
||||
{
|
||||
d_externalLegend = new QwtLegend();
|
||||
d_externalLegend->setWindowTitle("Plot Legend");
|
||||
|
||||
connect(
|
||||
this,
|
||||
SIGNAL( legendDataChanged( const QVariant &,
|
||||
const QList<QwtLegendData> & ) ),
|
||||
d_externalLegend,
|
||||
SLOT( updateLegend( const QVariant &,
|
||||
const QList<QwtLegendData> & ) ) );
|
||||
|
||||
d_externalLegend->show();
|
||||
|
||||
// populate the new legend
|
||||
updateLegend();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete d_externalLegend;
|
||||
d_externalLegend = NULL;
|
||||
|
||||
if ( legend() == NULL ||
|
||||
plotLayout()->legendPosition() != settings.legend.position )
|
||||
{
|
||||
insertLegend( new QwtLegend(),
|
||||
QwtPlot::LegendPosition( settings.legend.position ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
insertLegend( NULL );
|
||||
|
||||
delete d_externalLegend;
|
||||
d_externalLegend = NULL;
|
||||
}
|
||||
|
||||
if ( settings.legendItem.isEnabled )
|
||||
{
|
||||
if ( d_legendItem == NULL )
|
||||
{
|
||||
d_legendItem = new LegendItem();
|
||||
d_legendItem->attach( this );
|
||||
}
|
||||
|
||||
d_legendItem->setMaxColumns( settings.legendItem.numColumns );
|
||||
d_legendItem->setAlignment( Qt::Alignment( settings.legendItem.alignment ) );
|
||||
d_legendItem->setBackgroundMode(
|
||||
QwtPlotLegendItem::BackgroundMode( settings.legendItem.backgroundMode ) );
|
||||
if ( settings.legendItem.backgroundMode ==
|
||||
QwtPlotLegendItem::ItemBackground )
|
||||
{
|
||||
d_legendItem->setBorderRadius( 4 );
|
||||
d_legendItem->setMargin( 0 );
|
||||
d_legendItem->setSpacing( 4 );
|
||||
d_legendItem->setItemMargin( 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
d_legendItem->setBorderRadius( 8 );
|
||||
d_legendItem->setMargin( 4 );
|
||||
d_legendItem->setSpacing( 2 );
|
||||
d_legendItem->setItemMargin( 0 );
|
||||
}
|
||||
|
||||
QFont font = d_legendItem->font();
|
||||
font.setPointSize( settings.legendItem.size );
|
||||
d_legendItem->setFont( font );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete d_legendItem;
|
||||
d_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 ( d_isDirty )
|
||||
{
|
||||
d_isDirty = false;
|
||||
replot();
|
||||
}
|
||||
}
|
||||
|
||||
void Plot::replot()
|
||||
{
|
||||
if ( autoReplot() )
|
||||
{
|
||||
d_isDirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
QwtPlot::replot();
|
||||
}
|
||||
|
32
examples/legends/plot.h
Normal file
32
examples/legends/plot.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class Settings;
|
||||
class LegendItem;
|
||||
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();
|
||||
|
||||
private:
|
||||
void insertCurve();
|
||||
|
||||
QwtLegend *d_externalLegend;
|
||||
LegendItem *d_legendItem;
|
||||
bool d_isDirty;
|
||||
};
|
||||
|
||||
#endif
|
47
examples/legends/settings.h
Normal file
47
examples/legends/settings.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef _SETTINGS_
|
||||
#define _SETTINGS_
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue