apply many axes patch

This commit is contained in:
Sean Rhea
2009-09-20 10:12:23 -07:00
parent 2c138edbc6
commit 0dfed2c7b6
11 changed files with 482 additions and 60 deletions

View File

@@ -17,6 +17,7 @@ contains(CONFIG, QwtPlot) {
cpuplot \
curvdemo1 \
curvdemo2 \
many_axes \
simple_plot \
realtime_plot \
spectrogram \

View File

@@ -0,0 +1,56 @@
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlayout.h>
#include <qsignalmapper.h>
#include "plot.h"
#include "mainwindow.h"
MainWindow::MainWindow()
{
QFrame *w = new QFrame(this);
// create the box of checkboxes
QGroupBox *panel = new QGroupBox("Axes", w);
QVBoxLayout *vLayout = new QVBoxLayout(panel);
QStringList list;
list << "yLeft" << "yLeft1" << "yLeft2" << "yLeft3";
list << "yRight" << "yRight1" << "yRight2" << "yRight3";
QSignalMapper* signalMapper = new QSignalMapper(this);
QCheckBox* checkBox;
for(int i = 0; i < 8; i++)
{
checkBox = new QCheckBox(list[i], panel);
checkBox->setChecked(true);
connect(checkBox, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(checkBox, i);
vLayout->addWidget(checkBox);
}
connect(signalMapper, SIGNAL(mapped(int)),
this, SLOT(axisCheckBoxToggled(int)));
vLayout->addStretch(10);
// create the plot widget
d_plot = new Plot(w);
d_plot->replot();
// put the widgets in a horizontal box
QHBoxLayout *hLayout = new QHBoxLayout(w);
hLayout->setMargin(0);
hLayout->addWidget(panel, 10);
hLayout->addWidget(d_plot, 10);
setCentralWidget(w);
}
void MainWindow::axisCheckBoxToggled(int axis)
{
d_plot->enableAxis(axis, !d_plot->axisEnabled(axis));
}

View File

@@ -0,0 +1,22 @@
#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_
#include <qmainwindow.h>
class Plot;
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow();
private slots:
void axisCheckBoxToggled(int axis);
private:
Plot *d_plot;
};
#endif // _MAINWINDOW_H_

View File

@@ -0,0 +1,17 @@
#include <qapplication.h>
#include "mainwindow.h"
//-----------------------------------------------------------------
// many_axes.cpp
//
// An example that demonstrates a plot with many axes.
//-----------------------------------------------------------------
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return a.exec();
}

View File

@@ -0,0 +1,21 @@
# -*- mode: sh -*- ################################################
# 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( ../examples.pri )
TARGET = many_axes
CONFIG += static
SOURCES = \
many_axes.cpp \
mainwindow.cpp
HEADERS = \
plot.h \
mainwindow.h

View File

@@ -0,0 +1,152 @@
#ifndef _PLOT_H_
#define _PLOT_H_
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_data.h>
#include <qwt_text.h>
/*class FunctionData: public QwtSyntheticPointData
{
public:
FunctionData(double(*y)(double)):
QwtSyntheticPointData(100),
d_y(y)
{
}
virtual QwtSeriesData<QwtDoublePoint> *copy() const
{
return new FunctionData(d_y);
}
virtual double y(double x) const
{
return d_y(x);
}
private:
double(*d_y)(double);
};*/
//-----------------------------------------------------------------
// simple.cpp
//
// A simple example which shows how to use QwtPlot and QwtData
//-----------------------------------------------------------------
class SimpleData: public QwtData
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don´t need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
SimpleData(double(*y)(double), size_t size):
d_size(size),
d_y(y)
{
}
virtual QwtData *copy() const
{
return new SimpleData(d_y, d_size);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
return 0.1 * i;
}
virtual double y(size_t i) const
{
return d_y(x(i));
}
private:
size_t d_size;
double(*d_y)(double);
};
class Plot : public QwtPlot
{
public:
Plot(QWidget* widget) :
QwtPlot(widget)
{
setTitle("A Simple QwtPlot Demonstration");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// Set axes
setAxisTitle(xBottom, "xBottom");
setAxisScale(xBottom, 0.0, 10.0);
setAxisTitle(yLeft, "yLeft");
setAxisScale(yLeft, -1.0, 1.0);
enableAxis(yLeft1);
setAxisTitle(yLeft1, "yLeft1");
enableAxis(yLeft2);
setAxisTitle(yLeft2, "yLeft2");
enableAxis(yLeft3);
setAxisTitle(yLeft3, "yLeft3");
enableAxis(yRight);
setAxisTitle(yRight, "yRight");
enableAxis(yRight1);
setAxisTitle(yRight1, "yRight1");
enableAxis(yRight2);
setAxisTitle(yRight2, "yRight2");
enableAxis(yRight3);
setAxisTitle(yRight3, "yRight3");
// Insert new curves
QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
#if QT_VERSION >= 0x040000
cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
cSin->setPen(QPen(Qt::red));
cSin->attach(this);
//cSin->setAxis(QwtPlot::xBottom, QwtPlot::yLeft);
QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
#if QT_VERSION >= 0x040000
cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
cCos->setPen(QPen(Qt::blue));
cCos->attach(this);
//cCos->setAxis(QwtPlot::xBottom, QwtPlot::yRight);
// Create sin and cos data
const int nPoints = 100;
cSin->setData(SimpleData(::sin, nPoints));
cCos->setData(SimpleData(::cos, nPoints));
// Insert markers
// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);
// ...a vertical line at x = 2 * pi
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 2 pi"));
mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setXValue(6.284);
mX->attach(this);
}
};
#endif // _PLOT_H_