Beispiel #1
0
bool Spectrogram::hasColorScale() {
  QwtPlot *plot = this->plot();
  if (!plot)
    return false;

  if (!plot->axisEnabled(color_axis))
    return false;

  QwtScaleWidget *colorAxis = plot->axisWidget(color_axis);
  return colorAxis->isColorBarEnabled();
}
Beispiel #2
0
void Spectrogram::showColorScale(int axis, bool on)
{
  if (hasColorScale() == on && color_axis == axis)
    return;

  QwtPlot *plot = this->plot();
  if (!plot)
    return;

  QwtScaleWidget *colorAxis = plot->axisWidget(color_axis);
  colorAxis->setColorBarEnabled(false);

  color_axis = axis;

  // We must switch main and the color scale axes and their respective scales
  int xAxis = this->xAxis();
  int yAxis = this->yAxis();
  int oldMainAxis = yAxis;
  if (axis == QwtPlot::xBottom || axis == QwtPlot::xTop)
  {
    oldMainAxis = xAxis;
    xAxis = 5 - color_axis;
  }
  else if (axis == QwtPlot::yLeft || axis == QwtPlot::yRight)
  {
    oldMainAxis = yAxis;
    yAxis = 1 - color_axis;
  }

  // First we switch axes
  setAxis(xAxis, yAxis);

  // Next we switch axes scales
  QwtScaleDiv *scDiv = plot->axisScaleDiv(oldMainAxis);
  if (axis == QwtPlot::xBottom || axis == QwtPlot::xTop)
    plot->setAxisScale(xAxis, scDiv->lBound(), scDiv->hBound());
  else if (axis == QwtPlot::yLeft || color_axis == QwtPlot::yRight)
    plot->setAxisScale(yAxis, scDiv->lBound(), scDiv->hBound());

  colorAxis = plot->axisWidget(color_axis);
  plot->setAxisScale(color_axis, data().range().minValue(), data().range().maxValue());
  colorAxis->setColorBarEnabled(on);
  colorAxis->setColorMap(data().range(), colorMap());
  if (!plot->axisEnabled(color_axis))
    plot->enableAxis(color_axis);
  colorAxis->show();
  plot->updateLayout();
}