Bez popisu

xyplotwindow.cpp 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "xyplotwindow.h"
  2. #include "ui_xyplotwindow.h"
  3. #include "qcustomplot.h"
  4. #include <cmath>
  5. /// \fn XYPlotWindow::XYPlotWindow(QWidget *parent)
  6. /// \~English
  7. /// \brief Constructor
  8. /// \~Spanish
  9. /// \brief Constructor
  10. XYPlotWindow::XYPlotWindow(QWidget *parent) :
  11. QMainWindow(parent),
  12. ui(new Ui::XYPlotWindow)
  13. {
  14. ui->setupUi(this);
  15. }
  16. /// \fn void XYPlotWindow::AddPointToGraph(double x, double y)
  17. /// \~English
  18. /// \brief Adds a coordinate (x,y) to the XX and YY vectors.
  19. /// \param x value of the coordinate (x,y) to be added to vector XX.
  20. /// \param y value of the coordinate (x,y) to be added to vector YY.
  21. /// \~Spanish
  22. /// \brief Anade una coordenada (x,y) a los vectores XX y YY.
  23. /// \param x valor de la coordenada (x,y) a ser anadido al vector XX.
  24. /// \param y valor de la coordenada (x,y) a ser anadido al vector YY.
  25. void XYPlotWindow::AddPointToGraph(double x, double y) {
  26. XX.push_back(x);
  27. YY.push_back(y);
  28. }
  29. /// \fn void XYPlotWindow::Plot()
  30. /// \~English
  31. /// \brief Plots the coordinates inserted in the vectors XX and YY.
  32. /// \~Spanish
  33. /// \brief Grafica las coordenadas insertadas en los vectores XX y YY.
  34. void XYPlotWindow::Plot() {
  35. ui->customPlot->xAxis->setLabel("x");
  36. ui->customPlot->yAxis->setLabel("y");
  37. ui->customPlot->xAxis->setRange(-25.0, 25.0);
  38. ui->customPlot->yAxis->setRange(-25.0, 25.0);
  39. QCPCurve *myCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
  40. ui->customPlot->addPlottable(myCurve);
  41. myCurve->setData(XX,YY);
  42. }
  43. /// \fn XYPlotWindow::~XYPlotWindow()
  44. /// \~English
  45. /// \brief Destructor
  46. /// \~Spanish
  47. /// \brief Destructor
  48. XYPlotWindow::~XYPlotWindow()
  49. {
  50. delete ui;
  51. }