Beispiel #1
0
void caStripPlot::setLegendAttribute(QColor c, QFont f, LegendAtttribute SW)
{
    int i;

#if QWT_VERSION < 0x060100
    for(i=0; i < NumberOfCurves; i++) {

        switch (SW) {
        case TEXT:
            if(thisLegendshow) {
                QwtText text;
                text.setText(legendText(i));
                qobject_cast<QwtLegendItem*>(this->legend()->find(curve[i]))->setText(text);
            }
            break;

        case FONT:

            if(getLegendEnabled()) {
                if(legend() != (QwtLegend*) 0) {
                    QList<QWidget *> list =  legend()->legendItems();
                    for (QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) {
                        QWidget *w = *it;
                        w->setFont(f);
                    }
                }
            }
            break;

        case COLOR:
            if(legend() != (QwtLegend*) 0) {
                QList<QWidget *> list =  legend()->legendItems();
                for (QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) {
                    QWidget *w = *it;
                    QPalette palette = w->palette();
                    palette.setColor( QPalette::WindowText, c); // for ticks
                    palette.setColor( QPalette::Text, c);       // for ticks' labels
                    w->setPalette (palette);
                    w->setFont(f);
                }
            }

            break;
        }

    }
#else
    i=0;
    foreach (QwtPlotItem *plt_item, itemList()) {
        if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
            QwtLegend *lgd = qobject_cast<QwtLegend *>(legend());
            QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));
            if ( legendWidgets.size() == 1 ) {
                QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
                switch (SW) {

                case TEXT:

                    if(thisLegendshow) {

                        QwtText text;
                        text.setText(legendText(i++));
                        //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());
                        b->setText(text);
                        b->update();


                    }
                    break;

                case FONT:
                    //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());

                    b->setFont(f);
                    b->update();

                    break;

                case COLOR:

                    //printf("%s %s\n", b->plainText().toAscii().constData(), legendText(i-1).toAscii().constData());
                    QPalette palette = b->palette();
                    palette.setColor( QPalette::WindowText, c); // for ticks
                    palette.setColor( QPalette::Text, c);       // for ticks' labels
                    b->setPalette(palette);
                    b->update();

                    break;

                }


            }
        }
    }
#endif

}