QwtValueList ProbabilityScaleEngine::buildMajorTicks(
    const QwtDoubleInterval &interval, int stepSize) const
{
	QwtValueList baseTicks;

	baseTicks += 1e-4;
	baseTicks += 1e-3;
	baseTicks += 0.01;
	baseTicks += 0.1;
	baseTicks += 0.5;
	baseTicks += 1;
	baseTicks += 2;
	baseTicks += 5;
	for (int i = 1; i <= 5; i++)
		baseTicks += i*10;

	QwtValueList ticks;

	int size = baseTicks.size();
	for (int i = 0; i < size; i += stepSize)
		ticks += baseTicks[i];

	size = ticks.size();
	for (int i = 1; i < size; i++)
		ticks += 100 - ticks[size - i];

    return ticks;
}
QwtValueList LogitScaleEngine::buildMajorTicks(
    const QwtDoubleInterval &interval, int stepSize) const
{
	QwtValueList baseTicks;

	baseTicks += 0.01;
	baseTicks += 0.1;
	baseTicks += 1;
	baseTicks += 5;
	baseTicks += 10;
	baseTicks += 25;
	baseTicks += 50;

	QwtValueList ticks;

	int size = baseTicks.size();
	for (int i = 0; i < size; i += stepSize)
		ticks += baseTicks[i];

	size = ticks.size();
	for (int i = 1; i < size; i++)
		ticks += 100 - ticks[size - i];

    return ticks;
}
void Spectrogram::updateLabels(QPainter *p, const QwtScaleMap &, const QwtScaleMap &,
		const QwtRasterData::ContourLines &contourLines) const
{
	QwtValueList levels = contourLevels();
	const int numLevels = levels.size();
	int x_axis = xAxis();
	int y_axis = yAxis();
	for (int l = 0; l < numLevels; l++){
		const double level = levels[l];
		const QPolygonF &lines = contourLines[level];
		if (lines.isEmpty())
			continue;

		PlotMarker *mrk = d_labels_list[l];
		if (!mrk)
			return;

		QSize size = mrk->label().textSize();
		int dx = int((d_labels_x_offset + mrk->xLabelOffset())*0.01*size.height());
		int dy = -int(((d_labels_y_offset + mrk->yLabelOffset())*0.01 + 0.5)*size.height());

		int i = (int)lines.size()/2;
		double x = lines[i].x();
		double y = lines[i].y();

		int x2 = d_graph->transform(x_axis, x) + dx;
		int y2 = d_graph->transform(y_axis, y) + dy;

		if (p->device()->logicalDpiX() == plot()->logicalDpiX() ||
			p->device()->logicalDpiY() == plot()->logicalDpiY())
			mrk->setValue(d_graph->invTransform(x_axis, x2),
							d_graph->invTransform(y_axis, y2));
	}
}
void Spectrogram::drawContourLines (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtRasterData::ContourLines &contourLines) const
{
	//QwtPlotSpectrogram::drawContourLines(p, xMap, yMap, contourLines);

	QwtValueList levels = contourLevels();
    const int numLevels = (int)levels.size();
    for (int l = 0; l < numLevels; l++){
        const double level = levels[l];

        QPen pen = defaultContourPen();
        if ( pen.style() == Qt::NoPen )
            pen = contourPen(level);

        if ( pen.style() == Qt::NoPen )
            continue;

        p->setPen(QwtPainter::scaledPen(pen));

        const QPolygonF &lines = contourLines[level];
        for ( int i = 0; i < (int)lines.size(); i += 2 ){
            const QPointF p1( xMap.xTransform(lines[i].x()),
                yMap.transform(lines[i].y()) );
            const QPointF p2( xMap.xTransform(lines[i + 1].x()),
                yMap.transform(lines[i + 1].y()) );

            p->drawLine(p1, p2);
        }
    }

	if (d_show_labels)
		updateLabels(p, xMap, yMap, contourLines);
}
void Spectrogram::createLabels()
{
	clearLabels();

	QwtValueList levels = contourLevels();
	const int numLevels = levels.size();
    for (int l = 0; l < numLevels; l++){
		PlotMarker *m = new PlotMarker(l, d_labels_angle);

		QwtText t = QwtText(QString::number(levels[l]));
		t.setColor(d_labels_color);
		t.setFont(d_labels_font);

		if (d_white_out_labels)
			t.setBackgroundBrush(QBrush(Qt::white));
        else
            t.setBackgroundBrush(QBrush(Qt::transparent));
		m->setLabel(t);

        int x_axis = xAxis();
        int y_axis = yAxis();
		m->setAxis(x_axis, y_axis);

        if (d_graph && d_show_labels)
			m->attach(d_graph);
		d_labels_list << m;
	}
}
/*!
  Draw lines from the pole

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radius Length of the lines in painter coordinates
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param values Azimuth values, indicating the direction of the lines
*/
void QwtPolarGrid::drawRays(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, double radius,
  const QwtScaleMap &azimuthMap, const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    double azimuth = azimuthMap.xTransform( values[i] );
    azimuth = ::fmod( azimuth, 2 * M_PI );

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const QwtAbstractScaleDraw::ScaleComponent bone =
        QwtAbstractScaleDraw::Backbone;
      if ( isClose( azimuth, 0.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisRight];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI / 2 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisTop];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisLeft];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, 3 * M_PI / 2.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisBottom];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
    }
    if ( !skipLine )
    {
      const QwtDoublePoint pos = qwtPolar2Pos( pole, radius, azimuth );

      /*
          Qt4 is horrible slow, when painting primitives,
          with coordinates far outside the visible area.
       */

      QwtPolygon pa( 2 );
      pa.setPoint( 0, pole.toPoint() );
      pa.setPoint( 1, pos.toPoint() );

      if ( testDisplayFlag( ClipGridLines ) )
        pa = QwtClipper::clipPolygon( canvasRect.toRect(), pa );

      QwtPainter::drawPolyline( painter, pa );
    }
  }
}
Exemple #7
0
vector<double> AxisImp::getMinorTickLocations() const
{
    vector<double> minorTicks;
    QwtScaleDiv scaleDiv = mScaleDraw.scaleDiv();

    QwtValueList minorTickList = scaleDiv.ticks(QwtScaleDiv::MinorTick) + scaleDiv.ticks(QwtScaleDiv::MediumTick);
    for (int i = 0; i < minorTickList.size(); ++i)
    {
        double dValue = minorTickList[i];
        minorTicks.push_back(dValue);
    }

    return minorTicks;
}
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);
}
QString Spectrogram::saveToString()
{
QString s = "<spectrogram>\n";
s += "\t<matrix>" + QString(d_matrix->objectName()) + "</matrix>\n";
s += "\t<useMatrixFormula>" + QString::number(d_use_matrix_formula) + "</useMatrixFormula>\n";
s += "\t<xAxis>" + QString::number(xAxis()) + "</xAxis>\n";
s += "\t<yAxis>" + QString::number(yAxis()) + "</yAxis>\n";

if (color_map_policy != Custom)
	s += "\t<ColorPolicy>" + QString::number(color_map_policy) + "</ColorPolicy>\n";
else
	s += ColorMapEditor::saveToXmlString(color_map);
s += "\t<Image>"+QString::number(testDisplayMode(QwtPlotSpectrogram::ImageMode))+"</Image>\n";

bool contourLines = testDisplayMode(QwtPlotSpectrogram::ContourMode);
s += "\t<ContourLines>"+QString::number(contourLines)+"</ContourLines>\n";
if (contourLines){
	QwtValueList levels = contourLevels();
	s += "\t\t<Levels>" + QString::number(levels.size()) + "</Levels>\n";
	for (int i = 0; i < levels.size(); i++)
		s += "\t\t<z>" + QString::number(levels[i]) + "</z>\n";

	bool defaultPen = defaultContourPen().style() != Qt::NoPen;
	s += "\t\t<DefaultPen>" + QString::number(defaultPen) + "</DefaultPen>\n";
	if (defaultPen){
		s += "\t\t\t<PenColor>" + defaultContourPen().color().name() + "</PenColor>\n";
		s += "\t\t\t<PenWidth>" + QString::number(defaultContourPen().widthF()) + "</PenWidth>\n";
		s += "\t\t\t<PenStyle>" + QString::number(defaultContourPen().style() - 1) + "</PenStyle>\n";
	} else if (!d_color_map_pen && !d_pen_list.isEmpty()){
		s += "\t\t<PenList>\n";
		for (int i = 0; i < d_pen_list.size(); i++){
			QPen pen = d_pen_list[i];
			s += "\t\t\t<pen>" + pen.color().name () + "," + QString::number(pen.widthF()) + ",";
			s += QString::number(PenStyleBox::styleIndex(pen.style())) + "</pen>\n";
		}
		s += "\t\t</PenList>\n";
	}

	if (d_show_labels){
		s += "\t\t<Labels>\n";
		s += "\t\t\t<Color>" + d_labels_color.name() + "</Color>\n";
		s += "\t\t\t<WhiteOut>" + QString::number(d_white_out_labels) +"</WhiteOut>\n";
		s += "\t\t\t<Angle>" + QString::number(d_labels_angle) + "</Angle>\n";
		s += "\t\t\t<xOffset>" + QString::number(d_labels_x_offset) + "</xOffset>\n";
		s += "\t\t\t<yOffset>" + QString::number(d_labels_y_offset) + "</yOffset>\n";
		s += "\t\t\t<Font>" + d_labels_font.toString() + "</Font>\n";
		foreach(PlotMarker *m, d_labels_list){
			if (m->xLabelOffset() != 0.0 || m->xLabelOffset() != 0.0){
				s += "\t\t\t<offset>" + QString::number(m->index()) + ",";
				s += QString::number(m->xLabelOffset()) + ",";
				s += QString::number(m->yLabelOffset()) + "</offset>\n";
			}
		}
		s += "\t\t</Labels>\n";
	}
}

QwtScaleWidget *colorAxis = d_graph->axisWidget(color_axis);
if (colorAxis && colorAxis->isColorBarEnabled()){
	s += "\t<ColorBar>\n\t\t<axis>" + QString::number(color_axis) + "</axis>\n";
	s += "\t\t<width>" + QString::number(colorAxis->colorBarWidth()) + "</width>\n";
	s += "\t</ColorBar>\n";
	}
s += "\t<Visible>"+ QString::number(isVisible()) + "</Visible>\n";
return s+"</spectrogram>\n";
}
/*!
  Draw circles

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radialMap Maps radius values into painter coordinates.
  \param values Radial values, indicating the distances from the pole
*/
void QwtPolarGrid::drawCircles(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, const QwtScaleMap &radialMap,
  const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    const double val = values[i];

    const GridData &gridData =
      d_data->gridData[QwtPolar::Radius];

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth];
      if ( axis.isVisible &&
           axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) )
      {
#if QWT_VERSION < 0x050200
        if ( isClose( val, gridData.scaleDiv.hBound() ) )
#else
        if ( isClose( val, gridData.scaleDiv.upperBound() ) )
#endif
          skipLine = true;
      }
    }

#if QWT_VERSION < 0x050200
    if ( isClose( val, gridData.scaleDiv.lBound() ) )
#else
    if ( isClose( val, gridData.scaleDiv.lowerBound() ) )
#endif
      skipLine = true;

    if ( !skipLine )
    {
      const double radius = radialMap.transform( val );

      QwtDoubleRect outerRect( 0, 0, 2 * radius, 2 * radius );
      outerRect.moveCenter( pole );

#if QT_VERSION < 0x040000
      QwtPainter::drawEllipse( painter, outerRect.toRect() );
#else
      if ( testDisplayFlag( ClipGridLines ) )
      {

        /*
            Qt4 is horrible slow, when painting primitives,
            with coordinates far outside the visible area.
            We need to clip.
        */

        const QwtArray<QwtDoubleInterval> angles =
          QwtClipper::clipCircle( canvasRect, pole, radius );
        for ( int i = 0; i < angles.size(); i++ )
        {
          const QwtDoubleInterval intv = angles[i];
          if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI )
            QwtPainter::drawEllipse( painter, outerRect.toRect() );
          else
          {
            const double from = intv.minValue() / M_PI * 180;
            const double to = intv.maxValue() / M_PI * 180;
            double span = to - from;
            if ( span < 0.0 )
              span += 360.0;

            const QwtMetricsMap &mm = QwtPainter::metricsMap();
            const QRect r = outerRect.toRect();

            painter->drawArc( mm.layoutToDevice( r, painter ),
                              qRound( from * 16 ), qRound( span * 16 ) );
          }

        }
      }
      else
      {
        QwtPainter::drawEllipse( painter, outerRect.toRect() );
      }
#endif
    }
  }
}
QString ScaleDraw::labelString(double value) const
{
	switch (d_type){
		case Numeric:
		{
            QLocale locale = d_plot->locale();
			if (d_plot->parent())
				locale = d_plot->multiLayer()->locale();
			if ((d_numeric_format == Superscripts)||(d_numeric_format == SuperscriptsGER)){
				QString txt = locale.toString(transformValue(value), 'e', d_prec);
				QStringList list = txt.split("e", QString::SkipEmptyParts);
				if (list.isEmpty())
					return QString::null;

				if (list[0].toDouble() == 0.0)
					return "0";

				QString s = list[1];
				int l = s.length();
				QChar sign = s[0];
				s.remove (sign);

				while (l>1 && s.startsWith ("0", false)){
					s.remove ( 0, 1 );
					l = s.length();
				}

				if (sign == '-')
					s.prepend(sign);

				if (list[0] == "1")
					return "10<sup>" + s + "</sup>";
				else {
					if (d_numeric_format == SuperscriptsGER)
						return list[0] + "·10<sup>" + s + "</sup>";
					else
						return list[0] + QString(QChar(0x00D7)) + "10<sup>" + s + "</sup>";
				}
			} else if (d_numeric_format == Engineering){
				QString eng_suff;
				double new_value = value;

				if(fabs(new_value) >= 1e18){
					eng_suff = 'E';
					new_value /= 1e18;
				} else if(fabs(new_value) >= 1e15){
					eng_suff = 'P';
					new_value /= 1e15;
				} else if(fabs(new_value) >= 1e12){
					eng_suff = 'T';
					new_value /= 1e12;
				} else if(fabs(new_value) >= 1e9){
					eng_suff = 'G';
					new_value /= 1e9;
				} else if(fabs(new_value) >= 1e6){
					eng_suff = 'M';
					new_value /= 1e6;
				} else if(fabs(new_value) >= 1e3){
					eng_suff = 'k';
					new_value /= 1e3;
				} else if(fabs(new_value) >= 1){
					eng_suff = "";
					new_value /= 1.0;
				} else if(fabs(new_value) >= 1e-3){
					eng_suff = 'm';
					new_value /= 1e-3;
				} else if(fabs(new_value) >= 1e-6){
					eng_suff = 'µ';
					new_value /= 1e-6;
				} else if(fabs(new_value) >= 1e-9){
					eng_suff = 'n';
					new_value /= 1e-9;
				} else if(fabs(new_value) >= 1e-12){
					eng_suff = 'p';
					new_value /= 1e-12;
				} else if(fabs(new_value) >= 1e-15){
					eng_suff = 'f';
					new_value /= 1e-15;
				} else {
					eng_suff = 'a';
					new_value /= 1e-18;
				}

				QString txt = locale.toString((new_value), 'f', d_prec);

				if(txt.contains(QRegExp("^0[\\.,]?0*$")))
					return "0";

				return txt + eng_suff;
			} else
				return locale.toString(transformValue(value), d_fmt, d_prec);
		break;
		}

		case Day:
		{
			int val = int(transformValue(value))%7;
			if (val < 0)
				val = 7 - abs(val);
			else if (val == 0)
				val = 7;

			QString day;
			switch(d_name_format){
				case  ShortName:
					day = QDate::shortDayName (val);
				break;
				case  LongName:
					day = QDate::longDayName (val);
				break;
				case  Initial:
					day = (QDate::shortDayName (val)).left(1);
				break;
			}
			return day;
		break;
		}

		case Month:
		{
			int val = int(transformValue(value))%12;
			if (val < 0)
				val = 12 - abs(val);
			else if (val == 0)
				val = 12;

			QString day;
			switch(d_name_format){
				case  ShortName:
					day = QDate::shortMonthName (val);
				break;
				case  LongName:
					day = QDate::longMonthName (val);
				break;
				case  Initial:
					day = (QDate::shortMonthName (val)).left(1);
				break;
			}
			return day;
		break;
		}

		case Time:
		{
			QTime time = Table::dateTime(value).time();
			if (d_format_info == "M")
				return QString::number(60*time.hour() + time.minute());
			else if (d_format_info == "S")
				return QString::number(3600*time.hour() + 60*time.minute() + time.second());

			return time.toString(d_format_info);
		break;
		}

		case Date:
			return Table::dateTime(value).toString(d_format_info);
		break;

		case ColHeader:
		case Text:
		{
			const QwtScaleDiv scDiv = scaleDiv();
			if (!scDiv.contains (value) || floor(value) < value)
				return QString::null;

			QwtValueList ticks = scDiv.ticks (QwtScaleDiv::MajorTick);

			double break_offset = 0;
			ScaleEngine *se = (ScaleEngine *)d_plot->axisScaleEngine(axis());
			bool inverted = se->testAttribute(QwtScaleEngine::Inverted);
			if(se->hasBreak()){
			    double lb = se->axisBreakLeft();
			    double rb = se->axisBreakRight();
                if(inverted){
                    if (value <= lb){
						int n_ticks = (int)ticks.count() - 1;
                        double val0 = ticks[0];
						double val1 = ticks[n_ticks];
                        for (int i = 1; i < n_ticks; i++){
                            double aux = ticks[i];
                            if(aux >= rb && val0 > aux){
                                val0 = aux;
								continue;
                            }
							if(aux <= lb && val1 < aux)
                                val1 = aux;
                        }
						break_offset = fabs(val1 - val0);
                    }
				} else {
                    if (value >= rb){
                        double val0 = ticks[0];
                        for (int i = 1; i < (int)ticks.count(); i++){
                            double val = ticks[i];
                            if(val0 <= lb && val >= rb){
                                break_offset = fabs(val - val0);
                                break;
                            }
                            val0 = val;
                        }
                    }
			    }
			}

			if (ticks.size() < 2)
				return QString::null;

        	double step = ticks[1] - ticks[0];
        	int index = int(ticks[0] + step*ticks.indexOf(value) - 1);
            int offset = abs((int)floor(break_offset/step));
            if (offset)
                offset--;
            if (step > 0)
                index += offset;
            else
                index -= offset;
			if (index >= 0 && index < (int)d_text_labels.count())
				return d_text_labels[index];
			else
				return QString::null;
		break;
		}
	}
	return QString::null;
}
Exemple #12
0
    setDefaultContourPen(Qt::NoPen);
    d_pen_list.clear();
  }
}
/**
for creating contour line labels
 */
void Spectrogram::createLabels()
{
  foreach(QwtPlotMarker *m, d_labels_list){
    m->detach();
    delete m;
  }
  d_labels_list.clear();
  QwtValueList levels = contourLevels();
  const int numLevels = levels.size();
  for (int l = 0; l < numLevels; l++){
    PlotMarker *m = new PlotMarker(l, d_labels_angle);
    QwtText t = QwtText(QString::number(levels[l]));
    t.setColor(d_labels_color);
    t.setFont(d_labels_font);

    if (d_white_out_labels)
      t.setBackgroundBrush(QBrush(Qt::white));
    else
      t.setBackgroundBrush(QBrush(Qt::transparent));
    m->setLabel(t);

    int x_axis = xAxis();
    int y_axis = yAxis();
    m->setAxis(x_axis, y_axis);