コード例 #1
0
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));
	}
}
コード例 #2
0
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);
}
コード例 #3
0
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;
}
コード例 #4
0
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;
}
コード例 #5
0
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;
	}
}
コード例 #6
0
void ScaleDraw::drawTick(QPainter *p, double value, int len) const
{
	int axis = this->axis();
	ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis);
	if (sc_engine->hasBreak()){
		double dlb = sc_engine->axisBreakLeft();
		double drb = sc_engine->axisBreakRight();
		if ((dlb < value && drb > value) ||
			((axis == QwtPlot::yLeft || axis == QwtPlot::xBottom) && value == dlb) ||
			((axis == QwtPlot::yRight || axis == QwtPlot::xTop) && value == drb) ||
			(sc_engine->testAttribute(QwtScaleEngine::Inverted) && (value == dlb || value == drb)))
			return;

		if (d_plot->isPrinting()){
			QwtScaleMap scaleMap = map();
			double val = scaleMap.transform(value);
			if (val >= scaleMap.transform(dlb) && val <= scaleMap.transform(drb))
				return;
		}
	}

	QwtScaleDiv scDiv = scaleDiv();
	QwtValueList majTicks = scDiv.ticks(QwtScaleDiv::MajorTick);
	if (majTicks.contains(value)){
		if (d_majTicks == In || d_majTicks == None)
			return;

		switch (d_show_ticks_policy){
			case ShowAll:
			break;

			case HideBegin:
				if (majTicks.first() == value)
					return;
			break;
			case HideEnd:
				if (majTicks.last() == value)
					return;
			break;
			case HideBeginEnd:
				if (majTicks.first() == value || majTicks.last() == value)
					return;
			break;
		}
	}

    QwtValueList medTicks = scDiv.ticks(QwtScaleDiv::MediumTick);
    if (medTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
        return;

    QwtValueList minTicks = scDiv.ticks(QwtScaleDiv::MinorTick);
    if (minTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
        return;

	QwtScaleDraw::drawTick(p, value, len);
}
コード例 #7
0
ファイル: AxisImp.cpp プロジェクト: wzssyqa/opticks-cmake
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;
}
コード例 #8
0
QwtText QwtTextScaleDraw::label(double value) const
{
    const QwtScaleDiv scDiv = scaleDiv();
    if (!scDiv.contains (value))
        return QwtText();

    QwtValueList lst = scDiv.ticks (QwtScaleDiv::MajorTick);
    lst.pop_front();
    lst.pop_back();
    int index = lst.indexOf(value);
    if (index >= 0 && index < (int)labels.count())
        return QwtText(labels[index]);
    else
        return QwtText();
}
コード例 #9
0
/*!
  Remove ticks from a list, that are not inside an interval

  \param ticks Tick list
  \param interval Interval

  \return Stripped tick list
*/
QwtValueList QwtScaleEngine::strip( 
    const QwtValueList& ticks, 
    const QwtDoubleInterval &interval) const
{
    if ( !interval.isValid() || ticks.count() == 0 )
        return QwtValueList();

    QwtValueList strippedTicks;
    for ( int i = 0; i < (int)ticks.count(); i++ )
    {
		double v = ticks[i];
		if ( contains(interval, v) && !strippedTicks.contains(v))
			strippedTicks += v;
    }
    return strippedTicks;
}
コード例 #10
0
ファイル: plot.cpp プロジェクト: BackupTheBerlios/qtiplot-svn
void Grid::drawLines(QPainter *painter, const QRect &rect,
    Qt::Orientation orientation, const QwtScaleMap &map, 
    const QwtValueList &values) const
{
    const int x1 = rect.left();
    const int x2 = rect.right() + 1;
    const int y1 = rect.top();
    const int y2 = rect.bottom() + 1;
	const int margin = 10;

    for (uint i = 0; i < (uint)values.count(); i++)
    {
        const int value = map.transform(values[i]);
        if ( orientation == Qt::Horizontal )
        {
            if ((value >= y1 + margin) && (value <= y2 - margin))
                QwtPainter::drawLine(painter, x1, value, x2, value);
        }
        else
        {
            if ((value >= x1 + margin) && (value <= x2 - margin))
                QwtPainter::drawLine(painter, value, y1, value, y2);
        }
    }
}
コード例 #11
0
/*!
  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 );
    }
  }
}
コード例 #12
0
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);
}
コード例 #13
0
ファイル: qwt_scale_engine.cpp プロジェクト: 376473984/pvb
/*!
  Remove ticks from a list, that are not inside an interval

  \param ticks Tick list
  \param interval Interval

  \return Stripped tick list
*/
QwtValueList QwtScaleEngine::strip( 
    const QwtValueList& ticks, 
    const QwtDoubleInterval &interval) const
{
    if ( !interval.isValid() || ticks.count() == 0 )
        return QwtValueList();

    if ( contains(interval, ticks.first())
        && contains(interval, ticks.last()) )
    {
        return ticks;
    }

    QwtValueList strippedTicks;
    for ( int i = 0; i < (int)ticks.count(); i++ )
    {
        if ( contains(interval, ticks[i]) )
            strippedTicks += ticks[i];
    }
    return strippedTicks;
}
コード例 #14
0
ファイル: Grid.cpp プロジェクト: BackupTheBerlios/qtiplot-svn
void Grid::drawLines(QPainter *painter, const QRect &rect,
		Qt::Orientation orientation, const QwtScaleMap &map,
		const QwtValueList &values) const
{
	if (values.isEmpty())
		return;
		
	const int x1 = rect.left();
	const int x2 = rect.right();
	const int y1 = rect.top();
	const int y2 = rect.bottom();

	Graph *g = (Graph *)this->plot();
	if (g && g->canvasFrameWidth()){
		for (uint i = 0; i < (uint)values.count(); i++){
			const int value = map.transform(values[i]);
			if ( orientation == Qt::Horizontal ){
				if ((value > y1 + 1) && (value < y2 - 1))
					QwtPainter::drawLine(painter, x1, value, x2, value);
			} else {
				if ((value > x1 + 1) && (value < x2 - 1))
					QwtPainter::drawLine(painter, value, y1, value, y2);
			}
		}
	} else {
		for (uint i = 0; i < (uint)values.count(); i++){
			const int value = map.transform(values[i]);
			if ( orientation == Qt::Horizontal ){
				if ((value > y1) && (value < y2))
					QwtPainter::drawLine(painter, x1, value, x2, value);
			} else {
				if ((value > x1) && (value < x2))
					QwtPainter::drawLine(painter, value, y1, value, y2);
			}
		}
	}
}
コード例 #15
0
ファイル: qwt_scale_engine.cpp プロジェクト: 376473984/pvb
void QwtLinearScaleEngine::buildMinorTicks(
    const QwtValueList& majorTicks,
    int maxMinSteps, double stepSize,
    QwtValueList &minorTicks, 
    QwtValueList &mediumTicks) const
{   
    double minStep = divideInterval(stepSize, maxMinSteps);
    if (minStep == 0.0)  
        return; 
        
    // # ticks per interval
    int numTicks = (int)::ceil(qwtAbs(stepSize / minStep)) - 1;
    
    // Do the minor steps fit into the interval?
    if ( QwtScaleArithmetic::compareEps((numTicks +  1) * qwtAbs(minStep), 
        qwtAbs(stepSize), stepSize) > 0)
    {   
        numTicks = 1;
        minStep = stepSize * 0.5;
    }

    int medIndex = -1;
    if ( numTicks % 2 )
        medIndex = numTicks / 2;

    // calculate minor ticks

    for (int i = 0; i < (int)majorTicks.count(); i++)
    {
        double val = majorTicks[i];
        for (int k = 0; k < numTicks; k++)
        {
            val += minStep;

            double alignedValue = val;
            if (QwtScaleArithmetic::compareEps(val, 0.0, stepSize) == 0) 
                alignedValue = 0.0;

            if ( k == medIndex )
                mediumTicks += alignedValue;
            else
                minorTicks += alignedValue;
        }
    }
}
コード例 #16
0
QwtValueList Log2ScaleEngine::buildMinorTicks(const QwtValueList &majorTicks,
    int maxMinSteps, double stepSize) const
{
	if ( maxMinSteps < 1 )
		return QwtValueList();

	int majTicks = (int)majorTicks.count();
    if (majTicks > 1){
        QwtValueList minorTicks;
		for (int i = 0; i < majTicks - 1; i++){
			const double v = majorTicks[i];
            const double dv = fabs(majorTicks[i + 1] - majorTicks[i])/double(maxMinSteps - 1);
            for (int j = 0; j < maxMinSteps; j++)
                minorTicks += v + j*dv;
        }
        return minorTicks;
    }
    return QwtValueList();
}
コード例 #17
0
void ScaleDraw::drawTick(QPainter *p, double value, int len) const
{
    QwtScaleDiv scDiv = scaleDiv();
    QwtValueList majTicks = scDiv.ticks(QwtScaleDiv::MajorTick);
    if (majTicks.contains(value) && (d_majTicks == In || d_majTicks == None))
        return;

    QwtValueList medTicks = scDiv.ticks(QwtScaleDiv::MediumTick);
    if (medTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
        return;

    QwtValueList minTicks = scDiv.ticks(QwtScaleDiv::MinorTick);
    if (minTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
        return;

    QwtScaleDraw::drawTick(p, value, len);
}
コード例 #18
0
void QwtPlotGrid::drawLines(QPainter *painter, const QRect &canvasRect,
    Qt::Orientation orientation, const QwtScaleMap &scaleMap, 
    const QwtValueList &values) const
{
    const int x1 = canvasRect.left();
    const int x2 = canvasRect.right();
    const int y1 = canvasRect.top();
    const int y2 = canvasRect.bottom();

    for (uint i = 0; i < (uint)values.count(); i++)
    {
        const int value = scaleMap.transform(values[i]);
        if ( orientation == Qt::Horizontal )
        {
            if ((value >= y1) && (value <= y2))
                QwtPainter::drawLine(painter, x1, value, x2, value);
        }
        else
        {
            if ((value >= x1) && (value <= x2))
                QwtPainter::drawLine(painter, value, y1, value, y2);
        }
    }
}
コード例 #19
0
ファイル: plot.cpp プロジェクト: BackupTheBerlios/qtiplot-svn
void Plot::drawInwardTicks(QPainter *painter, const QRect &rect, 
							const QwtScaleMap &map, int axis, bool min, bool maj) const
{	
	int x1=rect.left();
	int x2=rect.right();
	int y1=rect.top();
	int y2=rect.bottom();
	
	QPalette pal=axisWidget(axis)->palette();
	QColor color=pal.color(QPalette::Active, QColorGroup::Foreground);
		
    painter->save();	
    painter->setPen(QPen(color, axesLinewidth(), QPainter::SolidLine));
		
	QwtScaleDiv *scDiv=(QwtScaleDiv *)axisScaleDiv(axis);
	const QwtValueList minTickList = scDiv->ticks(QwtScaleDiv::MinorTick);
	int minTicks = (int)minTickList.count();

	const QwtValueList medTickList = scDiv->ticks(QwtScaleDiv::MediumTick);
	int medTicks = (int)medTickList.count();

	const QwtValueList majTickList = scDiv->ticks(QwtScaleDiv::MajorTick);
	int majTicks = (int)majTickList.count();
	
int j, x, y, low,high;
switch (axis)
	{
	case QwtPlot::yLeft:
	x=x1;
	low=y1+majTickLength;
	high=y2-majTickLength;
	if (min)
	{
    for (j = 0; j < minTicks; j++)
        {
            y = map.transform(minTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x, y, x+minTickLength, y);
        }
	for (j = 0; j < medTicks; j++)
        {
            y = map.transform(medTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x, y, x+minTickLength, y);
        }
	}

	if (maj)
	{
	for (j = 0; j < majTicks; j++)
        {
            y = map.transform(majTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x, y, x+majTickLength, y);
        }
	}
	break;
		
	case QwtPlot::yRight:
		{
		x=x2;
		low=y1+majTickLength;
		high=y2-majTickLength;
		if (min)
		{
     	for (j = 0; j < minTicks; j++)
       	 	{
            y = map.transform(minTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x+1, y, x-minTickLength, y);
        	}
		for (j = 0; j < medTicks; j++)
       	 	{
            y = map.transform(medTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x+1, y, x-minTickLength, y);
        	}
		}

		if (maj)
		{
		 for (j = 0; j <majTicks; j++)
        	{
            y = map.transform(majTickList[j]);
			if (y>low && y< high)
            	QwtPainter::drawLine(painter, x+1, y, x-majTickLength, y);
        	}
		}
		}
	  break;
		
	case QwtPlot::xBottom:
		y=y2;
		low=x1+majTickLength;
		high=x2-majTickLength;
		if (min)
		{
     	for (j = 0; j < minTicks; j++)
        	{
            x = map.transform(minTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y+1, x, y-minTickLength);
       		 }
		for (j = 0; j < medTicks; j++)
        	{
            x = map.transform(medTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y+1, x, y-minTickLength);
       		 }
		}

		if (maj)
		{
	 	for (j = 0; j < majTicks; j++)
        	{
            x = map.transform(majTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y+1, x, y-majTickLength);
        	}
		}
		break;
	
	case QwtPlot::xTop:
		y=y1;
		low=x1+majTickLength;
		high=x2-majTickLength;

		if (min)
		{
    	for (j = 0; j < minTicks; j++)
       		{
             x = map.transform(minTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y, x, y + minTickLength);
       	    }
		for (j = 0; j < medTicks; j++)
       		{
             x = map.transform(medTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y, x, y + minTickLength);
       	    }
		}

		if (maj)
		{
	 	for (j = 0; j <majTicks; j++)
        	{
            x = map.transform(majTickList[j]);
			if (x>low && x<high)
            	QwtPainter::drawLine(painter, x, y, x, y + majTickLength);
        	}
		}
	break;
	}
painter->restore();
}
コード例 #20
0
ファイル: Spectrogram.cpp プロジェクト: stothe2/mantid
  if (on) {
    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();
コード例 #21
0
QwtText ScaleDraw::label(double value) const
{
	switch (d_type){
		case Numeric:
		{
            QLocale locale = ((Graph *)d_plot->parent())->multiLayer()->locale();
			if (d_numeric_format == Superscripts){
				QString txt = locale.toString(transformValue(value), 'e', d_prec);
				QStringList list = txt.split("e", QString::SkipEmptyParts);
				if (list[0].toDouble() == 0.0)
					return QString("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 QwtText("10<sup>" + s + "</sup>");
				else
					return QwtText(list[0] + "x10<sup>" + s + "</sup>");
			} else
				return QwtText(locale.toString(transformValue(value), d_fmt, d_prec));
		break;
		}

		case Day:
		{
			int val = static_cast<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 QwtText(day);
		break;
		}

		case Month:
		{
			int val = static_cast<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 QwtText(day);
		break;
		}

		case Time:
			return QwtText(d_date_time_origin.time().addMSecs((int)value).toString(d_format_info));
		break;

		case Date:
            return QwtText(d_date_time_origin.addSecs((int)value).toString(d_format_info));
		break;

		case ColHeader:
		case Text:
		{
			const QwtScaleDiv scDiv = scaleDiv();
			if (!scDiv.contains (value))
				return QwtText();

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

			double break_offset = 0;
			ScaleEngine *se = (ScaleEngine *)d_plot->axisScaleEngine(axis());
			/*QwtScaleEngine *qwtsc_engine=d_plot->axisScaleEngine(axis());
			ScaleEngine *se =dynamic_cast<ScaleEngine*>(qwtsc_engine);
			if(se!=NULL)
			{*/
				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;
							}
						}
					}
				}

				double step = ticks[1] - ticks[0];
				int index = static_cast<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 QwtText(d_text_labels[index]);
				else
					return QwtText();
			//}
		break;
		}
	}
	return QwtText();
}
コード例 #22
0
ファイル: qwt_scale_engine.cpp プロジェクト: 376473984/pvb
QwtValueList QwtLog10ScaleEngine::buildMinorTicks(
    const QwtValueList &majorTicks, 
    int maxMinSteps, double stepSize) const
{   
    if (stepSize < 1.1)            // major step width is one decade
    {
        if ( maxMinSteps < 1 )
            return QwtValueList();
            
        int k0, kstep, kmax;
        
        if (maxMinSteps >= 8)
        {
            k0 = 2;
            kmax = 9;
            kstep = 1;
        }   
        else if (maxMinSteps >= 4)
        {
            k0 = 2;
            kmax = 8;
            kstep = 2;
        }   
        else if (maxMinSteps >= 2)
        {
            k0 = 2;
            kmax = 5;
            kstep = 3;
        }
        else
        {
            k0 = 5;
            kmax = 5;
            kstep = 1;
        }

        QwtValueList minorTicks;

        for (int i = 0; i < (int)majorTicks.count(); i++)
        {
            const double v = majorTicks[i];
            for (int k = k0; k<= kmax; k+=kstep)
                minorTicks += v * double(k);
        }

        return minorTicks;
    }
    else  // major step > one decade
    {
        double minStep = divideInterval(stepSize, maxMinSteps);
        if ( minStep == 0.0 )
            return QwtValueList();

        if ( minStep < 1.0 )
            minStep = 1.0;

        // # subticks per interval
        int nMin = qRound(stepSize / minStep) - 1;

        // Do the minor steps fit into the interval?

        if ( QwtScaleArithmetic::compareEps((nMin +  1) * minStep, 
            qwtAbs(stepSize), stepSize) > 0)
        {
            nMin = 0;
        }

        if (nMin < 1)
            return QwtValueList();      // no subticks

        // substep factor = 10^substeps
        const double minFactor = qwtMax(pow(10.0, minStep), 10.0);

        QwtValueList minorTicks;
        for (int i = 0; i < (int)majorTicks.count(); i++)
        {
            double val = majorTicks[i];
            for (int k=0; k< nMin; k++)
            {
                val *= minFactor;
                minorTicks += val;
            }
        }
        return minorTicks;
    }
}
コード例 #23
0
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";
}
コード例 #24
0
ファイル: ScaleDetails.cpp プロジェクト: jkrueger1/mantid
/** Initialisation method. Sets up all widgets and variables not done in the constructor.
*
*/
void ScaleDetails::initWidgets()
{
  if (m_initialised)
  {
    return;
  }
  else
  {
    Plot *d_plot = m_graph->plotWidget();
    const QwtScaleDiv *scDiv = d_plot->axisScaleDiv(m_mappedaxis);
    double start = QMIN(scDiv->lBound(), scDiv->hBound());
    double end = QMAX(scDiv->lBound(), scDiv->hBound());
    ScaleDraw::ScaleType type = m_graph->axisType(m_mappedaxis);
    if (type == ScaleDraw::Date)
    {
      ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis));
      QDateTime origin = sclDraw->dateTimeOrigin();

      m_dspnStart->hide();
      m_timStartTime->hide();
      m_dteStartDateTime->show();
      m_dteStartDateTime->setDisplayFormat(sclDraw->format());
      m_dteStartDateTime->setDateTime(origin.addSecs((int) start));

      m_dspnEnd->hide();
      m_timEndTime->hide();
      m_dteEndDateTime->show();
      m_dteEndDateTime->setDisplayFormat(sclDraw->format());
      m_dteEndDateTime->setDateTime(origin.addSecs((int) end));

      m_cmbUnit->show();
      m_cmbUnit->insertItem(tr("days"));
      m_cmbUnit->insertItem(tr("weeks"));
      m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 86400.0);
      m_dspnStep->setSingleStep(1);
    }
    else if (type == ScaleDraw::Time)
    {
      ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis));
      QTime origin = sclDraw->dateTimeOrigin().time();

      m_dspnStart->hide();
      m_dteStartDateTime->hide();
      m_timStartTime->show();
      m_timStartTime->setDisplayFormat(sclDraw->format());
      m_timStartTime->setTime(origin.addMSecs((int) start));

      m_dspnEnd->hide();
      m_dteEndDateTime->hide();
      m_timEndTime->show();
      m_timEndTime->setDisplayFormat(sclDraw->format());
      m_timEndTime->setTime(origin.addMSecs((int) end));

      m_cmbUnit->show();
      m_cmbUnit->insertItem(tr("millisec."));
      m_cmbUnit->insertItem(tr("sec."));
      m_cmbUnit->insertItem(tr("min."));
      m_cmbUnit->insertItem(tr("hours"));
      m_cmbUnit->setCurrentIndex(1);
      m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 1e3);
      m_dspnStep->setSingleStep(1000);
    }
    else
    {
      m_dspnStart->show();
      m_dspnStart->setValue(start);
      m_timStartTime->hide();
      m_dteStartDateTime->hide();
      m_dspnEnd->show();
      m_dspnEnd->setValue(end);
      m_timEndTime->hide();
      m_dteEndDateTime->hide();
      m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis));
      m_dspnStep->setSingleStep(0.1);
    }

    double range = fabs(scDiv->range());
    QwtScaleEngine *qwtsc_engine = d_plot->axisScaleEngine(m_mappedaxis);
    ScaleEngine* sc_engine = dynamic_cast<ScaleEngine*>(qwtsc_engine);
    if (sc_engine)
    {
      if (sc_engine->axisBreakLeft() > -DBL_MAX)
      {
        m_dspnBreakStart->setValue(sc_engine->axisBreakLeft());
      }
      else
      {
        m_dspnBreakStart->setValue(start + 0.25 * range);
      }

      if (sc_engine->axisBreakRight() < DBL_MAX)
      {
        m_dspnBreakEnd->setValue(sc_engine->axisBreakRight());
      }
      else
      {
        m_dspnBreakEnd->setValue(start + 0.75 * range);
      }
      m_grpAxesBreaks->setChecked(sc_engine->hasBreak());

      m_spnBreakPosition->setValue(sc_engine->breakPosition());
      m_spnBreakWidth->setValue(sc_engine->breakWidth());
      m_dspnStepBeforeBreak->setValue(sc_engine->stepBeforeBreak());
      m_dspnStepAfterBreak->setValue(sc_engine->stepAfterBreak());

      QwtScaleTransformation::Type scale_type = sc_engine->type();
      m_cmbMinorTicksBeforeBreak->clear();
      if (scale_type == QwtScaleTransformation::Log10)
      {
        m_cmbMinorTicksBeforeBreak->addItems(QStringList() << "0" << "2" << "4" << "8");
      }
      else
      {
        m_cmbMinorTicksBeforeBreak->addItems(QStringList() << "0" << "1" << "4" << "9" << "14" << "19");
      }
      m_cmbMinorTicksBeforeBreak->setEditText(QString::number(sc_engine->minTicksBeforeBreak()));

      m_cmbMinorTicksAfterBreak->setEditText(QString::number(sc_engine->minTicksAfterBreak()));
      m_chkLog10AfterBreak->setChecked(sc_engine->log10ScaleAfterBreak());
      m_chkBreakDecoration->setChecked(sc_engine->hasBreakDecoration());
      m_chkInvert->setChecked(sc_engine->testAttribute(QwtScaleEngine::Inverted));
      m_cmbScaleType->setCurrentItem(scale_type);
      m_cmbMinorValue->clear();
      if (scale_type == QwtScaleTransformation::Log10)
      {
        m_cmbMinorValue->addItems(QStringList() << "0" << "2" << "4" << "8");
      }
      else
      {
        m_cmbMinorValue->addItems(QStringList() << "0" << "1" << "4" << "9" << "14" << "19");
      }
      m_cmbMinorValue->setEditText(QString::number(d_plot->axisMaxMinor(m_mappedaxis)));

      bool isColorMap = m_graph->isColorBarEnabled(m_mappedaxis);
      m_grpAxesBreaks->setEnabled(!isColorMap);
      if (isColorMap)
      {
        m_grpAxesBreaks->setChecked(false);
      }
    }
    else
    {
      m_grpAxesBreaks->setChecked(false);
      m_grpAxesBreaks->setEnabled(false);
    }

    QwtValueList lst = scDiv->ticks(QwtScaleDiv::MajorTick);
    m_spnMajorValue->setValue(lst.count());

    checkstep();

    connect(m_grpAxesBreaks,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkInvert,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkLog10AfterBreak,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkBreakDecoration,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_radStep,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_radMajor,SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_cmbMinorTicksBeforeBreak,SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
    connect(m_cmbMinorTicksAfterBreak,SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
    connect(m_cmbMinorValue,SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
    connect(m_cmbUnit,SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
    connect(m_cmbScaleType,SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
    connect(m_dspnEnd, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnStart, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnStep, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnBreakStart, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnStepBeforeBreak, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnStepAfterBreak, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_dspnBreakEnd, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
    connect(m_spnMajorValue, SIGNAL(valueChanged(int)), this, SLOT(setModified()));
    connect(m_spnBreakPosition, SIGNAL(valueChanged(int)), this, SLOT(setModified()));
    connect(m_spnBreakWidth, SIGNAL(valueChanged(int)), this, SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified()));

    m_initialised = true;
  }
}
コード例 #25
0
/*!
  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
    }
  }
}
コード例 #26
0
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;
}
コード例 #27
0
void ScaleDraw::drawLabel(QPainter *painter, double value) const
{
	if (!d_plot)
		return;

	ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
	if (sc_engine->hasBreak() && sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() > value)
		return;

	QwtValueList majTicks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
	if (majTicks.contains(value)){
		switch (d_show_ticks_policy){
			case ShowAll:
			break;

			case HideBegin:
				if (majTicks.first() == value)
					return;
			break;
			case HideEnd:
				if (majTicks.last() == value)
					return;
			break;
			case HideBeginEnd:
				if (majTicks.first() == value || majTicks.last() == value)
					return;
			break;
		}
	}

	QwtText lbl = tickLabel(painter->font(), value);
	if ( lbl.isEmpty() )
		return;

	QPoint pos = labelPosition(value);

	QSize labelSize = lbl.textSize(painter->font());
	if ( labelSize.height() % 2 )
		labelSize.setHeight(labelSize.height() + 1);

	const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
	QwtPainter::resetMetricsMap();

	labelSize = metricsMap.layoutToDevice(labelSize);
	pos = metricsMap.layoutToDevice(pos);

	painter->save();
	painter->setMatrix(labelMatrix( pos, labelSize), true);

	if (d_selected)
		lbl.setBackgroundPen(QPen(Qt::blue));
	else
		lbl.setBackgroundPen(QPen(Qt::NoPen));

	lbl.setRenderFlags(labelAlignment());

	lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );

	QwtPainter::setMetricsMap(metricsMap); // restore metrics map

	painter->restore();
}
コード例 #28
-1
void ScaleDraw::drawTick(QPainter *p, double value, int len) const
{
	ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
	/*QwtScaleEngine *qwtsc_engine=d_plot->axisScaleEngine(axis());
    ScaleEngine *sc_engine =dynamic_cast< ScaleEngine*>(qwtsc_engine);
	if(sc_engine!=NULL)
	{*/
		if (sc_engine->hasBreak()){
			int align = alignment();
			bool invertedScale = sc_engine->testAttribute(QwtScaleEngine::Inverted);
			if (align == BottomScale || align == LeftScale){
				if (invertedScale && sc_engine->axisBreakRight() == value)
					return;
				if (!invertedScale && sc_engine->axisBreakLeft() == value)
					return;
			} else {
				if (!invertedScale && sc_engine->axisBreakRight() == value)
					return;
				if (invertedScale && sc_engine->axisBreakLeft() == value)
					return;
			}
		}
	//}
		 QwtScaleDiv scDiv = scaleDiv();
		 QwtValueList majTicks = scDiv.ticks(QwtScaleDiv::MajorTick);
		 if (majTicks.contains(value) && (d_majTicks == In || d_majTicks == None))
			 return;

		 QwtValueList medTicks = scDiv.ticks(QwtScaleDiv::MediumTick);
		 if (medTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
			 return;

		 QwtValueList minTicks = scDiv.ticks(QwtScaleDiv::MinorTick);
		 if (minTicks.contains(value) && (d_minTicks == In || d_minTicks == None))
			 return;

		 QwtScaleDraw::drawTick(p, value, len);
}