本文整理汇总了C++中QwtLegendItem类的典型用法代码示例。如果您正苦于以下问题:C++ QwtLegendItem类的具体用法?C++ QwtLegendItem怎么用?C++ QwtLegendItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QwtLegendItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: legendItem
void QwtPlotItem::updateLegend(QwtLegend *legend) const
{
if ( !legend )
return;
QWidget *lgdItem = legend->find(this);
if ( testItemAttribute(QwtPlotItem::Legend) )
{
if ( lgdItem == NULL )
{
lgdItem = legendItem();
if ( lgdItem )
{
if ( lgdItem->inherits("QwtLegendItem") )
{
QwtLegendItem *label = (QwtLegendItem *)lgdItem;
label->setItemMode(legend->itemMode());
if ( d_data->plot )
{
QObject::connect(label, SIGNAL(clicked()),
d_data->plot, SLOT(legendItemClicked()));
QObject::connect(label, SIGNAL(checked(bool)),
d_data->plot, SLOT(legendItemChecked(bool)));
}
}
legend->insert(this, lgdItem);
}
示例2: 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);
}
示例3: showCurve
void MainWindow::showCurve(QwtPlotItem *item, bool on)
{
item->setVisible(on);
QwtLegendItem *legendItem = qobject_cast<QwtLegendItem*>(ui->plot->legend()->find(item));
if (legendItem) {
legendItem->setChecked(on);
}
}
示例4: sizeof
void MainWindow::sampleFormatChanged()
{
for (int i = 0; i < curves.size(); i++) {
curves[i].curve->detach();
delete curves[i].curve;
curves[i].data->clear();
delete curves[i].data;
}
curves.clear();
timeAxis.clear();
QList<sampleValue> sampleList = kwp.getSample();
int numSamples = settingsDialog->rate * settingsDialog->historySecs + 1;
timeAxis.clear();
for (int i = 0; i < numSamples; i++) {
timeAxis.prepend(-i / static_cast<double>(settingsDialog->rate));
}
int numColors = sizeof(colorList) / sizeof(QString);
for (int i = 0; i < sampleList.length(); i++) {
QwtPlotCurve* curve = new QwtPlotCurve;
QVector<double>* data = new QVector<double>();
data->reserve(numSamples+1);
data->fill(0, numSamples);
QColor curveColor;
curveColor.setNamedColor(colorList[i % numColors]);
int blockNum = sampleList.at(i).refs.at(0).blockNum;
int pos = sampleList.at(i).refs.at(0).pos;
blockLabels_t label = kwp.getBlockLabel(blockNum);
QString desc = label.desc[pos] + " " + label.subDesc[pos];
curve->setRenderHint(QwtPlotItem::RenderAntialiased);
curve->setPen(curveColor);
curve->setTitle(desc);
curve->setRawSamples(timeAxis.constData(), data->constData(), numSamples);
curve->attach(ui->plot);
// set legend checked
QwtLegendItem *legendItem = qobject_cast<QwtLegendItem*>(ui->plot->legend()->find(curve));
if (legendItem) {
legendItem->setChecked(true);
}
curveAndData tmp;
tmp.curve = curve;
tmp.data = data;
curves.append(tmp);
}
}
示例5: updateLegend
void PlotCurve::updateLegend(QwtLegend *legend) const
{
QwtPlotCurve::updateLegend(legend);
QwtLegendItem *pQwtLegendItem = dynamic_cast<QwtLegendItem*>(legend->find(this));
if (pQwtLegendItem)
{
pQwtLegendItem->setIdentifierMode(QwtLegendItem::ShowLine);
pQwtLegendItem->setIdentifierWidth(30);
}
QwtPlotItem::updateLegend(legend);
}
示例6: updateLegend
/*!
\brief Update the widget that represents the item on the legend
updateLegend() is called from itemChanged() to adopt the widget
representing the item on the legend to its new configuration.
The default implementation is made for QwtPolarCurve and updates a
QwtLegendItem(), but an item could be represented by any type of widget,
by overloading legendItem() and updateLegend().
\sa legendItem(), itemChanged(), QwtLegend()
*/
void QwtPolarItem::updateLegend( QwtLegend *legend ) const
{
if ( legend == NULL )
return;
QWidget *lgdItem = legend->find( this );
if ( testItemAttribute( QwtPolarItem::Legend ) )
{
if ( lgdItem == NULL )
{
lgdItem = legendItem();
if ( lgdItem )
legend->insert( this, lgdItem );
}
QwtLegendItem* label = qobject_cast<QwtLegendItem *>( lgdItem );
if ( label )
{
// paint the identifier
const QSize sz = label->identifierSize();
QPixmap identifier( sz.width(), sz.height() );
identifier.fill( Qt::transparent );
QPainter painter( &identifier );
painter.setRenderHint( QPainter::Antialiasing,
testRenderHint( QwtPolarItem::RenderAntialiased ) );
drawLegendIdentifier( &painter,
QRect( 0, 0, sz.width(), sz.height() ) );
painter.end();
const bool doUpdate = label->updatesEnabled();
if ( doUpdate )
label->setUpdatesEnabled( false );
label->setText( title() );
label->setIdentifier( identifier );
label->setItemMode( legend->itemMode() );
if ( doUpdate )
label->setUpdatesEnabled( true );
label->update();
}
}
else
{
if ( lgdItem )
{
lgdItem->hide();
lgdItem->deleteLater();
}
}
}
示例7: showCurve
//---------------------------------------------------------------------------
void JrkPlotDialog::showCurve(QwtPlotItem *item, bool on)
{
//qDebug("showCurve");
item->setVisible(on);
QwtLegendItem *legendItem =
qobject_cast<QwtLegendItem *>(ui->jrkPlot->legend()->find(item));
if(legendItem)
legendItem->setChecked(on);
//ui->jrkPlot->replot();
}
示例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: legendMenu
void Legend::legendMenu(const QPoint& pos)
{
QwtLegendItem *lgdItem = dynamic_cast<QwtLegendItem*>(childAt(pos));
if(lgdItem)
{
mLegendItemStr = lgdItem->text().text();
QMenu menu(mpPlot);
menu.addAction(mpChangeColorAction);
menu.addAction(mpAutomaticColorAction);
menu.addSeparator();
menu.addAction(mpHideAction);
menu.exec(mapToGlobal(pos));
}
}
示例10: legendItem
//! Update the widget that represents the curve on the legend
void QwtPolarCurve::updateLegend( QwtLegend *legend ) const
{
if ( legend && testItemAttribute( QwtPolarCurve::Legend )
&& ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol )
&& d_data->symbol
&& d_data->symbol->style() != QwtSymbol::NoSymbol )
{
QWidget *lgdItem = legend->find( this );
if ( lgdItem == NULL )
{
lgdItem = legendItem();
if ( lgdItem )
legend->insert( this, lgdItem );
}
QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem );
if ( l )
{
QSize sz = d_data->symbol->boundingSize();
sz += QSize( 2, 2 ); // margin
if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine )
{
// Avoid, that the line is completely covered by the symbol
int w = qCeil( 1.5 * sz.width() );
if ( w % 2 )
w++;
sz.setWidth( qMax( 8, w ) );
}
l->setIdentifierSize( sz );
}
}
QwtPolarItem::updateLegend( legend );
}
示例11: drawLegendIdentifier
/*!
\brief Update the widget that represents the item on the legend
\param legend Legend
\sa drawLegendIdentifier(), legendItem(), itemChanged(), QwtLegend()
*/
void QwtPlotCurve::updateLegend( QwtLegend *legend ) const
{
if ( legend && testItemAttribute( QwtPlotItem::Legend )
&& ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
&& d_data->symbol
&& d_data->symbol->style() != QwtSymbol::NoSymbol )
{
QWidget *lgdItem = legend->find( this );
if ( lgdItem == NULL )
{
lgdItem = legendItem();
if ( lgdItem )
legend->insert( this, lgdItem );
}
if ( lgdItem && lgdItem->inherits( "QwtLegendItem" ) )
{
QwtLegendItem *l = ( QwtLegendItem * )lgdItem;
l->setIdentifierSize( d_data->symbol->boundingSize() );
}
}
QwtPlotItem::updateLegend( legend );
}
示例12: legend
void QwtPlot::printLegend(QPainter *painter, const QRect &rect) const
{
if ( !legend() || legend()->isEmpty() )
return;
QLayout *l = legend()->contentsWidget()->layout();
if ( l == 0 || !l->inherits("QwtDynGridLayout") )
return;
QwtDynGridLayout *legendLayout = (QwtDynGridLayout *)l;
uint numCols = legendLayout->columnsForWidth(rect.width());
#if QT_VERSION < 0x040000
QValueList<QRect> itemRects =
legendLayout->layoutItems(rect, numCols);
#else
QList<QRect> itemRects =
legendLayout->layoutItems(rect, numCols);
#endif
int index = 0;
#if QT_VERSION < 0x040000
QLayoutIterator layoutIterator = legendLayout->iterator();
for ( QLayoutItem *item = layoutIterator.current();
item != 0; item = ++layoutIterator) {
#else
for ( int i = 0; i < legendLayout->count(); i++ ) {
QLayoutItem *item = legendLayout->itemAt(i);
#endif
QWidget *w = item->widget();
if ( w ) {
painter->save();
painter->setClipping(true);
QwtPainter::setClipRect(painter, itemRects[index]);
printLegendItem(painter, w, itemRects[index]);
index++;
painter->restore();
}
}
}
/*!
Print the legend item into a given rectangle.
\param painter Painter
\param w Widget representing a legend item
\param rect Bounding rectangle
*/
void QwtPlot::printLegendItem(QPainter *painter,
const QWidget *w, const QRect &rect) const
{
if ( w->inherits("QwtLegendItem") ) {
QwtLegendItem *item = (QwtLegendItem *)w;
painter->setFont(item->font());
item->drawItem(painter, rect);
}
}
/*!
\brief Paint a scale into a given rectangle.
Paint the scale into a given rectangle.
\param painter Painter
\param axisId Axis
\param startDist Start border distance
\param endDist End border distance
\param baseDist Base distance
\param rect Bounding rectangle
*/
void QwtPlot::printScale(QPainter *painter,
int axisId, int startDist, int endDist, int baseDist,
const QRect &rect) const
{
if (!axisEnabled(axisId))
return;
const QwtScaleWidget *scaleWidget = axisWidget(axisId);
if ( scaleWidget->isColorBarEnabled()
&& scaleWidget->colorBarWidth() > 0) {
const QwtMetricsMap map = QwtPainter::metricsMap();
QRect r = map.layoutToScreen(rect);
r.setWidth(r.width() - 1);
r.setHeight(r.height() - 1);
scaleWidget->drawColorBar(painter, scaleWidget->colorBarRect(r));
const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing();
if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal )
baseDist += map.screenToLayoutY(off);
else
baseDist += map.screenToLayoutX(off);
}
//.........这里部分代码省略.........
示例13: legend
void QwtPolarPlot::renderLegend( QPainter *painter, const QRect &rect ) const
{
#if 1
// Shift this code into QwtLegend, so that Qwt/QwtPolar can share it
#endif
if ( !legend() || legend()->isEmpty() )
return;
QLayout *l = legend()->contentsWidget()->layout();
if ( l == 0 || !l->inherits( "QwtDynGridLayout" ) )
return;
QwtDynGridLayout *legendLayout = ( QwtDynGridLayout * )l;
uint numCols = legendLayout->columnsForWidth( rect.width() );
#if QT_VERSION < 0x040000
QValueList<QRect> itemRects =
legendLayout->layoutItems( rect, numCols );
#else
QList<QRect> itemRects =
legendLayout->layoutItems( rect, numCols );
#endif
int index = 0;
#if QT_VERSION < 0x040000
QLayoutIterator layoutIterator = legendLayout->iterator();
for ( QLayoutItem *item = layoutIterator.current();
item != 0; item = ++layoutIterator )
{
#else
for ( int i = 0; i < legendLayout->count(); i++ )
{
QLayoutItem *item = legendLayout->itemAt( i );
#endif
QWidget *w = item->widget();
if ( w )
{
painter->save();
painter->setClipping( true );
QwtPainter::setClipRect( painter, itemRects[index] );
renderLegendItem( painter, w, itemRects[index] );
index++;
painter->restore();
}
}
}
/*!
Render the legend item into a given rectangle.
\param painter Painter
\param w Widget representing a legend item
\param rect Bounding rectangle
*/
void QwtPolarPlot::renderLegendItem( QPainter *painter,
const QWidget *w, const QRect &rect ) const
{
#if 1
// Shift this code into QwtLegend, so that Qwt/QwtPolar can share it
#endif
if ( w->inherits( "QwtLegendItem" ) )
{
QwtLegendItem *item = ( QwtLegendItem * )w;
painter->setFont( item->font() );
item->drawItem( painter, rect );
}
}
示例14: QPen
//! Update the widget that represents the curve on the legend
// this was adapted from QwtPlotCurve::updateLegend()
void HistogramItem::updateLegend( QwtLegend *legend ) const
{
if ( !legend )
return;
QwtPlotItem::updateLegend( legend );
QWidget *widget = legend->find( this );
if ( !widget || !widget->inherits( "QwtLegendItem" ) )
return;
QwtLegendItem *legendItem = ( QwtLegendItem * )widget;
const bool doUpdate = legendItem->updatesEnabled();
legendItem->setUpdatesEnabled( false );
const int policy = legend->displayPolicy();
if ( policy == QwtLegend::FixedIdentifier )
{
int mode = legend->identifierMode();
legendItem->setCurvePen( QPen( color() ) );
if ( mode & QwtLegendItem::ShowText )
legendItem->setText( title() );
else
legendItem->setText( QwtText() );
legendItem->setIdentifierMode( mode );
}
else if ( policy == QwtLegend::AutoIdentifier )
{
int mode = 0;
legendItem->setCurvePen( QPen( color() ) );
mode |= QwtLegendItem::ShowLine;
if ( !title().isEmpty() )
{
legendItem->setText( title() );
mode |= QwtLegendItem::ShowText;
}
else
{
legendItem->setText( QwtText() );
}
legendItem->setIdentifierMode( mode );
}
legendItem->setUpdatesEnabled( doUpdate );
legendItem->update();
}
示例15: if
//! Update the widget that represents the curve on the legend
void QwtPlotCurve::updateLegend(QwtLegend *legend) const
{
if ( !legend )
return;
QwtPlotItem::updateLegend(legend);
QWidget *widget = legend->find(this);
if ( !widget || !widget->inherits("QwtLegendItem") )
return;
QwtLegendItem *legendItem = (QwtLegendItem *)widget;
#if QT_VERSION < 0x040000
const bool doUpdate = legendItem->isUpdatesEnabled();
#else
const bool doUpdate = legendItem->updatesEnabled();
#endif
legendItem->setUpdatesEnabled(false);
const int policy = legend->displayPolicy();
if (policy == QwtLegend::FixedIdentifier)
{
int mode = legend->identifierMode();
if (mode & QwtLegendItem::ShowLine)
legendItem->setCurvePen(pen());
if (mode & QwtLegendItem::ShowSymbol)
legendItem->setSymbol(symbol());
if (mode & QwtLegendItem::ShowText)
legendItem->setText(title());
else
legendItem->setText(QwtText());
legendItem->setIdentifierMode(mode);
}
else if (policy == QwtLegend::AutoIdentifier)
{
int mode = 0;
if (QwtPlotCurve::NoCurve != style())
{
legendItem->setCurvePen(pen());
mode |= QwtLegendItem::ShowLine;
}
if (QwtSymbol::NoSymbol != symbol().style())
{
legendItem->setSymbol(symbol());
mode |= QwtLegendItem::ShowSymbol;
}
if ( !title().isEmpty() )
{
legendItem->setText(title());
mode |= QwtLegendItem::ShowText;
}
else
{
legendItem->setText(QwtText());
}
legendItem->setIdentifierMode(mode);
}
legendItem->setUpdatesEnabled(doUpdate);
legendItem->update();
}