#include <mainwindow.h> // здесь объявленна plot_first int plot_fat ( int spec_qty, SPEC_DATA *s, CURVE *c ){ вычисления...n= plot_first("передаются какие то параметры вычисления")}
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QtGui>#include<QMainWindow>//#include <qmainwindow.h>#include <QMessageBox>#include <QFile>//#include <QtCore/QObject>//хедеры qwt#include <qwt_plot_canvas.h>#include <qwt_plot_curve.h>#include <qwt_plot_grid.h>#include <qwt_symbol.h>#include <qwt_scale_engine.h>#include <qwt_legend.h>//namespace Ui{ class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent =0 ); ~MainWindow(); void plot_fat(); int plot_first(double AxisXmax, double AxisXmin, double AxisYmax, double AxisYmin, double errorX, double *x, double *y, const int N, int numberCurve); int plot_next(double *x, double *y, const int N, int numberCurve); void showData(double *x, double *y, /*double *x2, double *y2*/ const int N,int numberCurve); int i;private: Ui::MainWindow *ui;protected: QwtPlotGrid *grid; QwtPlotCurve *curv1,*curv2; QwtSymbol *symbol1, *symbol2; QwtLegend *leg; QMessageBox *error;private slots: void on_Log10X_toggled(); void on_Log10Y_toggled();};#endif // MAINWINDOW_H
int MainWindow::plot_first (double AxisXmax, double AxisXmin, double AxisYmax, double AxisYmin, double errorX, double *x, double *y, const int N, int numberCurve){////опре деление в каких осях рисовать в логарифмических или линейных //qDebug("1 i = %i", i); if(!ui->Log10X->isChecked () && !ui->Log10Y->isChecked ()) { if(i == 1) { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft, new QwtLog10ScaleEngine); ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom, new QwtLog10ScaleEngine); ui->Log10X->setChecked (true); ui->Log10Y->setChecked (true); AxisYmin=1; AxisXmin=1; if(errorX<0) { QMessageBox::warning (this,tr("Warning"),tr("There are negative values")); } } if(i == 2) { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft, new QwtLinearScaleEngine); ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom, new QwtLinearScaleEngine); } }else { if(ui->Log10X->isChecked ()) AxisXmin=1; if(ui->Log10Y->isChecked ()) AxisYmin=1; } ui->myPlot->setAxisTitle( QwtPlot::xBottom,QString::fromLocal8Bit("X")); ui->myPlot->setAxisScale(QwtPlot::xBottom, AxisXmin, AxisXmax); ui->myPlot->setAxisTitle( QwtPlot::yLeft,QString::fromLocal8Bit("Y")); ui->myPlot->setAxisScale(QwtPlot::yLeft, AxisYmin, AxisYmax); showData(x,y,N,numberCurve); ui->myPlot->replot (); return 0;}
#include <QtCore/QCoreApplication>#include <math.h>#include <mainwindow.h>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); const int N = 13; int n; int numberCurve; double x[N+1]={1,2,3,6,8,9,11,12,13,14,18,21,22}; //double x[N+1]={-10,-7,-6,-5,-4, -2,-1,0, 2,3,6,9,10}; double y[N+1]; double x2[N+1]; double y2[N+1]; double AxisXmax = 0; double AxisXmin = 0; double AxisYmax = 0; double AxisYmin = 0; double errorX; for(int k = 0; k < N; k++ ) { y[k]=exp(x[k]); //первый график x2[k]= x[k]+ 2; y2[k]=x2[k]*x[k] + 3 * x2[k]; //exp(x2[k]); //второй график//определяем минимум макимум х и у if(x[k] > AxisXmax) AxisXmax = x[k]; if(x[k] < AxisXmin) AxisXmin = x[k]; if(y[k] < AxisYmin) AxisYmin = y[k]; if(y[k] > AxisYmax) AxisYmax = y[k]; if(x[k] < 0 ) errorX = x[k]; } numberCurve = 1; n = MainWindow::plot_first(AxisXmax,AxisXmin,AxisYmax,AxisYmin,errorX,x,y,N,numberCurve);// if( n == 0 )// {// numberCurve++;// for(int k=0; k < N; k++)// {// x[k]=x2[k];// y[k]=y2[k];// }// n = plot_next(x,y,N,numberCurve);// } return a.exec();}
#include "mainwindow.h"#include "dialog.h"#include <ui_qwtplot.h>#include <ui_dialog.h>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi (this); ui->myPlot->setTitle (QString::fromLocal8Bit ("Графики")); grid = new QwtPlotGrid; grid->enableXMin (true); grid->enableYMin (true); grid->setMajPen (QPen(Qt::black,0,Qt::DotLine)); grid->setMinPen (QPen(Qt::gray,0,Qt::DotLine)); grid->attach (ui->myPlot); ui->myPlot->canvas ()->setCursor (Qt::ArrowCursor); curv1 = new QwtPlotCurve(QString::fromLocal8Bit("exp(x)")); curv1->setRenderHint(QwtPlotItem::RenderAntialiased); curv1->setPen(QPen(Qt::red)); symbol1 = new QwtSymbol(); symbol1->setStyle (QwtSymbol::Ellipse); symbol1->setPen (QColor(Qt::black)); symbol1->setSize (5); curv1->setSymbol (symbol1); curv2 = new QwtPlotCurve(QString::fromLocal8Bit ("X*X+3X")); curv2->setRenderHint (QwtPlotItem::RenderAntialiased); curv2->setPen (QPen(Qt::green)); symbol2 = new QwtSymbol(); symbol2->setStyle (QwtSymbol::Rect); symbol2->setPen (QColor(Qt::blue)); symbol2->setSize (5); curv2->setSymbol (symbol2); leg = new QwtLegend(); leg->setItemMode(QwtLegend::ReadOnlyItem); ui->myPlot->insertLegend(leg,QwtPlot::TopLegend); //plot_fat(); ui->myPlot->replot ();}MainWindow::~MainWindow(){ delete ui;}//void MainWindow::plot_fat ()//{// const int N = 13;// int n;// int numberCurve;// double x[N+1]={1,2,3,6,8,9,11,12,13,14,18,21,22};// //double x[N+1]={-10,-7,-6,-5,-4, -2,-1,0, 2,3,6,9,10};// double y[N+1];// double x2[N+1];// double y2[N+1];// double AxisXmax = 0;// double AxisXmin = 0;// double AxisYmax = 0;// double AxisYmin = 0;// double errorX;// for(int k = 0; k < N; k++ )// {// y[k]=exp(x[k]); //первый график// x2[k]= x[k]+ 2;// y2[k]=x2[k]*x[k] + 3 * x2[k]; //exp(x2[k]); //второй график////определяем минимум макимум х и у// if(x[k] > AxisXmax) AxisXmax = x[k];// if(x[k] < AxisXmin) AxisXmin = x[k];// if(y[k] < AxisYmin) AxisYmin = y[k];// if(y[k] > AxisYmax) AxisYmax = y[k];// if(x[k] < 0 ) errorX = x[k];// }// numberCurve = 1;// n = plot_first(AxisXmax,AxisXmin,AxisYmax,AxisYmin,errorX,x,y,N,numberCurve);// if( n == 0 )// {// numberCurve++;// for(int k=0; k < N; k++)// {// x[k]=x2[k];// y[k]=y2[k];// }// n = plot_next(x,y,N,numberCurve);// }//}int MainWindow::plot_first (double AxisXmax, double AxisXmin, double AxisYmax, double AxisYmin, double errorX, double *x, double *y, const int N, int numberCurve){////опре деление в каких осях рисовать в логарифмических или линейных //qDebug("1 i = %i", i); if(!ui->Log10X->isChecked () && !ui->Log10Y->isChecked ()) { if(i == 1) { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft, new QwtLog10ScaleEngine); ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom, new QwtLog10ScaleEngine); ui->Log10X->setChecked (true); ui->Log10Y->setChecked (true); AxisYmin=1; AxisXmin=1; if(errorX<0) { QMessageBox::warning (this,tr("Warning"),tr("There are negative values")); } } if(i == 2) { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft, new QwtLinearScaleEngine); ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom, new QwtLinearScaleEngine); } }else { if(ui->Log10X->isChecked ()) AxisXmin=1; if(ui->Log10Y->isChecked ()) AxisYmin=1; } ui->myPlot->setAxisTitle( QwtPlot::xBottom,QString::fromLocal8Bit("X")); ui->myPlot->setAxisScale(QwtPlot::xBottom, AxisXmin, AxisXmax); ui->myPlot->setAxisTitle( QwtPlot::yLeft,QString::fromLocal8Bit("Y")); ui->myPlot->setAxisScale(QwtPlot::yLeft, AxisYmin, AxisYmax); showData(x,y,N,numberCurve); ui->myPlot->replot (); return 0;}int MainWindow::plot_next (double *x, double *y, const int N, int numberCurve){ showData(x,y,N, numberCurve); ui->myPlot->replot (); return 1;}void MainWindow::showData (double *x, double *y, const int N, int numberCurve){ if(numberCurve == 1) { curv1->setSamples (x,y,N); curv1->attach (ui->myPlot); }else{ curv2->setSamples (x,y,N); curv2->attach (ui->myPlot); }}void MainWindow::on_Log10Y_toggled(){ if(ui->Log10Y->isChecked ()) { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft,new QwtLog10ScaleEngine); //plot_fat(); }else { ui->myPlot->setAxisScaleEngine (QwtPlot::yLeft,new QwtLinearScaleEngine); // plot_fat(); }}void MainWindow::on_Log10X_toggled(){ if(ui->Log10X->isChecked ()) { ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom,new QwtLog10ScaleEngine); //plot_fat(); }else { ui->myPlot->setAxisScaleEngine (QwtPlot::xBottom,new QwtLinearScaleEngine); //plot_fat(); }}