コード例 #1
0
ファイル: CQ3DBarsModifier.cpp プロジェクト: copasi/COPASI
void CQ3DBarsModifier::zoomToSelectedBar()
{
  m_animationCameraX.stop();
  m_animationCameraY.stop();
  m_animationCameraZoom.stop();
  m_animationCameraTarget.stop();

  Q3DCamera *camera = m_graph->scene()->activeCamera();
  float currentX = camera->xRotation();
  float currentY = camera->yRotation();
  float currentZoom = camera->zoomLevel();
  QVector3D currentTarget = camera->target();

  m_animationCameraX.setStartValue(QVariant::fromValue(currentX));
  m_animationCameraY.setStartValue(QVariant::fromValue(currentY));
  m_animationCameraZoom.setStartValue(QVariant::fromValue(currentZoom));
  m_animationCameraTarget.setStartValue(QVariant::fromValue(currentTarget));

  QPoint selectedBar = m_graph->selectedSeries()
                       ? m_graph->selectedSeries()->selectedBar()
                       : QBar3DSeries::invalidSelectionPosition();

  if (selectedBar != QBar3DSeries::invalidSelectionPosition())
    {
      // Normalize selected bar position within axis range to determine target coordinates
      QVector3D endTarget;
      float xMin = m_graph->columnAxis()->min();
      float xRange = m_graph->columnAxis()->max() - xMin;
      float zMin = m_graph->rowAxis()->min();
      float zRange = m_graph->rowAxis()->max() - zMin;
      endTarget.setX((selectedBar.y() - xMin) / xRange * 2.0f - 1.0f);
      endTarget.setZ((selectedBar.x() - zMin) / zRange * 2.0f - 1.0f);

      // Rotate the camera so that it always points approximately to the graph center
      qreal endAngleX = 90.0 - qRadiansToDegrees(qAtan(qreal(endTarget.z() / endTarget.x())));

      if (endTarget.x() > 0.0f)
        endAngleX -= 180.0f;

      float barValue = m_graph->selectedSeries()->dataProxy()->itemAt(selectedBar.x(),
                       selectedBar.y())->value();
      float endAngleY = barValue >= 0.0f ? 30.0f : -30.0f;

      if (m_graph->valueAxis()->reversed())
        endAngleY *= -1.0f;

      m_animationCameraX.setEndValue(QVariant::fromValue(float(endAngleX)));
      m_animationCameraY.setEndValue(QVariant::fromValue(endAngleY));
      m_animationCameraZoom.setEndValue(QVariant::fromValue(250));
      m_animationCameraTarget.setEndValue(QVariant::fromValue(endTarget));
    }
  else
    {
      // No selected bar, so return to the default view
      m_animationCameraX.setEndValue(QVariant::fromValue(m_defaultAngleX));
      m_animationCameraY.setEndValue(QVariant::fromValue(m_defaultAngleY));
      m_animationCameraZoom.setEndValue(QVariant::fromValue(m_defaultZoom));
      m_animationCameraTarget.setEndValue(QVariant::fromValue(m_defaultTarget));
    }

  m_animationCameraX.start();
  m_animationCameraY.start();
  m_animationCameraZoom.start();
  m_animationCameraTarget.start();
}
コード例 #2
0
ファイル: CQ3DBarsModifier.cpp プロジェクト: copasi/COPASI
CQ3DBarsModifier::CQ3DBarsModifier(CQArrayAnnotationsWidget* widget, Q3DBars *bargraph)
  : m_graph(bargraph),
    m_inputHandler(NULL),
    m_xRotation(0.0f),
    m_yRotation(0.0f),
    m_fontSize(30),
    m_segments(4),
    m_subSegments(3),
    m_minval(-1.0f),
    m_maxval(1.0f),
    m_valueAxis(new QValue3DAxis),
    m_rowAxis(new QCategory3DAxis),
    m_colAxis(new QCategory3DAxis),
    m_primarySeries(new QBar3DSeries),
    m_barMesh(QAbstract3DSeries::MeshBar),
    m_smooth(false)
{
  m_graph->activeTheme()->setType(Q3DTheme::ThemeArmyBlue);
  m_graph->activeTheme()->setBackgroundEnabled(false);
  m_graph->activeTheme()->setLabelBackgroundEnabled(true);
  m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualityNone);
  m_graph->setMultiSeriesUniform(true);

  m_valueAxis->setSegmentCount(m_segments);
  m_valueAxis->setSubSegmentCount(m_subSegments);
  m_valueAxis->setRange(m_minval, m_maxval);
  m_valueAxis->setLabelFormat(QString(QStringLiteral("%.1f ")));
  m_valueAxis->setLabelAutoRotation(30.0f);
  m_valueAxis->setTitleVisible(false);

  m_rowAxis->setLabelAutoRotation(30.0f);
  m_rowAxis->setTitleVisible(false);
  m_colAxis->setLabelAutoRotation(30.0f);
  m_colAxis->setTitleVisible(false);

  m_graph->setValueAxis(m_valueAxis);
  m_graph->setRowAxis(m_rowAxis);
  m_graph->setColumnAxis(m_colAxis);

  m_primarySeries->setItemLabelFormat(QStringLiteral("@rowLabel, @colLabel : @valueLabel"));
  m_primarySeries->setMesh(QAbstract3DSeries::MeshBar);
  m_primarySeries->setMeshSmooth(false);

  m_graph->addSeries(m_primarySeries);

  changePresetCamera();

  clearData();

  // Set up property animations for zooming to the selected bar
  Q3DCamera *camera = m_graph->scene()->activeCamera();
  camera->setCameraPreset(Q3DCamera::CameraPresetIsometricRight);
  m_defaultAngleX = camera->xRotation();
  m_defaultAngleY = camera->yRotation();
  m_defaultZoom = camera->zoomLevel();
  m_defaultTarget = camera->target();

  m_animationCameraX.setTargetObject(camera);
  m_animationCameraY.setTargetObject(camera);
  m_animationCameraZoom.setTargetObject(camera);
  m_animationCameraTarget.setTargetObject(camera);

  m_animationCameraX.setPropertyName("xRotation");
  m_animationCameraY.setPropertyName("yRotation");
  m_animationCameraZoom.setPropertyName("zoomLevel");
  m_animationCameraTarget.setPropertyName("target");

  int duration = 1700;
  m_animationCameraX.setDuration(duration);
  m_animationCameraY.setDuration(duration);
  m_animationCameraZoom.setDuration(duration);
  m_animationCameraTarget.setDuration(duration);

  // The zoom always first zooms out above the graph and then zooms in
  qreal zoomOutFraction = 0.3;
  m_animationCameraX.setKeyValueAt(zoomOutFraction, QVariant::fromValue(0.0f));
  m_animationCameraY.setKeyValueAt(zoomOutFraction, QVariant::fromValue(90.0f));
  m_animationCameraZoom.setKeyValueAt(zoomOutFraction, QVariant::fromValue(50.0f));
  m_animationCameraTarget.setKeyValueAt(zoomOutFraction,
                                        QVariant::fromValue(QVector3D(0.0f, 0.0f, 0.0f)));

  m_inputHandler = new CQCustomInputHandler(m_graph);
  m_inputHandler->setAxes(m_rowAxis, m_colAxis, m_valueAxis);
  m_graph->setActiveInputHandler(m_inputHandler);
  connect(m_inputHandler, SIGNAL(signalShowContextMenu(const QPoint &)), widget, SLOT(slotShowContextMenu(const QPoint&)));
  connect(m_inputHandler, SIGNAL(signalBarDoubleClicked(int, int)), widget, SLOT(selectTableCell(int, int)));

}