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(); } } }
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(); }
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); }
QwtPlotCurve* Plot::curve(int index) { QwtPlotItem *it = d_curves.value(index); if (it && it->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) return (QwtPlotCurve*)it; else return 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; }
/*! \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; }
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); }
/** * 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; }
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(); }
/*! 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; } } }
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; } } }
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; }
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(); }
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')); } }
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')); } }
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); }