TVPlot::TVPlot( QWidget *parent ): QwtPlot( parent ) { setTitle( "Watching TV during a weekend" ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setPalette( Qt::gray ); canvas->setBorderRadius( 10 ); setCanvas( canvas ); plotLayout()->setAlignCanvasToScales( true ); setAxisTitle( QwtPlot::yLeft, "Number of People" ); setAxisTitle( QwtPlot::xBottom, "Number of Hours" ); QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::Checkable ); insertLegend( legend, QwtPlot::RightLegend ); populate(); connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( showItem( const QVariant &, bool ) ) ); replot(); // creating the legend items QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotHistogram ); for ( int i = 0; i < items.size(); i++ ) { if ( i == 0 ) { const QVariant itemInfo = itemToInfo( items[i] ); QwtLegendLabel *legendLabel = qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) ); if ( legendLabel ) legendLabel->setChecked( true ); items[i]->setVisible( true ); } else { items[i]->setVisible( false ); } } setAutoReplot( true ); }
void CpuPlot::showCurve( QwtPlotItem *item, bool on ) { item->setVisible( on ); QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() ); QList<QWidget *> legendWidgets = lgd->legendWidgets( itemToInfo( item ) ); if ( legendWidgets.size() == 1 ) { QwtLegendLabel *legendLabel = qobject_cast<QwtLegendLabel *>( legendWidgets[0] ); if ( legendLabel ) legendLabel->setChecked( on ); } replot(); }
void Graph::initLegend() { QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode(QwtLegendData::Checkable); insertLegend(legend, QwtPlot::BottomLegend); connect(legend, SIGNAL(checked(QVariant,bool,int)), SLOT(showCurve(QVariant,bool,int))); QwtPlotItemList l = this->itemList(QwtPlotItem::Rtti_PlotCurve); for(int i = 0; i < l.size(); ++i) { QwtPlotItem *curve = l[i]; QVariant info = itemToInfo(curve); QWidget *w = legend->legendWidget(info); if(w && w->inherits("QwtLegendLabel")) ((QwtLegendLabel*)w)->setChecked(curve->isVisible()); } }
void Graph::showCurve(GraphCurve *curve, bool show) { showCurve(itemToInfo(curve), show, -1); }
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 }