Esempio n. 1
0
void Dialog::addTrend(QString attrName)
{

    QString s;
    s = QString("Adding ");
//    attrName = QString("gunlaser/devices/redpitayaevents2/measurementdata2");
    s.append(attrName);
    this->ui->infoLabel->setText(s);

    cout << "In Dialog::addTrend...\n";
    QCPAxis* ax = this->ui->plotWidget->axisRect()->addAxis(QCPAxis::AxisType::atLeft);
    ui->plotWidget->yAxis->setVisible(false);
    ax->setVisible(false);

    QCPGraph* graph = this->ui->plotWidget->addGraph(0, ax);

    QColor attrColor = this->mLightColorList[this->mCurrentColorListIndex];
    this->mCurrentColorListIndex++;
    if (this->mCurrentColorListIndex > this->mLightColorList.count())
    {
        this->mCurrentColorListIndex=0;
    }

    QTrendLegendWidget* leg = new QTrendLegendWidget(attrName, attrColor, this);
//    leg->setName(attrName);
    leg->setAxis(ax);
    leg->setGraph(graph);
    this->ui->verticalLayout_2->insertWidget(this->ui->verticalLayout_2->count()-1, leg);
//    this->ui->verticalLayout_2->addWidget(leg);
    this->trendLegendList.append(leg);

//    this->graphList.append(graph);
//    this->axisList.append(ax);
//    TrendCurve newCurve(attrName, graph, ax);

//    TrendCurve newCurve();
//    TrendCurve* newCurve = new TrendCurve(attrName, this->ui->plotWidget);
//    delete newCurve;
    try
    {
        TrendDataCollector* newCurve = new TrendDataCollector(attrName);
        QThread* thread = new QThread;
        newCurve->moveToThread(thread);
        connect(newCurve, SIGNAL(new_data(double,double)), leg, SLOT(updateData(double, double)));
        connect(thread, SIGNAL(started()), newCurve, SLOT(process()));

        connect(newCurve, SIGNAL(finished()), thread, SLOT(quit()));
        connect(newCurve, SIGNAL(finished()), newCurve, SLOT(deleteLater()));
        connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
        this->trendDataCollectorList.append(newCurve);
        this->threadList.append(thread);
        thread->start();
    }
    catch (...)
    {
        cout << "Error creating trend curve";
    };
}
Esempio n. 2
0
/*!
  Rescales the value axis of the plottable so the whole plottable is visible.
  
  Returns true if the axis was actually scaled. This might not be the case if this plottable has an
  invalid range, e.g. because it has no data points.
  
  See \ref rescaleAxes for detailed behaviour.
*/
void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge) const
{
  QCPAxis *valueAxis = mValueAxis.data();
  if (!valueAxis) { qDebug() << Q_FUNC_INFO << "invalid value axis"; return; }
  
  SignDomain signDomain = sdBoth;
  if (valueAxis->scaleType() == QCPAxis::stLogarithmic)
    signDomain = (valueAxis->range().upper < 0 ? sdNegative : sdPositive);
  
  bool foundRange;
  QCPRange newRange = getValueRange(foundRange, signDomain);
  if (foundRange)
  {
    if (onlyEnlarge)
      newRange.expand(valueAxis->range());
    if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable
    {
      double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason
      if (valueAxis->scaleType() == QCPAxis::stLinear)
      {
        newRange.lower = center-valueAxis->range().size()/2.0;
        newRange.upper = center+valueAxis->range().size()/2.0;
      } else // scaleType() == stLogarithmic
      {
        newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower);
        newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower);
      }
    }
    valueAxis->setRange(newRange);
  }
}
Esempio n. 3
0
/*! \internal
  \overload
  
  Returns the input as pixel coordinates in a QPointF.
*/
const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const
{
  QCPAxis *keyAxis = mKeyAxis.data();
  QCPAxis *valueAxis = mValueAxis.data();
  if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); }
  
  if (keyAxis->orientation() == Qt::Horizontal)
    return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value));
  else
    return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key));
}
Esempio n. 4
0
/*! \internal
  
  Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates,
  taking the orientations of the axes associated with this plottable into account (e.g. whether key
  represents x or y).
  
  \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value.
    
  \see coordsToPixels, QCPAxis::coordToPixel
*/
void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const
{
  QCPAxis *keyAxis = mKeyAxis.data();
  QCPAxis *valueAxis = mValueAxis.data();
  if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
  
  if (keyAxis->orientation() == Qt::Horizontal)
  {
    key = keyAxis->pixelToCoord(x);
    value = valueAxis->pixelToCoord(y);
  } else
  {
    key = keyAxis->pixelToCoord(y);
    value = valueAxis->pixelToCoord(x);
  }
}
Esempio n. 5
0
/*! \internal
  
  Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface,
  taking the orientations of the axes associated with this plottable into account (e.g. whether key
  represents x or y).
  
  \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y.
    
  \see pixelsToCoords, QCPAxis::coordToPixel
*/
void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const
{
  QCPAxis *keyAxis = mKeyAxis.data();
  QCPAxis *valueAxis = mValueAxis.data();
  if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
  
  if (keyAxis->orientation() == Qt::Horizontal)
  {
    x = keyAxis->coordToPixel(key);
    y = valueAxis->coordToPixel(value);
  } else
  {
    y = keyAxis->coordToPixel(key);
    x = valueAxis->coordToPixel(value);
  }
}
void AP2DataPlot2D::navModeChanged(int uasid, int mode, const QString& text)
{
    Q_UNUSED(mode);
    if (m_uas->getUASID() != uasid)
    {
        return;
    }
    if (m_logLoaded)
    {
        //If a log is currently loaded, we don't care about incoming data.
        return;
    }
    qint64 msec_current = QDateTime::currentMSecsSinceEpoch();
    m_currentIndex = msec_current;
    qint64 newmsec = (msec_current - m_startIndex) + m_timeDiff;
    if (m_graphCount > 0 && ui.autoScrollCheckBox->isChecked())
    {
        double diff = (newmsec / 1000.0) - m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().upper;
        m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeLower(m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().lower + diff);
        m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeUpper((newmsec / 1000.0));
    }
    if (!m_graphClassMap.contains("MODE"))
    {
        QCPAxis *axis = m_wideAxisRect->addAxis(QCPAxis::atLeft);
        axis->setLabel("MODE");

        if (m_graphCount > 0)
        {
            connect(m_wideAxisRect->axis(QCPAxis::atLeft,0),SIGNAL(rangeChanged(QCPRange)),axis,SLOT(setRange(QCPRange)));
        }
        QColor color = QColor::fromRgb(rand()%255,rand()%255,rand()%255);
        axis->setLabelColor(color);
        axis->setTickLabelColor(color);
        axis->setTickLabelColor(color); // add an extra axis on the left and color its numbers
        QCPGraph *mainGraph1 = m_plot->addGraph(m_wideAxisRect->axis(QCPAxis::atBottom), m_wideAxisRect->axis(QCPAxis::atLeft,m_graphCount++));
        m_graphNameList.append("MODE");

        mainGraph1->setPen(QPen(color, 2));
        Graph graph;
        graph.axis = axis;
        graph.groupName = "";
        graph.graph=  mainGraph1;
        graph.isInGroup = false;
        graph.isManualRange = false;
        m_graphClassMap["MODE"] = graph;

        mainGraph1->rescaleValueAxis();
        if (m_graphCount == 1)
        {
            mainGraph1->rescaleKeyAxis();
        }
    }
    QCPAxis *xAxis = m_wideAxisRect->axis(QCPAxis::atBottom);
    QCPItemText *itemtext = new QCPItemText(m_plot);
    itemtext->setText(text);
    itemtext->position->setAxes(xAxis,m_graphClassMap["MODE"].axis);
    itemtext->position->setCoords((newmsec / 1000.0),2.0);
    m_plot->addItem(itemtext);
    m_graphClassMap["MODE"].itemList.append(itemtext);
    m_graphClassMap["MODE"].modeMap[newmsec / 1000.0] = text;


    QCPItemLine *itemline = new QCPItemLine(m_plot);
    m_graphClassMap["MODE"].itemList.append(itemline);
    itemline->start->setParentAnchor(itemtext->bottom);
    itemline->start->setAxes(xAxis, m_graphClassMap["MODE"].axis);
    itemline->start->setCoords(0.0, 0.0);
    itemline->end->setAxes(xAxis, m_graphClassMap["MODE"].axis);
    itemline->end->setCoords((newmsec / 1000.0), 0.0);
    itemline->setTail(QCPLineEnding::esDisc);
    itemline->setHead(QCPLineEnding::esSpikeArrow);
    m_plot->addItem(itemline);
}
Esempio n. 7
0
void graphWidget::setBezPoints()
{
    if(!selFunc || selFunc->degree != freeform) {
        if(bezPoints.size()) {
            for(int i = 0; i < bezPoints.size(); ++i) {
                delete bezPoints[i];
            }
            bezPoints.clear();
        }
        return;
    }
    if(selFunc && selFunc->degree == freeform) {
        QCPAxis* yAxis;
        switch(selFunc->parent->type) {
        case funcRoll:
            yAxis = yAxes[0];
            break;
        case funcNormal:
        case funcLateral:
            yAxis = yAxes[1];
            break;
        case funcPitch:
            yAxis = yAxes[2];
            break;
        case funcYaw:
            yAxis = yAxes[3];
            break;
        }

        float until;
        if(selFunc->parent->secParent->bArgument == TIME) {
            until = selTrack->trackData->getNumPoints(selFunc->parent->secParent)/F_HZ;
        } else {
			until = selFunc->parent->secParent->lNodes.first().fTotalHeartLength;
        }
        int x1 = ui->plotter->xAxis->coordToPixel(selFunc->minArgument+until);
        int x2 = ui->plotter->xAxis->coordToPixel(selFunc->maxArgument+until);
        int y1 = yAxis->coordToPixel(selFunc->startValue);
        int y2 = yAxis->coordToPixel(selFunc->startValue+selFunc->symArg);
        if(selFunc->pointList.size() != bezPoints.size()) {
            for(int i = 0; i < bezPoints.size(); ++i) {
                delete bezPoints[i];
            }
            bezPoints.clear();
            for(int i = 0; i < selFunc->pointList.size(); ++i) {
                bezPoints.append(new dragLabel(ui->plotter));
                bezPoints[i]->setText("x");
                bezPoints[i]->setGeometry(QRect(0, 0, 12, 12));
                bezPoints[i]->setAlignment(Qt::AlignCenter);
                bezPoints[i]->show();
            }
        }
        for(int i = 0; i < selFunc->pointList.size(); ++i) {
            if(bezPoints[i]->isDragged) {
                selFunc->pointList[i].x = (ui->plotter->xAxis->pixelToCoord(bezPoints[i]->pos().x()+6)-selFunc->minArgument-until)/(selFunc->maxArgument-selFunc->minArgument);
                selFunc->pointList[i].y = (yAxis->pixelToCoord(bezPoints[i]->pos().y()+6)-selFunc->startValue)/(selFunc->symArg);
                selFunc->updateBez();
                selTrack->trackData->updateTrack(selTrack->trackData->activeSection, (int)(selFunc->minArgument*F_HZ-1.5f));
            } else {
                int x = x1*(1-selFunc->pointList[i].x) + x2*selFunc->pointList[i].x-6;
                int y = y1*(1-selFunc->pointList[i].y) + y2*selFunc->pointList[i].y-6;
                bezPoints[i]->move(x, y);
            }
        }
        redrawGraphs();
    }
    return;
}