コード例 #1
0
void DataCurve::clearLabels()
{
	if (!validCurveType())
		return;

	foreach(PlotMarker *m, d_labels_list){
		m->detach();
		delete m;
	}
コード例 #2
0
ファイル: PlotCurve.cpp プロジェクト: kuzavas/qtiplot
void DataCurve::setLabelsColumnName(const QString& name)
{
    if (!validCurveType())
        return;

    if (d_labels_column == name && !d_labels_list.isEmpty())
        return;

    d_labels_column = name;
    loadLabels();
}
コード例 #3
0
ファイル: PlotCurve.cpp プロジェクト: kuzavas/qtiplot
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;
}