Esempio n. 1
0
void TerrainProfileGraph::onCopyToClipboard()
{
  const osgEarth::Util::TerrainProfile profile = _calculator->getProfile();
  if (profile.getNumElevations() > 0)
  {
    const QLatin1String fieldSeparator(",");
    GeoPoint startPt = _calculator->getStart(ALTMODE_ABSOLUTE);
    GeoPoint endPt = _calculator->getEnd(ALTMODE_ABSOLUTE);
    QString profileInfo = QString("Start:,%1,%2\nEnd:,%3,%4\n")
      .arg(_coordinateFormatter->format(startPt).c_str()).arg(startPt.alt())
      .arg(_coordinateFormatter->format(endPt).c_str()).arg(endPt.alt());
    QString distanceInfo("Distance:");
    QString elevationInfo("Elevation:");
    for (unsigned int i = 0; i < profile.getNumElevations(); i++)
    {
      distanceInfo += fieldSeparator + QString::number(profile.getDistance(i));
      elevationInfo += fieldSeparator + QString::number(profile.getElevation(i));
    }
    profileInfo += distanceInfo + QString("\n") + elevationInfo;

    QImage graphImage(_graphWidth, _graphHeight, QImage::Format_RGB32);
    QPainter p;
    p.begin(&graphImage);
    _scene->render(&p);
    p.end();
    QMimeData* clipData = new QMimeData();
    clipData->setText(profileInfo);
    clipData->setImageData(graphImage);
    QApplication::clipboard()->setMimeData(clipData);
  }
}
Esempio n. 2
0
void TerrainProfileGraph::redrawGraph()
{
  _scene->clear();
  _graphLines.clear();
  _graphField.setCoords(0, 0, 0, 0);
  _hoverLine = 0L;

  const osgEarth::Util::TerrainProfile profile = _calculator->getProfile();
  if (profile.getNumElevations() > 0)
  {
    double minElevation, maxElevation;
    profile.getElevationRanges( minElevation, maxElevation );
    _totalDistance = profile.getTotalDistance();

    int mag = (int)pow(10.0, (double)((int)log10(maxElevation - minElevation)));
    _graphMinY = ((int)(minElevation / mag) - (minElevation < 0 ? 1 : 0)) * mag;
    _graphMaxY = ((int)(maxElevation / mag) + (maxElevation < 0 ? 0 : 1)) * mag;

    int graphRangeY = _graphMaxY - _graphMinY;
    double scale = (double)graphRangeY / 10.0;

    drawAxes(_graphMinY, _graphMaxY, scale, _totalDistance, _graphField);

    double lastX = _graphField.x();
    double lastY = (1.0 - ((profile.getElevation(0) - _graphMinY) / graphRangeY)) * _graphField.height() + _graphField.y();

    QPolygonF graphPoly;
    graphPoly << QPointF(_graphField.x(), _graphField.y() + _graphField.height());
    graphPoly << QPointF(lastX, lastY);

    for (unsigned int i = 0; i < profile.getNumElevations(); i++)
    {
      double distance = profile.getDistance( i );
      double elevation = profile.getElevation( i );

      double x = (distance / _totalDistance) * _graphField.width() + _graphField.x();
      double y = (1.0 - ((elevation - _graphMinY) / graphRangeY)) * _graphField.height() + _graphField.y();

      graphPoly << QPointF(x, y);

      QLineF line(lastX, lastY, x, y);
      _graphLines.push_back(line);
      _scene->addLine(line, _linePen)->setZValue(GRAPH_Z);

      lastX = x;
      lastY = y;
    }

    // Add gradient polygon beneath the graph line
    graphPoly << QPointF(_graphField.x() + _graphField.width(), _graphField.y() + _graphField.height());
    QLinearGradient polyGrad(0, 0, 0, (_graphField.y() + _graphField.height()) * 1.25);
    polyGrad.setColorAt(0, _graphFillColor);
    polyGrad.setColorAt(1, QColor(255, 255, 255, 0));
    polyGrad.setSpread(QGradient::PadSpread);
    _scene->addPolygon(graphPoly, QPen(Qt::NoPen), QBrush(polyGrad))->setZValue(GRAPH_Z - 1);
  }
}