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; }
/*! * \brief Update ChartSeries map * * This method updates the waveforms list given a ChartView. This is * usually used when changing between views to keep the list of available * waveforms synchronized with the currently selected chart. */ void SidebarChartsBrowser::updateChartSeriesMap() { // Get the current view DocumentViewManager *manager = DocumentViewManager::instance(); ChartView *view = static_cast<ChartView*>(manager->currentView()->toWidget()); // Populate the waveforms list QwtPlotItemList list = view->itemList(QwtPlotItem::Rtti_PlotCurve); m_chartSeriesMap.clear(); for(int i=0; i<list.size(); ++i) { m_chartSeriesMap.insert(list.at(i)->title().text(), list.at(i)->isVisible()); } // Create a new table model m_model = new SidebarChartsModel(m_chartSeriesMap, this); //! \todo What happens with the old pointer??? Should we destroy it first? m_proxyModel->setSourceModel(m_model); // Resize the table columns to fit the contents. This must be done // here instead of the constructor because the columns are created // here when filling the model (in the constructor the columns do // not yet exist, resulting in a crash if resized there). m_tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); }
void scopePlot::init(QString title) { setup=true; setCentralWidget(wd); connect(ui.offsetWheel, SIGNAL(valueChanged(double)),SLOT(slotOffsetChanged(double ))); connect(ui.rangeWheel, SIGNAL(valueChanged(double)), SLOT(slotRangeChanged(double ))); connect(ui.samplesPushButton, SIGNAL(clicked()), this, SLOT(slotSamplesButtton())); plW=ui.plotWindow; plW->setTitle(title); plW->setCanvasBackground(Qt::darkBlue); curve1->attach(plW); curve2->attach(plW); curve3->attach(plW); curve4->attach(plW); plW->setAxisTitle(QwtPlot::xBottom,xAxisTitle); plW->setAxisScale(QwtPlot::xBottom, 0, 100); plW->setAxisTitle(QwtPlot::yLeft, "Values"); plW->setAxisScale(QwtPlot::yLeft, -1.5, 1.5); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajorPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(plW); QwtText m1("M1"); m1.setColor(QColor(Qt::white)); marker1=new QwtPlotMarker(); marker1->setValue(0.0, 0.0); marker1->setLabel(m1); marker1->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom); marker1->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine)); marker1->setSymbol( new QwtSymbol(QwtSymbol::Diamond,QColor(Qt::green), QColor(Qt::green), QSize(7,7))); // marker1->hide(); marker1->attach(plW); QwtText m2("M2"); m2.setColor(QColor(Qt::white)); marker2=new QwtPlotMarker(); marker2->setValue(0.0, 0.0); marker2->setLabel(m2); marker2->setLabelAlignment(Qt::AlignLeft | Qt::AlignTop); marker2->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine)); marker2->setSymbol( new QwtSymbol(QwtSymbol::Diamond,QColor(Qt::yellow), QColor(Qt::yellow), QSize(7,7))); // marker2->hide(); marker2->attach(plW); legend = new QwtLegend; legend->setFrameStyle(QFrame::Box|QFrame::Sunken); legend->setDefaultItemMode(QwtLegendData::Checkable); QPalette pal(legend->palette()); pal.setColor(QPalette::Window,Qt::darkBlue); pal.setColor(QPalette::WindowText,Qt::white); pal.setColor(QPalette::Text,Qt::black); legend->setPalette(pal); plW->insertLegend(legend, QwtPlot::BottomLegend); picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, plW->canvas()); picker->setStateMachine(new QwtPickerDragPointMachine()); picker->setRubberBandPen(QColor(Qt::green)); picker->setRubberBand(QwtPicker::CrossRubberBand); picker->setTrackerPen(QColor(Qt::white)); picker->setEnabled(true); plW->replot(); QwtPlotItemList items = plW->itemList( QwtPlotItem::Rtti_PlotCurve); for ( int i = 0; i < items.size(); i++ ) { const QVariant itemInfo = plW->itemToInfo( items[i] ); QwtLegendLabel *legendLabel =qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) ); if (legendLabel ) { legendLabel->setChecked( true ); } items[i]->setVisible( true ); } connect(picker, SIGNAL(moved(const QPointF &)),SLOT(pickerMoved(const QPointF &))); connect(picker, SIGNAL(selected(const QPointF &)), SLOT(pickerSelected(const QPointF &))); connect(legend, SIGNAL(checked(const QVariant &, bool ,int)),SLOT(legendClicked(const QVariant &,bool))); connect(ui.nextButton, SIGNAL(clicked()),SLOT(slotNext())); connect(ui.previousButton, SIGNAL(clicked()),SLOT(slotPrevious())); plW->setAxisTitle(QwtPlot::xBottom,xAxisTitle); xOffset=0; }
// Select the next/previous curve void CanvasPicker::shiftCurveCursor( bool up ) { QwtPlotItemIterator it; const QwtPlotItemList &itemList = plot()->itemList(); QwtPlotItemList curveList; for ( it = itemList.begin(); it != itemList.end(); ++it ) { if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve ) curveList += *it; } if ( curveList.isEmpty() ) return; it = curveList.begin(); if ( d_selectedCurve ) { for ( it = curveList.begin(); it != curveList.end(); ++it ) { if ( d_selectedCurve == *it ) break; } if ( it == curveList.end() ) // not found it = curveList.begin(); if ( up ) { ++it; if ( it == curveList.end() ) it = curveList.begin(); } else { if ( it == curveList.begin() ) it = curveList.end(); --it; } } showCursor( false ); d_selectedPoint = 0; d_selectedCurve = static_cast<QwtPlotCurve *>( *it ); showCursor( true ); }
void QwtCustomPlotPicker::drawRubberBand(QPainter* painter) const { if ( rubberBand() < UserRubberBand ) QwtPlotPicker::drawRubberBand( painter ); else { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QPolygon p = selection(); if ( p.count() != 1 ) return; const QPoint& pt1 = p[0]; const double x_val = plot()->invTransform(QwtPlot::xBottom,pt1.x()); // determine x value (time or dist) // Draw vertical line where curser is const int bot = 400; const int top = 0; painter->drawLine(pt1.x(), bot, pt1.x(), top); // Set pen and fond for all coming text painter->setPen(QColor(Qt::black)); painter->setFont(QFont("Helvetica", 8, QFont::Bold)); // Compute the index based on the x value int idx; if (_x_axis_units == TimeAxis) { painter->drawText(QPoint(pt1.x()-65, 10), "time: " + DataProcessing::minsFromSecs(x_val)); idx = _data_log->indexFromTime(x_val); } else if (_x_axis_units == DistAxis) { painter->drawText(QPoint(pt1.x()-60, 10), "dist: " + DataProcessing::kmFromMeters(x_val,2)); idx = _data_log->indexFromDist(x_val); } // Using the index, determine the curve values const double hr = (int)_data_log->heartRateFltd(idx); const QPoint pt1_hr(pt1.x(),plot()->transform(QwtPlot::yLeft,hr)); const double speed = _data_log->speedFltd(idx); const QPoint pt1_speed(pt1.x(),plot()->transform(QwtPlot::yLeft,speed)); const double alt = (int)_data_log->altFltd(idx); const QPoint pt1_alt(pt1.x(),plot()->transform(QwtPlot::yRight,alt)); const double cadence = (int)_data_log->cadenceFltd(idx); const QPoint pt1_cadence(pt1.x(),plot()->transform(QwtPlot::yLeft,cadence)); const double power = _data_log->powerFltd(idx); const QPoint pt1_power(pt1.x(),plot()->transform(QwtPlot::yLeft,power)); const double temp = _data_log->temp(idx); const QPoint pt1_temp(pt1.x(),plot()->transform(QwtPlot::yLeft,temp)); // Draw highlights on all curves const QPoint offset(8,-5); const QwtPlotItemList item_list = plot()->itemList(QwtPlotCurve::Rtti_PlotCurve); for (int i = 0; i < item_list.size(); ++i) { if (item_list.at(i)->title().text() == "Heart Rate" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_hr.x(), pt1_hr.y(), pt1_hr.x()+6, pt1_hr.y()); painter->drawText(pt1_hr + offset, QString::number(hr,'g',3)); } if (item_list.at(i)->title().text() == "Speed" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_speed.x(), pt1_speed.y(), pt1_speed.x()+6, pt1_speed.y()); painter->drawText(pt1_speed + offset, QString::number(speed,'g',3)); } if (item_list.at(i)->title().text() == "Elevation" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_alt.x(), pt1_alt.y(), pt1_alt.x()+6, pt1_alt.y()); painter->drawText(pt1_alt + offset, QString::number(alt,'g',4)); } if (item_list.at(i)->title().text() == "Cadence" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_cadence.x(), pt1_cadence.y(), pt1_cadence.x()+6, pt1_cadence.y()); painter->drawText(pt1_cadence + offset, QString::number(cadence,'g',3)); } if (item_list.at(i)->title().text() == "Power" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_power.x(), pt1_power.y(), pt1_power.x()+6, pt1_power.y()); painter->drawText(pt1_power + offset, QString::number(power,'g',3)); } if (item_list.at(i)->title().text() == "Temp" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_temp.x(), pt1_temp.y(), pt1_temp.x()+6, pt1_temp.y()); painter->drawText(pt1_temp + offset, QString::number(temp,'g',3)); } // Draw current values on graph labels if (_hr_cb->isChecked()) _hr_cb->setText("Heart Rate " + QString::number(hr,'g',3).leftJustified(3,' ') + " bpm"); else _hr_cb->setText("Heart Rate"); if (_speed_cb->isChecked()) _speed_cb->setText("Speed " + QString::number(speed,'g',3) + " km/h"); else _speed_cb->setText("Speed"); if (_alt_cb->isChecked()) _alt_cb->setText("Elevation " + QString::number(alt,'g',4).leftJustified(4,' ') + " m"); else _alt_cb->setText("Elevation"); if (_cadence_cb->isChecked()) _cadence_cb->setText("Cadence " + QString::number(cadence,'g',3) + " rpm"); else _cadence_cb->setText("Cadence"); if (_power_cb->isChecked()) _power_cb->setText("Power " + QString::number(power,'g',3) + " W"); else _power_cb->setText("Power"); if (_temp_cb->isChecked()) _temp_cb->setText("Temp " + QString::number(temp,'g',3) + " C"); else _temp_cb->setText("Temp"); } } }
LevelOneMuChart::LevelOneMuChart(QWidget *parent) : QwtPlot(parent) { setAutoReplot(false); /* Panning with the left mouse button */ (void)new QwtPlotPanner(canvas()); /* Zoom in/out with the wheel */ (void)new QwtPlotMagnifier(canvas()); /* Picker */ plotPicker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas()); plotPicker->setStateMachine(new QwtPickerDragPointMachine()); plotPicker->setRubberBandPen(QColor(Qt::blue)); plotPicker->setRubberBand(QwtPicker::CrossRubberBand); plotPicker->setTrackerPen(QColor(Qt::black)); setAutoFillBackground(true); setPalette(QPalette(QColor(199, 237, 255))); // Light Blue updateWidgetGradient(); setTitle(tr("Chart of available deviations")); /* Legend */ legend = new QwtLegend(); legend->setItemMode(QwtLegend::CheckableItem); insertLegend(legend, QwtPlot::RightLegend); /* Canvas Settings */ canvas()->setLineWidth(1); canvas()->setFrameStyle(QFrame::Box | QFrame::Plain); QPalette canvasPalette(Qt::white); canvasPalette.setColor(QPalette::Foreground, QColor(133, 190, 232)); canvas()->setPalette(canvasPalette); plotAssay(); /* Legend */ connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showItem(QwtPlotItem *, bool))); QwtPlotItemList items = itemList(QwtPlotItem::Rtti_PlotCurve); for (int i = 0; i < items.size(); i++) { if (i < 3) { QwtLegendItem *legendItem = qobject_cast<QwtLegendItem *>(legend->find(items[i])); if (legendItem) { legendItem->setChecked(true); } items[i]->setVisible(true); } else { items[i]->setVisible(false); } } setAutoReplot(true); }