コード例 #1
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);
}
コード例 #2
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;
}
コード例 #3
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();
}