本文整理汇总了C++中QwtLegend类的典型用法代码示例。如果您正苦于以下问题:C++ QwtLegend类的具体用法?C++ QwtLegend怎么用?C++ QwtLegend使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QwtLegend类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderLegend
void QwtPolarRenderer::renderLegend(
QPainter *painter, const QRectF &rect ) const
{
QwtLegend *legend = d_data->plot->legend();
if ( legend == NULL || legend->isEmpty() )
return;
const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>(
legend->contentsWidget()->layout() );
if ( legendLayout == NULL )
return;
uint numCols = legendLayout->columnsForWidth( rect.width() );
const QList<QRect> itemRects =
legendLayout->layoutItems( rect.toRect(), numCols );
int index = 0;
for ( int i = 0; i < legendLayout->count(); i++ )
{
QLayoutItem *item = legendLayout->itemAt( i );
QWidget *w = item->widget();
if ( w )
{
painter->save();
painter->setClipRect( itemRects[index] );
renderLegendItem( painter, w, itemRects[index] );
index++;
painter->restore();
}
}
}
示例2: connect
void MainWindow::setupPlot()
{
plotTimer.setInterval(1000/settingsDialog->rate);
connect(&plotTimer, SIGNAL(timeout()), this, SLOT(plotUpdate()));
plotTimer.start();
if (!ui->plot->legend()) {
QwtLegend* legend = new QwtLegend;
legend->setItemMode(QwtLegend::CheckableItem);
ui->plot->insertLegend(legend, QwtPlot::RightLegend);
}
ui->plot->setAxisTitle(QwtPlot::xBottom, "seconds");
ui->plot->setCanvasBackground(Qt::white);
QColor gridColor;
gridColor.setNamedColor("grey");
QPen gridPen(gridColor);
gridPen.setStyle(Qt::DotLine);
QwtPlotGrid* grid = new QwtPlotGrid;
grid->setMajPen(gridPen);
grid->attach(ui->plot);
connect(ui->plot, SIGNAL(legendChecked(QwtPlotItem*,bool)), this, SLOT(showCurve(QwtPlotItem*,bool)));
}
示例3: QwtPlot
CopasiPlot::CopasiPlot(const CPlotSpecification* plotspec, QWidget* parent):
QwtPlot(parent),
mCurves(0),
mCurveMap(),
mDataBefore(0),
mDataDuring(0),
mDataAfter(0),
mHaveBefore(false),
mHaveDuring(false),
mHaveAfter(false),
mpPlotSpecification(NULL),
mNextPlotTime(),
mIgnoreUpdate(false),
mpZoomer(NULL),
mReplotFinished(false)
{
QwtLegend *legend = new QwtLegend;
legend->setItemMode(QwtLegend::CheckableItem);
// whole legend can not be displayed at bottom on DARWIN
// maybe a Qwt bug ?!?
#ifdef Darwin
insertLegend(legend, QwtPlot::TopLegend);
#else
insertLegend(legend, QwtPlot::BottomLegend);
#endif
// Set up the zoom facility
mpZoomer = new ScrollZoomer(canvas());
mpZoomer->setRubberBandPen(QColor(Qt::black));
mpZoomer->setTrackerPen(QColor(Qt::black));
mpZoomer->setTrackerMode(QwtPicker::AlwaysOn);
mpZoomer->setTrackerFont(this->font());
// white background better for printing...
setCanvasBackground(Qt::white);
// setTitle(FROM_UTF8(plotspec->getTitle()));
setCanvasLineWidth(0);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
SLOT(showCurve(QwtPlotItem *, bool)));
// Size the vectors to be able to store information for all activities.
mData.resize(ActivitySize);
mObjectValues.resize(ActivitySize);
mObjectInteger.resize(ActivitySize);
mDataSize.resize(ActivitySize);
mDataIndex.clear();
// Initialize from the plot specification
initFromSpec(plotspec);
connect(this, SIGNAL(replotSignal()), this, SLOT(replot()));
}
示例4: tracking
void GenericHistogramView::init()
{
this->setMouseTracking(true); //Switch on mouse tracking (no need to press button)
_qwtPlot->setTitle("Histogram");
_qwtPlot->setCanvasBackground(QColor(Qt::gray));
_qwtPlot->plotLayout()->setAlignCanvasToScales(true);
_qwtPlot->setAxisTitle(QwtPlot::yLeft, "Number of specimen");
_qwtPlot->setAxisTitle(QwtPlot::xBottom, "Pixel value");
QwtLegend* legend = new QwtLegend();
legend->setItemMode(QwtLegend::CheckableItem);
_qwtPlot->insertLegend(legend, QwtPlot::RightLegend);
populate();
_qwtPlot->canvas()->setMouseTracking(true);
if(_horizontal)
_principalPicker = new HistogramPicker(QwtPlotPicker::HLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
else
_principalPicker = new HistogramPicker(QwtPlotPicker::VLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
_principalPicker->setStateMachine(new QwtPickerDragPointMachine());
_principalPicker->setTrackerPen(QColor(Qt::white));
_principalPicker->setRubberBandPen(QColor(Qt::yellow));
_leftPicker = new HistogramPicker(_qwtPlot->canvas());
_leftPicker->setStateMachine(new QwtPickerDragPointMachine());
_rightPicker = new HistogramPicker(_qwtPlot->canvas());
_rightPicker->setStateMachine(new QwtPickerDragPointMachine());
_rightPicker->setRubberBand(QwtPlotPicker::VLineRubberBand);
_rightPicker->setRubberBandPen(QColor(Qt::yellow));
_rightPicker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton);
connect(_qwtPlot, SIGNAL(legendChecked(QwtPlotItem*, bool)), this, SLOT(showItem(QwtPlotItem*, bool)));
connect(_rightPicker, SIGNAL(selected(const QPointF&)), this, SLOT(rightClick(const QPointF&)));
connect(_leftPicker, SIGNAL(selected(const QPointF&)), this, SLOT(leftClick(const QPointF&)));
connect(_principalPicker, SIGNAL(moved(const QPointF&)), this, SLOT(move(const QPointF&)));
_qwtPlot->replot(); // creating the legend items
QwtPlotItemList items = _qwtPlot->itemList(QwtPlotItem::Rtti_PlotHistogram);
for(int i = 0; i < items.size(); i++)
{
QwtLegendItem* legendItem = qobject_cast<QwtLegendItem*>(legend->find(items[i]));
if(legendItem)
legendItem->setChecked(true);
items[i]->setVisible(true);
}
_qwtPlot->setAutoReplot(true);
}
示例5: curve
/*
void MyPlot2D::toggleCurve(long curveId) {
QwtPlotCurve *c = curve(curveId);
if ( c ) {
c->setEnabled(!c->enabled());
replot();
}
}
*/
void MyPlot2D::enableLegend(bool value) {
if (value) {
// legend
QwtLegend *legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
this->insertLegend(legend, QwtPlot::RightLegend);
}
else {
this->insertLegend(NULL);
}
replot();
}
示例6: QwtPlot
MavPlot::MavPlot(QWidget *parent) : QwtPlot(parent), _havePrintColors(false) {
setAutoReplot(false);
setTitle("MAV System Data Plot");
setCanvasBackground(QColor(Qt::darkGray));
// legend
QwtLegend *legend = new QwtLegend;
insertLegend(legend, QwtPlot::BottomLegend);
#if (QWT_VERSION < QWT_VERSION_CHECK(6,1,0))
legend->setItemMode(QwtLegend::ClickableItem);
connect(this, SIGNAL(legendClicked(QwtPlotItem*)), SLOT(legendClicked(QwtPlotItem*)));
#else
legend->setDefaultItemMode(QwtLegendData::Clickable);
connect(legend, SIGNAL(clicked(const QVariant&, int)), SLOT(legendClickedNew(const QVariant&, int)));
#endif
// grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
#if (QWT_VERSION < QWT_VERSION_CHECK(6,1,0))
grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
grid->setMinPen(QPen(QColor(0x8, 0x8, 0x8), 0 , Qt::DotLine));
#else
grid->setMajorPen(QPen(Qt::gray, 0, Qt::DotLine));
grid->setMinorPen(QPen(QColor(0x8, 0x8, 0x8), 0 , Qt::DotLine));
#endif
grid->attach(this);
// axes
//enableAxis(QwtPlot::yRight);
setAxisTitle(QwtPlot::xBottom, "time");
setAxisScaleDraw(QwtPlot::xBottom, new HumanReadableTime()); // no need to de-alloc or store, plot does it
// A-B markers
for (int i=0; i<2; i++) {
_user_markers[i].setLineStyle(QwtPlotMarker::VLine);
_user_markers[i].setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
_user_markers[i].setLinePen(QPen(QColor(255, 140, 0), 0, Qt::SolidLine));
_user_markers_visible[i] = false;
}
_user_markers[0].setLabel(QwtText("A"));
_user_markers[1].setLabel(QwtText("B"));
// data marker
_data_marker.setLineStyle(QwtPlotMarker::VLine);
_data_marker.setLinePen(QPen(QColor(255, 160, 47), 2, Qt::SolidLine));
_data_marker.setLabel(QwtText("data"));
_data_marker.setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
_data_marker_visible = false;
_data_marker.setZ(9999); // higher value -> paint on top of everything else
setAutoReplot(true);
}
示例7: QwtPlot
QTabWidget* ResultsPage::createDataTabWidget()
{
QTabWidget *tabWidget = new QTabWidget;
// Plot
m_plot = new QwtPlot(tabWidget);
m_plot->setCanvasBackground(Qt::white);
m_plot->setContextMenuPolicy(Qt::CustomContextMenu);
m_plot->setAutoReplot(false);
connect(m_plot, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(showPlotContextMenu(QPoint)));
// Picker to allow for selection of the closest curve and displays curve
// coordinates with a cross rubber band.
QwtPlotPicker *picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPicker::CrossRubberBand, QwtPicker::ActiveOnly,
m_plot->canvas());
picker->setStateMachine(new QwtPickerDragPointMachine());
connect(picker, SIGNAL(appended(QPoint)), this, SLOT(pointSelected(QPoint)));
// Legend
QwtLegend* legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
m_plot->insertLegend(legend, QwtPlot::BottomLegend);
#if QWT_VERSION >= 0x060100
connect(m_plot,
SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)),
legend,
SLOT(updateLegend(QVariant,QList<QwtLegendData>)));
#endif
// Add the generic curves to the legend
QList<QPair<QString, Qt::GlobalColor> > pairs;
pairs << qMakePair(tr("Unselected Realization"), Qt::darkGray)
<< qMakePair(tr("Selected and Enabled Realization"), Qt::darkGreen)
<< qMakePair(tr("Selected and Disabled Realization"), Qt::darkRed);
QPair<QString, Qt::GlobalColor> pair;
foreach (pair, pairs) {
QwtPlotCurve *curve = new QwtPlotCurve(pair.first);
curve->setLegendIconSize(QSize(32, 8));
curve->setPen(QPen(QBrush(pair.second), 2));
curve->setLegendAttribute(QwtPlotCurve::LegendShowLine);
#if QWT_VERSION < 0x060100
curve->updateLegend(legend);
#else
m_plot->updateLegend(curve);
#endif
}
示例8: plot
void LineChart::setTooltip(QString t)
{
tooltip = t;
QwtPlot *p = plot();
if (p == NULL)
return;
QwtLegend *l = p->legend();
if (l == NULL)
return;
QwtLegendItem *legendItem = (QwtLegendItem *)l->find(this);
if (legendItem != NULL)
legendItem->setToolTip(tooltip);
}
示例9: QwtPlot
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 );
}
示例10: legend
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();
}
示例11: insertLegend
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());
}
}
示例12: QwtPlot
PlotWidget::PlotWidget(QWidget *parent) :
QwtPlot(parent),
ui(new Ui::PlotWidget)
{
ui->setupUi(this);
// Setup plot stuff
setAutoReplot(false);
canvas()->setBorderRadius( 10 );
plotLayout()->setAlignCanvasToScales(true);
QwtLegend *legend = new QwtLegend;
legend->setItemMode(QwtLegend::CheckableItem);
insertLegend(legend, QwtPlot::RightLegend);
setAxisTitle(QwtPlot::xBottom, " Time [s]");
setAxisScaleDraw(QwtPlot::xBottom,
new QwtScaleDraw());
setAxisAutoScale(QwtPlot::xBottom, false);
setAxisScale(QwtPlot::xBottom, 0, Market::EXPERIMENT_RUNNING_TIME);
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
setAxisTitle(QwtPlot::yLeft, " Price [$]");
setAxisScaleDraw(QwtPlot::yLeft,
new QwtScaleDraw());
setAxisScale(QwtPlot::yLeft, 0, MAX_PRICE_PLOT);
setAxisLabelRotation(QwtPlot::yLeft, -50.0);
setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignLeft | Qt::AlignBottom);
// Setup the data
asset1Data = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4); // Running time, /2 for data every 2 seconds, + a safety buffer
asset2Data = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4);
timeData = new CircularBuffer((Market::EXPERIMENT_RUNNING_TIME)/2 + 4);
asset1Curve = new QwtPlotCurve("Asset 1");
asset1Curve->setPen(QPen(Qt::red));
asset1Curve->attach(this);
asset2Curve = new QwtPlotCurve("Asset 2");
asset2Curve->setPen(QPen(Qt::blue));
asset2Curve->attach(this);
}
示例13: QwtPlot
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
setTitle( "Trading Chart" );
QwtDateScaleDraw *scaleDraw = new DateScaleDraw( Qt::UTC );
QwtDateScaleEngine *scaleEngine = new QwtDateScaleEngine( Qt::UTC );
setAxisTitle( QwtPlot::xBottom, QString( "2010" ) );
setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
setAxisTitle( QwtPlot::yLeft, QString( "Price [EUR]" ) );
#if 0
QwtLegend *legend = new QwtLegend;
legend->setDefaultItemMode( QwtLegendData::Checkable );
insertLegend( legend, QwtPlot::RightLegend );
#else
Legend *legend = new Legend;
insertLegend( legend, QwtPlot::RightLegend );
#endif
populate();
// LeftButton for the zooming
// MidButton for the panning
// RightButton: zoom out by 1
// Ctrl+RighButton: zoom out to full size
Zoomer* zoomer = new Zoomer( canvas() );
zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier );
zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
Qt::RightButton );
QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
panner->setMouseButton( Qt::MidButton );
connect( legend, SIGNAL( checked( QwtPlotItem *, bool, int ) ),
SLOT( showItem( QwtPlotItem *, bool ) ) );
}
示例14: QWidget
PowerBarHistoryPlot::PowerBarHistoryPlot(double defaultTime, double defaultPowerLevel, QWidget* parent)
: QWidget(parent)
, m_overalTime(0.0)
, m_lastSampleTime(0.0)
, m_firstTime(true)
, m_defaultTime(defaultTime)
, m_defaultPowerLevel(defaultPowerLevel)
, m_powerAxisMax(defaultPowerLevel)
, m_powerAxisMin(-1*defaultPowerLevel)
, m_timeAxisMax(defaultTime)
{
m_plot = new QwtPlot();
m_plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_plot->setAxisScale(QwtPlot::xBottom, 0, defaultTime, defaultTime/20.0);
m_plot->setAxisScale(QwtPlot::yLeft, -1 * defaultPowerLevel, defaultPowerLevel, defaultPowerLevel/2.0);
m_plot->setAxisAutoScale(QwtPlot::xBottom, false);
m_plot->setCanvasBackground(QBrush(Qt::white));
m_plot->setAxisTitle(QwtPlot::xBottom, tr(TIME_AXIS_NAME));
m_plot->setAxisTitle(QwtPlot::yLeft, tr(POWER_AXIS_NAME));
// legend
QwtLegend *legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
m_plot->insertLegend(legend, QwtPlot::BottomLegend);
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableX(false);
grid->enableYMin(true);
grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::transparent, 0 , Qt::NoPen));
grid->attach(m_plot);
setupCurves();
QHBoxLayout* historyPlotlayout = new QHBoxLayout;
historyPlotlayout->addWidget(m_plot);
historyPlotlayout->setSpacing(0);
setColors(Qt::blue, Qt::red);
setLayout(historyPlotlayout);
}
示例15: QDialog
BatteryHistoryDialog::BatteryHistoryDialog (int histSize, QWidget *parent)
: QDialog (parent)
, Percent_ (new QwtPlotCurve (tr ("Percentage")))
, Energy_ (new QwtPlotCurve (tr ("Energy rate")))
{
Ui_.setupUi (this);
Ui_.PercentPlot_->setAxisAutoScale (QwtPlot::xBottom, false);
Ui_.PercentPlot_->setAxisAutoScale (QwtPlot::yLeft, false);
Ui_.PercentPlot_->setAxisScale (QwtPlot::xBottom, 0, histSize);
Ui_.PercentPlot_->setAxisScale (QwtPlot::yLeft, 0, 100);
Ui_.PercentPlot_->enableAxis (QwtPlot::yRight);
Ui_.PercentPlot_->setAxisTitle (QwtPlot::yLeft, tr ("Percent"));
Ui_.PercentPlot_->setAxisTitle (QwtPlot::yRight, tr ("Energy rate, W"));
QColor percentColor (Qt::blue);
Percent_->setPen (QPen (percentColor));
percentColor.setAlpha (20);
Percent_->setBrush (percentColor);
Percent_->setRenderHint (QwtPlotItem::RenderAntialiased);
Percent_->attach (Ui_.PercentPlot_);
QColor energyColor (Qt::red);
Energy_->setPen (QPen (energyColor));
energyColor.setAlpha (20);
Energy_->setBrush (energyColor);
Energy_->setRenderHint (QwtPlotItem::RenderAntialiased);
Energy_->setYAxis (QwtPlot::yRight);
Energy_->attach (Ui_.PercentPlot_);
QwtLegend *legend = new QwtLegend;
legend->setItemMode (QwtLegend::ClickableItem);
Ui_.PercentPlot_->insertLegend (legend, QwtPlot::BottomLegend);
}