void GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints (const LineStyle &lineStyle)
{
  // LOG4CPP_INFO_S is below

  bool needRenumbering = needOrdinalRenumbering ();
  if (needRenumbering) {

    renumberOrdinals();

  }

  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
                              << " numberPoints=" << m_graphicsPoints.count()
                              << " ordinalRenumbering=" << (needRenumbering ? "true" : "false");

  if (lineStyle.curveConnectAs() != CONNECT_SKIP_FOR_AXIS_CURVE) {

    // Draw as either straight or smoothed. The function/relation differences were handled already with ordinals. The
    // Spline algorithm will crash with fewer than three points so it is only called when there are enough points
    QPainterPath path;
    if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_STRAIGHT ||
        lineStyle.curveConnectAs() == CONNECT_AS_RELATION_STRAIGHT ||
        m_graphicsPoints.count () < 3) {

      path = drawLinesStraight ();
    } else {
      path = drawLinesSmooth ();
    }

   setPath (path);
  }
}
void GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints (const LineStyle &lineStyle)
{
  OrdinalToPointIdentifier ordinalToPointIdentifier;

  // Order by ordinals locally
  PointIdentifierToPoint::const_iterator itr;
  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {

    const Point &point = *itr;
    ordinalToPointIdentifier [point.ordinal ()] = point.identifier ();

  }

  // Draw as either straight or smoothed. The function/relation differences were handled already with ordinals. The
  // Spline algorithm will crash with fewer than three points so it is only called when there are enough points
  QPainterPath path;
  if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_STRAIGHT ||
      lineStyle.curveConnectAs() == CONNECT_AS_RELATION_STRAIGHT ||
      m_graphicsPoints.count () < 3) {

    path = drawLinesStraight (ordinalToPointIdentifier);
  } else {
    path = drawLinesSmooth (ordinalToPointIdentifier);
  }

  setPath (path);
}
void GraphicsLinesForCurve::updatePointOrdinalsAfterDrag (const LineStyle &lineStyle,
                                                          const Transformation &transformation)
{
  CurveConnectAs curveConnectAs = lineStyle.curveConnectAs();

  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
                               << " curve=" << m_curveName.toLatin1().data()
                               << " curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();

  if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
      curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {

    // Make sure ordinals are properly ordered

    // Get a map of x/theta values as keys with point identifiers as the values
    XOrThetaToOrdinal xOrThetaToOrdinal;
    OrdinalToGraphicsPoint::iterator itrP;
    for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {

       double ordinal = itrP.key();
       const GraphicsPoint *point = itrP.value();

       // Convert screen coordinate to graph coordinates, which gives us x/theta
       QPointF pointGraph;
       transformation.transformScreenToRawGraph(point->pos (),
                                                pointGraph);

       xOrThetaToOrdinal [pointGraph.x()] = ordinal;
    }

    // Loop through the sorted x/theta values. Since QMap is used, the x/theta keys are sorted
    OrdinalToGraphicsPoint temporaryList;
    int ordinalNew = 0;
    XOrThetaToOrdinal::const_iterator itrX;
    for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {

      double ordinalOld = *itrX;
      GraphicsPoint *point = m_graphicsPoints [ordinalOld];

      temporaryList [ordinalNew++] = point;
    }

    // Copy from temporary back to original map
    m_graphicsPoints.clear();
    for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {

      double ordinal = itrP.key();
      GraphicsPoint *point = itrP.value();

      m_graphicsPoints [ordinal] = point;
    }
  }
}
Exemple #4
0
void DlgSettingsCurveProperties::drawLine (bool isRelation,
                                           const LineStyle &lineStyle)
{
  const double Z_LINE = -1.0; // Looks nicer if line goes under the points, so points are unobscured

  // Line between points. Start with function connection
  QPainterPath path;
  QPointF p0 (POS_LEFT), p1 (POS_CENTER), p2 (POS_RIGHT);
  if (isRelation) {

    // Relation connection
    p1 = POS_RIGHT;
    p2 = POS_CENTER;
  }

  // Draw straight or smooth
  if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_SMOOTH ||
      lineStyle.curveConnectAs() == CONNECT_AS_RELATION_SMOOTH) {

    vector<double> t;
    vector<SplinePair> xy;
    t.push_back(0);
    t.push_back(1);
    t.push_back(2);
    xy.push_back (SplinePair (p0.x(), p0.y()));
    xy.push_back (SplinePair (p1.x(), p1.y()));
    xy.push_back (SplinePair (p2.x(), p2.y()));
    Spline spline (t, xy);
    path.moveTo (p0);
    path.cubicTo (QPointF (spline.p1(0).x(),
                           spline.p1(0).y()),
                  QPointF (spline.p2(0).x(),
                           spline.p2(0).y()),
                  p1);
    path.cubicTo (QPointF (spline.p1(1).x(),
                           spline.p1(1).y()),
                  QPointF (spline.p2(1).x(),
                           spline.p2(1).y()),
                  p2);
  } else {
    path.moveTo (p0);
    path.lineTo (p1);
    path.lineTo (p2);
  }

  QGraphicsPathItem *line = new QGraphicsPathItem (path);
  line->setPen (QPen (QBrush (ColorPaletteToQColor (lineStyle.paletteColor())),
                      lineStyle.width()));
  line->setZValue (Z_LINE);
  m_scenePreview->addItem (line);
}
Exemple #5
0
void DlgSettingsCurveProperties::updatePreview()
{
  m_scenePreview->clear();

  QString currentCurve = m_cmbCurveName->currentText();

  const PointStyle pointStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).pointStyle();
  const LineStyle lineStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).lineStyle();

  // Function or relation?
  bool isRelation = (lineStyle.curveConnectAs() == CONNECT_AS_RELATION_SMOOTH ||
                     lineStyle.curveConnectAs() == CONNECT_AS_RELATION_STRAIGHT);

  drawPoints (pointStyle);
  drawLine (isRelation,
            lineStyle);

  resetSceneRectangle();
}
void GraphicsLinesForCurve::updatePointOrdinalsAfterDrag (const LineStyle &lineStyle,
                                                          const Transformation &transformation)
{
  if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_SMOOTH ||
      lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_STRAIGHT) {

    // Make sure ordinals are properly ordered

    // Get a map of x/theta values as keys with point identifiers as the values
    XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
    PointIdentifierToPoint::iterator itrP;
    for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {

       QString pointIdentifier = itrP.key();
       const Point &pointScreen = itrP.value();

       // Convert screen coordinate to graph coordinates, which gives us x/theta
       QPointF pointGraph;
       transformation.transformScreenToRawGraph(pointScreen.posScreen(),
                                                pointGraph);

       xOrThetaToPointIdentifier [pointGraph.x()] = pointIdentifier;
    }

    // Loop through the sorted x/theta values. Since QMap is used, the x/theta keys are sorted
    int ordinal = 0;
    XOrThetaToPointIdentifier::const_iterator itrX;
    for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {

      QString pointIdentifier = itrX.value();
      Point &point = m_graphicsPoints [pointIdentifier];

      point.setOrdinal (ordinal++); // Override the old ordinal
    }
  }
}
Exemple #7
0
LineStyle::LineStyle (const LineStyle &other) :
  m_width (other.width ()),
  m_paletteColor (other.paletteColor()),
  m_curveConnectAs (other.curveConnectAs())
{
}