Ejemplo n.º 1
0
void Plot::removeCurve(int index)
{
	QwtPlotItem *c = d_curves[index];
  	if (!c)
  		return;

  	if (c->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
  	{
  		Spectrogram *sp = (Spectrogram *)c;
  	    QwtScaleWidget *colorAxis = axisWidget(sp->colorScaleAxis());
  	    if (colorAxis)
  	    	colorAxis->setColorBarEnabled(false);
  	}

	c->detach();
	QwtPlotItem* p = d_curves.take (index);
  // RNT: Making curve_key unique prevents clashes elsewhere
	//--curve_key;
	// MG: This is a rather crude but effective way of delaying the
	// deletion of the curve objects. This is necessary because in
	// a tight loop a curve may not have been completely removed 
	// but the object has been deleted.
	Detacher *detacher = new Detacher(p);
	detacher->deleteLater();
}
Ejemplo n.º 2
0
void CurvesDialog::showCurveBtn(int)
{
	QwtPlotItem *it = d_graph->plotItem(contents->currentRow());
	if (!it)
		return;

    if (it->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
    {
        btnEditFunction->setEnabled(false);
        btnAssociations->setEnabled(false);
        btnRange->setEnabled(false);
        return;
    }

    PlotCurve *c = (PlotCurve *)it;
	if (c->type() == Graph::Function)
	{
		btnEditFunction->setEnabled(true);
		btnAssociations->setEnabled(false);
		btnRange->setEnabled(false);
		return;
	}

    btnAssociations->setEnabled(true);

    btnRange->setEnabled(true);
	if (c->type() == Graph::ErrorBars)
  		btnRange->setEnabled(false);
}
Ejemplo n.º 3
0
QwtPlotCurve* Plot::curve(int index)
{
    QwtPlotItem *it = d_curves.value(index);
    if (it && it->rtti() != QwtPlotItem::Rtti_PlotSpectrogram)
        return (QwtPlotCurve*)it;
    else
        return 0;
}
Ejemplo n.º 4
0
void scopePlot::legendClicked(const QVariant &itemInfo, bool on)
{
  QwtPlotItem *plotItem = plW->infoToItem( itemInfo );
  if ( plotItem )
    {
      plotItem->setVisible( on );
      plW->replot();
    }
}
Ejemplo n.º 5
0
void Graph::showCurve(const QVariant &itemInfo, bool on, int index )
{
    QwtPlotItem *it = infoToItem(itemInfo);
    if(it)
        it->setVisible(on);

    if(legend())
    {
        QWidget *w = ((QwtLegend*)legend())->legendWidget(itemInfo);
        if(w && w->inherits("QwtLegendLabel"))
            ((QwtLegendLabel*)w)->setChecked(on);
    }

    replot();
}
Ejemplo n.º 6
0
void SAChartDatasViewWidget::onActionPasteTriggered()
{
    SAWaitCursor waitCursor;
    SAPlotDataModel* model = getPlotModel();
    QItemSelectionModel* selModel = ui->tableView->selectionModel();
    if(nullptr == selModel || nullptr == model)
        return;
    //获取当前选择的列
    QModelIndexList selColIndexs = selModel->selectedIndexes();
    //说明只选择了一个单元格
    if(selColIndexs.isEmpty())
    {
        return;
    }
    int col = selColIndexs[0].column();
    int row = selColIndexs[0].row();
    //获取对应的item
    QwtPlotItem* item = model->getItemFromCol(col);
    if(nullptr == item)
        return;
    //获取这个数据在表格里的起始列和终止列
    int startCol,endCol;
    model->getItemColumnRange(item,&startCol,&endCol);
    if(-1 == startCol || -1 == endCol)
        return;

    QList<QStringList> stringClipboardTable;
    getClipboardTextTable(stringClipboardTable);
    SAChart2D* chart = qobject_cast<SAChart2D*>(item->plot());
    if(chart)
    {
        QScopedPointer<SAFigureTablePasteInSeriesCommand> cmd(new SAFigureTablePasteInSeriesCommand(
                    chart
                    ,item
                    ,stringClipboardTable
                    ,row
                    ,col-startCol
                    ,tr("paste in figure chart table")
                    ));
        if(!cmd->isValid())
        {
            return;
        }

        chart->appendCommand(cmd.take());
        model->updateRow();
    }
}
Ejemplo n.º 7
0
int LinePlot::numberOfCurves()
{
  /// multiple curves based on units
  const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList();
  QwtPlotItemIterator itPlotItem;
  int curveCount = 0;
  for (itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem)
  {
    QwtPlotItem *plotItem = *itPlotItem;
    if ( plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve)
    {
      curveCount++;
    }
  }
  return curveCount;
}
Ejemplo n.º 8
0
/*!
  \return List of all attached plot items of a specific type.
  \param rtti See QwtPlotItem::RttiValues
  \sa QwtPlotItem::rtti()
*/
QwtPlotItemList QwtPlotDict::itemList( int rtti ) const
{
    if ( rtti == QwtPlotItem::Rtti_PlotItem )
        return d_data->itemList;

    QwtPlotItemList items;

    PrivateData::ItemList list = d_data->itemList;
    for ( QwtPlotItemIterator it = list.begin(); it != list.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item->rtti() == rtti )
            items += item;
    }

    return items;
}
Ejemplo n.º 9
0
void Plot::removeCurve(int index)
{
	QwtPlotItem *c = d_curves[index];
  	if (!c)
  		return;

  	if (c->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
  	{
  		Spectrogram *sp = (Spectrogram *)c;
  	    QwtScaleWidget *colorAxis = axisWidget(sp->colorScaleAxis());
  	    if (colorAxis)
  	    	colorAxis->setColorBarEnabled(false);
  	}

	c->detach();
	d_curves.remove (index);
}
Ejemplo n.º 10
0
void QwtPlot::drawItems(QPainter *painter, const QRect &rect, 
        const QwtScaleMap map[axisCnt], 
        const QwtPlotPrintFilter &pfilter) const
{
    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid)
                && item->rtti() == QwtPlotItem::Rtti_PlotGrid )
            {
                continue;
            }

            painter->save();

#if QT_VERSION >= 0x040000
            painter->setRenderHint(QPainter::Antialiasing,
                item->testRenderHint(QwtPlotItem::RenderAntialiased) );
#endif

            item->draw(painter, 
                map[item->xAxis()], map[item->yAxis()],
                rect);

            painter->restore();
        }
    }
}
Ejemplo n.º 11
0
void QwtPlot::drawItems( QPainter *painter, const QRectF &canvasRect,
        const QwtScaleMap maps[axisCnt] ) const
{
    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            painter->save();

            painter->setRenderHint( QPainter::Antialiasing,
                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );
            painter->setRenderHint( QPainter::HighQualityAntialiasing,
                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );

            item->draw( painter,
                maps[item->xAxis()], maps[item->yAxis()],
                canvasRect );

            painter->restore();
        }
    }
}
Ejemplo n.º 12
0
/**
 * Returns the index of the closest curve to a point on the canvas.
 * Also returns index of the nearest data point on that curve.
 * @param xpos :: x coordinate of a point on the canvas in pixels.
 * @param ypos :: y coordinate of a point on the canvas in pixels.
 * @param dist :: ?
 * @param point :: Output index of the nearest data point to the point with coordinates (xpos,ypos)
 */
int Plot::closestCurve(int xpos, int ypos, int &dist, int &point)
{
	QwtScaleMap map[QwtPlot::axisCnt];
	for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
		map[axis] = canvasMap(axis);

  double dmin = std::numeric_limits<double>::max();
	int key = -1;
	for (QMap<int, QwtPlotItem *>::iterator iter = d_curves.begin(); iter != d_curves.end(); ++iter )
	{
		QwtPlotItem *item = (QwtPlotItem *)iter.data();
		if (!item)
			continue;

    if(item->rtti() != QwtPlotItem::Rtti_PlotSpectrogram)
    {
      PlotCurve *c = (PlotCurve *)item;
      DataCurve *dc = dynamic_cast<DataCurve *>(item);
      if (dc)
      {
        if (c->type() != Graph::Function && dc->hasLabels() &&
          dc->selectedLabels(QPoint(xpos, ypos))){
            dist = 0;
            return iter.key();
        } else
          dc->setLabelsSelected(false);
      }

      for (int i=0; i<c->dataSize(); i++)
      {
        double cx = map[c->xAxis()].xTransform(c->x(i)) - double(xpos);
        double cy = map[c->yAxis()].xTransform(c->y(i)) - double(ypos);
        double f = qwtSqr(cx) + qwtSqr(cy);
        if (f < dmin && c->type() != Graph::ErrorBars)
        {
          dmin = f;
          key = iter.key();
          point = i;
        }
      }
    }
  }
	dist = static_cast<int>(sqrt(dmin));
	return key;
}
Ejemplo n.º 13
0
/*!
   Detach items from the dictionary

   \param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items
               otherwise only those items of the type rtti.
   \param autoDelete If true, delete all detached items
*/
void QwtPlotDict::detachItems( int rtti, bool autoDelete )
{
    PrivateData::ItemList list = d_data->itemList;
    QwtPlotItemIterator it = list.begin();
    while ( it != list.end() )
    {
        QwtPlotItem *item = *it;

        ++it; // increment before removing item from the list

        if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
        {
            item->attach( NULL );
            if ( autoDelete )
                delete item;
        }
    }
}
Ejemplo n.º 14
0
void Graph::initLegend()
{
    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode(QwtLegendData::Checkable);
    insertLegend(legend, QwtPlot::BottomLegend);

    connect(legend, SIGNAL(checked(QVariant,bool,int)), SLOT(showCurve(QVariant,bool,int)));

    QwtPlotItemList l = this->itemList(QwtPlotItem::Rtti_PlotCurve);
    for(int i = 0; i < l.size(); ++i)
    {
        QwtPlotItem *curve = l[i];
        QVariant info = itemToInfo(curve);
        QWidget *w = legend->legendWidget(info);
        if(w && w->inherits("QwtLegendLabel"))
            ((QwtLegendLabel*)w)->setChecked(curve->isVisible());
    }
}
Ejemplo n.º 15
0
void LinePlot::setLineThickness(const int &width)
{
  const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList();
  QwtPlotItemIterator itPlotItem;
  for (itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem)
  {
    QwtPlotItem *plotItem = *itPlotItem;
    if ( plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve)
    {
      QwtPlotCurve *curve = (QwtPlotCurve *) plotItem;
      QPen pen(curve->pen()); 
      pen.setWidth(width);
      curve->setPen(pen);
    }
  }
  m_qwtPlot->replot();

}
Ejemplo n.º 16
0
void Editor::raiseItem( QwtPlotShapeItem *shapeItem )
{
    const QwtPlot *plot = this->plot();
    if ( plot == NULL || shapeItem == NULL )
        return;

    const QwtPlotItemList items = plot->itemList();
    for ( int i = items.size() - 1; i >= 0; i-- )
    {
        QwtPlotItem *item = items[ i ];
        if ( shapeItem == item )
            return;

        if ( item->isVisible() &&
            item->rtti() == QwtPlotItem::Rtti_PlotShape )
        {
            shapeItem->setZ( item->z() + 1 );
            return;
        }
    }
}
Ejemplo n.º 17
0
/*!
  Set the legend display policy to:

  \param policy Legend display policy
  \param mode Identifier mode (or'd ShowLine, ShowSymbol, ShowText)

  \sa displayPolicy, LegendDisplayPolicy
*/
void QwtLegend::setDisplayPolicy(LegendDisplayPolicy policy, int mode)
{
    d_data->displayPolicy = policy;
    if (-1 != mode)
       d_data->identifierMode = mode;

    QMap<QWidget *, const QwtPlotItem *> &map = 
        d_data->map.widgetMap();

    QMap<QWidget *, const QwtPlotItem *>::iterator it;
    for ( it = map.begin(); it != map.end(); ++it ) 
    {
#if QT_VERSION < 0x040000
        QwtPlotItem *item = (QwtPlotItem *)it.data();
#else
        QwtPlotItem *item = (QwtPlotItem *)it.value();
#endif
        if ( item )
            item->updateLegend(this);
    }
}
Ejemplo n.º 18
0
QwtPlotShapeItem* Editor::itemAt( const QPoint& pos ) const
{
    const QwtPlot *plot = this->plot();
    if ( plot == NULL )
        return NULL;

    // translate pos into the plot coordinates
    double coords[ QwtPlot::axisCnt ];
    coords[ QwtPlot::xBottom ] =
        plot->canvasMap( QwtPlot::xBottom ).invTransform( pos.x() );
    coords[ QwtPlot::xTop ] =
        plot->canvasMap( QwtPlot::xTop ).invTransform( pos.x() );
    coords[ QwtPlot::yLeft ] =
        plot->canvasMap( QwtPlot::yLeft ).invTransform( pos.y() );
    coords[ QwtPlot::yRight ] =
        plot->canvasMap( QwtPlot::yRight ).invTransform( pos.y() );

    QwtPlotItemList items = plot->itemList();
    for ( int i = items.size() - 1; i >= 0; i-- )
    {
        QwtPlotItem *item = items[ i ];
        if ( item->isVisible() &&
            item->rtti() == QwtPlotItem::Rtti_PlotShape )
        {
            QwtPlotShapeItem *shapeItem = static_cast<QwtPlotShapeItem *>( item );
            const QPointF p( coords[ item->xAxis() ], coords[ item->yAxis() ] );

            if ( shapeItem->boundingRect().contains( p )
                && shapeItem->shape().contains( p ) )
            {
                return shapeItem;
            }
        }
    }

    return NULL;
}
Ejemplo n.º 19
0
void QwtPlot::drawItems(QPainter *painter, const QRect &rect, 
        const QwtArray<QwtScaleMap> &map, 
        const QwtPlotPrintFilter &pfilter) const
{
    painter->save();

    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid)
                && item->rtti() == QwtPlotItem::Rtti_PlotGrid )
            {
                continue;
            }

#if QT_VERSION >= 0x040000
            const QPaintEngine *pe = painter->device()->paintEngine();
            if (pe->hasFeature(QPaintEngine::Antialiasing) )
            {
                painter->setRenderHint(QPainter::Antialiasing,
                    item->testRenderHint(QwtPlotItem::RenderAntialiased) );
            }
#endif

            item->draw(painter, 
                map[item->xAxis()], map[item->yAxis()],
                rect);
        }
    }

    painter->restore();
}
Ejemplo n.º 20
0
bool CanvasPicker::eventFilter(QObject *object, QEvent *e)
{
	if (object != (QObject *)plot()->canvas())
		return false;

	Graph *g = plot();
	QList<QwtPlotMarker *> lines = g->linesList();
	switch(e->type())
	{
		case QEvent::MouseButtonPress:
			{
                const QMouseEvent *me = (const QMouseEvent *)e;
				if (!(me->modifiers() & Qt::ShiftModifier))
                    g->deselect();

				emit selectPlot();

				bool allAxisDisabled = true;
				for (int i=0; i < QwtPlot::axisCnt; i++){
					if (g->axisEnabled(i)){
						allAxisDisabled = false;
						break;
					}
				}

                int dist, point;
                g->closestCurve(me->pos().x(), me->pos().y(), dist, point);

				if (me->button() == Qt::LeftButton && (g->drawLineActive())){
					startLinePoint = me->pos();
					return true;
				}

				if (!g->zoomOn() && selectMarker(me)){
					if (me->button() == Qt::RightButton)
						emit showMarkerPopupMenu();
					return true;
				}

				if (me->button() == Qt::LeftButton && !g->zoomOn() &&
					!g->hasPanningMagnifierEnabled() && !g->activeTool() && !g->selectedCurveLabels()){
					QDrag *drag = new QDrag(plot());
					QMimeData *mimeData = new QMimeData;
					QPoint p = plot()->canvas()->mapToParent(me->pos());
					mimeData->setText(QString::number(abs(plot()->x() - p.x())) + ";" +
									QString::number(abs(plot()->y() - p.y())));
					drag->setMimeData(mimeData);
					drag->setPixmap(plot()->multiLayer()->windowIcon().pixmap(16));
					drag->exec();
					return true;
				}

				return !(me->modifiers() & Qt::ShiftModifier);
			}
			break;

		case QEvent::MouseButtonDblClick:
			{
				if (d_editing_marker) {
					return d_editing_marker->eventFilter(g->canvas(), e);
				} else if (g->selectedMarker()) {
					if (lines.contains(g->selectedMarker())){
						emit viewLineDialog();
						return true;
					}
				} else if (g->isPiePlot()){
                	emit showPlotDialog(0);
                    return true;
				} else {
					const QMouseEvent *me = (const QMouseEvent *)e;
                    int dist, point;
                    QwtPlotItem *c = g->closestCurve(me->pos().x(), me->pos().y(), dist, point);
                    if (c && dist < 10)
                        emit showPlotDialog(g->curveIndex(c));
                    else
                        emit showPlotDialog(-1);
					return true;
				}
			}
			break;

		case QEvent::MouseMove:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->state() != Qt::LeftButton)
  	            	return true;

				QPoint pos = me->pos();

				QwtPlotItem *c = g->selectedCurveLabels();
				if (c){
					if (c->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
						((Spectrogram *)c)->moveLabel(pos);
					else
						((DataCurve *)c)->moveLabels(pos);
					return true;
				}

				if (plot()->drawLineActive()) {
					drawLineMarker(pos, g->drawArrow());
					return true;
				}

				return false;
			}
			break;

		case QEvent::MouseButtonRelease:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (g->drawLineActive()) {
					ApplicationWindow *app = g->multiLayer()->applicationWindow();
					if (!app)
						return true;

					ArrowMarker mrk;
					mrk.attach(g);
					mrk.setStartPoint(startLinePoint);
					mrk.setEndPoint(QPoint(me->x(), me->y()));
					mrk.setColor(app->defaultArrowColor);
					mrk.setWidth(app->defaultArrowLineWidth);
					mrk.setStyle(app->defaultArrowLineStyle);
					mrk.setHeadLength(app->defaultArrowHeadLength);
					mrk.setHeadAngle(app->defaultArrowHeadAngle);
					mrk.fillArrowHead(app->defaultArrowHeadFill);
					mrk.drawEndArrow(g->drawArrow());
					mrk.drawStartArrow(false);

					g->addArrow(&mrk);
					g->drawLine(false);
					mrk.detach();
					g->replot();

					return true;
				}
				return false;
			}
			break;

		case QEvent::KeyPress:
			{
				int key = ((const QKeyEvent *)e)->key();

				QwtPlotMarker *selectedMarker = g->selectedMarker();
				if (lines.contains(selectedMarker) &&
					(key == Qt::Key_Enter || key == Qt::Key_Return)){
					emit viewLineDialog();
					return true;
				}
			}
			break;

		default:
			break;
	}
	return QObject::eventFilter(object, e);
}
Ejemplo n.º 21
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'));
    }
}
Ejemplo n.º 22
0
void pointSmooth(SAUIInterface* ui)
{
    QList<QwtPlotItem*> curs;
    SAChart2D* chart = filter_xy_series(ui,curs);
    if(nullptr == chart || curs.size() <= 0)
    {
        ui->showMessageInfo(TR("unsupport chart items"),SA::WarningMessage);
        return;
    }
    int m,n;
    if(!getPointSmoothPorperty(m,n,ui))
    {
        return;
    }
    QStringList infos;
    QScopedPointer<SAFigureOptCommand> topCmd(new SAFigureOptCommand(chart,QString("%1 point %2 power").arg(m).arg(n)));
    for (int i = 0;i<curs.size();++i)
    {
        QwtPlotItem* item = curs[i];
        QString title = item->title().text();

        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());});
            }
            QVector<double> res;
            if(!saFun::pointSmooth(ys,m,n,res))
            {
                continue;
            }
            QVector<QPointF> xys;
            saFun::makeVectorPointF(xs,res,xys);

            new SAFigureReplaceAllDatasCommand<QPointF,QwtPlotCurve,decltype(&SAChart::setPlotCurveSample)>
                    (chart
                   ,item
                   ,xys
                   ,TR("%1 m%2n%3").arg(title).arg(m).arg(n)
                   ,&SAChart::setPlotCurveSample
                   ,&SAChart::getPlotCurveSample
                   ,topCmd.data()
                   );
            infos.append(TR("%1 m%2n%3 smooth").arg(title).arg(m).arg(n));
            break;
        }
        }

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

        if(!chart->getXYData(&xs,&ys,item))
        {
            continue;
        }
        if(!chart->getXYData(&xs,&ys,item))
        {
            continue;
        }
        QVector<double> res;
        if(!saFun::pointSmooth(ys,m,n,res))
        {
            continue;
        }
        QVector<QPointF> xys;
        saFun::makeVectorPointF(xs,res,xys);
        new SAFigureChangeXYSeriesDataCommand(chart
                                             ,series
                                             ,TR("%1 m%2n%3").arg(title).arg(m).arg(n)
                                             ,xys
                                             ,topCmd.data());

        infos.append(TR("%1 m%2n%3 smooth").arg(title).arg(m).arg(n));
        */
    }
    if(topCmd->childCount() > 0)
    {
        chart->appendCommand(topCmd.take());
        ui->showNormalMessageInfo(infos.join('\n'));
    }
}
Ejemplo n.º 23
0
void polyfitInChart(SAUIInterface* ui)
{
    QList<QwtPlotItem*> curs;
    SAChart2D* chart = filter_xy_series(ui,curs);
    if(nullptr == chart || curs.size() <= 0)
    {
        ui->showMessageInfo(TR("unsupport chart items"),SA::WarningMessage);
        return;
    }
    int order = 1;
    if(!getPolyfitConfig(order,ui))
    {
        return;
    }

    QString strDes("");
    for (int i = 0;i<curs.size();++i)
    {
        QwtPlotItem* item = curs[i];
        QVector<double> xs,ys;
        if(chart->isRegionVisible())
        {
            if(!chart->getXYDataInRange(&xs,&ys,nullptr,item))
            {
                continue;
            }
        }
        else
        {
            if(!chart->getXYData(&xs,&ys,item))
            {
                continue;
            }
        }
        QString title = item->title().text();

        std::shared_ptr<SAVectorDouble> factor;//拟合的系数
        std::shared_ptr<SATableVariant> info;//拟合的误差参数
        std::tie(factor,info) = saFun::polyfit(xs,ys,order);
        if(nullptr == factor)
        {
            continue;
        }
        info->setName(QString("%1_%2PolyFitInfo").arg(title).arg(order));
        std::shared_ptr<SAVectorPointF> pfitVal = SAValueManager::makeData<SAVectorPointF>(QString("%1_%2PolyFit").arg(title).arg(order));
        saFun::polyval(xs,factor.get(),pfitVal.get());
        saValueManager->addData(info);
        saValueManager->addData(pfitVal);
        //
        strDes += "<p>";
        strDes += TR("%1-Polynomial Fittin, order:%2 ")
                .arg(title).arg(order);
        strDes += "<br/>";
        const size_t factorSize = factor->getSize();
        QString fun;
        for (size_t j = 0;j<factorSize;++j)
        {
            double f = factor->getAt({j}).toDouble();
            if (0 == j)
            {
                fun = QString("y = %1").arg(factor->getAt({j}).toString());
                continue;
            }
            if (1 == j)
            {
                if (f>0)
                    fun += QString("+%1x").arg(f);
                else
                    fun += QString("%1x").arg(f);
                continue;
            }
            if(f>0)
                fun += QString("+%1x^%2").arg(f).arg(j);
            else
                fun += QString("%1x^%2").arg(f).arg(j);
        }
        strDes += (TR("fitting results:")+fun);
        strDes += "<br/>";
        //残差,残差平方和,回归平方和,均方根误差

        strDes += TR("error:");
        strDes += "<br/>";

        strDes += TR("SSR(Regression Square Sum)=%1").arg(info->getAt({0,1}).toString());
        strDes += "<br/>";

        strDes += TR("SSE(Sum of Squares for Error)=%1").arg(info->getAt({1,1}).toString());
        strDes += "<br/>";

        strDes += TR("SST=%1").arg(info->getAt({2,1}).toString());
        strDes += "<br/>";

        strDes += TR("RMSE(Root mean square error)=%1").arg(info->getAt({3,1}).toString());
        strDes += "<br/>";

        strDes += TR("R-square(coefficient of determination)=%1").arg(info->getAt({4,1}).toString());
        strDes += "<br/>";

        strDes += TR("Goodness=%1").arg(info->getAt({5,1}).toString());
        strDes += "</p>";

        chart->addCurve(pfitVal.get());
        saUI->showNormalMessageInfo(strDes);
    }

}
Ejemplo n.º 24
0
void TVPlot::showItem( const QVariant &itemInfo, bool on )
{
    QwtPlotItem *plotItem = infoToItem( itemInfo );
    if ( plotItem )
        plotItem->setVisible( on );
}
Ejemplo n.º 25
0
//! Rebuild the scales and maps
void QwtPlot::updateAxes() 
{
    // Find bounding interval of the item data
    // for all axes, where autoscaling is enabled
    
    QwtDoubleInterval intv[axisCnt];

    const QwtPlotItemList& itmList = itemList();

    QwtPlotItemIterator it;
    for ( it = itmList.begin(); it != itmList.end(); ++it )
    {
        const QwtPlotItem *item = *it;

        if ( !item->testItemAttribute(QwtPlotItem::AutoScale) )
            continue;

        if ( axisAutoScale(item->xAxis()) || axisAutoScale(item->yAxis()) )
        {
            const QwtDoubleRect rect = item->boundingRect();
            intv[item->xAxis()] |= QwtDoubleInterval(rect.left(), rect.right());
            intv[item->yAxis()] |= QwtDoubleInterval(rect.top(), rect.bottom());
        }
    }

    // Adjust scales

    for (int axisId = 0; axisId < axisCnt; axisId++)
    {
        AxisData &d = *d_axisData[axisId];

        double minValue = d.minValue;
        double maxValue = d.maxValue;
        double stepSize = d.stepSize;

        if ( d.doAutoScale && intv[axisId].isValid() )
        {
            d.scaleDiv.invalidate();

            minValue = intv[axisId].minValue();
            maxValue = intv[axisId].maxValue();

            d.scaleEngine->autoScale(d.maxMajor, 
                minValue, maxValue, stepSize);
        }
        if ( !d.scaleDiv.isValid() )
        {
            d.scaleDiv = d.scaleEngine->divideScale(
                minValue, maxValue, 
                d.maxMajor, d.maxMinor, stepSize);
        }

        QwtScaleWidget *scaleWidget = axisWidget(axisId);
        scaleWidget->setScaleDiv(
            d.scaleEngine->transformation(), d.scaleDiv);

        int startDist, endDist;
        scaleWidget->getBorderDistHint(startDist, endDist);
        scaleWidget->setBorderDist(startDist, endDist);
    }

    for ( it = itmList.begin(); it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        item->updateScaleDiv( *axisScaleDiv(item->xAxis()),
            *axisScaleDiv(item->yAxis()));
    }
}