Beispiel #1
0
/**
 * Normalize the value to the range[0,1]
 * @param interval :: The data range
 * @param value :: The data value
 * @returns The fraction along the given interval using the current scale type
 */
double MantidColorMap::normalize(const QwtDoubleInterval &interval,
                                 double value) const {
  // nan numbers have the property that nan != nan, treat nan as being invalid
  if (interval.isNull() || m_num_colors == 0 || boost::math::isnan(value))
    return m_nan;

  const double width = interval.width();
  if (width <= 0.0 || value <= interval.minValue())
    return 0.0;

  if (value >= interval.maxValue())
    return 1.0;

  double ratio(0.0);
  if (m_scale_type == GraphOptions::Linear) {
    ratio = (value - interval.minValue()) / width;
  } else if (m_scale_type == GraphOptions::Power) {
    ratio = (pow(value, m_nth_power) - pow(interval.minValue(), m_nth_power)) /
            (pow(interval.maxValue(), m_nth_power) -
             pow(interval.minValue(), m_nth_power));
  } else {
    // Assume log10 type
    // Have to deal with the possibility that a user has entered 0 as a minimum
    double minValue = interval.minValue();
    if (minValue < LOG_ZERO_CUTOFF) {
      minValue = 1.0;
    }
    ratio = std::log10(value / minValue) /
            std::log10(interval.maxValue() / minValue);
  }
  return ratio;
}
void ContourLinesEditor::insertLevel()
{
	if (!d_spectrogram)
		return;

	int row = table->currentRow();
	DoubleSpinBox *sb = (DoubleSpinBox*)table->cellWidget(row, 0);
	if (!sb)
		return;

	QwtDoubleInterval range = d_spectrogram->data().range();
	double current_value = sb->value();
	double previous_value = range.minValue ();
	sb = (DoubleSpinBox*)table->cellWidget(row - 1, 0);
	if (sb)
		previous_value = sb->value();

	double val = 0.5*(current_value + previous_value);

	table->blockSignals(true);
	table->insertRow(row);

	sb = new DoubleSpinBox();
	sb->setLocale(d_locale);
	sb->setDecimals(d_precision);
	sb->setValue(val);
	sb->setRange(range.minValue (), range.maxValue ());
	connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *)));
    table->setCellWidget(row, 0, sb);

	QPen pen = d_spectrogram->defaultContourPen();
	if (pen.style() == Qt::NoPen)
		pen = d_spectrogram->contourPen (val);

	int width = 80;
	int height = 20;
	QPixmap pix(width, height);
	pix.fill(Qt::white);
	QPainter paint(&pix);
	paint.setRenderHint(QPainter::Antialiasing);
	paint.setPen(pen);
	paint.drawLine(0, height/2, width, height/2);
	paint.end();

	QLabel *lbl = new QLabel();
	lbl->setPixmap(pix);

	table->setCellWidget(row, 1, lbl);
	table->blockSignals(false);

	enableButtons(table->currentRow());
	d_pen_list.insert(row, pen);
}
/*!
  \brief Align an interval to a step size

  The limits of an interval are aligned that both are integer
  multiples of the step size.

  \param interval Interval
  \param stepSize Step size

  \return Aligned interval
*/
QwtDoubleInterval QwtLinearScaleEngine::align(
    const QwtDoubleInterval &interval, double stepSize) const
{
    double x1 = QwtScaleArithmetic::floorEps(interval.minValue(), stepSize);
    if ( QwtScaleArithmetic::compareEps(interval.minValue(), x1, stepSize) == 0 )
        x1 = interval.minValue();

    double x2 = QwtScaleArithmetic::ceilEps(interval.maxValue(), stepSize);
    if ( QwtScaleArithmetic::compareEps(interval.maxValue(), x2, stepSize) == 0 )
        x2 = interval.maxValue();

    return QwtDoubleInterval(x1, x2);
}
/**
 Executes any meta-data loading required.
*/
void MDHWInMemoryLoadingPresenter::executeLoadMetadata() {
  using namespace Mantid::API;

  Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName);
  IMDHistoWorkspace_sptr histoWs =
      boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws);
  m_wsTypeName = histoWs->id();
  m_specialCoords = histoWs->getSpecialCoordinateSystem();

  MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs);

  // Set the minimum and maximum of the workspace data.
  QwtDoubleInterval minMaxContainer =
      m_metaDataExtractor->getMinAndMax(histoWs);
  m_metadataJsonManager->setMinValue(minMaxContainer.minValue());
  m_metadataJsonManager->setMaxValue(minMaxContainer.maxValue());

  // Set the instrument which is associated with the workspace.
  m_metadataJsonManager->setInstrument(
      m_metaDataExtractor->extractInstrument(m_cachedVisualHistoWs));

  // Set the special coordinates
  m_metadataJsonManager->setSpecialCoordinates(m_specialCoords);

  // Call base-class extraction method.
  this->extractMetadata(m_cachedVisualHistoWs);
}
Beispiel #5
0
QwtValueList QwtLinearScaleEngine::buildMajorTicks(
    const QwtDoubleInterval &interval, double stepSize) const
{
    int numTicks = qRound(interval.width() / stepSize) + 1;
    if ( numTicks > 10000 )
        numTicks = 10000;

    QwtValueList ticks;

    ticks += interval.minValue();
    for (int i = 1; i < numTicks - 1; i++)
        ticks += interval.minValue() + i * stepSize;
    ticks += interval.maxValue();

    return ticks;
}
Beispiel #6
0
/*!
  \brief Align an interval to a step size

  The limits of an interval are aligned that both are integer
  multiples of the step size.

  \param interval Interval
  \param stepSize Step size

  \return Aligned interval
*/
QwtDoubleInterval QwtLog10ScaleEngine::align(
    const QwtDoubleInterval &interval, double stepSize) const
{
    const QwtDoubleInterval intv = log10(interval);

    const double x1 = QwtScaleArithmetic::floorEps(intv.minValue(), stepSize);
    const double x2 = QwtScaleArithmetic::ceilEps(intv.maxValue(), stepSize);

    return pow10(QwtDoubleInterval(x1, x2));
}
Beispiel #7
0
/*!
  \brief Align an interval to a step size

  The limits of an interval are aligned that both are integer
  multiples of the step size.

  \param interval Interval
  \param stepSize Step size

  \return Aligned interval
*/
QwtDoubleInterval QwtLinearScaleEngine::align(
    const QwtDoubleInterval &interval, double stepSize) const
{
    const double x1 = 
        QwtScaleArithmetic::floorEps(interval.minValue(), stepSize);
    const double x2 = 
        QwtScaleArithmetic::ceilEps(interval.maxValue(), stepSize);

    return QwtDoubleInterval(x1, x2);
}
Beispiel #8
0
/*! 
  Construct QwtScaleDiv instance.

  \param interval Interval
  \param ticks List of major, medium and minor ticks
*/
QwtScaleDiv::QwtScaleDiv(
        const QwtDoubleInterval &interval, 
        QwtTickList ticks[NTickTypes]):
    d_lBound(interval.minValue()),
    d_hBound(interval.maxValue()),
    d_isValid(true)
{
    for ( int i = 0; i < NTickTypes; i++ )
        d_ticks[i] = ticks[i];
}
/*!
  \brief Align an interval to a step size

  The limits of an interval are aligned that both are integer
  multiples of the step size.

  \param interval Interval
  \param stepSize Step size

  \return Aligned interval
*/
QwtDoubleInterval Log2ScaleEngine::align(
    const QwtDoubleInterval &interval, double stepSize) const
{
    const QwtDoubleInterval intv = log2(interval);

    const double x1 = QwtScaleArithmetic::floorEps(intv.minValue(), stepSize);
    const double x2 = QwtScaleArithmetic::ceilEps(intv.maxValue(), stepSize);

    return QwtDoubleInterval(pow(2, x1), pow(2, x2));
}
QwtDoubleRect QwtIntervalData::boundingRect() const
{
    double minX, maxX, minY, maxY;
    minX = maxX = minY = maxY = 0.0;

    bool isValid = false;

    const size_t sz = size();
    for ( size_t i = 0; i < sz; i++ )
    {
        const QwtDoubleInterval intv = interval(i);
        if ( !intv.isValid() )
            continue;

        const double v = value(i);

        if ( !isValid )
        {
            minX = intv.minValue();
            maxX = intv.maxValue();
            minY = maxY = v;

            isValid = true;
        }
        else
        {
            if ( intv.minValue() < minX )
                minX = intv.minValue();
            if ( intv.maxValue() > maxX )
                maxX = intv.maxValue();

            if ( v < minY )
                minY = v;
            if ( v > maxY )
                maxY = v;
        }
    }
    if ( !isValid )
        return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
Beispiel #11
0
void EditColorMap::SetData (
    const QwtIntervalData& intervalData, double maxValue,
    const ColorBarModel& colorBarModel, bool gridEnabled)
{
    m_colorMap = colorBarModel;
    setCombos (m_colorMap.GetPalette ());
    widgetHistogram->SetDataAllBinsSelected (
	intervalData, maxValue, 
	m_colorMap.GetTitle ().c_str ());
    widgetHistogram->SetColorTransferFunction (
	m_colorMap.GetInterval (), m_colorMap.GetQwtColorMap ());
    widgetHistogram->SetGridEnabled (gridEnabled);
    QwtDoubleInterval interval = m_colorMap.GetInterval ();
    QwtDoubleInterval clampValues = m_colorMap.GetClampInterval ();
    if (clampValues.minValue () > interval.minValue ())
	widgetHistogram->SetItemsSelectionLow (false, clampValues.minValue ());
    if (clampValues.maxValue () < interval.maxValue ())
	widgetHistogram->SetItemsSelectionHigh (false, clampValues.maxValue ());
    setHighlightColors ();
 }
Beispiel #12
0
/*!
  Map a value of a given interval into a rgb value

  \param interval Range for all values
  \param value Value to map into a rgb value
*/
QRgb QwtLinearColorMap::rgb(
    const QwtDoubleInterval &interval, double value) const
{
    const double width = interval.width();

    double ratio = 0.0;
    if ( width > 0.0 )
        ratio = (value - interval.minValue()) / width;

    return d_data->colorStops.rgb(d_data->mode, ratio);
}
Beispiel #13
0
/*!
  Map a value of a given interval into a rgb value

  \param interval Range for all values
  \param value Value to map into a rgb value
*/
QRgb LinearTransparentColorMap::rgb(
    const QwtDoubleInterval& interval, double value) const
{
    const double width = interval.width();

    double ratio = 0.0;
    if (width > 0.0)
        ratio = (value - interval.minValue()) / width;
    if (ratio < 0)
        return qRgba(0, 0, 0, 0);
    return d_data->colorStops.rgb(d_data->mode, ratio);
}
/*!
   \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;
}
Beispiel #15
0
/*!
  Map a value of a given interval into a color index, between 0 and 255

  \param interval Range for all values
  \param value Value to map into a color index
*/
unsigned char QwtLinearColorMap::colorIndex(
    const QwtDoubleInterval &interval, double value) const
{
    const double width = interval.width();

    if ( width <= 0.0 || value <= interval.minValue() )
        return 0;

    if ( value >= interval.maxValue() )
        return (unsigned char)255;

    const double ratio = (value - interval.minValue()) / width;

    unsigned char index;
    if ( d_data->mode == FixedColors )
        index = (unsigned char)(ratio * 255); // always floor
    else
        index = (unsigned char)qRound(ratio * 255);

    return index;
}
Beispiel #16
0
/*!
   Build and return a color map of 256 colors

   The color table is needed for rendering indexed images in combination
   with using colorIndex().

   \param interval Range for the values
   \return A color table, that can be used for a QImage
*/
QwtColorTable QwtColorMap::colorTable(
    const QwtDoubleInterval &interval) const
{
    QwtColorTable table(256);

    if ( interval.isValid() ) {
        const double step = interval.width() / (table.size() - 1);
        for ( int i = 0; i < (int) table.size(); i++ )
            table[i] = rgb(interval, interval.minValue() + step * i);
    }

    return table;
}
QwtValueList Log2ScaleEngine::buildMajorTicks(
    const QwtDoubleInterval &interval, double stepSize) const
{
    double width = log2(interval).width();

    int numTicks = qRound(width / stepSize) + 1;
    if ( numTicks > 10000 )
        numTicks = 10000;

    const double lxmin = ::log2(interval.minValue());
    const double lxmax = ::log2(interval.maxValue());
    const double lstep = (lxmax - lxmin) / double(numTicks - 1);

    QwtValueList ticks;
    ticks += interval.minValue();

    for (int i = 1; i < numTicks; i++)
       ticks += pow(2, lxmin + double(i) * lstep);

    ticks += interval.maxValue();

    return ticks;
}
Beispiel #18
0
void QwtPolarPlot::updateScale( int scaleId )
{
  if ( scaleId < 0 || scaleId >= QwtPolar::ScaleCount )
    return;

  ScaleData &d = d_data->scaleData[scaleId];

  double minValue = d.minValue;
  double maxValue = d.maxValue;
  double stepSize = d.stepSize;

  if ( scaleId == QwtPolar::ScaleRadius && d.doAutoScale )
  {
    QwtDoubleInterval interval;

    const QwtPolarItemList& itmList = itemList();
    for ( QwtPolarItemIterator it = itmList.begin();
          it != itmList.end(); ++it )
    {
      const QwtPolarItem *item = *it;
      if ( item->testItemAttribute( QwtPolarItem::AutoScale ) )
        interval |= item->boundingInterval( scaleId );
    }

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

    d.scaleEngine->autoScale( d.maxMajor,
                              minValue, maxValue, stepSize );
    d.scaleDiv.invalidate();
  }

  if ( !d.scaleDiv.isValid() )
  {
    d.scaleDiv = d.scaleEngine->divideScale(
                   minValue, maxValue,
                   d.maxMajor, d.maxMinor, stepSize );
  }

  const QwtDoubleInterval interval = visibleInterval();

  const QwtPolarItemList& itmList = itemList();
  for ( QwtPolarItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
  {
    QwtPolarItem *item = *it;
    item->updateScaleDiv( *scaleDiv( QwtPolar::Azimuth ),
                          *scaleDiv( QwtPolar::Radius ), interval );
  }
}
/*! 
  Expand the interval

  \param interval Interval to be expanded
  \param width Distance to be added to the interval
  \param direction Direction of the expand operation

  \return Expanded interval
*/
QwtDoubleInterval QwtPlotRescaler::expandInterval(
    const QwtDoubleInterval &interval, double width,    
    ExpandingDirection direction) const
{
    QwtDoubleInterval expanded = interval;

    switch(direction)
    {
        case ExpandUp:
            expanded.setMinValue(interval.minValue());
            expanded.setMaxValue(interval.minValue() + width);
            break;
        case ExpandDown:
            expanded.setMaxValue(interval.maxValue());
            expanded.setMinValue(interval.maxValue() - width);
            break;
        case ExpandBoth:
        default:
            expanded.setMinValue(interval.minValue() +
                interval.width() / 2.0 - width / 2.0);
            expanded.setMaxValue(expanded.minValue() + width);
    }
    return expanded;
}
Beispiel #20
0
/*!
  \brief Map a value of a given interval into a alpha value

  alpha := (value - interval.minValue()) / interval.width();

  \param interval Range for all values
  \param value Value to map into a rgb value
  \return rgb value, with an alpha value
*/
QRgb QwtAlphaColorMap::rgb(const QwtDoubleInterval &interval,
                           double value) const
{
    const double width = interval.width();
    if ( width >= 0.0 ) {
        const double ratio = (value - interval.minValue()) / width;
        int alpha = qRound(255 * ratio);
        if ( alpha < 0 )
            alpha = 0;
        if ( alpha > 255 )
            alpha = 255;

        return d_data->rgb | (alpha << 24);
    }
    return d_data->rgb;
}
void ContourLinesEditor::updateContents()
{
	if (!d_spectrogram)
		return;

	QwtValueList levels = d_spectrogram->contourLevels ();

	int rows = (int)levels.size();
	table->setRowCount(rows);
	table->blockSignals(true);

	QwtDoubleInterval range = d_spectrogram->data().range();
	for (int i = 0; i < rows; i++){
		DoubleSpinBox *sb = new DoubleSpinBox();
		sb->setLocale(d_locale);
		sb->setDecimals(d_precision);
		sb->setValue(levels[i]);
		sb->setRange(range.minValue (), range.maxValue ());
		connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *)));
    	table->setCellWidget(i, 0, sb);

		QPen pen = d_spectrogram->defaultContourPen();
		if (pen.style() == Qt::NoPen)
			pen = d_spectrogram->contourPen (levels[i]);

		int width = 80;
		int height = 20;
    	QPixmap pix(width, height);
    	pix.fill(Qt::white);
    	QPainter paint(&pix);
    	paint.setRenderHint(QPainter::Antialiasing);
    	paint.setPen(pen);
    	paint.drawLine(0, height/2, width, height/2);
    	paint.end();

    	QLabel *lbl = new QLabel();
    	lbl->setPixmap(pix);

    	table->setCellWidget(i, 1, lbl);

    	d_pen_list << pen;
	}
	table->blockSignals(false);
}
Beispiel #22
0
/*!
  Check if an interval "contains" a value

  \param interval Interval
  \param value Value

  \sa QwtScaleArithmetic::compareEps()
*/
bool QwtScaleEngine::contains(
    const QwtDoubleInterval &interval, double value) const
{
    if (!interval.isValid() )
        return false;
    
    if ( QwtScaleArithmetic::compareEps(value, 
        interval.minValue(), interval.width()) < 0 )
    {
        return false;
    }

    if ( QwtScaleArithmetic::compareEps(value, 
        interval.maxValue(), interval.width()) > 0 )
    {
        return false;
    }

    return true;
}
Beispiel #23
0
/**
 * Compute a lookup table
 *
 * @param interval :: The interval of values of the RGB component for
 * the table to cover
 */
QVector<QRgb>
MantidColorMap::colorTable(const QwtDoubleInterval &interval) const {
  // Swicth to linear scaling when computing the lookup table
  GraphOptions::ScaleType current_type = m_scale_type;
  m_scale_type = GraphOptions::Linear;

  short table_size = (m_num_colors > 1) ? m_num_colors : 2;
  QVector<QRgb> rgbtable(table_size + 1);
  if (interval.isValid()) {
    const double step = interval.width() / table_size;
    for (short i = 0; i < table_size; ++i) {
      rgbtable[i + 1] = rgb(interval, interval.minValue() + step * i);
    }
    // Special NAN at index 0
    rgbtable[0] = rgb(interval, m_nan);
  }

  // Restore scaling type
  m_scale_type = current_type;
  return rgbtable;
}
/*!
   \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;
}
//! Adjust the plot axes scales
void QwtPlotRescaler::rescale() const
{
#if 0
    const int axis = referenceAxis();
    if ( axis < 0 || axis >= QwtPlot::axisCnt )
        return;

    const QwtDoubleInterval hint = intervalHint(axis);
    if ( !hint.isNull() )
    {
        QwtPlot *plt = (QwtPlot *)plot();

        const bool doReplot = plt->autoReplot();
        plt->setAutoReplot(false);
        plt->setAxisScale(axis, hint.minValue(), hint.maxValue());
        plt->setAutoReplot(doReplot);
        plt->updateAxes();
    }
#endif

    const QSize size = canvas()->contentsRect().size();
    rescale(size, size);
}
QwtDoubleInterval Log2ScaleEngine::log2(
    const QwtDoubleInterval &interval) const
{
    return QwtDoubleInterval(::log2(interval.minValue()),
            ::log2(interval.maxValue()));
}
Beispiel #27
0
void ColorBarWidget::setViewRange(QwtDoubleInterval range)
{
    this->setViewRange(range.minValue(), range.maxValue());
}
Beispiel #28
0
/*!
  Redraw the canvas items.

  \param painter Painter used for drawing
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param radius Radius of the complete plot area in painter coordinates
  \param canvasRect Contents rect of the canvas in painter coordinates
*/
void QwtPolarPlot::drawItems( QPainter *painter,
                              const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                              const QwtDoublePoint &pole, double radius,
                              const QwtDoubleRect &canvasRect ) const
{
  const QwtDoubleRect pr = plotRect( canvasRect.toRect() );

  const QwtPolarItemList& itmList = itemList();
  for ( QwtPolarItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
  {
    QwtPolarItem *item = *it;
    if ( item && item->isVisible() )
    {
      painter->save();

      // Unfortunately circular clipping slows down
      // painting a lot. So we better try to avoid it.

      bool doClipping = false;
      if ( item->rtti() != QwtPolarItem::Rtti_PolarGrid )
      {
        const QwtDoubleInterval intv =
          item->boundingInterval( QwtPolar::Radius );

        if ( !intv.isValid() )
          doClipping = true;
        else
        {
          if ( radialMap.s1() < radialMap.s2() )
            doClipping = intv.maxValue() > radialMap.s2();
          else
            doClipping = intv.minValue() < radialMap.s2();
        }
      }

      if ( doClipping )
      {
        const int margin = item->marginHint();
        const QwtDoubleRect clipRect( pr.x() - margin, pr.y() - margin,
                                      pr.width() + 2 * margin, pr.height() + 2 * margin );

        if ( !clipRect.contains( canvasRect ) )
        {
          QRegion clipRegion( clipRect.toRect(), QRegion::Ellipse );
#if QT_VERSION >= 0x040000
          painter->setClipRegion( clipRegion, Qt::IntersectClip );
#else
          if ( painter->hasClipping() )
            clipRegion &= painter->clipRegion();

          painter->setClipRegion( clipRegion );
#endif
        }
      }

#if QT_VERSION >= 0x040000
      painter->setRenderHint( QPainter::Antialiasing,
                              item->testRenderHint( QwtPolarItem::RenderAntialiased ) );
#endif

      item->draw( painter, azimuthMap, radialMap,
                  pole, radius, canvasRect );
      painter->restore();
    }
  }

}
void QwtPolarGrid::updateScaleDiv( const QwtScaleDiv &azimuthScaleDiv,
                                   const QwtScaleDiv &radialScaleDiv, const QwtDoubleInterval &interval )
{
  GridData &radialGrid = d_data->gridData[QwtPolar::Radius];

  const QwtPolarPlot *plt = plot();
  if ( plt && testGridAttribute( AutoScaling ) )
  {
    const QwtScaleEngine *se = plt->scaleEngine( QwtPolar::Radius );
    radialGrid.scaleDiv = se->divideScale(
                            interval.minValue(), interval.maxValue(),
                            plt->scaleMaxMajor( QwtPolar::Radius ),
                            plt->scaleMaxMinor( QwtPolar::Radius ), 0 );
  }
  else
  {
    if ( radialGrid.scaleDiv != radialScaleDiv )
      radialGrid.scaleDiv = radialScaleDiv;
  }

  GridData &azimuthGrid = d_data->gridData[QwtPolar::Azimuth];
  if ( azimuthGrid.scaleDiv != azimuthScaleDiv )
  {
    azimuthGrid.scaleDiv = azimuthScaleDiv;
  }

  bool hasOrigin = false;
  for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
  {
    AxisData &axis = d_data->axisData[axisId];
    if ( axis.isVisible && axis.scaleDraw )
    {
      if ( axisId == QwtPolar::AxisAzimuth )
      {
        axis.scaleDraw->setScaleDiv( azimuthGrid.scaleDiv );
        if ( testDisplayFlag( SmartScaleDraw ) )
        {
          axis.scaleDraw->enableComponent(
            QwtAbstractScaleDraw::Ticks, !azimuthGrid.isVisible );
        }
      }
      else
      {
        QwtScaleDiv sd = radialGrid.scaleDiv;

        QwtValueList &ticks =
          ( QwtValueList & )sd.ticks( QwtScaleDiv::MajorTick );

        if ( testDisplayFlag( SmartOriginLabel ) )
        {
          bool skipOrigin = hasOrigin;
          if ( !skipOrigin )
          {
            if ( axisId == QwtPolar::AxisLeft
                 || axisId == QwtPolar::AxisRight )
            {
              if ( d_data->axisData[QwtPolar::AxisBottom].isVisible )
                skipOrigin = true;
            }
            else
            {
              if ( d_data->axisData[QwtPolar::AxisLeft].isVisible )
                skipOrigin = true;
            }
          }
#if QWT_VERSION < 0x050200
          if ( ticks.size() > 0 && ticks.first() == sd.lBound() )
#else
          if ( ticks.size() > 0 && ticks.first() == sd.lowerBound() )
#endif
          {
            if ( skipOrigin )
            {
#if QT_VERSION < 0x040000
              ticks.pop_front();
#else
              ticks.removeFirst();
#endif
            }
            else
              hasOrigin = true;
          }
        }

        if ( testDisplayFlag( HideMaxRadiusLabel ) )
        {
#if QWT_VERSION < 0x050200
          if ( ticks.size() > 0 && ticks.last() == sd.hBound() )
#else
          if ( ticks.size() > 0 && ticks.last() == sd.upperBound() )
#endif
#if QT_VERSION < 0x040000
            ticks.pop_back();
#else
            ticks.removeLast();
#endif
        }

        axis.scaleDraw->setScaleDiv( sd );

        if ( testDisplayFlag( SmartScaleDraw ) )
        {
          axis.scaleDraw->enableComponent(
            QwtAbstractScaleDraw::Ticks, !radialGrid.isVisible );
        }

      }
    }
  }
}
/*!
   Update the axis scale draw geometries

   \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
   \param radialMap Maps radius values into painter coordinates.
   \param pole Position of the pole in painter coordinates
   \param radius Radius of the complete plot area in painter coordinates

   \sa updateScaleDiv()
*/
void QwtPolarGrid::updateScaleDraws(
  const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
  const QwtDoublePoint &pole, double radius ) const
{
  const QPoint p = pole.toPoint();

  const QwtDoubleInterval interval =
    d_data->gridData[QwtPolar::ScaleRadius].scaleDiv.interval();

  const int min = radialMap.transform( interval.minValue() );
  const int max = radialMap.transform( interval.maxValue() );
  const int l = max - min;

  for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
  {
    AxisData &axis = d_data->axisData[axisId];

    if ( axisId == QwtPolar::AxisAzimuth )
    {
      QwtRoundScaleDraw *scaleDraw = ( QwtRoundScaleDraw * )axis.scaleDraw;

      scaleDraw->setRadius( qRound( radius ) );
      scaleDraw->moveCenter( p );

      double from = ::fmod( 90.0 - azimuthMap.p1() * 180.0 / M_PI, 360.0 );
      if ( from < 0.0 )
        from += 360.0;

      scaleDraw->setAngleRange( from, from - 360.0 );
      scaleDraw->setTransformation( azimuthMap.transformation()->copy() );
    }
    else
    {
      QwtScaleDraw *scaleDraw = ( QwtScaleDraw * )axis.scaleDraw;
      switch ( axisId )
      {
        case QwtPolar::AxisLeft:
        {
          scaleDraw->move( p.x() - min, p.y() );
          scaleDraw->setLength( -l );
          break;
        }
        case QwtPolar::AxisRight:
        {
          scaleDraw->move( p.x() + min, p.y() );
          scaleDraw->setLength( l );
          break;
        }
        case QwtPolar::AxisTop:
        {
          scaleDraw->move( p.x(), p.y() - max );
          scaleDraw->setLength( l );
          break;
        }
        case QwtPolar::AxisBottom:
        {
          scaleDraw->move( p.x(), p.y() + max );
          scaleDraw->setLength( -l );
          break;
        }
      }
      scaleDraw->setTransformation( radialMap.transformation()->copy() );
    }
  }
}