void Spectrogram::updateLabels(QPainter *p, const QwtScaleMap &, const QwtScaleMap &, const QwtRasterData::ContourLines &contourLines) const { QwtValueList levels = contourLevels(); const int numLevels = levels.size(); int x_axis = xAxis(); int y_axis = yAxis(); for (int l = 0; l < numLevels; l++){ const double level = levels[l]; const QPolygonF &lines = contourLines[level]; if (lines.isEmpty()) continue; PlotMarker *mrk = d_labels_list[l]; if (!mrk) return; QSize size = mrk->label().textSize(); int dx = int((d_labels_x_offset + mrk->xLabelOffset())*0.01*size.height()); int dy = -int(((d_labels_y_offset + mrk->yLabelOffset())*0.01 + 0.5)*size.height()); int i = (int)lines.size()/2; double x = lines[i].x(); double y = lines[i].y(); int x2 = d_graph->transform(x_axis, x) + dx; int y2 = d_graph->transform(y_axis, y) + dy; if (p->device()->logicalDpiX() == plot()->logicalDpiX() || p->device()->logicalDpiY() == plot()->logicalDpiY()) mrk->setValue(d_graph->invTransform(x_axis, x2), d_graph->invTransform(y_axis, y2)); } }
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; } }
Spectrogram* Spectrogram::copy(Graph *g) { Spectrogram *new_s = new Spectrogram(g, matrix()); new_s->setDisplayMode(QwtPlotSpectrogram::ImageMode, testDisplayMode(QwtPlotSpectrogram::ImageMode)); new_s->setDisplayMode(QwtPlotSpectrogram::ContourMode, testDisplayMode(QwtPlotSpectrogram::ContourMode)); new_s->setCustomColorMap(color_map); new_s->setAxis(xAxis(), yAxis()); new_s->setDefaultContourPen(defaultContourPen()); new_s->color_map_policy = color_map_policy; new_s->d_show_labels = d_show_labels; new_s->d_labels_angle = d_labels_angle; new_s->d_labels_color = d_labels_color; new_s->d_white_out_labels = d_white_out_labels; new_s->d_labels_font = d_labels_font; new_s->d_labels_x_offset = d_labels_x_offset; new_s->d_labels_y_offset = d_labels_y_offset; new_s->setContourLevels(contourLevels()); if (defaultContourPen().style() == Qt::NoPen && !d_color_map_pen) new_s->setContourPenList(d_pen_list); else new_s->d_color_map_pen = d_color_map_pen; QList <PlotMarker *> lst = new_s->labelsList(); int count = lst.size(); for(int i = 0; i < count; i++){ PlotMarker *m = lst[i]; PlotMarker *mrk = d_labels_list[i]; if (m && mrk) m->setLabelOffset(mrk->xLabelOffset(), mrk->yLabelOffset()); } return new_s; }
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; }