Example #1
0
void PlotScene::displayLabels(const QPointF& mousePos, const QPointF& scenePos)
{
    QPalette palette;
    PlotCurve* currentCurve = NULL;

    for (int i(0); i < this->curves.count(); i++)
    {
        currentCurve = this->curves.at(i);

        /* Get the CoordinateItem which abscisse is the nearest
         * to the mouse position abscisse */
        CoordinateItem* itemAtMousePos =
                currentCurve->nearestCoordinateitemsOfX(scenePos.x());

        if (itemAtMousePos == NULL) continue;

        // Get the label associate to the curve
        QLabel* curveLabel = this->curveLabels.at(i);
        if (curveLabel == NULL) continue;

        // Change the text color of the label associate to the curve
        palette.setColor(QPalette::WindowText, currentCurve->getPen().color());
        curveLabel->setPalette(palette);

        // Change the text of the label associate to the curve
        curveLabel->setText(QString("%1, %2").arg(
                                itemAtMousePos->x(), 6, 'f', 2).arg(
                                itemAtMousePos->y(), 6, 'f', 2));
        curveLabel->adjustSize();

        // Move the label
        curveLabel->move(mousePos.x(), mousePos.y() - (i * 12));
    }
}
Example #2
0
void PlotScene::highlightSector(float t1, float t2, const QVariant& trackId)
{
    qDebug() << "sector délimité sur mapping. Bornes : " << t1 << t2;

    PlotCurve* targetPlotCurve = NULL;

    // Find the curve associate to trackId of the point selected on the mapping
    for(int i(0); targetPlotCurve == NULL && i < this->curves.count(); i++)
        if (this->curves.at(i)->id() == trackId)
            targetPlotCurve = this->curves[i];

    if (targetPlotCurve == NULL)
    {
        qDebug() << "No PlotCurve associate to the trackId found";
        return;
    }

    /* Get the sector that contains all the points
     * corresponding to the time interval t1 to t2 */
    AnimateSectorItem* sect = targetPlotCurve->sectorOn(t1, t2);
    if (sect == NULL)
    {
        qDebug() << "impossible de déterminer le secteur correspondant "
                 << "à la sélection de la vue mapping";
        return;
    }

    // The sector will have the same color that the curve
    sect->setBrush(targetPlotCurve->getPen().brush());

    /* Create the group that will contain all the GraphicsItem corresponding
     * to the selected zone or point */
    if (this->selectedGroup == NULL)
    {
        this->selectedGroup = new QGraphicsItemGroup;
        this->addItem(this->selectedGroup);
    }

    this->selectedGroup->addToGroup(sect);
    sect->launchAnimation();
}