예제 #1
0
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);
        }
    }
}
/*!
  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;
}
예제 #3
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();

    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;
}
예제 #4
0
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);
			}
		}
	}
}
예제 #5
0
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;
        }
    }
}
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();
}
예제 #7
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);
        }
    }
}
예제 #8
0
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();
}
예제 #9
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();
}
예제 #10
0
/** 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;
  }
}
예제 #11
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;
}
예제 #12
0
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;
    }
}