void Spectrogram::createLabels() { clearLabels(); QwtValueList levels = contourLevels(); const int numLevels = levels.size(); for (int l = 0; l < numLevels; l++){ PlotMarker *m = new PlotMarker(l, d_labels_angle); QwtText t = QwtText(QString::number(levels[l])); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); if (d_graph && d_show_labels) m->attach(d_graph); d_labels_list << m; } }
void QwtHistogram::loadLabels() { clearLabels(); int size = this->dataSize(); if (!size) return; QwtPlot *d_plot = plot(); if (!d_plot) return; int index = 0; for (int i = 0; i < size; i++){ PlotMarker *m = new PlotMarker(index, d_labels_angle); QwtText t = QwtText(QString::number(y(i))); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); QSize size = t.textSize(); int dx = int(d_labels_x_offset*0.01*size.height()); int dy = -int((d_labels_y_offset*0.01 + 0.5)*size.height()); int x2 = d_plot->transform(x_axis, x(index)) + dx; int y2 = d_plot->transform(y_axis, y(index)) + dy; switch(d_labels_align){ case Qt::AlignLeft: break; case Qt::AlignHCenter: x2 -= size.width()/2; break; case Qt::AlignRight: x2 -= size.width(); break; } m->setXValue(d_plot->invTransform(x_axis, x2)); m->setYValue(d_plot->invTransform(y_axis, y2)); m->attach(d_plot); d_labels_list << m; index++; } d_show_labels = true; }
QwtText CurveTracker::trackerTextF( const QPointF &pos ) const { QwtText trackerText; trackerText.setColor( Qt::black ); QColor c( "#333333" ); trackerText.setBorderPen( QPen( c, 2 ) ); c.setAlpha( 200 ); trackerText.setBackgroundBrush( c ); QString info; const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve ); for ( int i = 0; i < curves.size(); i++ ) { const QString curveInfo = curveInfoAt( static_cast<const QwtPlotCurve *>( curves[i] ), pos ); if ( !curveInfo.isEmpty() ) { if ( !info.isEmpty() ) info += "<br>"; info += curveInfo; } } trackerText.setText( info ); return trackerText; }
//将位置转换成字符串 QwtText RectPicker::trackerTextF(const QPointF &pos) const { QwtText text; const QPolygon points = selection();//选择的点 if (!points.isEmpty()) { QString num; QPoint point = points[0]; QPointF point2 = invTransform(point); num = QString("(%1,%2),(,)").arg(point2.x()).arg(point2.y()); QColor bg(Qt::white); bg.setAlpha(200); if (points.size() == 2) { QPointF point0 = invTransform(points[0]); QPointF point1 = invTransform(points[1]); num = QString("(%1,%2),(%3,%4)").arg(point0.x()).arg(point0.y()).arg(point1.x()).arg(point1.y()); } text.setBackgroundBrush(QBrush(bg)); text.setText(num); } return text; }
virtual QwtText trackerTextF(const QPointF &pos) const { QColor bg(Qt::white); QwtText text = QwtPlotZoomer::trackerTextF(pos); text.setBackgroundBrush( QBrush( bg )); return text; }
virtual QwtText trackerText(const QwtDoublePoint &pos) const { QColor bg(Qt::white); bg.setAlpha(200); QwtText text = QwtPlotZoomer::trackerText(pos); text.setBackgroundBrush( QBrush( bg )); return text; }
QwtText Zoomer::trackerTextF( const QPointF &pos ) const { QColor bg( Qt::white ); bg.setAlpha( 128 ); QwtText text; if ( tracker2_ && ( p1_.x() || p1_.y() ) ) { // has 1st point text = tracker2_( invTransform( p1_ ), pos ); } else if ( tracker1_ ) { text = tracker1_( pos ); } else { text = QwtPlotZoomer::trackerTextF( pos ); } text.setBackgroundBrush( QBrush( bg ) ); return text; }
virtual QwtText trackerTextF( const QPointF &pos ) const { // the white text is hard to see over a light canvas background QColor bg( Qt::darkGray ); bg.setAlpha( 160 ); QwtText text; const int idx = dynamic_cast<const Plot*>( plot() )->frameAt( pos.x() ); if ( idx >= 0 ) { text = infoText( idx ); text.setBackgroundBrush( QBrush( bg ) ); } return text; }
virtual QwtText trackerTextF( const QPointF &pos ) const { QwtText text; const QPolygon points = selection(); if ( !points.isEmpty() ) { QString num; num.setNum( QLineF( pos, invTransform( points[0] ) ).length() ); QColor bg( Qt::green ); bg.setAlpha( 200 ); text.setBackgroundBrush( QBrush( bg ) ); text.setText( num ); } return text; }
virtual QwtText trackerText(const QPoint& pos) const { // find all points near cursor QSet<uint> nearbySampleIds = GetNearbySamples(pos); QString tooltipStr; if(nearbySampleIds.size() != 0) { foreach(uint id, nearbySampleIds) tooltipStr += m_samples->GetSample(id).GetName() + QString(", "); tooltipStr = tooltipStr.left(tooltipStr.size()-2); } QwtText tooltipText; if(!tooltipStr.isEmpty()) { tooltipText.setText(tooltipStr); tooltipText.setBackgroundBrush(QBrush(QColor(255,255,255,192))); } return tooltipText; }
void DataCurve::loadLabels() { if (!validCurveType()) return; clearLabels(); int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); int labelsCol = d_table->colIndex(d_labels_column); int cols = d_table->numCols(); if (xcol < 0 || ycol < 0 || labelsCol < 0 || xcol >= cols || ycol >= cols || labelsCol >= cols) return; QwtPlot *d_plot = plot(); if (!d_plot) return; int index = 0; for (int i = d_start_row; i <= d_end_row; i++) { if (d_table->text(i, xcol).isEmpty() || d_table->text(i, ycol).isEmpty()) continue; PlotMarker *m = new PlotMarker(index, d_labels_angle); QwtText t = QwtText(d_table->text(i, labelsCol)); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); QSize size = t.textSize(); int dx = int(d_labels_x_offset*0.01*size.height()); int dy = -int((d_labels_y_offset*0.01 + 0.5)*size.height()); int x2 = d_plot->transform(x_axis, x(index)) + dx; int y2 = d_plot->transform(y_axis, y(index)) + dy; switch(d_labels_align) { case Qt::AlignLeft: break; case Qt::AlignHCenter: x2 -= size.width()/2; break; case Qt::AlignRight: x2 -= size.width(); break; } m->setXValue(d_plot->invTransform(x_axis, x2)); m->setYValue(d_plot->invTransform(y_axis, y2)); m->attach(d_plot); d_labels_list << m; index++; } d_show_labels = true; }