Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // qcustomparabola.h
- #ifndef QCUSTOMPARABOLA_H
- #define QCUSTOMPARABOLA_H
- #include <qcustomplot.h>
- class QCustomParabola
- {
- QVector < double > x, y;
- double x_min, x_max,
- a, b, c, y_min, y_max;
- int accuracy;
- QCPGraph *parabola;
- QCustomPlot *plot;
- QString name;
- void fillXY();
- QBrush brush;
- QPen pen;
- QColor color;
- QCPItemText *headLabel;
- public:
- QCustomParabola( double __x_min,
- double __x_max,
- int __accuracy,
- double __a,
- double __b,
- double __c, QString __name,
- QCustomPlot *__plot );
- QCustomParabola( QCustomPlot *__plot );
- ~ QCustomParabola();
- public slots:
- void setXRange( double __x_min, double __x_max );
- void setAccuracy( int __accuracy );
- void setABC( double __a,
- double __b,
- double __c );
- void setName( QString __name );
- void setBrush( QBrush __brush );
- void setPen( QPen __pen );
- void setColor( QColor __color );
- void show();
- void showHead( bool visible );
- double getXMIN();
- double getXMAX();
- double getYMAX();
- double getYMIN();
- double getA();
- double getB();
- double getC();
- QString getName();
- double getHeadX();
- double getHeadY();
- double getDiscriminant();
- QVector < double > getX();
- QVector < double > getY();
- QCPGraph *getGraph();
- QBrush getBrush();
- QPen getPen();
- };
- #endif // QCUSTOMPARABOLA_H
- //--------------------------------------------------------------------------------------------------------------------
- // qcustomparabola.cpp
- #include "qcustomparabola.h"
- void QCustomParabola::fillXY()
- {
- int k = 0;
- y_min = 0;
- for ( double i = x_min * accuracy; i <= x_max * accuracy; ++i ) {
- x.push_back( i/accuracy) ;
- y.push_back( a * x[k] * x[k] + b * x[k] + c);
- if (y[k] < y_min)
- y_min = y[k];
- k++;
- }
- y_max = y[y.size() - 1];
- }
- QCustomParabola::QCustomParabola(double __x_min,
- double __x_max,
- int __accuracy,
- double __a,
- double __b,
- double __c,
- QString __name,
- QCustomPlot *__plot )
- {
- x.clear(); y.clear();
- x_min = __x_min;
- x_max = __x_max;
- accuracy = __accuracy;
- a = __a;
- b = __b;
- c = __c;
- name = __name;
- fillXY();
- plot = __plot;
- parabola = plot->addGraph();
- parabola->setName( __name );
- brush = parabola->brush();
- pen = parabola->pen();
- parabola->setData( x, y );
- }
- QCustomParabola::QCustomParabola( QCustomPlot *__plot )
- {
- plot = __plot;
- parabola = plot->addGraph();
- }
- QCustomParabola::~QCustomParabola()
- {
- }
- void QCustomParabola::setXRange(double __x_min,
- double __x_max)
- {
- x_min = __x_min;
- x_max = __x_max;
- }
- void QCustomParabola::setAccuracy(int __accuracy)
- {
- accuracy = __accuracy;
- }
- void QCustomParabola::setABC(double __a, double __b, double __c)
- {
- a = __a;
- b = __b;
- c = __c;
- }
- void QCustomParabola::setName(QString __name)
- {
- name = __name;
- parabola->setName( name );
- }
- void QCustomParabola::setBrush(QBrush __brush)
- {
- brush = __brush;
- parabola->setBrush( brush );
- }
- void QCustomParabola::setPen(QPen __pen)
- {
- pen = __pen;
- parabola->setPen( pen );
- }
- void QCustomParabola::setColor(QColor __color)
- {
- color = __color;
- pen = QPen( color );
- parabola->setPen( QPen( color ) );
- }
- void QCustomParabola::show()
- {
- x.clear(); y.clear();
- fillXY();
- parabola->setData( x, y );
- }
- void QCustomParabola::showHead(bool visible)
- {
- if ( visible == true ) {
- headLabel = new QCPItemText( plot );
- plot->addItem( headLabel );
- headLabel->position->setCoords( this->getHeadX(),
- this->getHeadY() - 2);
- headLabel->setText("[" + QString::number( this->getHeadX() )
- + ";" + QString::number( this->getHeadY() ) + "]");
- } else {
- delete headLabel;
- }
- }
- double QCustomParabola::getXMIN()
- {
- return x_min;
- }
- double QCustomParabola::getXMAX()
- {
- return x_max;
- }
- double QCustomParabola::getYMAX()
- {
- return y_max;
- }
- double QCustomParabola::getYMIN()
- {
- return y_min;
- }
- double QCustomParabola::getA()
- {
- return a;
- }
- double QCustomParabola::getB()
- {
- return b;
- }
- double QCustomParabola::getC()
- {
- return c;
- }
- QString QCustomParabola::getName()
- {
- return name;
- }
- double QCustomParabola::getHeadX()
- {
- return ( -b/(2 * a) );
- }
- double QCustomParabola::getHeadY()
- {
- return ( -getDiscriminant() / (4 * a) );
- }
- double QCustomParabola::getDiscriminant()
- {
- return ( b * b - 4 * a * c );
- }
- QVector<double> QCustomParabola::getX()
- {
- return x;
- }
- QVector<double> QCustomParabola::getY()
- {
- return y;
- }
- QCPGraph *QCustomParabola::getGraph()
- {
- return parabola;
- }
- QBrush QCustomParabola::getBrush()
- {
- return brush;
- }
- QPen QCustomParabola::getPen()
- {
- return pen;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement