This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
#include <qwt_plot_curve.h> | |
#include <qwt_legend.h> | |
#include <qwt_plot_marker.h> | |
#include <qwt_symbol.h> | |
MainWindow::MainWindow(QWidget *parent) : | |
QwtPlot(parent) | |
{ | |
setTitle( "サイン・コサインカーブ" );//グラフのタイトル | |
insertLegend( new QwtLegend() ); | |
resize( 600, 400 ); | |
// サイン・コサインカーブを描画 | |
QVector<double> sinX;//空のベクタ宣言 | |
QVector<double> sinY;//空のベクタ宣言 | |
QVector<double> cosX;//空のベクタ宣言 | |
QVector<double> cosY;//空のベクタ宣言 | |
QwtPlotCurve *sinCurve = new QwtPlotCurve(); | |
sinCurve->setTitle( "sin curve" ); | |
sinCurve->setPen( Qt::blue, 2 ),sinCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); | |
//setAxisScale(QwtPlot::xBottom, 0,1 );// 目盛 | |
QwtPlotCurve *cosCurve = new QwtPlotCurve(); | |
cosCurve->setTitle( "cos curve" ); | |
cosCurve->setPen( Qt::red, 2 ),sinCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); | |
for( double d = 0.0 ; d <= 2.0 ; d += 0.01 ){ | |
sinX.append( d ); | |
sinY.append( sin(2.0*M_PI*d) ); | |
sinCurve->setSamples(sinX.data(), sinY.data(), sinX.count()); | |
cosX.append( d ); | |
cosY.append( cos(2.0*M_PI*d) ); | |
cosCurve->setSamples(cosX.data(), cosY.data(), cosX.count()); | |
} | |
sinCurve->attach( this ); | |
cosCurve->attach( this ); | |
// プロットマーカー | |
QwtPlotMarker *pPMarker = new QwtPlotMarker(); | |
pPMarker->setXValue( 1.0 ); | |
pPMarker->setYValue( 0.0 ); | |
pPMarker->setLabelAlignment( Qt::AlignCenter | Qt::AlignCenter ); | |
QwtText textPMarker( "Qwt Point Marker" ); | |
pPMarker->setLabel( textPMarker ); | |
pPMarker->attach( this ); | |
//横ラインマーカー | |
QwtPlotMarker *markerH = new QwtPlotMarker(); | |
markerH->setLineStyle(QwtPlotMarker::HLine);// 横ライン | |
markerH->setLabel( QString::fromLatin1("y=0") );// ラベル | |
markerH->setYValue(0.0);// 線の位置 | |
markerH->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);// マーカーラベルの位置 | |
markerH->attach(this); | |
// 縦ラインマーカー | |
QwtPlotMarker *markerV = new QwtPlotMarker(); | |
markerV->setLineStyle( QwtPlotMarker::VLine );// 縦ライン | |
markerV->setLabel( QString::fromLatin1("x=0.5") ); | |
markerV->setXValue( 0.5 ); | |
markerV->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); | |
markerV->setLinePen( QPen( Qt::magenta, 0, Qt::DashDotDotLine ) );// 線の種類 二点鎖線 | |
markerV->attach( this ); | |
// シンボルを使ったポイントマーカー | |
QwtPlotMarker *pointMarker = new QwtPlotMarker(); | |
pointMarker->setXValue( 1.5 ); | |
pointMarker->setYValue( 0.5 ); | |
pointMarker->setLabel( QString::fromLatin1("x=1.5,y=0.5") ); | |
pointMarker->setLabelAlignment( Qt::AlignTop | Qt::AlignCenter ); | |
QwtSymbol *pSymbol = new QwtSymbol( QwtSymbol::Diamond , QBrush( QColor::fromRgb( 0, 0, 0 ) ), | |
QPen( QColor::fromRgb( 0, 0, 0 ) ), QSize( 10, 10 ) ); | |
pointMarker->setSymbol( pSymbol ); | |
pointMarker->attach( this ); | |
} | |
MainWindow::~MainWindow() | |
{ | |
//delete ui; | |
} |
0 件のコメント:
コメントを投稿