/**
		* Update the colour scale after the range changes.
		*/
		void ColorMapWidget::updateScale()
		{
			double minValue = m_minValueBox->displayText().toDouble();
			double maxValue = m_maxValueBox->displayText().toDouble();
			GraphOptions::ScaleType type = (GraphOptions::ScaleType)m_scaleOptions->itemData(m_scaleOptions->currentIndex()).toUInt();
			if (type == GraphOptions::Linear)
			{
				QwtLinearScaleEngine linScaler;
				m_scaleWidget->setScaleDiv(linScaler.transformation(), linScaler.divideScale(minValue, maxValue, 20, 5));
			}
			else if (type == GraphOptions::Power)
			{
				PowerScaleEngine powerScaler;
				m_scaleWidget->setScaleDiv(powerScaler.transformation(), powerScaler.divideScale(minValue, maxValue, 20, 5));
			}
			else
			{
				QwtLog10ScaleEngine logScaler;
				double logmin(minValue);
				if (logmin <= 0.0)
				{
					logmin = m_minPositiveValue;
				}
				m_scaleWidget->setScaleDiv(logScaler.transformation(), logScaler.divideScale(logmin, maxValue, 20, 5));
			}
		}
Exemple #2
0
/** Update the widget when the color map is changed */
void ColorBarWidget::updateColorMap()
{
  // The color bar alway shows the same range. Doesn't matter since the ticks don't show up
  QwtDoubleInterval range(1.0, 100.0);
  m_colorBar->setColorBarEnabled(true);
  m_colorBar->setColorMap( range, m_colorMap);
  m_colorBar->setColorBarWidth(15);
  m_colorBar->setEnabled(true);

  // Try to limit the number of steps based on the height of the color bar
  int maxMajorSteps = m_colorBar->height()/15; // 15 pixels per div looked about right
  //std::cout << "maxMajorSteps" << maxMajorSteps << std::endl;
  if (maxMajorSteps > 10) maxMajorSteps = 10;

  // Show the scale on the right
  double minValue = m_min;
  double maxValue = m_max;
  GraphOptions::ScaleType type = m_colorMap.getScaleType();
  if( type == GraphOptions::Linear )
  {
    QwtLinearScaleEngine linScaler;
    m_colorBar->setScaleDiv(linScaler.transformation(), linScaler.divideScale(minValue, maxValue, maxMajorSteps, 5));
    m_colorBar->setColorMap(QwtDoubleInterval(minValue, maxValue),m_colorMap);
  }
  else
 {
    QwtLog10ScaleEngine logScaler;
    m_colorBar->setScaleDiv(logScaler.transformation(), logScaler.divideScale(minValue, maxValue, maxMajorSteps, 5));
    m_colorBar->setColorMap(QwtDoubleInterval(minValue, maxValue), m_colorMap);
  }

}
/*!
   \brief Calculate a scale division for an interval

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajorSteps Maximum for the number of major steps
   \param maxMinorSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the engine
                   calculates one.

   \return Calculated scale division
*/
QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2,
    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
{
    QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() <= 0 )
        return QwtScaleDiv();

    const double logBase = base();

    if ( interval.maxValue() / interval.minValue() < logBase )
    {
        // scale width is less than one decade -> build linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes( attributes() );
        linearScaler.setReference( reference() );
        linearScaler.setMargins( lowerMargin(), upperMargin() );

        if ( stepSize != 0.0 )
        {
            if ( stepSize < 0.0 )
                stepSize = -qPow( logBase, -stepSize );
            else
                stepSize = qPow( logBase, stepSize );
        }

        return linearScaler.divideScale( x1, x2,
            maxMajorSteps, maxMinorSteps, stepSize );
    }

    stepSize = qAbs( stepSize );
    if ( stepSize == 0.0 )
    {
        if ( maxMajorSteps < 1 )
            maxMajorSteps = 1;

        stepSize = divideInterval( 
            qwtLogInterval( logBase, interval ).width(), maxMajorSteps );
        if ( stepSize < 1.0 )
            stepSize = 1.0; // major step must be >= 1 decade
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 )
    {
        QList<double> ticks[QwtScaleDiv::NTickTypes];
        buildTicks( interval, stepSize, maxMinorSteps, ticks );

        scaleDiv = QwtScaleDiv( interval, ticks );
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
/*!
   \brief Calculate a scale division

   \param x1 First interval limit 
   \param x2 Second interval limit 
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.

   \sa QwtScaleEngine::stepSize, LogTimeScaleEngine::subDivide
*/
QwtScaleDiv LogTimeScaleEngine::divideScale(double x1, double x2,
    int maxMajSteps, int maxMinSteps, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() <= 0 )
        return QwtScaleDiv();

    if (interval.maxValue() / interval.minValue() < 10.0)
    {
        // scale width is less than one decade -> build linear scale
    
        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes(attributes());
        linearScaler.setReference(reference());
        linearScaler.setMargins(
                                #if (QWT_VERSION >= 0x050200)
				lowerMargin(), upperMargin()
				#else
				loMargin(), hiMargin()
				#endif
				);

        return linearScaler.divideScale(x1, x2, 
            maxMajSteps, maxMinSteps, stepSize);
    }

    stepSize = qwtAbs(stepSize);
    if ( stepSize == 0.0 )
    {
        if ( maxMajSteps < 1 )
            maxMajSteps = 1;

        stepSize = divideInterval(log10(interval).width(), maxMajSteps);
        if ( stepSize < 1.0 )
            stepSize = 1.0; // major step must be >= 1 decade
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 )
    {
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
        buildTicks(interval, stepSize, maxMinSteps, ticks);

        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Exemple #5
0
/*! 
  Update the scale with the current attributes
  \sa QwtDial::setScale
*/
void QwtDial::updateScale()
{
    if ( d_data->scaleDraw )
    {
        QwtLinearScaleEngine scaleEngine;

        const QwtScaleDiv scaleDiv = scaleEngine.divideScale(
            minValue(), maxValue(), 
            d_data->maxMajIntv, d_data->maxMinIntv, d_data->scaleStep);

        d_data->scaleDraw->setTransformation(scaleEngine.transformation());
        d_data->scaleDraw->setScaleDiv(scaleDiv);
    }
}
Exemple #6
0
/**
 * Set up a new colour map.
 * @param colorMap :: Reference to the new colour map.
 */
void ColorMapWidget::setupColorBarScaling(const MantidColorMap& colorMap)
{
  double minValue = m_minValueBox->displayText().toDouble();
  double maxValue = m_maxValueBox->displayText().toDouble();

  GraphOptions::ScaleType type = colorMap.getScaleType();
  if( type == GraphOptions::Linear )
  {
    QwtLinearScaleEngine linScaler;
    m_scaleWidget->setScaleDiv(linScaler.transformation(), linScaler.divideScale(minValue, maxValue,  20, 5));
    m_scaleWidget->setColorMap(QwtDoubleInterval(minValue, maxValue),colorMap);
  }
  else if( type == GraphOptions::Power )
  {
      PowerScaleEngine powerScaler;
      m_scaleWidget->setScaleDiv(powerScaler.transformation(), powerScaler.divideScale(minValue, maxValue,  20, 5));
      m_scaleWidget->setColorMap(QwtDoubleInterval(minValue, maxValue),colorMap);
  }
  else
 {
    QwtLog10ScaleEngine logScaler;    
    double logmin(minValue);
    if( logmin <= 0.0 )
    {
      logmin = m_minPositiveValue;
      m_minValueBox->blockSignals(true);
      setMinValue(logmin);
      m_minValueBox->blockSignals(false);
    }
    if (maxValue <= 0)
    {
      maxValue = 10.;
      m_maxValueBox->blockSignals(true);
      setMaxValue(maxValue);
      m_maxValueBox->blockSignals(false);
    }
    m_scaleWidget->setScaleDiv(logScaler.transformation(), logScaler.divideScale(logmin, maxValue, 20, 5));
    m_scaleWidget->setColorMap(QwtDoubleInterval(logmin, maxValue), colorMap);
  }
  m_scaleOptions->blockSignals(true);
  m_scaleOptions->setCurrentIndex(m_scaleOptions->findData(type));
  m_dspnN->setEnabled(false);
  if (m_scaleOptions->findData(type) == 2) {
    m_dspnN->setEnabled(true);
  }
  m_scaleOptions->blockSignals(false);
}
/*!
   \brief Calculate a scale division

   \param x1 First interval limit
   \param x2 Second interval limit
   \param maxMajSteps Maximum for the number of major steps
   \param maxMinSteps Maximum number of minor steps
   \param stepSize Step size. If stepSize == 0, the scaleEngine
                   calculates one.
*/
QwtScaleDiv Log2ScaleEngine::divideScale(double x1, double x2,
    int maxMajSteps, int maxMinSteps, double stepSize) const
{
    QwtDoubleInterval interval = QwtDoubleInterval(x1, x2).normalized();
    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() <= 0 )
        return QwtScaleDiv();

    if (interval.maxValue() / interval.minValue() < 2){
        // scale width is less than 2 -> build linear scale
        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes(attributes());
        linearScaler.setReference(reference());
        linearScaler.setMargins(lowerMargin(), upperMargin());

        return linearScaler.divideScale(x1, x2,
            maxMajSteps, maxMinSteps, stepSize);
    }

    stepSize = qwtAbs(stepSize);
    if ( stepSize == 0.0 ){
        if ( maxMajSteps < 1 )
            maxMajSteps = 1;

		stepSize = ceil(log2(interval).width()/double(maxMajSteps));
    }

    QwtScaleDiv scaleDiv;
    if ( stepSize != 0.0 ){
        QwtValueList ticks[QwtScaleDiv::NTickTypes];
		buildTicks(interval, stepSize, maxMinSteps, ticks);
        scaleDiv = QwtScaleDiv(interval, ticks);
    }

    if ( x1 > x2 )
        scaleDiv.invert();

    return scaleDiv;
}
Exemple #8
0
xyPlot::xyPlot(QTScope* caller, QWidget* parent, const char* name, int id, Qt::WindowFlags wflags, int numberOfSamples)
	: scopePlotPlugin(caller, parent, name, id, wflags,numberOfSamples)
{
  cout << "xyPlot::xyPlot: xyPlot Plugin generated\n";
  callingWidget = caller;
  idThis = id;

  setWindowTitle( QString().sprintf("Channel %s",name) );

  plotLength = numberOfSamples;
  x=new double[plotLength];
  y=new double[plotLength];

  // initialize the data arrays
  clearData();

  // allow Docking
  //setDockEnabled ( Qt::DockTop, TRUE );
  //setDockEnabled ( Qt::DockLeft, TRUE );

  // conmstruct a toolbar
  QVBoxLayout *plotTools = new QVBoxLayout();
  QGroupBox *groupTools = new QGroupBox();

  QLabel *y_max = new QLabel(tr("Y max:"));
  plotTools->addWidget( y_max );
  ymaxCounter = new QwtCounter( );
  plotTools->addWidget( ymaxCounter );
  ymaxCounter->setRange(-1, 20.0);
  ymaxCounter->setSingleStep(0.01);
  ymaxCounter->setNumButtons(2);
  ymaxCounter->setIncSteps(QwtCounter::Button1, 10);
  ymaxCounter->setIncSteps(QwtCounter::Button2, 100);
  ymaxCounter->setValue(1);
  ymaxCounter->resize(200,200);
  connect(ymaxCounter, SIGNAL(valueChanged(double)), this, SLOT(slotYmaxChanged(double)));
  ymaxCounter->setDisabled(TRUE);

  QLabel *y_min = new QLabel(tr("Y min:"));
  plotTools->addWidget( y_min );
  yminCounter = new QwtCounter( );
  plotTools->addWidget( yminCounter );
  yminCounter->setRange(-20.0, 1);
  yminCounter->setSingleStep(0.01);
  yminCounter->setNumButtons(2);
  yminCounter->setIncSteps(QwtCounter::Button1, 10);
  yminCounter->setIncSteps(QwtCounter::Button2, 100);
  yminCounter->setValue(-1);
  connect(yminCounter, SIGNAL(valueChanged(double)), this, SLOT(slotYminChanged(double)));
  yminCounter->setDisabled(TRUE);

  //plotTools->addSeparator();

  QLabel *x_min = new QLabel(tr("X min:"));
  plotTools->addWidget( x_min );
  xminCounter = new QwtCounter( );
  plotTools->addWidget( xminCounter );
  xminCounter->setRange(-20.0, 1);
  xminCounter->setSingleStep(0.01);
  xminCounter->setNumButtons(2);
  xminCounter->setIncSteps(QwtCounter::Button1, 10);
  xminCounter->setIncSteps(QwtCounter::Button2, 100);
  xminCounter->setValue(-1);
  connect(xminCounter, SIGNAL(valueChanged(double)), this, SLOT(slotXminChanged(double)));
  xminCounter->setDisabled(TRUE);

  QLabel *x_max = new QLabel(tr("X max:"));
  plotTools->addWidget( x_max );
  xmaxCounter = new QwtCounter( );
  plotTools->addWidget( xmaxCounter );
  xmaxCounter->setRange(-1, 20.0);
  xmaxCounter->setSingleStep(0.01);
  xmaxCounter->setNumButtons(2);
  xmaxCounter->setIncSteps(QwtCounter::Button1, 10);
  xmaxCounter->setIncSteps(QwtCounter::Button2, 100);
  xmaxCounter->setValue(1);
  connect(xmaxCounter, SIGNAL(valueChanged(double)), this, SLOT(slotXmaxChanged(double)));
  xmaxCounter->setDisabled(TRUE);


  //plotTools->addSeparator();
  QLabel *dataPoints = new QLabel(tr("Data Points:"));
  plotTools->addWidget( dataPoints );
  rangeCounter = new QwtCounter( );
  plotTools->addWidget( rangeCounter );
  rangeCounter->setRange(0, plotLength);
  rangeCounter->setSingleStep(1);
  rangeCounter->setNumButtons(2);
  rangeCounter->setIncSteps(QwtCounter::Button1, 100);
  rangeCounter->setIncSteps(QwtCounter::Button3, 1000);
  rangeCounter->setValue(100);
  connect(rangeCounter, SIGNAL(valueChanged(double)), this, SLOT(slotRangeChanged(double)));
  rangeCounter->setDisabled(FALSE);

  //plotTools->addSeparator();
  autoscaleCheck = new QCheckBox("Autoscale");
  plotTools->addWidget( autoscaleCheck );
  autoscaleCheck->setChecked(TRUE);
  connect(autoscaleCheck, SIGNAL(clicked()), this, SLOT(slotAutoscaleToggled()));

  //moveDockWindow( plotTools, Qt::DockLeft );

  // contruct a QwtPlot Widget
  plotWidget = new QwtPlot(this);

  // QwtPlot specific defaults:
  // colour
  plotWidget->setCanvasBackground(Qt::white);
  // outline
  //plotWidget->enableOutline(FALSE);
  // no legend
  //plotWidget->enableLegend(FALSE);
  
  // no grid
  grid = new QwtPlotGrid();
  grid->enableX(true);
  grid->enableXMin(true);

  // for major grid line
  grid->setMajorPen( QPen(Qt::black,1) );
  // for minor grid line
  grid->setMinorPen( QPen(Qt::gray,1) );

  QwtScaleDiv div;
  QwtLinearScaleEngine *lineSE = new QwtLinearScaleEngine();
  div = lineSE->divideScale(0, 150, 2, 5, 15);
  
  grid->attach( plotWidget );
  
  // set some defaults for the axes
  plotWidget->setAxisTitle(QwtPlot::xBottom, "Amplitude/V");
  plotWidget->setAxisTitle(QwtPlot::yLeft, "Amplitude/V");
  // default xrange
  plotWidget->setAxisScale( QwtPlot::xBottom, 0, 1000);
  // yrange autoscale
  plotWidget->setAxisAutoScale(QwtPlot::yLeft);
  plotWidget->setAxisAutoScale(QwtPlot::xBottom);

  curve = new QwtPlotCurve("Graph");
     
  //set curve color
  curve->setPen(QPen(Qt::green, 2));
     
  // add curves
  curve->attach(plotWidget);
      
  // copy the data into the curves
  curve->setRawSamples(x, y, plotLength);
     
  // finally, refresh the plot
  plotWidget->replot(); 
  
  groupTools->setLayout(plotTools);
  QSize size = groupTools->sizeHint();
  size.setWidth( size.width()*1.3 );
  groupTools->setFixedSize( size );

  QHBoxLayout *hbox = new QHBoxLayout();
  hbox->addWidget(groupTools);
  hbox->addWidget(plotWidget);
  
  setLayout(hbox);
}