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; }
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; }