Exemplo n.º 1
0
void VectorPlot::addDotPlot(const MarkupQwtAdapter&adapter,
		QColor color,
		const QString &name,
		bool addToLegend) {
	QwtPlotCurve *curve = new QwtPlotCurve(name);

    QwtSymbol sym;
    sym.setPen(QColor(color));
    sym.setBrush(QColor(color));
    sym.setStyle(QwtSymbol::Rect);
    sym.setSize(
			QSize(1, 20)
			);
	curve->setSymbol(sym);
	curve->setStyle(QwtPlotCurve::NoCurve);

	if(adapter.size() > 0) {
		setupPlot(adapter.boundingRect());
		curve->setData(adapter);
		curve->attach(plot);
	}

	if(!legend) {
		return;
	}

    // Добавляем кривую в легенду
	QwtLegendItem *item = new QwtLegendItem(0);
	item->setText(curve->title());
	item->setSymbol(sym);
	item->setIdentifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText);
	legend->insert(curve, item);
}
Exemplo n.º 2
0
void LinePlot::scaleCurves(QwtPlotCurve *curve)
{

  /// multiple curves based on units
  const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList();
  QwtPlotCurve *plotCurve;
  QwtPlotItemIterator itPlotItem;
  int curveCount = numberOfCurves();

  switch (curveCount)
  {
    case 0:
    {
      curve->setYAxis(QwtPlot::yLeft);
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      break;
    }
    case 1:
    {
      curve->setYAxis(QwtPlot::yRight);
      m_qwtPlot->enableAxis(QwtPlot::yRight, true);
      break;
    }
    default: //scale
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      // find min, max of all curves
      // scale
      int i;
      for ( itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem)
      {
        if ( (*itPlotItem)->rtti() == QwtPlotItem::Rtti_PlotCurve)
        {
          plotCurve = (QwtPlotCurve*) (*itPlotItem);

          if ((plotCurve->minYValue() != 0) || (plotCurve->maxYValue() != 1))
          {

            QwtArray<double> xData(plotCurve->dataSize());
            QwtArray<double> yData(plotCurve->dataSize());
            for (i = 0; i < plotCurve->dataSize(); i++)
            {
              xData[i] = plotCurve->x(i);
              yData[i] = (plotCurve->y(i) - plotCurve->minYValue())/ (plotCurve->maxYValue() - plotCurve->minYValue());
            }
            // reset data
            plotCurve->setTitle(plotCurve->title().text() + "[" + QString::number(plotCurve->minYValue()) + ", "  + QString::number(plotCurve->maxYValue()) + "]");
            plotCurve->setData(xData,yData);
          }
        }
      }
      break;
  }

}
Exemplo n.º 3
0
void RTVTPlotWindow::addCurveWithDataFromChannel(QVector<qreal> frequency, QVector<qreal> amplitude, unsigned int channel)
{
    QwtPlotCurve *curve = new QwtPlotCurve(QString("Channel " + QString::number(channel)));
    curve->setPen(selectPen());
    curve->setSamples(frequency, amplitude);
    curve->setAxes(QwtPlot::xBottom, QwtPlot::yLeft);
    curves << curve;

    channelStringList << curve->title().text();
    channelListStringModel->setStringList(channelStringList);
}
Exemplo n.º 4
0
/*!
  \brief Enable or disable the legend
  \param tf \c TRUE (enabled) or \c FALSE (disabled)
  \param curveKey Key of a existing curve.
                  If curveKey < 0 the legends for all
                  curves will be updated.
  \sa QwtPlot::setAutoLegend()
  \sa QwtPlot::setLegendPos()
*/
void QwtPlot::enableLegend(
#ifndef QWT_NO_LEGEND
    bool enable, long curveKey
#else
    bool, long
#endif
)
{
#ifndef QWT_NO_LEGEND
    QwtPlotCurve *curCurve;

    bool isUpdateEnabled = d_legend->isUpdatesEnabled();
    d_legend->setUpdatesEnabled(FALSE);

    if ( curveKey < 0 ) // legends for all curves
    {
        if ( enable )
        {
            if ( d_legend->itemCnt() < d_curves->count() )
            {
                // not all curves have a legend

                d_legend->clear();

                QIntDictIterator<QwtPlotCurve> itc(*d_curves);
                itc.toFirst();

                while ((curCurve = itc.current()))
                {
                    d_legend->appendItem(curCurve->title(),
                        curCurve->symbol(), curCurve->pen(), itc.currentKey());

                    ++itc;
                }
            }
        }
        else
        {
            if ( d_legend->itemCnt() > 0 )
                d_legend->clear();
        }
    }
    else
    {
        uint index = d_legend->findFirstKey(curveKey);
        if ( enable )
        {
            curCurve = d_curves->find(curveKey);
            if ( curCurve && ( index >= d_legend->itemCnt() ) )
            {
                // curve exists and has no legend

                d_legend->appendItem(curCurve->title(),
                        curCurve->symbol(), curCurve->pen(), curveKey);
            }
        }
        else
        {
            if ( index < d_legend->itemCnt() )
                d_legend->removeItem(index);
        }
    }

    d_legend->setUpdatesEnabled(isUpdateEnabled);
	updateLayout();
#endif
}