/**
		* 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);
  }

}
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute()
*/
void QwtLog10ScaleEngine::autoScale(int maxNumSteps, 
    double &x1, double &x2, double &stepSize) const
{
    if ( x1 > x2 )
        qSwap(x1, x2);

    QwtDoubleInterval interval(x1 / pow(10.0, lowerMargin()), 
        x2 * pow(10.0, upperMargin()) );

    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(lowerMargin(), upperMargin());

        linearScaler.autoScale(maxNumSteps, x1, x2, stepSize);
        stepSize = ::log10(stepSize);

        return;
    }

    double logRef = 1.0;
    if (reference() > LOG_MIN / 2)
        logRef = qwtMin(reference(), LOG_MAX / 2);

    if (testAttribute(QwtScaleEngine::Symmetric))
    {
        const double delta = qwtMax(interval.maxValue() / logRef,  
            logRef / interval.minValue());
        interval.setInterval(logRef / delta, logRef * delta);
    }

    if (testAttribute(QwtScaleEngine::IncludeReference))
        interval = interval.extend(logRef);

    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() == 0.0)
        interval = buildInterval(interval.minValue());

    stepSize = divideInterval(log10(interval).width(), qwtMax(maxNumSteps, 1));
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if (!testAttribute(QwtScaleEngine::Floating))
        interval = align(interval, stepSize);

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if (testAttribute(QwtScaleEngine::Inverted))
    {
        qSwap(x1, x2);
        stepSize = -stepSize;
    }
}
/*!
   \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 #6
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 #7
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 #9
0
void Plot::setTransformation( QwtTransform *transform )
{
    QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
    scaleEngine->setTransformation( transform );

    setAxisScaleEngine( QwtAxis::xBottom, scaleEngine );

    // we have to reassign the axis settinge, because they are
    // invalidated, when the scale engine has changed

    QwtScaleDiv scaleDiv =
        axisScaleEngine( QwtAxis::xBottom )->divideScale( 10.0, 1000.0, 8, 10 );

    QList<double> ticks;
    ticks += 10.0;
    ticks += scaleDiv.ticks( QwtScaleDiv::MajorTick );
    scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );

    setAxisScaleDiv( QwtAxis::xBottom, scaleDiv );

    replot();
}
Exemple #10
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);
}
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute()
*/
void QwtLogScaleEngine::autoScale( int maxNumSteps,
    double &x1, double &x2, double &stepSize ) const
{
    if ( x1 > x2 )
        qSwap( x1, x2 );

    const double logBase = base();

    QwtInterval interval( x1 / qPow( logBase, lowerMargin() ),
        x2 * qPow( logBase, upperMargin() ) );

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

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

        linearScaler.autoScale( maxNumSteps, x1, x2, stepSize );

        QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized();
        linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX );

        if ( linearInterval.maxValue() / linearInterval.minValue() < logBase )
        {
            // the aligned scale is still less than one step
            if ( stepSize < 0.0 )
                stepSize = -qwtLog( logBase, qAbs( stepSize ) );
            else
                stepSize = qwtLog( logBase, stepSize );

            return;
        }
    }

    double logRef = 1.0;
    if ( reference() > LOG_MIN / 2 )
        logRef = qMin( reference(), LOG_MAX / 2 );

    if ( testAttribute( QwtScaleEngine::Symmetric ) )
    {
        const double delta = qMax( interval.maxValue() / logRef,
            logRef / interval.minValue() );
        interval.setInterval( logRef / delta, logRef * delta );
    }

    if ( testAttribute( QwtScaleEngine::IncludeReference ) )
        interval = interval.extend( logRef );

    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() == 0.0 )
        interval = buildInterval( interval.minValue() );

    stepSize = divideInterval( qwtLogInterval( logBase, interval ).width(), 
        qMax( maxNumSteps, 1 ) );
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if ( !testAttribute( QwtScaleEngine::Floating ) )
        interval = align( interval, stepSize );

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if ( testAttribute( QwtScaleEngine::Inverted ) )
    {
        qSwap( x1, x2 );
        stepSize = -stepSize;
    }
}
Exemple #12
0
QWidget *WheelBox::createBox( 
    Qt::Orientation orientation, int type ) 
{
    d_wheel = new QwtWheel();
    d_wheel->setValue( 80 );
    d_wheel->setWheelWidth( 20 );
    d_wheel->setMass( 1.0 );

    d_thermo = new QwtThermo();
    if ( orientation == Qt::Horizontal )
    {
        d_thermo->setOrientation( orientation, QwtThermo::TopScale );
        d_wheel->setOrientation( Qt::Vertical );
    }
    else
    {
        d_thermo->setOrientation( orientation, QwtThermo::LeftScale );
        d_wheel->setOrientation( Qt::Horizontal );
    }

    switch( type )
    {
        case 0:
        {
            QwtLinearColorMap *colorMap = new QwtLinearColorMap(); 
            colorMap->setColorInterval( Qt::blue, Qt::red );
            d_thermo->setColorMap( colorMap );

            break;
        }
        case 1:
        {
            QwtLinearColorMap *colorMap = new QwtLinearColorMap();
            colorMap->setMode( QwtLinearColorMap::FixedColors );

            int idx = 4;

            colorMap->setColorInterval( Qt::GlobalColor( idx ),
                Qt::GlobalColor( idx + 10 ) );
            for ( int i = 1; i < 10; i++ )
            {
                colorMap->addColorStop( i / 10.0, 
                    Qt::GlobalColor( idx + i ) );
            }

            d_thermo->setColorMap( colorMap );
            break;
        }
        case 2:
        {
            d_wheel->setRange( 10, 1000 );
            d_wheel->setSingleStep( 1.0 );

            d_thermo->setScaleEngine( new QwtLogScaleEngine );
            d_thermo->setScaleMaxMinor( 10 );

            d_thermo->setFillBrush( Qt::darkCyan );
            d_thermo->setAlarmBrush( Qt::magenta );
            d_thermo->setAlarmLevel( 500.0 );

            d_wheel->setValue( 800 );

            break;
        }
        case 3:
        {
            d_wheel->setRange( -1000, 1000 );
            d_wheel->setSingleStep( 1.0 );
            d_wheel->setPalette( QColor( "Tan" ) );

            QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
            scaleEngine->setTransformation( new QwtPowerTransform( 2 ) );

            d_thermo->setScaleMaxMinor( 5 );
            d_thermo->setScaleEngine( scaleEngine );

            QPalette pal = palette();
            pal.setColor( QPalette::Base, Qt::darkGray );
            pal.setColor( QPalette::ButtonText, QColor( "darkKhaki" ) );

            d_thermo->setPalette( pal );
            break;
        }
        case 4:
        {
            break;
        }
    }

    d_thermo->setScale( d_wheel->minimum(), d_wheel->maximum() );
    d_thermo->setValue( d_wheel->value() );

    connect( d_wheel, SIGNAL( valueChanged( double ) ), 
        d_thermo, SLOT( setValue( double ) ) );

    QWidget *box = new QWidget();

    QBoxLayout *layout;

    if ( orientation == Qt::Horizontal )
        layout = new QHBoxLayout( box );
    else
        layout = new QVBoxLayout( box );

    layout->addWidget( d_thermo, Qt::AlignCenter );
    layout->addWidget( d_wheel );

    return box;
}
Exemple #13
0
QwtSlider * createSlider (int sliderType)
{
    QwtSlider * slider = new QwtSlider();

    switch( sliderType )
    {
        case 0:
        {
            slider->setOrientation( Qt::Horizontal );
            slider->setScalePosition( QwtSlider::TrailingScale );
            slider->setTrough( true );
            slider->setGroove( false );
            slider->setSpacing( 0 );
            slider->setHandleSize( QSize( 30, 16 ) );
            slider->setScale( 10.0, -10.0 );
            slider->setTotalSteps( 8 );
            slider->setSingleSteps( 1 );
            slider->setPageSteps( 1 );
            slider->setWrapping( true );
            break;
        }
        case 1:
        {
            slider->setOrientation( Qt::Horizontal );
            slider->setScalePosition( QwtSlider::NoScale );
            slider->setTrough( true );
            slider->setGroove( true );
            slider->setScale( 0.0, 1.0 );
            slider->setTotalSteps( 100 );
            slider->setSingleSteps( 1 );
            slider->setPageSteps( 5 );
            break;
        }
        case 2:
        {
            slider->setOrientation( Qt::Horizontal );
            slider->setScalePosition( QwtSlider::LeadingScale );
            slider->setTrough( false );
            slider->setGroove( true );
            slider->setHandleSize( QSize( 12, 25 ) );
            slider->setScale( 1000.0, 3000.0 );
            slider->setTotalSteps( 200.0 );
            slider->setSingleSteps( 2 );
            slider->setPageSteps( 10 );
            break;
        }
        case 3:
        {
            slider->setOrientation( Qt::Horizontal );
            slider->setScalePosition( QwtSlider::TrailingScale );
            slider->setTrough( true );
            slider->setGroove( true );

            QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine( 2 );
            scaleEngine->setTransformation( new QwtPowerTransform( 2 ) );
            slider->setScaleEngine( scaleEngine );
            slider->setScale( 0.0, 128.0 );
            slider->setTotalSteps( 100 );
            slider->setStepAlignment( false );
            slider->setSingleSteps( 1 );
            slider->setPageSteps( 5 );
            break;
        }
    }

    if (slider)
    {
        QString name( "Slider %1" );
        slider->setObjectName( name.arg( sliderType ) );
    }
    return slider;
}