void DlgSettingsSegments::updatePreview()
{
  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsSegments::updatePreview"
                              << " loading=" << (m_loading ? "true" : "false");

  const QString ARBITRARY_IDENTIFIER ("");
  const QColor COLOR (Qt::blue);
  const int RADIUS = 5;

  if (!m_loading) {

    SegmentFactory segmentFactory (*m_scenePreview,
                                   mainWindow().isGnuplot());

    clearPoints();
    segmentFactory.clearSegments (m_segments);

    // Create new segments
    segmentFactory.makeSegments (createPreviewImage(),
                                 *m_modelSegmentsAfter,
                                 m_segments);

    // Make the segment visible
    QList<Segment*>::iterator itrS;
    for (itrS = m_segments.begin(); itrS != m_segments.end(); itrS++) {
      Segment *segment = *itrS;
      segment->slotHover (true);
    }

    // Create some points
    PointStyle pointStyle (POINT_SHAPE_CROSS,
                           RADIUS,
                           BRUSH_WIDTH,
                           COLOR_PALETTE_BLUE);
    QPolygonF polygon = pointStyle.polygon();
    QList<QPoint> points = segmentFactory.fillPoints (*m_modelSegmentsAfter,
                                                      m_segments);
    QList<QPoint>::iterator itrP;
    for (itrP = points.begin(); itrP != points.end(); itrP++) {
      QPoint pos = *itrP;
      GraphicsPoint *graphicsPoint = new GraphicsPoint (*m_scenePreview,
                                                        ARBITRARY_IDENTIFIER,
                                                        pos,
                                                        COLOR,
                                                        polygon,
                                                        BRUSH_WIDTH);
      m_points.push_back (graphicsPoint);
    }
  }
}
예제 #2
0
void DigitizeStateSegment::slotMouseClickOnSegment(QPointF posSegmentStart)
{
    LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::slotMouseClickOnSegment";

    Segment *segment = segmentFromSegmentStart (posSegmentStart);

    // Create single-entry list that is expected by SegmentFactory
    QList<Segment*> segments;
    segments.push_back (segment);

    // Generate point coordinates. Nothing is created in the GraphicsScene at this point
    GraphicsScene &scene = context().mainWindow().scene();
    SegmentFactory segmentFactory ((QGraphicsScene &) scene,
                                   context().isGnuplot());

    QList<QPoint> points = segmentFactory.fillPoints (m_cmdMediator->document().modelSegments(),
                           segments);

    // Create one ordinal for each point
    OrdinalGenerator ordinalGenerator;
    Document &document = m_cmdMediator->document ();
    const Transformation &transformation = context ().mainWindow ().transformation();
    QList<double> ordinals;
    QList<QPoint>::iterator itr;
    for (itr = points.begin(); itr != points.end(); itr++) {

        QPoint point = *itr;
        ordinals << ordinalGenerator.generateCurvePointOrdinal(document,
                 transformation,
                 point,
                 activeCurve ());
    }

    // Create command to add points
    QUndoCommand *cmd = new CmdAddPointsGraph (context ().mainWindow(),
            document,
            context ().mainWindow().selectedGraphCurve(),
            points,
            ordinals);
    context().appendNewCmd(m_cmdMediator,
                           cmd);
}