Exemplo n.º 1
0
bool Plotter::compareBand(int pId)
{
    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    QVector<QPointF> data =curveMap[pId];
    double dx=0.0,dy=0.0;
    double y =0.0,x=0.0;
    bool isPass=true;
    for(int j=0; j< data.count();++j)
    {
        dx = data[j].x();
        dy = data[j].y();
        x = ((rect.width()/2)+5.0  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
        y = ((Margin+rect.height()/2) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));
       // qDebug() << "Inside Compare Band"<<dx<<dy;
        if(!((x>=m_lstLO.at(j).x()&&y>=m_lstLO.at(j).y()) && (x<=m_lstUP.at(j).x()&&y<=m_lstUP.at(j).y())))
        {
            isPass=false;
            m_nCompareWaveIndex = j;
            break;
        }
    }
    if(isPass == true)
        return true;
    else
        return false;
}
Exemplo n.º 2
0
QPainterPath GraphParametric::getPath(const QRect &plotRect, const PlotSettings &settings)
{
    double pdx=settings.spanX()/plotRect.width();
    double pdy=settings.spanY()/plotRect.height();
    double min=graphSettings.getMin();
    double max=graphSettings.getMax();
    int steps_count = graphSettings.getStepsCount();
    if (steps_count == 0)
        steps_count = 500;
    double dt=(max-min)/steps_count;
    QPainterPath path;
    if (!xVals)
        xVals = createFValsStruct(f, min, dt, steps_count+1, graphSettings.getMaxGap());
    if (!yVals)
        yVals = createFValsStruct(fY, min, dt, steps_count+1, graphSettings.getMaxGap());
    double t=min;
    for (int j=0; j<xVals->count; j++)
    {
        if (xVals->actions[j] == LINE && yVals->actions[j] == LINE)
        {
            path.lineTo(QPointF(plotRect.left() + (xVals->values[j]-settings.minX)/pdx,
                                plotRect.bottom() - (yVals->values[j]-settings.minY)/pdy));
        }
        else if (xVals->actions[j] == MOVE || yVals->actions[j] == MOVE)
        {
            path.moveTo(QPointF(plotRect.left() + (xVals->values[j]-settings.minX)/pdx,
                                plotRect.bottom() - (yVals->values[j]-settings.minY)/pdy));
        }
        t += dt;
    }
    return path;
}
Exemplo n.º 3
0
void plotter::drawGrid(QPainter *painter)
{
    QRect rect(xMargin, Margin, width()-2*xMargin, height() -2*Margin);
    if(!rect.isValid()) return;

    PlotSettings settings = zoomStack[curZoom];
    QPen quiteDark = palette().dark().color().light();
    QPen light = palette().light().color();

    for(int i=0; i<=settings.numXTicks;++i)
    {
        int x = rect.left() + (i*(rect.width()-1)/settings.numXTicks);
        double label = settings.minX + (i*settings.spanX()/settings.numXTicks);
        painter->setPen(quiteDark);
        painter->drawLine(x,rect.top(),x,rect.bottom());
        painter->setPen(light);
        painter->drawLine(x,rect.bottom(),x,rect.bottom()-5);
        painter->drawText(x,rect.bottom()+5,100,20,Qt::AlignLeft, QString::number(label));
    }

    for(int j=0; j<=settings.numYTicks;++j)
    {
        int y = rect.bottom() - (j*(rect.height()-1)/settings.numYTicks);
        double label = settings.minY + (j*settings.spanY()/settings.numYTicks);
        painter->setPen(quiteDark);
        painter->drawLine(rect.left(),y,rect.right(),y);
        painter->setPen(light);
        painter->drawLine(rect.left()+5 ,y, rect.left(),y);
        painter->drawText(rect.left()- xMargin -20, y-10, 100,20,
                          Qt::AlignVCenter|Qt::AlignRight, QString::number(label));
    }
    painter->drawRect(rect.adjusted(0,0,-1,-1));

}
Exemplo n.º 4
0
void Plotter::loopDrawCurves(QPainter *painter)
{

    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
     QVector<QPointF> data = loopMap;
    QPolygonF polyline(data.count());
    //qDebug() << "Data Count:"<<data.count();
    double y =0.0,x=0.0;
    int l_nCounter =0;
    m_nOffset =0.0;
    double dx=0.0,dy=0.0;
    for(int j=0; j< data.count();++j)
    {
         dx = data[j].x();
         dy = data[j].y();
         if(m_bUniPolar == true)
         {
             float l_nDiv = (dy/2.0);
//             printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
         }
         if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
         {
             //printf("X:%f Y:%f\n",dx,dy);
         }
        y =0.0,x=0.0;
        if(m_bVIMode == true)
            x = ((rect.width()/2)+5.0  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
        else
            x = (rect.left()+ ((dx)*(((rect.width()-1)))/(settings.spanX())));

        if( m_bUniPolar == true){
            y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            //y+=10;
//            printf(" Coord-Y %f\n",dy/2.0);
        }
        else
            y = ((Margin+rect.height()/2) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));
       // printf(" Coord- X & Y %f %f\n",x,y);
        if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
        {
            polyline[j] = QPointF(x,y);
            l_nCounter++;
        }
    }
    y =0.0,x=0.0;
//    for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
//    {
//        QPointF(x,y);
//        x = polyline.at(l_nIndex).x();
//        y = polyline.at(l_nIndex).y();
//    }

    painter->setPen(Qt::red);
     painter->drawPolyline(polyline);
     loopMap.clear();
    // qDebug() << "Inside Loop Draw Curves";

}
Exemplo n.º 5
0
void plotter::mouseReleaseEvent(QMouseEvent *event)
{
    if ((event->button() == Qt::LeftButton) && rubberBandIsShown) {
        rubberBandIsShown = false;
        updateRubberBandRegion();
        unsetCursor();

        QRect rect = rubberBandRect.normalized();
        if (rect.width() < 4 || rect.height() < 4)
            return;
        rect.translate(-Margin, -Margin);

        PlotSettings prevSettings = zoomStack[curZoom];
        PlotSettings settings;
        double dx = prevSettings.spanX() / (width() - 2 * Margin);
        double dy = prevSettings.spanY() / (height() - 2 * Margin);
        settings.minX = prevSettings.minX + dx * rect.left();
        settings.maxX = prevSettings.minX + dx * rect.right();
        settings.minY = prevSettings.maxY - dy * rect.bottom();
        settings.maxY = prevSettings.maxY - dy * rect.top();
        settings.adjust();

        zoomStack.resize(curZoom + 1);
        zoomStack.append(settings);
        zoomIn();
    }
}
Exemplo n.º 6
0
void plotter::drawCurves(QPainter *painter)
{
    static const QColor colorForIds[6] = {
        Qt::blue, Qt::green, Qt::red, Qt::cyan, Qt::magenta, Qt::yellow
    };
    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);
    if (!rect.isValid())
        return;

    painter->setClipRect(rect.adjusted(+1, +1, -1, -1));

    //Esto lo deje asi porque en teoria serviria para graficar varias funciones en un mismo plot
    QMapIterator<int, QVector<QPointF> > i(curveMap);
    while (i.hasNext()) {
        i.next();

        int id = i.key();
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        for (int j = 0; j < data.count(); ++j) {
            double dx = data[j].x() - settings.minX;
            double dy = data[j].y() - settings.minY;
            double x = rect.left() + (dx * (rect.width() - 1)
                                         / settings.spanX());
            double y = rect.bottom() - (dy * (rect.height() - 1)
                                           / settings.spanY());
            polyline[j] = QPointF(x, y);
        }
        painter->setPen(colorForIds[uint(id) % 6]);
        painter->drawPolyline(polyline);
    }
}
Exemplo n.º 7
0
void plotter::drawGrid(QPainter *painter)
{
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);
    if (!rect.isValid())
        return;

    PlotSettings settings = zoomStack[curZoom];
    QPen quiteDark=palette().dark().color().dark();

    //chepia del libro de QT
    for (int i = 0; i <= settings.numXTicks; ++i) {

         int x = rect.left() + (i * (rect.width() - 1)
                                  / settings.numXTicks);
         double label = settings.minX + (i * settings.spanX()
                                           / settings.numXTicks);
         painter->setPen(quiteDark);
         //painter->drawLine(x, rect.bottom(), x, rect.bottom() + 5);
         painter->drawText(x - 50, rect.bottom() + 5, 100, 20,
                              Qt::AlignHCenter | Qt::AlignTop,
                              QString::number(label));
    }
    for (int j = 0; j <= settings.numYTicks; ++j) {
        int y = rect.bottom() - (j * (rect.height() - 1)
                                   / settings.numYTicks);
        double label = settings.minY + (j * settings.spanY()
                                          / settings.numYTicks);
        painter->setPen(quiteDark);
        //painter->drawLine(rect.left() - 5, y, rect.left(), y);
        painter->drawText(rect.left() - Margin, y - 10, Margin - 5, 20,
                             Qt::AlignRight | Qt::AlignVCenter,
                             QString::number(label));
    }
    painter->drawRect(rect.adjusted(0, 0, -1, -1));


    //esto si es mio :)
    quiteDark.setBrush(Qt::red);
    quiteDark.setStyle(Qt::DashLine);
    painter->setPen(quiteDark);
    int x=rect.left() + ((-settings.minX*settings.numXTicks/settings.spanX()) * (rect.width() - 1)
                         / settings.numXTicks);
    painter->drawLine(x, rect.top(), x, rect.bottom());

    int y=rect.bottom() + ((-settings.minY*settings.numYTicks/settings.spanY()) * (rect.width() - 1)
                         / settings.numYTicks);
    painter->drawLine(rect.left(), y, rect.right(), y);
}
Exemplo n.º 8
0
QPainterPath GraphYx::getPath(const QRect& plotRect, const PlotSettings &settings)
{
    // границы построения - исходя из границ области построения и настроек графика
    double min=std::max(graphSettings.getMin(), settings.minX);
    double max=std::min(graphSettings.getMax(), settings.maxX);

    // реальные интервалы которые занимают пиксели по x и по y
    double pdx=settings.spanX()/plotRect.width();
    double pdy=settings.spanY()/plotRect.height();

    // количество интервалов, исходя из разрешения виджета -
    // количество пикселей, укладывающихся в границах построения
    int steps_count=(max-min)/pdx;
    double dx=pdx;
    int user_steps_count = graphSettings.getStepsCount();
    if ((user_steps_count != 0)&&(user_steps_count < steps_count))
    {
        // количество интервалов ограничивается исходя из пользовательских настроек
        steps_count = user_steps_count;
        dx = (max-min)/steps_count; // новый шаг построения
    }
    QPainterPath path;
    Graph::FValsStruct* fVals=
            createFValsStruct(f, min, dx, steps_count+1, graphSettings.getMaxGap());
    double x=min;
    for (int j=0; j<fVals->count; j++)
    {
        switch (fVals->actions[j]) {
        case MOVE:
            path.moveTo(QPointF(plotRect.left()+(x-settings.minX)/pdx,
                                plotRect.bottom() - (fVals->values[j]-settings.minY)/pdy));
            break;
        case LINE:
            path.lineTo(QPointF(plotRect.left()+(x-settings.minX)/pdx,
                                plotRect.bottom() - (fVals->values[j]-settings.minY)/pdy));
            break;
        case NO_DRAW:
            break;
        }
        x+=dx;
    }
    delete fVals;
    return path;
}
Exemplo n.º 9
0
void Plotter::drawBand(QPainter *painter,int pId)
{
/*    // double xPointHeight = y- m_objPlotData->m_nEnvelopBand;

     //if(l_nIndex==1)
     //pen.setBrush(QColor(162,162,161,100));
     QRectF rect(x - m_objPlotData->m_nEnvelopBand,y - m_objPlotData->m_nEnvelopBand,m_objPlotData->m_nEnvelopBand*2, m_objPlotData->m_nEnvelopBand*2);
     //painter->fillRect(rect,QColor(162,162,161,255));
         //painter->drawRect();
     //polyline1[l_nIndex] = QPointF(x - m_objPlotData->m_nEnvelopBand,y+m_objPlotData->m_nEnvelopBand*2);
  */
  //  qDebug() << "Draw Band:"<<m_objPlotData->m_nEnvelopBand;

    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
     QVector<QPointF> data =bandMap[pId];
     QPolygonF polyline1(data.count());
  //  qDebug() << "Data Count:"<<data.count();
    double y =0.0,x=0.0;
    m_nOffset =0.0;
    double dx=0.0,dy=0.0;
    for(int j=0; j< data.count();++j)
    {
         dx = data[j].x();
         dy = data[j].y();
        x = ((rect.width()/2)+5.0  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
        y = ((Margin+rect.height()/2) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));
        polyline1[j] =QPointF(x,y);
    }
    QPen pen;
    pen.setWidthF(m_objPlotData->m_nEnvelopBand*2);
    pen.setBrush(QColor(162,162,161,100));
    pen.setCapStyle(Qt::SquareCap);
    pen.setJoinStyle(Qt::RoundJoin);
    painter->setPen(pen);
    painter->drawPolyline(polyline1);
    pen.setWidthF(1);
    painter->setPen(pen);
    painter->drawPolyline(polyline1);
}
Exemplo n.º 10
0
void Plotter::drawCurves(QPainter *painter)
{
    //设置为静态变量,可以使得函数调用时不用每次都进行初始化。
    static const QColor colorForIds[6] =
    {
        Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow
    };

    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin, Margin, width() - 2 * Margin, height() - 2 * Margin);
    if (!rect.isValid())
        return;

    /*We start by calling setClipRect() to set the QPainter's clip region to the
      rectangle that contains the curves (excluding the margins and the frame around the graph).
      QPainter will then ignore drawing operations on pixels outside the area.
     */
    painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
    while (i.hasNext())
    {
        i.next();
        int id = i.key();
        const QVector<QPointF> &data = i.value();
        QPolygonF polyline(data.count());
        for (int j = 0; j < data.count(); ++j)
        {
            double dx = data[j].x() - settings.minX;
            double dy = data[j].y() - settings.minY;
            double x = rect.left() + (dx * (rect.width() - 1)
                                         / settings.spanX());
            double y = rect.bottom() - (dy * (rect.height() - 1)
                                           / settings.spanY());
            polyline[j] = QPointF(x, y);
        }
        painter->setPen(colorForIds[uint(id) % 6]);
        painter->drawPolyline(polyline);
    }
}
Exemplo n.º 11
0
QPainterPath GraphPolar::getPath(const QRect &plotRect, const PlotSettings &settings)
{
    double pdx=settings.spanX()/plotRect.width();
    double pdy=settings.spanY()/plotRect.height();
    double min=graphSettings.getMin();
    double da;
    int steps_count;
    if (graphSettings.getStepsCount()==0)
    {
        da=atan(1)/45;
        steps_count=(graphSettings.getMax()-graphSettings.getMin())/da;
    }
    else
    {
        steps_count=graphSettings.getStepsCount();
        da=(graphSettings.getMax()-graphSettings.getMin())/steps_count;
    }
    QPainterPath path;
    if (!fVals)
        fVals=createFValsStruct(f, min, da, steps_count+1, graphSettings.getMaxGap());
    double a=min;
    for (int j=0; j<fVals->count; j++)
    {
        switch (fVals->actions[j]) {
        case MOVE:
            path.moveTo(QPointF(plotRect.left()+(fVals->values[j]*cos(a)-settings.minX)/pdx,
                                plotRect.bottom() - (fVals->values[j]*sin(a)-settings.minY)/pdy));
            break;
        case LINE:
            path.lineTo(QPointF(plotRect.left()+(fVals->values[j]*cos(a)-settings.minX)/pdx,
                                plotRect.bottom() - (fVals->values[j]*sin(a)-settings.minY)/pdy));
            break;
        case NO_DRAW:
            break;
        }
        a+=da;
    }
    return path;
}
Exemplo n.º 12
0
void Plotter::drawCurves(QPainter *painter)
{
    static const QColor colorForIds[6] = {
        red, green, blue, cyan, magenta, yellow
    };
    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);

    painter->setClipRect(rect.x() + 1, rect.y() + 1,
                         rect.width() - 2, rect.height() - 2);

    map<int, CurveData>::const_iterator it = curveMap.begin();
    while (it != curveMap.end()) {
        int id = (*it).first;
        const CurveData &data = (*it).second;
        int numPoints = 0;
        int maxPoints = data.size() / 2;
        QPointArray points(maxPoints);

        for (int i = 0; i < maxPoints; ++i) {
            double dx = data[2 * i] - settings.minX;
            double dy = data[2 * i + 1] - settings.minY;
            double x = rect.left() + (dx * (rect.width() - 1)
                                         / settings.spanX());
            double y = rect.bottom() - (dy * (rect.height() - 1)
                                           / settings.spanY());
            if (fabs(x) < 32768 && fabs(y) < 32768) {
                points[numPoints] = QPoint((int)x, (int)y);
                ++numPoints;
            }
        }
        points.truncate(numPoints);
        painter->setPen(colorForIds[(uint)id % 6]);
        painter->drawPolyline(points);
        ++it;
    }
}
Exemplo n.º 13
0
void Plotter::drawGrid(QPainter *painter)
{
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);
    PlotSettings settings = zoomStack[curZoom];
    QPen quiteDark = colorGroup().dark().light();
    QPen light = colorGroup().light();

    for (int i = 0; i <= settings.numXTicks; ++i) {
        int x = rect.left() + (i * (rect.width() - 1)
                                 / settings.numXTicks);
        double label = settings.minX + (i * settings.spanX()
                                          / settings.numXTicks);
        painter->setPen(quiteDark);
        painter->drawLine(x, rect.top(), x, rect.bottom());
        painter->setPen(light);
        painter->drawLine(x, rect.bottom(), x, rect.bottom() + 5);
        painter->drawText(x - 50, rect.bottom() + 5, 100, 15,
                          AlignHCenter | AlignTop,
                          QString::number(label));
    }
    for (int j = 0; j <= settings.numYTicks; ++j) {
        int y = rect.bottom() - (j * (rect.height() - 1)
                                   / settings.numYTicks);
        double label = settings.minY + (j * settings.spanY()
                                          / settings.numYTicks);
        painter->setPen(quiteDark);
        painter->drawLine(rect.left(), y, rect.right(), y);
        painter->setPen(light);
        painter->drawLine(rect.left() - 5, y, rect.left(), y);
        painter->drawText(rect.left() - Margin, y - 10,
                          Margin - 5, 20,
                          AlignRight | AlignVCenter,
                          QString::number(label));
    }
    painter->drawRect(rect);
}
Exemplo n.º 14
0
void Plotter::generateCompareValues(int pId)
{
    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    m_lstLO.clear();m_lstUP.clear();
    QVector<QPointF> data =bandMap[pId];
    double y =0.0,x=0.0;
    double dx=0.0,dy=0.0;
    //qDebug() << "Inside Compare Values";
    for(int j=0; j< data.count();++j)
    {
         dx = data[j].x();
         dy = data[j].y();
         x = ((rect.width()/2)+5.0  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
         y = ((Margin+rect.height()/2) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));
         //qDebug()<<dx<<dy;
        m_lstLO.insert(j,QPointF(x-m_objPlotData->m_nEnvelopBand,y-m_objPlotData->m_nEnvelopBand));
        m_lstUP.insert(j,QPointF(x+m_objPlotData->m_nEnvelopBand*2,y+m_objPlotData->m_nEnvelopBand*2));
    }
    //QRectF rect(x - m_objPlotData->m_nEnvelopBand,y - m_objPlotData->m_nEnvelopBand,m_objPlotData->m_nEnvelopBand*2, m_objPlotData->m_nEnvelopBand*2);
    //    qDebug()<<"RectXStart:"<<x - m_objPlotData->m_nEnvelopBand<<"RectYStart:"<<y - m_objPlotData->m_nEnvelopBand<<
    //"RectXWidt:"<<x+m_objPlotData->m_nEnvelopBand*2<<
      //          "RectYHeigt"<<y+m_objPlotData->m_nEnvelopBand;
}
Exemplo n.º 15
0
QPainterPath GraphXy::getPath(const QRect& plotRect, const PlotSettings& settings)
{
    double min=std::max(graphSettings.getMin(), settings.minY);
    double max=std::min(graphSettings.getMax(), settings.maxY);
    double pdx=settings.spanX()/plotRect.width();
    double pdy=settings.spanY()/plotRect.height();
    int steps_count=(max-min)/pdy;
    double dy=pdy;
    if ((graphSettings.getStepsCount()!=0)&&(graphSettings.getStepsCount()<steps_count))
    {
        steps_count=graphSettings.getStepsCount();
        dy=(max-min)/steps_count;
    }
    QPainterPath path;
    Graph::FValsStruct* fVals=
            createFValsStruct(f, min, dy, steps_count+1, graphSettings.getMaxGap());
    double y=min;
    for (int j=0; j<fVals->count; j++)
    {
        switch (fVals->actions[j]) {
        case MOVE:
            path.moveTo(QPointF(plotRect.left()+(fVals->values[j]-settings.minX)/pdx,
                                plotRect.bottom() - (y-settings.minY)/pdy));
            break;
        case LINE:
            path.lineTo(QPointF(plotRect.left()+(fVals->values[j]-settings.minX)/pdx,
                               plotRect.bottom() - (y-settings.minY)/pdy));
            break;
        case NO_DRAW:
            break;
        }
        y+=dy;
    }
    delete fVals;
    return path;
}
Exemplo n.º 16
0
QRect ScatterView::getObjectRect(long int row)
{
	if(!table) return QRect();

	QRect rect(LMargin, TMargin, this->width() - (LMargin+RMargin), this->height() - (BMargin+TMargin));
	PlotSettings settings = *mySettings;

	//double valueX = table->GetValue(row,columnNumForX).ToDouble();
    double valueX = table->data(table->index(row, columnNumForX, QModelIndex())).toDouble();
	//double valueY = table->GetValue(row,columnNumForY).ToDouble();
    double valueY = table->data(table->index(row, columnNumForY, QModelIndex())).toDouble();
	//Adjust for normalization:
	if(settings.normalize == true)
	{
		valueX = -1 + 2* (valueX - settings.d_minX)/(settings.d_maxX - settings.d_minX);
		valueY = -1 + 2* (valueY - settings.d_minY)/(settings.d_maxY - settings.d_minY);
	}

    double dx = valueX - settings.minX;
	double dy = valueY - settings.minY;
	double x = rect.left() + (dx * (rect.width() - 1) / settings.spanX());
	double y = rect.bottom() - (dy * (rect.height() - 1) / settings.spanY());
	return QRect(int(x-2),int(y-2),5,5);
}
Exemplo n.º 17
0
//***************************************************************************************************
//The drawGrid() function draws the grid behind the curves and the axes. The area on which we draw
//the grid is specified by rect. If the widget isn't large enough to accommodate the graph, we return
//immediately.
//The first for loop draws the grid's vertical lines and the ticks along the x axis. The second for loop
//draws the grid's horizontal lines and the ticks along the y axis. At the end, we draw a rectangle
//along the margins. The drawText() function is used to draw the numbers corresponding to the tick
//marks on both axes.
//The calls to drawText() have the following syntax:
//painter->drawText(x, y, width, height, alignment, text);
//where (x, y, width, height) define a rectangle, alignment the position of the text within that
//rectangle, and text the text to draw.
//***************************************************************************************************
void ScatterView::drawGrid(QPainter *painter)
{	
	//This rectangle is the graph area
	QRect rect(LMargin, TMargin, this->width() - (LMargin+RMargin), this->height() - (BMargin+TMargin));
	if (!rect.isValid())
		return;
	//Retrieve current plotSettings
	//PlotSettings settings = PlotSettings();
	PlotSettings settings = *mySettings;
	QPen quiteDark = palette().dark().color().light();
	QPen light = palette().light().color();
	//Draw vertical lines
	for (int i = 0; i <= settings.numXTicks; ++i) 
	{
		int x = rect.left() + (i * (rect.width() - 1) / settings.numXTicks);
		double label = settings.minX + (i * settings.spanX() / settings.numXTicks);
		//painter->setPen(quiteDark);
		painter->setPen(QPen(QBrush(Qt::black),1,Qt::DotLine));
		painter->drawLine(x, rect.top(), x, rect.bottom());
		//painter->setPen(light);
		painter->drawLine(x, rect.bottom(), x, rect.bottom() + 5);
		painter->setPen(QPen(QBrush(Qt::black),1));
		painter->drawText(x - 50, rect.bottom() + 5, 100, 15, Qt::AlignHCenter | Qt::AlignTop, QString::number(label));
	}
	for (int j = 0; j <= settings.numYTicks; ++j) 
	{
		int y = rect.bottom() - (j * (rect.height() - 1) / settings.numYTicks);
		double label = settings.minY + (j * settings.spanY() / settings.numYTicks);
		//painter->setPen(quiteDark);
		painter->setPen(QPen(QBrush(Qt::black),1,Qt::DotLine));
		painter->drawLine(rect.left(), y, rect.right(), y);
		//painter->setPen(light);
		painter->drawLine(rect.left() - 5, y, rect.left(), y);
		painter->setPen(QPen(QBrush(Qt::black),1));
		painter->drawText(rect.left() - LMargin, y - 10, LMargin - 5, 20,
			Qt::AlignRight | Qt::AlignVCenter,
			QString::number(label));
	}
	painter->drawRect(rect.adjusted(0, 0, -1, -1));
	
	//Now draw the labels for the x and y axis:
	QString xName;
	QString yName;
	if(table)
	{
		//xName = QString( table->GetColumnName(columnNumForX) );
		xName = table->headerData(columnNumForX, Qt::Horizontal).toString();
		//yName = QString( table->GetColumnName(columnNumForY) );
		yName = table->headerData(columnNumForY, Qt::Horizontal).toString();
	}
	else
	{
		xName = QString("x");
		yName = QString("y");
	}

    QFont fp = painter->font();
    fp.setBold(true);
    painter->setFont(fp);
	painter->setPen(Qt::blue);
	painter->drawText(rect.left(),rect.bottom() + 20, rect.width(), 20, Qt::AlignHCenter, xName);
	painter->save();
	painter->rotate(-90);
	painter->drawText(-1*rect.bottom(), rect.top() - TMargin, rect.height(), 20, Qt::AlignHCenter, yName);
	painter->restore();
}
Exemplo n.º 18
0
Arquivo: plotter.cpp Projeto: Qmax/PT6
void Plotter::drawCurves(QPainter *painter)
{
	//printf("Inside DrawCurves\n");


    static const QColor colorForIds[7] = {Qt::red,Qt::green,Qt::cyan,Qt::magenta,Qt::yellow,Qt::blue,Qt::white};
    PlotSettings settings = zoomStack[curZoom];
    if( m_moveFlag == true)
    {
        settings.maxX = m_ZoomSettings->maxX;
        settings.maxY = m_ZoomSettings->maxY;
        settings.minX = m_ZoomSettings->minX;
        settings.minY = m_ZoomSettings->minY;
        settings.m_nOffset = m_ZoomSettings->m_nOffset;
        settings.numXTicks = m_ZoomSettings->numXTicks;
        settings.numYTicks = m_ZoomSettings->numYTicks;
    }
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    //qDebug()<<"Draw Curves:"<< settings.m_nOffset;
    if(m_bshowZoomRect == true)
    {
        painter->setPen(colorForIds[6]);
        painter->drawRect(rubberBandRect);
    }

    if(!rect.isValid())
        return;
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
//    printf("Rect Left: %d\n",rect.left());
//    printf("Rect Height: %d\n",rect.height());
//    printf("Rect width: %d\n",rect.width());
//    printf("Rect Bottom: %d\n",rect.bottomLeft().y());
//    printf("Rect Top: %d\n",rect.top());
    double dx,dy;
    while(i.hasNext()){

        i.next();
        int id = i.key();
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        double y =0.0,x=0.0;
        int l_nCounter =0;
        //printf("MinY:%f\n",settings.minY);
        //printf("Offset:%f\n",m_nOffset);
        for(int j=0; j< data.count();++j)
        {
             dx = data[j].x();
             dy = data[j].y();
             if(m_bUniPolar == true)
             {
                 float l_nDiv = (dy/2.0);
                 printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
             }
             if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
             {
                 //printf("X:%f Y:%f\n",dx,dy);
             }
            y =0.0,x=0.0;
            if(m_ZoomFlag == false)
            {
                if(m_bVIMode == true)
                    x = (rect.width()/2+ (dx*(((rect.width()-1)))/(settings.spanX())));
                else
                    x = (rect.left()+ (dx*(((rect.width()-1)))/(settings.spanX())));

                if( m_bUniPolar == true){
                    y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                    printf(" Coord-Y %f\n",dy/2.0);
                }
                else
                    y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                	//y = ((Margin+rect.height()/2) - ((dy*rect.height()-1)/4.096));/*((rect.height()-1))));*/
                	//y = (Margin+rect.height()/2) - (dy);
               // printf(" Coord- X & Y %f %f\n",x,y);
               // qDebug() << dy;
            }
            else if(m_ZoomFlag == true)
            {
                x = (rect.left() + ((dx-settings.minX)*(((rect.width()-1)))/(settings.spanX())));
                y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            }
            if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
            {
                polyline[j] = QPointF(x,y);
                l_nCounter++;
            }
        }
        QPolygonF zoomPolyline(l_nCounter);
        y =0.0,x=0.0;
        int l_nIndex1 =0;
        for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
        {
            QPointF(x,y);
            x = polyline.at(l_nIndex).x();
            y = polyline.at(l_nIndex).y();
            if(x!=0.0 || y!=0.0 )
            {
                zoomPolyline[l_nIndex1] = QPointF(x,y);
                l_nIndex1++;
            }
        }
        painter->setPen(colorForIds[uint(id) %6]);
        if(m_ZoomFlag == false)
            painter->drawPolyline(polyline);
        else
            painter->drawPolyline(zoomPolyline);
        }
    }
Exemplo n.º 19
0
Arquivo: plotter.cpp Projeto: Qmax/PT6
void Plotter::drawGrid(QPainter *painter)
{
	//printf("Inside DrawGrid\n");
	//qDebug() << "Inside DrawGrid";
    QRect rect(Margin,Margin,width()-2*Margin,height()-2*Margin);
    if(!rect.isValid())
        return;
    QPen pen;
    QColor objColor(80,80,80,255);
    pen.setBrush(Qt::gray);
    pen.setStyle(Qt::DotLine);
    pen.setColor(objColor);
    pen.setCapStyle(Qt::RoundCap);
    pen.setJoinStyle(Qt::RoundJoin);
    painter->setPen(pen);
    //QPoint *pixPoint = new QPoint();
    PlotSettings settings = zoomStack[curZoom];
    if(m_bGrid)
    {
        for(int i=0;i<settings.numXTicks;i++)
        {
            int x = rect.left() + (i * (rect.width()) / settings.numXTicks);
            double label = settings.minX + (i*settings.spanX()/settings.numXTicks);
            //printf("X Axis:%f\n",label);
            for(float l_nPoint=1;l_nPoint<rect.height();l_nPoint+=2.0)
                painter->drawPoint(QPointF(x,rect.top()+l_nPoint));
            //painter->drawLine(x,rect.bottom(),x,rect.bottom()+5);
            painter->drawText(x-50,rect.bottom()+5,100,20, Qt::AlignHCenter|Qt::AlignTop,QString::number(label,5,2));
        }
        for(int j=0;j<settings.numYTicks;j++)
        {

            int y = rect.bottom() - (j * (rect.height()) / settings.numYTicks);
            double label = (settings.minY+settings.m_nOffset) + (j*settings.spanY()/settings.numYTicks);
           // qDebug()<<"Label:"<<label;
            //double label = (settings.m_nOffset)+(-4 *settings.maxY) + (j*settings.maxY);
            //printf("Y Axis:%f\n",label);
            for(float l_nPoint=0;l_nPoint<rect.width();l_nPoint+=2.0)
                painter->drawPoint(QPointF(rect.left()+l_nPoint,y));
            //painter->drawLine(rect.left(),y,rect.right(),y);
            painter->drawText(rect.left()-Margin,y-10,Margin, 20,Qt::AlignRight|Qt::AlignVCenter,QString::number(label,'e',2));
        }

    pen.setStyle(Qt::SolidLine);
    painter->setPen(pen);
    //int Value =0;
    
        for(int i=0;i<rect.height();i+=((rect.height()/settings.numYTicks)/5))
        {
            if(i!=0 && i%5!=0){
                //painter->drawLine(Margin+rect.width()/2-3,Margin+i,Margin+rect.width()/2+3,Margin+i);
            }
        }
        for(int j=0;j<rect.width();j+=(rect.width()/settings.numXTicks)/5 )
        {
            if(j!=0 && j%5!=0){
                //painter->drawLine(Margin+j,Margin+rect.height()/2-3,Margin+j,Margin+rect.height()/2+3);
            }
        }
    }
    if(m_bGrid == false){
        pen.setStyle(Qt::SolidLine);
        pen.setBrush(Qt::gray);
        pen.setWidth(1);
        painter->setPen(pen);
        painter->drawLine(Margin+rect.width()/2,Margin,Margin+rect.width()/2,Margin+rect.height());
        painter->drawLine(Margin,Margin+rect.height()/2-1,Margin+rect.width(),Margin+rect.height()/2-1);
    }
    if(m_bVILabels == true)
    {
        painter->drawText(Margin+rect.width()/2,0,20,20,Qt::AlignHCenter|Qt::AlignTop,QString::number(3.5));
        painter->drawText(0,Margin+rect.height()/2,20,20,Qt::AlignHCenter|Qt::AlignTop,QString::number(3.5));
        painter->drawText(Margin+rect.width()-20,Margin+rect.height()/2,20,20,Qt::AlignHCenter|Qt::AlignTop,QString::number(3.5));
        painter->drawText(Margin+rect.height(),Margin+rect.height()-20,20,20,Qt::AlignHCenter|Qt::AlignTop,QString::number(3.5));

    }
    painter->drawRect(rect.adjusted(+1,+1,-1,-1));
    //printf("outSide DrawGrid\n");
    //painter->drawRect(rect.adjusted(+0,+0,-1,-1));
}
Exemplo n.º 20
0
Arquivo: plotter.cpp Projeto: Qmax/PT6
void Plotter::keyPressEvent(QKeyEvent *event)
{
    switch(event->key())
    {
    case Qt::Key_Right:
        if(rubberBandRect.x() < this->width()-(rubberBandRect.width()-10))
        {
        rubberBandRect.setLeft(rubberBandRect.x() + 10);
        rubberBandRect.setWidth(rubberBandRect.width()+10);
        updateRubberBandRegion();
        }
        break;
    case Qt::Key_Left:
        if(rubberBandRect.x() > 10){
        rubberBandRect.setLeft(rubberBandRect.x() - 10);
        rubberBandRect.setWidth(rubberBandRect.width()-10);
        updateRubberBandRegion();

    }
        break;
    case Qt::Key_Down:
        if(rubberBandRect.y() < this->height()-rubberBandRect.height()){
        rubberBandRect.setTop(rubberBandRect.y() + 10);
        rubberBandRect.setHeight(rubberBandRect.height()+10);
        updateRubberBandRegion();

    }
        break;
    case Qt::Key_Up:
        if(rubberBandRect.y() >0){
        rubberBandRect.setTop(rubberBandRect.y() - 10);
        rubberBandRect.setHeight(rubberBandRect.height()-10);
        updateRubberBandRegion();

    }
        break;
     default: QWidget::keyPressEvent(event);
    }
    QRect rect = rubberBandRect.normalized();
    if(rect.width() < 4 || rect.height() < 4 )
    {
        return;
    }
    rect.translate(-Margin,-Margin);
    PlotSettings prevSettings = zoomStack[curZoom];
    PlotSettings settings;
    settings.m_nOffset = prevSettings.m_nOffset;
    double dx = prevSettings.spanX() / (width()-2*Margin);
    double dy = prevSettings.spanY() / (height()-2*Margin);
    settings.minX = prevSettings.minX + dx * rect.left();
    settings.maxX = prevSettings.minX + dx * rect.right();
    settings.minY = prevSettings.maxY - dy * rect.bottom();
    settings.maxY = prevSettings.maxY - dy * rect.top();
    settings.adjust();
    PlotSettings *pTemp = new PlotSettings();
    pTemp = &settings;
    zoomStack.resize(curZoom + 1);
    zoomStack.append(settings);
    refreshPixmap();
    emit moveWindow(rubberBandRect,settings);
}
Exemplo n.º 21
0
void InterpolatingGraph::update(const PlotSettings &settings)
{
    rescale(settings.scalingMode, settings.scaleType(series.fullName()));
    updatePlot(settings.scalingMode);
}
Exemplo n.º 22
0
void PlotSettingsDialog::setupSourceTable(const QStringList &dataSeriesNames, const PlotSettings &preset, bool offsetsEditable)
{
    ui->sourceTable->setColumnCount(COLCOUNT);

    QTableWidgetItem *sourceNameColHeader = new QTableWidgetItem(tr("Data Series Name"));
    sourceNameColHeader->setToolTip(tr("The name of the data series."));
    ui->sourceTable->setHorizontalHeaderItem(SOURCENAMECOL, sourceNameColHeader);

    QTableWidgetItem *offsetColHeader = new QTableWidgetItem(tr("Offset"));
    offsetColHeader->setToolTip(tr("The offset in milliseconds.\n\n"
                                   "This value is added to each timestamp\n"
                                   "of the respective data series.\n"
                                   "You can use this for example to adjust for\n"
                                   "time lags in the transmission of signals."));
    ui->sourceTable->setHorizontalHeaderItem(OFFSETCOL, offsetColHeader);

    QTableWidgetItem *scaleColHeader = new QTableWidgetItem(tr("Scale Type"));
    if (offsetsEditable) {
        scaleColHeader->setToolTip(tr("The <i>default</i> type of scale to be used for the data series."));
    } else {
        scaleColHeader->setToolTip(tr("The type of scale to be used for the data series."));
    }
    ui->sourceTable->setHorizontalHeaderItem(SCALECOL, scaleColHeader);

    QHeaderView *hHeader = ui->sourceTable->horizontalHeader();
    hHeader->setDefaultAlignment(Qt::AlignLeft);
    hHeader->setResizeMode(SOURCENAMECOL, QHeaderView::Stretch);
    hHeader->setResizeMode(OFFSETCOL, QHeaderView::ResizeToContents);
    hHeader->setResizeMode(SCALECOL, QHeaderView::ResizeToContents);
    hHeader->setMinimumSectionSize(120);

    QHeaderView *vHeader = ui->sourceTable->verticalHeader();
    vHeader->setVisible(false);

    foreach (QString sourceName, dataSeriesNames) {
        int row = ui->sourceTable->rowCount();
        ui->sourceTable->setRowCount(row + 1);

        QTableWidgetItem *sourceItem = new QTableWidgetItem(sourceName);
        // the item showing the data series name should not be editable
        sourceItem->setFlags(sourceItem->flags() & ~Qt::ItemIsEditable);
        ui->sourceTable->setItem(row, SOURCENAMECOL, sourceItem);

        QDoubleSpinBox *offsetSpinner = new QDoubleSpinBox(ui->sourceTable);
        offsetSpinner->setAlignment(Qt::AlignRight);
        // helps to set the min/max before you set the value ;)
        offsetSpinner->setMinimum(0.0);
        offsetSpinner->setMaximum(std::numeric_limits<double>::max());
        offsetSpinner->setDecimals(qRound(qLn(OFFSETDIVISOR)/qLn(10)));
        offsetSpinner->setValue(preset.offset(sourceName)/OFFSETDIVISOR);
        offsetSpinner->setEnabled(offsetsEditable);
        ui->sourceTable->setCellWidget(row, OFFSETCOL, offsetSpinner);

        if (preset.scaleType(sourceName) == PlotSettings::NOT_SCALABLE) {
            QTableWidgetItem *scaleItem = new QTableWidgetItem(tr("n/a"));
            scaleItem->setFlags(scaleItem->flags() & ~Qt::ItemIsEditable);
            ui->sourceTable->setItem(row, SCALECOL, scaleItem);
        } else {
            QComboBox *scaleCombo = new QComboBox();
            scaleCombo->addItems(PlotSettings::scaleTypeNames);
            scaleCombo->setCurrentIndex(preset.scaleType(sourceName));
            ui->sourceTable->setCellWidget(row, SCALECOL, scaleCombo);
        }
    }
Exemplo n.º 23
0
void Plotter::drawGrid(QPainter *painter)
{
        //qDebug() << "Inside DrawGrid";
    QRect rect(Margin,Margin,width()-2*Margin,height()-2*Margin);
    if(!rect.isValid())
        return;
    QPen pen;
    QColor objColor(55,55,55,255);
    pen.setBrush(Qt::darkGray);
    pen.setStyle(Qt::DotLine);
    pen.setColor(objColor);
    pen.setCapStyle(Qt::RoundCap);
    pen.setJoinStyle(Qt::RoundJoin);
    painter->setPen(pen);
    //QPoint *pixPoint = new QPoint();
    PlotSettings settings = zoomStack[curZoom];
    if(m_bGrid)
    {
        for(int i=0;i<settings.numXTicks;i++)
        {
            int x = rect.left() + (i * (rect.width()) / settings.numXTicks);
            double label = settings.minX + (i*settings.spanX()/settings.numXTicks);
            //printf("X Axis:%f\n",label);
            for(float l_nPoint=1;l_nPoint<rect.height();l_nPoint+=2.0)
                painter->drawPoint(QPointF(x,rect.top()+l_nPoint));

            painter->drawLine(x,rect.bottom(),x,rect.bottom()+5);
            painter->drawText(x-50,rect.bottom()+5,100,20, Qt::AlignHCenter|Qt::AlignTop,QString::number(label,5,2));
        }
        for(int j=0;j<settings.numYTicks;j++)
        {
            int y = rect.bottom() - (j * (rect.height()) / settings.numYTicks);
            double label = settings.minY + (j*settings.spanY()/settings.numYTicks);
            //printf("Y Axis:%f\n",label);
            for(float l_nPoint=0;l_nPoint<rect.width();l_nPoint+=2.0)
                painter->drawPoint(QPointF(rect.left()+l_nPoint,y));
            painter->drawLine(rect.left(),y,rect.right(),y);
            painter->drawText(rect.left()-Margin,y-10,Margin-5, 20,Qt::AlignRight|Qt::AlignVCenter,QString::number(label,5,2));
        }

    pen.setStyle(Qt::SolidLine);
    painter->setPen(pen);
    //int Value =0;
    
        for(int i=0;i<rect.height();i+=((rect.height()/settings.numYTicks)/5))
        {
            if(i!=0 && i%5!=0){
                //painter->drawLine(Margin+rect.width()/2-3,Margin+i,Margin+rect.width()/2+3,Margin+i);
            }
        }
        for(int j=0;j<rect.width();j+=(rect.width()/settings.numXTicks)/5 )
        {
            if(j!=0 && j%5!=0){
               // painter->drawLine(Margin+j,Margin+rect.height()/2-3,Margin+j,Margin+rect.height()/2+3);
            }
        }
    }
    if(m_bGrid == false){
        pen.setStyle(Qt::SolidLine);
        pen.setBrush(Qt::darkGray);
        pen.setColor(objColor);
        pen.setWidth(1);
        painter->setPen(pen);
        if(zoomScreenFlag==true){
/*vertical line*/        painter->drawLine(Margin+rect.width()/2-1,Margin,Margin+rect.width()/2-1,Margin+rect.height());
/*horizontal line*/      painter->drawLine(Margin,Margin+rect.height()/2-1,Margin+rect.width(),Margin+rect.height()/2-1);
        }
        else if(zoomScreenFlag==false){
/*vertical line*/        painter->drawLine(Margin+rect.width()/2-1,Margin,Margin+rect.width()/2-1,Margin+rect.height());
/*horizontal line*/      painter->drawLine(Margin,Margin+rect.height()/2-1,Margin+rect.width(),Margin+rect.height()/2-1);
        }

        for(int i=0;i<rect.height();i+=((rect.height()/settings.numYTicks)/2))
        {
            if(i!=0 && i%2!=0)
            {
            if(zoomScreenFlag==true){
            	//painter->drawLine((Margin+rect.width()/2-3)-1,Margin+i,(Margin+rect.width()/2+3)-1,Margin+i);
            }
           }
        }
        for(int j=0;j<rect.width();j=j+(rect.width()/settings.numXTicks)+5 )
        {
            if(j!=0)
            {
            	//painter->drawLine(Margin+j-5,Margin+rect.height()/2-3,Margin+j-5,Margin+rect.height()/2+3);
            }
        }


    }
    if(m_bVILabels == true)
    {
        pen.setWidth(2);
        pen.setBrush(Qt::gray);
        painter->setPen(pen);
    	//qDebug() << "XLabel" << m_strXLabel << "YLabel" << m_strYLabel;
//        painter->drawText(Margin+rect.width()/2+8,3,65,45,Qt::AlignLeft|Qt::AlignTop,m_strY1Label);
//        painter->drawText(4,Margin+rect.height()/2+2,35,45,Qt::AlignLeft|Qt::AlignTop,m_strX1Label);
//        painter->drawText(Margin+rect.width()-35,Margin+rect.height()/2,35,45,Qt::AlignHCenter|Qt::AlignTop,m_strX2Label);
//        painter->drawText(Margin+rect.width()/2+8,Margin+rect.height()-20,65,45,Qt::AlignLeft|Qt::AlignTop,m_strY2Label);
        painter->drawText(Margin+rect.width()/2+8,8,65,45,Qt::AlignLeft|Qt::AlignTop,"+"+m_strY1Label);
        painter->drawText(15,Margin+rect.height()/2+2,35,45,Qt::AlignLeft|Qt::AlignTop,"+"+m_strX1Label);
        painter->drawText(Margin+rect.width()-45,Margin+rect.height()/2,35,45,Qt::AlignHCenter|Qt::AlignTop,m_strX2Label);
        painter->drawText(Margin+rect.width()/2+8,Margin+rect.height()-25,65,45,Qt::AlignLeft|Qt::AlignTop,m_strY2Label);
    }
    //painter->drawRect(rect.adjusted(+0,+0,-1,-1));
   // qDebug() << "outSide DrawGrid";
    //painter->drawRect(rect.adjusted(+0,+0,-1,-1));
}
Exemplo n.º 24
0
void Plotter::drawCurves(QPainter *painter)
{
	//~~~~~~~~Adjust X-y Axis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    QStringList stringList;
    bool ok=true;
    QFile textFile("AdjustXYaxisVI.txt");
    if (textFile.open(QIODevice::ReadOnly))
    {
        QTextStream textStream(&textFile);
        while (!textStream.atEnd())
        {
            stringList.append(textStream.readLine());
        }
        adjustXaxis=stringList.value(0).toDouble(&ok) * m_nXZoomFactor;
        adjustYaxis=stringList.value(1).toDouble(&ok) * m_nYZoomFactor;
    }else{
        adjustXaxis=5.5;
        adjustYaxis=0;
    }
//    qDebug() << "Zoom Factor:" << m_nXZoomFactor << m_nYZoomFactor;
//    qDebug() << "Adjust Axis:" << adjustXaxis << adjustYaxis;
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    static const QColor colorForIds[8] = {Qt::red,Qt::green,Qt::cyan,Qt::magenta,Qt::yellow,Qt::white,Qt::gray,Qt::black};
    PlotSettings settings = zoomStack[curZoom];
    if( m_moveFlag == true)
    {
        settings.maxX = m_ZoomSettings->maxX;
        settings.maxY = m_ZoomSettings->maxY;
        settings.minX = m_ZoomSettings->minX;
        settings.minY = m_ZoomSettings->minY;
        settings.m_nOffset = m_ZoomSettings->m_nOffset;
        settings.numXTicks = m_ZoomSettings->numXTicks;
        settings.numYTicks = m_ZoomSettings->numYTicks;
    }
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    if(m_bshowZoomRect == true)
    {
        painter->setPen(colorForIds[6]);
        painter->drawRect(rubberBandRect);
    }

    if(!rect.isValid())
        return;
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
//    printf("Rect Left: %d\n",rect.left());
//    printf("Rect Height: %d\n",rect.height());
//    printf("Rect width: %d\n",rect.width());
//    printf("Rect Bottom: %d\n",rect.bottomLeft().y());
//    printf("Rect Top: %d\n",rect.top());
    double dx,dy;
    while(i.hasNext()){

        i.next();
        int id = i.key();
      //  qDebug() << "Curve ID" << id;
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        double y =0.0,x=0.0;
        int l_nCounter =0;
        //printf("MinY:%f\n",settings.minY);
        //printf("Offset:%f\n",m_nOffset);
        m_nOffset =0.0;
        for(int j=0; j< data.count();++j)
        {
             dx = data[j].x();
             dy = data[j].y();
             if(m_bUniPolar == true)
             {
                 float l_nDiv = (dy/2.0);
//                 printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
             }
             if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
             {
                 //printf("X:%f Y:%f\n",dx,dy);
             }
            y =0.0,x=0.0;
            if(m_ZoomFlag == false)
            {
                if(m_bVIMode == true)
                    x = ((rect.width()/2)+adjustXaxis  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
                else
                    x = (rect.left()+ ((dx)*(((rect.width()-1)))/(settings.spanX())));

                if( m_bUniPolar == true){
                    y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                    //y+=10;
//                    printf(" Coord-Y %f\n",dy/2.0);
                }
                else
                    y = (((Margin+rect.height()/2)+adjustYaxis) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));//TO CHANGE THE Y AXIS IN THE GRAPH
               // printf(" Coord- X & Y %f %f\n",x,y);
            }
            else if(m_ZoomFlag == true)
            {
                x = (rect.left() + ((dx-settings.minX)*(((rect.width()-1)))/(settings.spanX())));
                y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            }
            if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
            {

            	polyline[j] = QPointF(x,y);
                l_nCounter++;
            }
        }
        QPolygonF zoomPolyline(l_nCounter);
        y =0.0,x=0.0;
        int l_nIndex1 =0;
        for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
        {
            QPointF(x,y);
            x = polyline.at(l_nIndex).x();
            y = polyline.at(l_nIndex).y();
            //qDebug()<<x<<y;
            if(x!=0.0 || y!=0.0 )
            {
                zoomPolyline[l_nIndex1] = QPointF(x,y);
                l_nIndex1++;
            }
        }
//        if( m_nClearID == id)
//        	painter->setPen(Qt::black);
        //else
        	QPen pen;
        	painter->setPen(colorForIds[uint(id) %6]);
//        	pen.setColor(colorForIds[uint(id) %6]);
//            pen.setWidth(20);
//            painter->setPen(pen);


        if(m_ZoomFlag == false)
        {
        	painter->setPen(colorForIds[uint(id) %6]);
                painter->drawPolyline(polyline);
//            qDebug()<<"Band:"<<m_objPlotData->m_nEnvelopBand;
            //compareCurvePoints(polyline1);
        }
        else
            painter->drawPolyline(zoomPolyline);
        }
   // qDebug() << "Exit Draw Cruves.";
}