Exemplo n.º 1
0
void Plot::drawDots(QVector< QVector<struct numCluster> > data, double n, double k, int index, int size, int number)
{
    int j, l;
    QPolygonF points;
    QwtPlotCurve *curve;

    QwtSymbol *symbol;

    points.clear();
    curve = new QwtPlotCurve();//QString("y = norm%1(x)").arg(index));
    curve->setItemAttribute(QwtPlotItem::Legend, false);
    curve->setStyle( QwtPlotCurve::Dots );
    for (l = 0; l < data.size(); l++){
        if (data[l][number].cluster == index){
            // ПЕРЕДЕЛАТЬ если возможно!!! Нужно, чтобы он печатал сразу для всех кластеров одной л.п.
            if (index == 0 && data[l][number].number < n){
                points << QPointF(data[l][number].number, 1);
            }else if (index == size - 1 && data[l][number].number > n){
                points << QPointF(data[l][number].number, 1);
            }else{
                points << QPointF(data[l][number].number, func_normal(data[l][number].number,n,k));
            }

            //std::cout << index << "data = " << data[l][i].number << std::endl;
        }
    }
    curve->setSamples(points);
    switch (index % 5){
    case 0:
        symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                QBrush( Qt::yellow ), QPen( Qt::red, 1 ), QSize( 8, 8 ) );
        curve->setSymbol(symbol);
        break;
    case 1:
        symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                QBrush( Qt::green ), QPen( Qt::red, 1 ), QSize( 8, 8 ) );
        curve->setSymbol(symbol);
        break;
    case 2:
        symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                QBrush( Qt::cyan ), QPen( Qt::red, 1 ), QSize( 8, 8 ) );
        curve->setSymbol(symbol);
        break;
    case 3:
        symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                QBrush( Qt::magenta ), QPen( Qt::red, 1 ), QSize( 8, 8 ) );
        curve->setSymbol(symbol);
        break;
    case 4:
        symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                QBrush( Qt::gray ), QPen( Qt::red, 1 ), QSize( 8, 8 ) );
        curve->setSymbol(symbol);
        break;
    default:
        break;
    }
    curve->attach(this);
    this->replot();
}
Exemplo n.º 2
0
void Plot::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setMinorPen( Qt::black, 0, Qt::DashLine );
    grid->enableXMin( true );
    grid->attach( this );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle("Some Points");
    curve->setPen( Qt::blue, 4 ),
          curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                       QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );

    QPolygonF points;
    points << QPointF( 10.0, 4.4 )
           << QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 )
           << QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 )
           << QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 )
           << QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 )
           << QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 );
    curve->setSamples( points );
    curve->attach( this );
}
Exemplo n.º 3
0
void PlotWidget::AddPlotData(QString title, float* plotData, int size, bool showMarkers)
{	
	if(_curves.contains(title))
		return;
	QwtPointSeriesData *points = CreatePointSeriesFromArray(plotData, size);
	QwtPlotCurve *curve = new QwtPlotCurve(title);	
	curve->setData(points);
	//Устанавливается цвет
	curve->setPen(QColor(255,0,0), 2.0);
	if(size < 1000)
		curve->setRenderHint(QwtPlotItem::RenderAntialiased);
	//Marker
	if(_showMarkers || showMarkers)
	{
		/*QwtSymbol *symbol1 = new QwtSymbol();
		symbol1->setStyle(QwtSymbol::Ellipse);
		symbol1->setPen(QColor(Qt::black));	
		symbol1->setSize(4);*/
		curve->setSymbol(GetDefaultMarker());
	}
	//Кривая добавляется на график
	curve->attach(_plot);
	//Добавляется в список кривых
	_curves.insert(title, curve);
	//Область рисования перерисовывается, если включен автоматический режим
	CheckNReplot();
}
Exemplo n.º 4
0
void Plot::add() {
    Q_ASSERT(plotWidget && x && y && x->size()==y->size());
    setIntervals();
    for (int i = 0; i < intervals.size(); ++i) {
        QwtPlotCurve *curve = new QwtPlotCurve(yLegend);
        curve->setItemAttribute(QwtPlotItem::Legend, showLegend && i==0);
        plotWidget->addCurve(curve);

        if (type == Trace::Symbols) {
            curve->setStyle(QwtPlotCurve::NoCurve);
        }
        if (type == Trace::Symbols || type == Trace::Both) {
            Q_ASSERT(symbol);
            curve->setSymbol(symbol);
        }
        if (type == Trace::Line || type == Trace::Both) {
            curve->setPen(pen);
        }
        Interval iv = intervals[i];
        int numPoints = iv.second - iv.first + 1;
        if (numPoints <=0 )
        Q_ASSERT(numPoints > 0);
        curve->setSamples(x->data() + iv.first, y->data() + iv.first, numPoints);
    }

}
Exemplo n.º 5
0
void HistoricPlot::addCurve(quint32 idVariable, std::vector<VariablePoint> data)
{
    m_zoomer->setZoomBase(true);

    QwtPlotCurve *c = new QwtPlotCurve(QString("id : %1").arg(idVariable));
    c->setPen( QColor(qrand() % 255,qrand() % 255,qrand() % 255), 2 ),
    c->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 5, 5 ) );
    c->setSymbol( symbol );

    QVector<VariablePoint> d2 = QVector<VariablePoint>::fromStdVector(data);
    QVector<QPointF> cleanData;

    for (int i = 0; i < data.size(); ++i) {
        VariablePoint vp = d2.at(i);
        qDebug() << QString("ID: %1, VALUE: %2").arg(vp.idVariable()).arg(vp.value().toDouble());

        if (vp.value().type() == QVariant::Double)
            cleanData.append(QPointF(QwtDate::toDouble(QDateTime::fromMSecsSinceEpoch(vp.timeStamp())),
                                 vp.value().toDouble()));
        else
            cleanData.append(QPointF(QwtDate::toDouble(QDateTime::fromMSecsSinceEpoch(vp.timeStamp())),
                                 (double)vp.value().toLongLong()));
    }

    c->setSamples(cleanData);
    c->attach(this);
}
Exemplo n.º 6
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.º 7
0
void Plot::insertCurve(Qt::Orientation o,
    const QColor &c, double base)
{
    QwtPlotCurve *curve = new QwtPlotCurve();

    curve->setPen(c);
    curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
        Qt::gray, c, QSize(8, 8)));

    double x[10];
    double y[sizeof(x) / sizeof(x[0])];

    for ( uint i = 0; i < sizeof(x) / sizeof(x[0]); i++ )
    {
        double v = 5.0 + i * 10.0;
        if ( o == Qt::Horizontal )
        {
            x[i] = v;
            y[i] = base;
        }
        else
        {
            x[i] = base;
            y[i] = v;
        }
    }
        
    curve->setSamples(x, y, sizeof(x) / sizeof(x[0]));
    curve->attach(this);
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
	/*const int L = 10; 
	fftw_complex *in; 
	fftw_complex *out;
	gsl_sf_bessel_k0_scaled(0.684684);
	fftw_plan p;

	in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L);
	out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L);
	p = fftw_plan_dft_1d(L, in, out,FFTW_FORWARD,FFTW_MEASURE); 

	fftw_execute(p);
	fftw_destroy_plan(p);
	fftw_free(in);
	fftw_free(out);
	 
	QApplication a(argc, argv);
	Ekg w;
	w.show();
	qDebug() << "sdfsdfsd";
	std::cout << "ALKO PROJEKT CPP CHLOSTA!";			
	
	return a.exec();*/

	    QApplication a( argc, argv );
 
    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );
    plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    plot.insertLegend( new QwtLegend() );
 
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( &plot );
 
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Some Points" );
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
 
    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
        QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );
 
    QPolygonF points;
    points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
        << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
        << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    curve->setSamples( points );
 
    curve->attach( &plot );
  
    plot.resize( 600, 400 );
    plot.show(); 
  
    return a.exec();
}
Exemplo n.º 9
0
void IncrementalPlot::startNewCurve()
{
  if (!curves.empty())
    curCurveOffset += curves.back()->dataSize();
  QwtPlotCurve *newCurve = new QwtPlotCurve("Line");
  newCurve->setStyle(QwtPlotCurve::Lines);
  newCurve->setPaintAttribute(QwtPlotCurve::PaintFiltered);
  newCurve->setPen(QColor(Qt::white));
  const QColor &c = Qt::white;
  newCurve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, QBrush(c), QPen(c), QSize(6, 6)));

  curves.push_back(newCurve);
  newCurve->attach(this);
}
Exemplo n.º 10
0
void VectorPlot::addLinePlot(const VectorQwtAdapter &adapter) {
	setupPlot(adapter.boundingRect());
	QwtPlotCurve *curve = new QwtPlotCurve();

    QwtSymbol sym;
    sym.setStyle(QwtSymbol::Cross);
    sym.setPen(QColor(Qt::black));
    sym.setSize(2);
	curve->setSymbol(sym);
	curve->setPen(QColor(Qt::darkGreen));

	curve->setData(adapter);
	curve->attach(plot);
}
Exemplo n.º 11
0
void PlotPropertiesGUI::symbolSizeValue(int value)
{
    QwtPlotCurve *plotCurve = internalCurves.value(currentCurve)->plotCurve;

    // Changes only the symbol width
    QwtSymbol symbol = plotCurve->symbol();
    symbol.setStyle((QwtSymbol::Style) (ui->curveSymbolCombo->currentIndex() - 1)); // starts in -1 

    if (symbol.brush().style() != Qt::NoBrush)
        symbol.setBrush(QBrush(plotCurve->pen().color()));

    symbol.setSize(value);
    plotCurve->setSymbol(symbol);
    plotter->replot();
}
Exemplo n.º 12
0
void Plot::insertCurve( const QString &title,
                        const QColor &color, const QPolygonF &points )
{
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( title );
    curve->setPen( color, 2 ),
          curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                       QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );

    curve->setSamples( points );

    curve->attach( this );
}
Exemplo n.º 13
0
void PlotPropertiesGUI::selectedSymbol(int value)
{
    QwtPlotCurve *plotCurve = internalCurves.value(currentCurve)->plotCurve;

    QwtSymbol symbol, oldSym = plotCurve->symbol();
    symbol.setStyle((QwtSymbol::Style) (value - 1)); // starts in -1); 
    symbol.setSize(ui->symbolSizeSpinBox->value());
    symbol.setPen(oldSym.pen());

    if (symbol.brush().style() != Qt::NoBrush)
	    // symbol.setBrush(QBrush(oldSym.pen().color()));
        symbol.setBrush(QBrush(plotCurve->pen().color()));

    plotCurve->setSymbol(symbol);
    plotter->replot();
}
Exemplo n.º 14
0
void PlotPropertiesGUI::consistCurveTab(const QString &name)
{
    QwtPlotCurve *plotCurve = internalCurves.value(name)->plotCurve;

    QwtSymbol symbol = plotCurve->symbol();
    ui->symbolSizeSpinBox->setValue( symbol.size().width() );
    ui->curveSymbolCombo->setCurrentIndex( (int)symbol.style() + 1); // Starts in -1
    // Fixes bug built when used 'plotCurve->symbol()'
    plotCurve->setSymbol(symbol);

    ui->curveWidthSpinBox->setValue( plotCurve->pen().width() );
    ui->curveStyleCombo->setCurrentIndex( (int)plotCurve->style() );
    ui->lineStylecombo->setCurrentIndex( (int)plotCurve->pen().style() );

    ui->curveColorButton->setStyleSheet(QString("  border-radius: 4px; "
            "border: 1px solid rgb(0, 0, 0); background-color: %1")
            .arg(plotCurve->pen().color().name()));
}
Exemplo n.º 15
0
void PlotWidget::AddPlotData(QString title, float plotData)
{
	if(!_curves.contains(title))
	{
		//QwtPointSeriesData *points = CreatePointSeriesFromArray(&plotData, 1);
		QwtPlotCurve *curve = new QwtPlotCurve(title);
		curve->setPen(QColor(255,0,0), 2.0);
		
		if(_showMarkers)
		{
			/*QwtSymbol *symbol1 = new QwtSymbol();
			symbol1->setStyle(QwtSymbol::Ellipse);
			symbol1->setPen(QColor(Qt::black));	
			symbol1->setSize(4);*/
			curve->setSymbol(GetDefaultMarker());
		}
		QVector<QPointF> nData;
		QPointF p(0, plotData);		
		nData.append(p);
		curve->setSamples(nData);

		curve->attach(_plot);		
		_curves.insert(title, curve);
	}
	else
	{		
		QwtPlotCurve *curve =_curves.value(title);
		QwtSeriesData<QPointF>* data = curve->data();
		int s = data->size();
		QPointF p(s, plotData);
		//QVector<QPointF> nData(s+1);
		QVector<QPointF> nData;
		for(int i = 0; i < s; i++)
		{			
			QPointF p(data->sample(i).x(), data->sample(i).y());
			nData.append(p);
		}
		nData.append(p);
		curve->setSamples(nData);
	}
	
	CheckNReplot();	
}
Exemplo n.º 16
0
void QcepPlot::onLegendChecked(const QVariant &itemInfo, bool on, int index)
{
//  if (g_Application) {
//    g_Application->printMessage(tr("QxrdPlot::onLegendChecked(%1,%2,%3)").arg(itemInfo.toString()).arg(on).arg(index));
//  }

  QwtPlotItem *item = infoToItem(itemInfo);

  if (item) {
    QwtPlotCurve *pc = dynamic_cast<QwtPlotCurve*>(item);

    if (pc) {
      QPen pen = pc->pen();
      const QwtSymbol *oldsym = pc->symbol();
      QwtSymbol *sym = NULL;

      if (oldsym) {
       sym = new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
      }

      if (on) {
        pen.setWidth(3);
        if (sym) {
          sym->setSize(9,9);
        }
      } else {
        pen.setWidth(1);
        if (sym) {
          sym->setSize(5,5);
        }
      }
      pc->setPen(pen);
      if (sym) {
        pc->setSymbol(sym);
      }
    }

    replot();
  }
}
Exemplo n.º 17
0
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const
{
    PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            cache.gridColors[0] = pen.color();
            pen.setColor(color(pen.color(), MajorGrid));
            grid->setMajPen(pen);

            pen = grid->minPen();
            cache.gridColors[1] = pen.color();
            pen.setColor(color(pen.color(), MinorGrid));
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            QPen pen = symbol.pen();
            cache.curveSymbolPenColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), CurveSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.curveSymbolBrushColors.insert(c, brush.color());
            brush.setColor(color(brush.color(), CurveSymbol));
            symbol.setBrush(brush);

            c->setSymbol(symbol);

            pen = c->pen();
            cache.curveColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), Curve));
            c->setPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            QwtText label = m->label();
            cache.markerFonts.insert(m, label.font());
            label.setFont(font(label.font(), Marker));
            cache.markerLabelColors.insert(m, label.color());
            label.setColor(color(label.color(), Marker));
            m->setLabel(label);
            
            QPen pen = m->linePen();
            cache.markerLineColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), Marker));
            m->setLinePen(pen);

            QwtSymbol symbol = m->symbol();

            pen = symbol.pen();
            cache.markerSymbolPenColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), MarkerSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.markerSymbolBrushColors.insert(m, brush.color());
            brush.setColor(color(brush.color(), MarkerSymbol));
            symbol.setBrush(brush);

            m->setSymbol(symbol);

            break;
        }
        default:    
            break;
    }
}
Exemplo n.º 18
0
int main(int argc, char *argv[])
{

    //  QGuiApplication a(argc, argv);
    QApplication a(argc, argv);
    QwtPlot *plot = new QwtPlot();
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setBorderRadius(10);

    plot->setCanvas(canvas);
    plot->setCanvasBackground(QColor("LIGHTGRAY"));

    plot->enableAxis(QwtPlot::yRight);
    plot->enableAxis(QwtPlot::xTop);
    plot->setAxisTitle(QwtPlot::xBottom, "Xline");
    plot->setAxisTitle(QwtPlot::xTop, "Xline");
    plot->setAxisTitle(QwtPlot::yLeft, "Inline");
    plot->setAxisTitle(QwtPlot::yRight, "Inline");
    //    float minx = srv->getStations().first().x();
    //    float maxx = srv->getStations().last().x();
        plot->setAxisScale( QwtPlot::xBottom,3500,300);
    //    plot->setAxisScale( QwtPlot::xTop,minx,maxx );
    //    QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft );
    //    sd->setMinimumExtent( sd->extent( axisWidget( QwtPlot::yLeft )->font() ) );
    plot->plotLayout()->setAlignCanvasToScales( true );
    QFileDialog custDialog;
    QStringList names = custDialog.getOpenFileNames(NULL, ("Open Files..."),QString(), ("UKOOA Files (*.p190 *.p90);;All Files (*)"));

    // handle if the dialog was "Cancelled"
    if(names.isEmpty())
    {
        return 0;
    }
    qSort(names.begin(), names.end());
    QVector <QwtPlotCurve *> curves;
    foreach (QString name, names)
    {


        QwtPlotCurve *vCurve = new QwtPlotCurve;
       if(name.contains(QString( "NS1763")) || name.contains(QString("NS2029")))
        {
           QColor c = Qt::red;
            vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::red,c , QSize( 2, 2 ) ) );
        }
        else
        {
           QColor c = Qt::green;
            vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::green,c , QSize( 2, 2 ) ) );
        }
        vCurve->setStyle( QwtPlotCurve::NoCurve );
        vCurve->setPen( Qt::gray );

        cout << name.toStdString() << endl;
        QVector<QPointF> curveData;

        //  m_nameLineLable->setText(m_names.at(0));
        QFile *ukFile = new QFile(QString(name));

        bool rt = ukFile->open(QIODevice::ReadOnly);

        cout << "return " << rt << endl;

        qint64 icount = 0;

        qint64 fileSize = ukFile->size();
        char *data = new char[fileSize];
        ukFile->read(data,fileSize);
        QString sData = data;
        QString shot = "SNS";
        while (true)
        {
            ukFile->seek(icount);
            ukFile->read(data,fileSize);
            sData = data;;
            if(icount>=fileSize)
            {
                break;
            }
            auto sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            QString cr = sData.mid(sPos,19);
            if(cr.contains("\n"))
            {
                sPos +=2;
            }
            // auto shotNo  = sData.mid(sPos+20,sPos+5);
            QString shotNo = sData.mid(sPos+19,6);
            int shotNos;

            if(shotNo.contains("\n") || shotNo.contains("\r"))
            {
                shotNo = sData.mid(sPos+19,8);
                int shift1 = shotNo.indexOf("\r");
                int shift = shotNo.indexOf("\n");
                //    cout << shift1 << " " << shift << endl;
                QString tmp = shotNo.mid(0,shift1);
                tmp.append(shotNo.mid(shift+1,3));
                shotNos = tmp.toInt();
            }
            else
            {
                shotNos = sData.mid(sPos+19,6).toInt();
            }

            float shotYs;
            sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            cr = sData.mid(sPos,55);
            if(cr.contains("\n"))
            {
                //       cout << " cr " << sPos << endl;
                sPos +=2;
            }

            QString shotY = sData.mid(sPos+55,10);
            //   cout << "shotx " << shotX.toStdString() << endl;
            if(shotY.contains("\n") || shotY.contains("\r"))
            {
                shotY = sData.mid(sPos+55,12);
                int shift1 = shotY.indexOf("\r");
                int shift = shotY.indexOf("\n");
                //           cout << shift1 << " " << shift << endl;
                QString tmp = shotY.mid(0,shift1);
                tmp.append(shotY.mid(shift+1,12));
                shotYs = tmp.toFloat();
            }
            else
            {
                shotYs = shotY.toFloat();
            }

            float shotXs;
            sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            cr = sData.mid(sPos,46);
            if(cr.contains("\n"))
            {
                //       cout << " cr " << sPos << endl;
                sPos +=2;
            }

            QString shotX = sData.mid(sPos+46,10);
            //   cout << "shotx " << shotX.toStdString() << endl;
            if(shotX.contains("\n") || shotX.contains("\r"))
            {
                shotX = sData.mid(sPos+46,12);
                int shift1 = shotX.indexOf("\r");
                int shift = shotX.indexOf("\n");
                //           cout << shift1 << " " << shift << endl;
                QString tmp = shotX.mid(0,shift1);
                tmp.append(shotX.mid(shift+1,12));
                shotXs = tmp.toFloat();
            }
            else
            {
                shotXs = shotX.toFloat();
            }
            icount +=sPos+1;
            //     cout << shotNos << endl;
            float shotXt = shotXs - 757551.46;


            float shotYt = shotYs - 978769.0;
            float shotYr = shotYt * cosf(13.661f * M_PI/180.0f) + shotXt * sinf(13.661f * M_PI/180.0f);
            int shotYy = 981 + shotYr/25.0;
            float shotXr = shotXt * cosf(13.661f * M_PI/180.0f) - shotYt * sinf(13.661f * M_PI/180.0f);
            int shotXx = 2570 - shotXr/25.0;
//            if(shotXx>0 && shotYy>0)
//            {
                QPointF shotPoint(shotXx,shotYy);
                curveData.append(shotPoint);
            //    cout << " shot " << shotNos << " " << shotXs  << " " << shotYs << " "  << shotXx << " " << shotYy << endl;
 //           }



        }
        vCurve->setSamples(curveData);
        curves.append(vCurve);
        ukFile->close();
    }
Exemplo n.º 19
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuPvtPlotWidget::plotCurves(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector<RigFlowDiagSolverInterface::PvtCurve>& curveArr, double pressure, double pointMarkerYValue, QString pointMarkerLabel, QString plotTitle, QString yAxisTitle)
{
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotCurve);
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotMarker);
    m_qwtCurveArr.clear();
    m_pvtCurveArr.clear();
    m_trackerPlotMarker = nullptr;


    // Construct an auxiliary curve that connects the first point in all the input curves as a visual aid
    // This should only be shown when the phase being plotted is oil
    // Will not be added to our array of qwt curves since we do not expect the user to interact with it
    {
        std::vector<double> xVals;
        std::vector<double> yVals;
        for (size_t i = 0; i < curveArr.size(); i++)
        {
            const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
            if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL && curve.pressureVals.size() > 0 && curve.yVals.size() > 0)
            {
                xVals.push_back(curve.pressureVals[0]);
                yVals.push_back(curve.yVals[0]);
            }
        }

        if (xVals.size() > 1)
        {
            QwtPlotCurve* qwtCurve = new QwtPlotCurve();
            qwtCurve->setSamples(xVals.data(), yVals.data(), static_cast<int>(xVals.size()));

            qwtCurve->setStyle(QwtPlotCurve::Lines);
            qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

            QColor curveClr = Qt::darkGreen;
            const QPen curvePen(curveClr);
            qwtCurve->setPen(curvePen);

            qwtCurve->attach(m_qwtPlot);
        }
    }


    // Add the primary curves
    for (size_t i = 0; i < curveArr.size(); i++)
    {
        const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
        QwtPlotCurve* qwtCurve = new QwtPlotCurve();

        CVF_ASSERT(curve.pressureVals.size() == curve.yVals.size());
        qwtCurve->setSamples(curve.pressureVals.data(), curve.yVals.data(), static_cast<int>(curve.pressureVals.size()));

        qwtCurve->setStyle(QwtPlotCurve::Lines);

        QColor curveClr = Qt::magenta;
        if      (curve.phase == RigFlowDiagSolverInterface::PvtCurve::GAS)   curveClr = QColor(Qt::red);
        else if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL)   curveClr = QColor(Qt::green);
        const QPen curvePen(curveClr);
        qwtCurve->setPen(curvePen);

        qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

        QwtSymbol* curveSymbol = new QwtSymbol(QwtSymbol::Ellipse);
        curveSymbol->setSize(6, 6);
        curveSymbol->setPen(curvePen);
        curveSymbol->setBrush(Qt::NoBrush);
        qwtCurve->setSymbol(curveSymbol);

        qwtCurve->attach(m_qwtPlot);

        m_qwtCurveArr.push_back(qwtCurve);
    }

    m_pvtCurveArr = curveArr;
    CVF_ASSERT(m_pvtCurveArr.size() == m_qwtCurveArr.size());


    // Add vertical marker line to indicate cell pressure
    if (pressure != HUGE_VAL)
    {
        QwtPlotMarker* lineMarker = new QwtPlotMarker;
        lineMarker->setXValue(pressure);
        lineMarker->setLineStyle(QwtPlotMarker::VLine);
        lineMarker->setLinePen(QPen(QColor(128, 128, 255), 1, Qt::DashLine));
        lineMarker->setLabel(QString("PRESSURE"));
        lineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        lineMarker->setLabelOrientation(Qt::Vertical);
        lineMarker->attach(m_qwtPlot);
    }

    // Then point marker
    if (pressure != HUGE_VAL && pointMarkerYValue != HUGE_VAL)
    {
        QwtPlotMarker* pointMarker = new QwtPlotMarker;
        pointMarker->setValue(pressure, pointMarkerYValue);

        QColor markerClr(128, 0, 255);
        QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Ellipse);
        symbol->setSize(13, 13);
        symbol->setPen(QPen(markerClr, 2));
        symbol->setBrush(Qt::NoBrush);
        pointMarker->setSymbol(symbol);

        if (!pointMarkerLabel.isEmpty())
        {
            QwtText text(pointMarkerLabel);
            text.setRenderFlags(Qt::AlignLeft);
            text.setColor(markerClr);
            pointMarker->setLabel(text);
            pointMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        }

        pointMarker->attach(m_qwtPlot);
    }

    m_qwtPlot->setTitle(plotTitle);

    m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QString("Pressure [%1]").arg(RiaEclipseUnitTools::unitStringPressure(unitSystem)));
    m_qwtPlot->setAxisTitle(QwtPlot::yLeft, yAxisTitle);

    updateTrackerPlotMarkerAndLabelFromPicker();

    m_qwtPlot->replot();
}
Exemplo n.º 20
0
int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );

    plot.setAxisScale( QwtPlot::xBottom, -1.0, 6.0 );

    QwtLegend *legend = new QwtLegend();
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    plot.insertLegend( legend );

    for ( int i = 0; i < 4; i++ )
    {
        QwtPlotCurve *curve = new QwtPlotCurve();
        curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
        curve->setPen( Qt::blue );

        QBrush brush;
        QwtSymbol::Style style = QwtSymbol::NoSymbol;
        QString title;
        if ( i == 0 )
        {
            brush = Qt::magenta;
            style = QwtSymbol::Path;
            title = "Path";
        }
        else if ( i == 2 )
        {
            brush = Qt::red;
            style = QwtSymbol::Graphic;
            title = "Graphic";
        }
        else if ( i == 1 )
        {
            brush = Qt::yellow;
            style = QwtSymbol::SvgDocument;
            title = "Svg";
        }
        else if ( i == 3 )
        {
            brush = Qt::cyan;
            style = QwtSymbol::Pixmap;
            title = "Pixmap";
        }

        MySymbol *symbol = new MySymbol( style, brush );

        curve->setSymbol( symbol );
        curve->setTitle( title );
        curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol, true );
        curve->setLegendIconSize( QSize( 15, 18 ) );

        QPolygonF points;
        points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
            << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
            << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );

        points.translate( 0.0, i * 2.0 );

        curve->setSamples( points );
        curve->attach( &plot );
    }

    plot.resize( 600, 400 );
    plot.show();

    return a.exec();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void StatsGenMDFWidget::updateMDFPlot(QVector<float>& odf)
{
  int err = 0;
  int size = 100000;

  // These are the input vectors
  QVector<float> angles;
  QVector<float> axes;
  QVector<float> weights;

  angles = m_MDFTableModel->getData(SGMDFTableModel::Angle);
  weights = m_MDFTableModel->getData(SGMDFTableModel::Weight);
  axes = m_MDFTableModel->getData(SGMDFTableModel::Axis);

  // These are the output vectors
  QVector<float> x;
  QVector<float> y;
  if ( Ebsd::CrystalStructure::Cubic_High == m_CrystalStructure )
  {
    // Allocate a new vector to hold the mdf data
    QVector<float> mdf(CubicOps::k_MdfSize);
    // Calculate the MDF Data using the ODF data and the rows from the MDF Table model
    Texture::CalculateMDFData<float, CubicOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size()));
    // Now generate the actual XY point data that gets plotted.
    int npoints = 13;
    x.resize(npoints);
    y.resize(npoints);
    err = StatsGen::GenCubicMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size);
    if (err < 0)
    {
      return;
    }
  }
  else if ( Ebsd::CrystalStructure::Hexagonal_High == m_CrystalStructure )
  {
    // Allocate a new vector to hold the mdf data
    QVector<float> mdf(HexagonalOps::k_MdfSize);
    // Calculate the MDF Data using the ODF data and the rows from the MDF Table model
    Texture::CalculateMDFData<float, HexagonalOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size()));
    // Now generate the actual XY point data that gets plotted.
    int npoints = 20;
    x.resize(npoints);
    y.resize(npoints);
    err = StatsGen::GenHexMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size);
    if (err < 0) { return; }
  }

  QwtArray<double> xD(static_cast<int>(x.size()));
  QwtArray<double> yD(static_cast<int>(x.size()));
  for (qint32 i = 0; i < x.size(); ++i)
  {
    xD[i] = static_cast<double>(x.at(i));
    yD[i] = static_cast<double>(y.at(i));
  }


  // This will actually plot the XY data in the Qwt plot widget
  QwtPlotCurve* curve = m_PlotCurve;
#if QWT_VERSION >= 0x060000
  curve->setSamples(xD, yD);
#else
  curve->setData(xD, yD);
#endif
  QColor color = QColor("DodgerBlue");
  curve->setPen(color, 2);
  curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  curve->setStyle(QwtPlotCurve::Lines);
  QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
      QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
  curve->setSymbol( symbol );
  curve->attach(m_MDFPlot);
  m_MDFPlot->replot();
}
/*! 
   Reset color and fonts of a plot
   \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::reset(QwtPlot *plot) const
{
    if ( d_cache == 0 )
        return;

    QFont *font;
    QColor *color;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        palette.setColor(
            QPalette::Active, QColorGroup::Foreground, d_cache->titleColor);
        plot->d_lblTitle->setPalette(palette);

        plot->d_lblTitle->setFont(d_cache->titleFont);
    }

    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            font = d_cache->legendFonts.find(key);
            if ( font )
                w->setFont(*font);

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                color = d_cache->curveSymbolPenColors.find(key);
                if ( color )
                {
                    QPen pen = symbol.pen();
                    pen.setColor(*color);
                    symbol.setPen(pen);
                }

                color = d_cache->curveSymbolBrushColors.find(key);
                if ( color )
                {
                    QBrush brush = symbol.brush();
                    brush.setColor(*color);
                    symbol.setBrush(brush);
                }
                btn->setSymbol(symbol);

                color = d_cache->curveColors.find(key);
                if ( color )
                {
                    QPen pen = btn->curvePen();
                    pen.setColor(*color);
                    btn->setCurvePen(pen);
                }
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             d_cache->scaleColor[axis]);
            scale->setPalette(palette);
            scale->setFont(d_cache->scaleFont[axis]);

            scale->setTitleColor(d_cache->scaleTitleColor[axis]);
            scale->setTitleFont(d_cache->scaleTitleFont[axis]);

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    plot->setBackgroundColor(d_cache->widgetBackground);
    plot->setCanvasBackground(d_cache->canvasBackground);

    QPen pen = plot->d_grid->majPen();
    pen.setColor(d_cache->gridColors[0]);
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    pen.setColor(d_cache->gridColors[1]);
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        color = d_cache->curveSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->curveSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }
        c->setSymbol(symbol);

        color = d_cache->curveColors.find(key);
        if ( color )
        {
            QPen pen = c->pen();
            pen.setColor(*color);
            c->setPen(pen);
        }
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        font = d_cache->markerFonts.find(key);
        if ( font )
            m->setFont(*font);

        color = d_cache->markerLabelColors.find(key);
        if ( color )
        {
            QPen pen = m->labelPen();
            pen.setColor(*color);
            m->setLabelPen(pen);
        }

        color = d_cache->markerLineColors.find(key);
        if ( color )
        {
            QPen pen = m->linePen();
            pen.setColor(*color);
            m->setLinePen(pen);
        }
        
        QwtSymbol symbol = m->symbol();

        color = d_cache->markerSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->markerSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }

        m->setSymbol(symbol);

    }

    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;
    delete that->d_cache;
    that->d_cache = 0;
}
/*! 
  Change color and fonts of a plot
  \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;

    delete that->d_cache;
    that->d_cache = new QwtPlotPrintFilterCache;

    QwtPlotPrintFilterCache &cache = *that->d_cache;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        cache.titleColor = palette.color(
            QPalette::Active, QColorGroup::Foreground);
        palette.setColor(QPalette::Active, QColorGroup::Foreground,
                         color(cache.titleColor, Title));
        plot->d_lblTitle->setPalette(palette);

        cache.titleFont = plot->d_lblTitle->font();
        plot->d_lblTitle->setFont(font(cache.titleFont, Title));
    }
    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            cache.legendFonts.insert(it.currentKey(), new QFont(w->font()));
            w->setFont(font(w->font(), Legend, key));

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                QPen pen = symbol.pen();
                QBrush brush = symbol.brush();

                pen.setColor(color(pen.color(), CurveSymbol, key));
                brush.setColor(color(brush.color(), CurveSymbol, key));

                symbol.setPen(pen);
                symbol.setBrush(brush);
                btn->setSymbol(symbol);

                pen = btn->curvePen();
                pen.setColor(color(pen.color(), Curve, key));
                btn->setCurvePen(pen);
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            cache.scaleColor[axis] = scale->palette().color(
                QPalette::Active, QColorGroup::Foreground);
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             color(cache.scaleColor[axis], AxisScale, axis));
            scale->setPalette(palette);

            cache.scaleFont[axis] = scale->font();
            scale->setFont(font(cache.scaleFont[axis], AxisScale, axis));

            cache.scaleTitleColor[axis] = scale->titleColor();
            scale->setTitleColor(
                color(cache.scaleTitleColor[axis], AxisTitle, axis));

            cache.scaleTitleFont[axis] = scale->titleFont();
            scale->setTitleFont(
                font(cache.scaleTitleFont[axis], AxisTitle, axis));

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    cache.widgetBackground = plot->backgroundColor();
    plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground));

    cache.canvasBackground = plot->canvasBackground();
    plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));

    QPen pen = plot->d_grid->majPen();
    cache.gridColors[0] = pen.color();
    pen.setColor(color(pen.color(), MajorGrid));
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    cache.gridColors[1] = pen.color();
    pen.setColor(color(pen.color(), MinorGrid));
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        QPen pen = symbol.pen();
        cache.curveSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), CurveSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.curveSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), CurveSymbol, key));
        symbol.setBrush(brush);

        c->setSymbol(symbol);

        pen = c->pen();
        cache.curveColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Curve, key));
        c->setPen(pen);
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        cache.markerFonts.insert(key, new QFont(m->font()));
        m->setFont(font(m->font(), Marker, key));

        QPen pen = m->labelPen();
        cache.markerLabelColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLabelPen(pen);
        
        pen = m->linePen();
        cache.markerLineColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLinePen(pen);

        QwtSymbol symbol = m->symbol();

        pen = symbol.pen();
        cache.markerSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), MarkerSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.markerSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), MarkerSymbol, key));
        symbol.setBrush(brush);

        m->setSymbol(symbol);
    }
}
Exemplo n.º 24
0
bool CurvesModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
    SolvWidget* solv =  solvers->at(index.row());
    QwtPlotCurve* curve = solv->curve;
    QPen pen = curve->pen(); /// This makes a copy of Pen
    QColor col;
    Qt::PenStyle ps;
    QwtSymbol *symbol;
    QwtSymbol::Style symbolStyle;
    QBrush brush;
    QSize symSize;

    bool ok;
    double lw;
    int ss;
    if( role != Qt::EditRole ) return false;
    switch(index.column()) {
    case 0:// title
        if(value.toString().size() > 1) {
            QString newTitle = value.toString();
            if( newTitle != solv->getTitle() ) {
                solv->setTitle(value.toString());
                emit newdata();
                return true;
            }
        }
        return false;
    case 1:// line color
        col = value.value<QColor>();
        if(pen.color() != col ) {
            pen.setColor(col);
            curve->setPen(pen);
            solv->setColor(col);
            emit newdata();
            return true;
        }
        return false;
    case 2:// line style
        ps = Qt::PenStyle(value.toInt());
        if( ps != pen.style()) {
            pen.setStyle(ps);
            curve->setPen(pen);
            emit newdata();
            return true;
        }
        return false;
    case 3:// line width
        lw = value.toDouble(&ok);
        if(ok && (lw != curve->pen().widthF())) {
            pen.setWidthF(lw);
            curve->setPen(pen);
            emit newdata();
            return true;
        }
        return false;
    case 4:// symbol style
        symbolStyle = QwtSymbol::Style(value.toInt());
        if(curve->symbol() == NULL) {
            if(symbolStyle == QwtSymbol::NoSymbol ) return false;
	    pen.setStyle(Qt::SolidLine);
            symbol = new QwtSymbol(symbolStyle,QBrush(),pen,QSize(7,7));//Qt::transparent
        } else {
            if(curve->symbol()->style() == symbolStyle) return false;
            if(symbolStyle == QwtSymbol::NoSymbol) {
                symbol = NULL;
            } else {
                symbol = new QwtSymbol(symbolStyle,curve->symbol()->brush(),curve->symbol()->pen(),curve->symbol()->size());
            }
        }
        curve->setSymbol(symbol);
        emit newdata();
        return true;
    case 5:// symbol color
        col = value.value<QColor>();
        if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol ) return false;
        if(curve->symbol()->pen().color() == col ) return false;
        pen = curve->symbol()->pen();
        pen.setColor(col);
        symbol = new QwtSymbol(curve->symbol()->style(),curve->symbol()->brush(),pen,curve->symbol()->size());
        curve->setSymbol(symbol);
        emit newdata();
        return true;
    case 6: // symbol size
        ss = value.toInt();
	if(ss < 1) return false;
        if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol ) return false;
        if(curve->symbol()->size().width() == ss ) return false;
        symbol = new QwtSymbol(curve->symbol()->style(),curve->symbol()->brush(),curve->symbol()->pen(),QSize(ss,ss));
        curve->setSymbol(symbol);
        emit newdata();
        return false;
    }
    return QAbstractItemModel::setData(index, value, role);
}
Exemplo n.º 25
0
void ScatterPlot::setData (ScatterSettings *settings)
{
    // get application settings
    cranklength = appsettings->value(this, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0;

    // if there are no settings or incomplete settings
    // create a null data plot
    if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL ||
        settings->x == 0 || settings->y == 0 ) {
        return;
    }


    // if its not setup or no settings exist default to 175mm cranks
    if (cranklength == 0.0) cranklength = 0.175;

    //
    // Create Main Plot dataset - used to frame intervals
    //
    int points=0;

    x.clear();
    y.clear();
    x.resize(settings->ride->ride()->dataPoints().count());
    y.resize(settings->ride->ride()->dataPoints().count());

    double maxY = maxX = -65535;
    double minY = minX = 65535;

    foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

        double xv = x[points] = pointType(point, settings->x, context->athlete->useMetricUnits, cranklength);
        double yv = y[points] = pointType(point, settings->y, context->athlete->useMetricUnits, cranklength);

        // skip zeroes?
        if (!(settings->ignore && (x[points] == 0 || y[points] == 0))) {
            points++;
            if (yv > maxY) maxY = yv;
            if (yv < minY) minY = yv;
            if (xv > maxX) maxX = xv;
            if (xv < minX) minX = xv;
        }
    }

    QwtSymbol sym;
    sym.setStyle(QwtSymbol::Ellipse);
    sym.setSize(6);
    sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND)));
    sym.setBrush(QBrush(Qt::NoBrush));
    QPen p;
    p.setColor(GColor(CPLOTSYMBOL));
    sym.setPen(p);

    // wipe away existing
	if (all) {
        all->detach();
	    delete all;
    }

    // setup the framing curve
    if (settings->frame) {
        all = new QwtPlotCurve();
        all->setSymbol(new QwtSymbol(sym));
        all->setStyle(QwtPlotCurve::Dots);
        all->setRenderHint(QwtPlotItem::RenderAntialiased);
	    all->setData(x.constData(), y.constData(), points);
        all->attach(this);
    } else {
        all = NULL;
    }

    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);

    if (grid) {
        grid->detach();
        delete grid;
    }

    if (settings->gridlines) {
        grid = new QwtPlotGrid();
        grid->setPen(gridPen);
        grid->enableX(true);
        grid->enableY(true);
        grid->attach(this);
    } else {
        grid = NULL;
    }

    setAxisTitle(yLeft, describeType(settings->y, true, useMetricUnits));
    setAxisTitle(xBottom, describeType(settings->x, true, useMetricUnits));

    // truncate PfPv values to make easier to read
    if (settings->y == MODEL_AEPF) setAxisScale(yLeft, 0, 600);
    else setAxisScale(yLeft, minY, maxY);
    if (settings->x == MODEL_CPV) setAxisScale(xBottom, 0, 3);
    else setAxisScale(xBottom, minX, maxX);

    //
    // Create Interval Plot dataset - used to frame intervals
    //

    // clear out any interval curves which are presently defined
    if (intervalCurves.size()) {
       QListIterator<QwtPlotCurve *> i(intervalCurves);
       while (i.hasNext()) {
           QwtPlotCurve *curve = i.next();
           curve->detach();
           delete curve;
       }
    }
    intervalCurves.clear();

    // which ones are highlighted then?
    QVector<int> intervals;
    QMap<int,int> displaySequence;

    for (int child=0; child<context->athlete->allIntervalItems()->childCount(); child++) {
        IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(child));
        if ((current != NULL) && current->isSelected()) {
            intervals.append(child);
            displaySequence.insert(current->displaySequence, intervals.count()-1);
        }
    }

    if (intervals.count() > 0) {

        // interval data in here
        QVector<QVector<double> > xvals(intervals.count()); // array of curve x arrays
        QVector<QVector<double> > yvals(intervals.count()); // array of curve x arrays
        QVector<int> points(intervals.count());             // points in eac curve

        // extract interval data
        foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

            double x = pointType(point, settings->x, useMetricUnits, cranklength);
            double y = pointType(point, settings->y, useMetricUnits, cranklength);

            if (!(settings->ignore && (x == 0 && y ==0))) {

                // which interval is it in?
                for (int idx=0; idx<intervals.count(); idx++) {

                    IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(intervals[idx]));

                    if (point->secs+settings->ride->ride()->recIntSecs() > current->start && point->secs< current->stop) {
                        xvals[idx].append(x);
                        yvals[idx].append(y);
                        points[idx]++;
                    }
                }
            }
        }

        // now we have the interval data lets create the curves
        QMapIterator<int, int> order(displaySequence);
        while (order.hasNext()) {
            order.next();
            int idx = order.value();

            QPen pen;
            QColor intervalColor;
            intervalColor.setHsv((255/context->athlete->allIntervalItems()->childCount()) * (intervals[idx]), 255,255);
            pen.setColor(intervalColor);
            sym.setPen(pen);

            QwtPlotCurve *curve = new QwtPlotCurve();

            curve->setSymbol(new QwtSymbol(sym));
            curve->setStyle(QwtPlotCurve::Dots);
            curve->setRenderHint(QwtPlotItem::RenderAntialiased);
            curve->setData(xvals[idx].constData(), yvals[idx].constData(), points[idx]);
            curve->attach(this);

            intervalCurves.append(curve);
        }
    }
Exemplo n.º 26
0
void sigmaDetect(SAUIInterface* ui)
{
    QList<QwtPlotItem*> curs;
    SAChart2D* chart = filter_xy_series(ui,curs);
    if(nullptr == chart || curs.size() <= 0)
    {
        saUI->showMessageInfo(TR("unsupport chart items"),SA::WarningMessage);
        return;
    }
    double sigma;
    bool isMark,isChangedPlot;
    if(!getSigmaDetectPorperty(sigma,&isMark,&isChangedPlot,ui))
    {
        return;
    }
    if(!isMark && !isChangedPlot)
    {
        return;
    }
    QStringList infos;
    QScopedPointer<SAFigureOptCommand> topCmd(new SAFigureOptCommand(chart,QString("sigma %1").arg(sigma)));
    for (int i = 0;i<curs.size();++i)
    {
        QwtPlotItem* item = curs[i];
        switch(item->rtti())
        {
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QVector<double> xs,ys;
            {
                QVector<QPointF> wave;
                SAChart::getPlotCurveSample(item,wave);
                xs.reserve(wave.size());
                ys.reserve(wave.size());
                std::for_each(wave.begin(),wave.end(),[&xs](const QPointF& p){xs.push_back(p.x());});
                std::for_each(wave.begin(),wave.end(),[&ys](const QPointF& p){ys.push_back(p.y());});
            }
            QString info;
            QString title = item->title().text();
            QVector<int> indexs;
            saFun::sigmaDenoising(xs,ys,sigma,indexs);
            info = QString("sigma(\"%1\") out range datas count:%2").arg(title).arg(indexs.size());
            infos.append(info);
            if(0 == indexs.size())
            {
                continue;
            }
            if(isMark)
            {
                QVector<double> oxs,oys;
                czy::copy_inner_indexs(xs.begin(),indexs.begin(),indexs.end(),std::back_inserter(oxs));
                czy::copy_inner_indexs(ys.begin(),indexs.begin(),indexs.end(),std::back_inserter(oys));
                QwtPlotCurve* curs = new QwtPlotCurve(QString("%1_outSigmaMarker").arg(title));
                curs->setSamples(oxs,oys);
                SAChart::setCurvePenStyle(curs,Qt::NoPen);
                QwtSymbol* sym = new QwtSymbol(QwtSymbol::XCross);
                sym->setColor(SARandColorMaker::getCurveColor());
                sym->setSize(QSize(6,6));
                curs->setSymbol(sym);
                new SAFigureChartItemAddCommand(chart
                                                ,curs
                                                ,QString("%1 - sigma out rang").arg(title)
                                                ,topCmd.data());
            }
            if(isChangedPlot)
            {
                QVector<int> allIndex;
                QVector<int> innerIndex;
                const int count = xs.size();
                innerIndex.resize(count);
                allIndex.reserve(count);
                for(int i=0;i<count;++i)
                {
                    allIndex.append(i);
                }
                czy::copy_out_of_indexs(allIndex.begin(),allIndex.end(),indexs.begin(),indexs.end(),std::back_inserter(innerIndex));
                QVector<double> oxs,oys;
                czy::copy_inner_indexs(xs.begin(),innerIndex.begin(),innerIndex.end(),std::back_inserter(oxs));
                czy::copy_inner_indexs(ys.begin(),innerIndex.begin(),innerIndex.end(),std::back_inserter(oys));
                QVector<QPointF> oxys;
                saFun::makeVectorPointF(oxs,oys,oxys);;

                new SAFigureReplaceAllDatasCommand<QPointF,QwtPlotCurve,decltype(&SAChart::setPlotCurveSample)>
                        (chart
                       ,item
                       ,oxys
                       ,TR("%1 sigma %2").arg(title).arg(sigma)
                       ,&SAChart::setPlotCurveSample
                       ,&SAChart::getPlotCurveSample
                       ,topCmd.data()
                       );

            }
            break;
        }
        }

        /*
        QwtSeriesStore<QPointF>* series = dynamic_cast<QwtSeriesStore<QPointF>*>(item);
        if(nullptr == series)
        {
            continue;
        }
        QVector<double> xs,ys;
        if(!chart->getXYData(&xs,&ys,item))
        {
            continue;
        }

        QString info;
        QString title = item->title().text();
        QVector<int> indexs;
        saFun::sigmaDenoising(xs,ys,sigma,indexs);
        info = QString("sigma(\"%1\") out range datas count:%2").arg(title).arg(indexs.size());
        infos.append(info);
        if(0 == indexs.size())
        {
            continue;
        }
        if(isMark)
        {
            QVector<double> oxs,oys;
            czy::copy_inner_indexs(xs.begin(),indexs.begin(),indexs.end(),std::back_inserter(oxs));
            czy::copy_inner_indexs(ys.begin(),indexs.begin(),indexs.end(),std::back_inserter(oys));
            QwtPlotCurve* curs = new QwtPlotCurve(QString("%1_outSigmaMarker").arg(title));
            curs->setSamples(oxs,oys);
            SAChart::setCurvePenStyle(curs,Qt::NoPen);
            QwtSymbol* sym = new QwtSymbol(QwtSymbol::XCross);
            sym->setColor(SARandColorMaker::getCurveColor());
            sym->setSize(QSize(6,6));
            curs->setSymbol(sym);
            new SAFigureChartItemAddCommand(chart
                                            ,curs
                                            ,QString("%1 - sigma out rang").arg(title)
                                            ,topCmd.data());
        }
        if(isChangedPlot)
        {
            QVector<int> allIndex;
            QVector<int> innerIndex;
            const int count = xs.size();
            innerIndex.resize(count);
            allIndex.reserve(count);
            for(int i=0;i<count;++i)
            {
                allIndex.append(i);
            }
            czy::copy_out_of_indexs(allIndex.begin(),allIndex.end(),indexs.begin(),indexs.end(),std::back_inserter(innerIndex));
            QVector<double> oxs,oys;
            czy::copy_inner_indexs(xs.begin(),innerIndex.begin(),innerIndex.end(),std::back_inserter(oxs));
            czy::copy_inner_indexs(ys.begin(),innerIndex.begin(),innerIndex.end(),std::back_inserter(oys));
            QVector<QPointF> oxys;
            saFun::makeVectorPointF(oxs,oys,oxys);
            new SAFigureChangeXYSeriesDataCommand(chart
                                                 ,series
                                                 ,TR("%1 sigma %2").arg(title).arg(sigma)
                                                 ,oxys
                                                 ,topCmd.data());

            new SAFigureReplaceAllDatasCommand<>(chart
                                              ,series
                                              ,);
        }
        */
    }
    if(topCmd->childCount() > 0)
    {
        chart->appendCommand(topCmd.take());
        saUI->showNormalMessageInfo(infos.join('\n'));
    }
}
Exemplo n.º 27
0
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const
{
    if ( d_data->cache == 0 )
        return;

    const PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            pen.setColor(cache.gridColors[0]);
            grid->setMajPen(pen);

            pen = grid->minPen();
            pen.setColor(cache.gridColors[1]);
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            if ( cache.curveSymbolPenColors.contains(c) )
            {
                symbol.setPen(cache.curveSymbolPenColors[c]);
            }

            if ( cache.curveSymbolBrushColors.contains(c) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.curveSymbolBrushColors[c]);
                symbol.setBrush(brush);
            }
            c->setSymbol(symbol);

            if ( cache.curveColors.contains(c) )
            {
                QPen pen = c->pen();
                pen.setColor(cache.curveColors[c]);
                c->setPen(pen);
            }

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            if ( cache.markerFonts.contains(m) )
            {
                QwtText label = m->label();
                label.setFont(cache.markerFonts[m]);
                m->setLabel(label);
            }

            if ( cache.markerLabelColors.contains(m) )
            {
                QwtText label = m->label();
                label.setColor(cache.markerLabelColors[m]);
                m->setLabel(label);
            }

            if ( cache.markerLineColors.contains(m) )
            {
                QPen pen = m->linePen();
                pen.setColor(cache.markerLineColors[m]);
                m->setLinePen(pen);
            }
            
            QwtSymbol symbol = m->symbol();

            if ( cache.markerSymbolPenColors.contains(m) )
            {
                QPen pen = symbol.pen();
                pen.setColor(cache.markerSymbolPenColors[m]);
                symbol.setPen(pen);
            }

            if ( cache.markerSymbolBrushColors.contains(m) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.markerSymbolBrushColors[m]);
                symbol.setBrush(brush);
            }

            m->setSymbol(symbol);

            break;
        }
        default:
            break;
    }
}