The legend widget. More...
#include <qwt_legend.h>
Classes | |
class | PrivateData |
Public Types | |
enum | LegendDisplayPolicy { NoIdentifier = 0, FixedIdentifier = 1, AutoIdentifier = 2 } |
Display policy. More... | |
enum | LegendItemMode { ReadOnlyItem, ClickableItem, CheckableItem } |
Interaction mode for the legend items. More... | |
Public Member Functions | |
QwtLegend (QWidget *parent=NULL) | |
virtual | ~QwtLegend () |
Destructor. | |
void | setDisplayPolicy (LegendDisplayPolicy policy, int mode) |
LegendDisplayPolicy | displayPolicy () const |
void | setItemMode (LegendItemMode) |
LegendItemMode | itemMode () const |
int | identifierMode () const |
QWidget * | contentsWidget () |
const QWidget * | contentsWidget () const |
void | insert (const QwtLegendItemManager *, QWidget *) |
void | remove (const QwtLegendItemManager *) |
QWidget * | find (const QwtLegendItemManager *) const |
QwtLegendItemManager * | find (const QWidget *) const |
virtual QValueList< QWidget * > | legendItems () const |
Return a list of all legend items. | |
void | clear () |
Remove all items. | |
bool | isEmpty () const |
Return true, if there are no legend items. | |
uint | itemCount () const |
Return the number of legend items. | |
virtual bool | eventFilter (QObject *, QEvent *) |
virtual QSize | sizeHint () const |
Return a size hint. | |
virtual int | heightForWidth (int w) const |
QScrollBar * | horizontalScrollBar () const |
QScrollBar * | verticalScrollBar () const |
Protected Member Functions | |
virtual void | resizeEvent (QResizeEvent *) |
virtual void | layoutContents () |
The legend widget.
The QwtLegend widget is a tabular arrangement of legend items. Legend items might be any type of widget, but in general they will be a QwtLegendItem.
Definition at line 36 of file qwt_legend.h.
Display policy.
Default is AutoIdentifier.
Definition at line 62 of file qwt_legend.h.
{ NoIdentifier = 0, FixedIdentifier = 1, AutoIdentifier = 2 };
Interaction mode for the legend items.
Default is ReadOnlyItem.
Definition at line 87 of file qwt_legend.h.
QwtLegend::QwtLegend | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructor
parent | Parent widget |
Definition at line 260 of file qwt_legend.cpp.
References AutoIdentifier, QwtLegend::PrivateData::displayPolicy, QwtLegend::PrivateData::identifierMode, QwtLegend::PrivateData::itemMode, ReadOnlyItem, QwtLegendItem::ShowLine, QwtLegendItem::ShowSymbol, QwtLegendItem::ShowText, and QwtLegend::PrivateData::view.
: QFrame(parent) { setFrameStyle(NoFrame); d_data = new QwtLegend::PrivateData; d_data->itemMode = QwtLegend::ReadOnlyItem; d_data->displayPolicy = QwtLegend::AutoIdentifier; d_data->identifierMode = QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText; d_data->view = new QwtLegend::PrivateData::LegendView(this); d_data->view->setFrameStyle(NoFrame); QwtDynGridLayout *layout = new QwtDynGridLayout( d_data->view->contentsWidget); #if QT_VERSION < 0x040000 layout->setAutoAdd(true); #endif layout->setAlignment(Qt::AlignHCenter | Qt::AlignTop); d_data->view->contentsWidget->installEventFilter(this); }
QwtLegend::~QwtLegend | ( | ) | [virtual] |
void QwtLegend::clear | ( | ) |
Remove all items.
Definition at line 500 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
{ #if QT_VERSION < 0x040000 bool doUpdate = isUpdatesEnabled(); #else bool doUpdate = updatesEnabled(); #endif setUpdatesEnabled(false); d_data->map.clear(); setUpdatesEnabled(doUpdate); update(); }
QWidget * QwtLegend::contentsWidget | ( | ) |
The contents widget is the only child of the viewport() and the parent widget of all legend items.
Definition at line 358 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
Referenced by insert(), and QwtPlot::printLegend().
{ return d_data->view->contentsWidget; }
const QWidget * QwtLegend::contentsWidget | ( | ) | const |
The contents widget is the only child of the viewport() and the parent widget of all legend items.
Definition at line 385 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
{ return d_data->view->contentsWidget; }
QwtLegend::LegendDisplayPolicy QwtLegend::displayPolicy | ( | ) | const |
Definition at line 326 of file qwt_legend.cpp.
References QwtLegend::PrivateData::displayPolicy.
Referenced by QwtPlotCurve::updateLegend().
{ return d_data->displayPolicy; }
bool QwtLegend::eventFilter | ( | QObject * | o, |
QEvent * | e | ||
) | [virtual] |
Filter layout related events of QwtLegend::contentsWidget().
o | Object to be filtered |
e | Event |
Definition at line 587 of file qwt_legend.cpp.
References layoutContents(), QwtLegend::PrivateData::map, and QwtLegend::PrivateData::view.
{ if ( o == d_data->view->contentsWidget ) { switch(e->type()) { case QEvent::ChildRemoved: { const QChildEvent *ce = (const QChildEvent *)e; if ( ce->child()->isWidgetType() ) d_data->map.remove((QWidget *)ce->child()); break; } #if QT_VERSION < 0x040000 case QEvent::LayoutHint: #else case QEvent::LayoutRequest: #endif { layoutContents(); break; } #if QT_VERSION < 0x040000 case QEvent::Resize: { updateGeometry(); break; } #endif default: break; } } return QFrame::eventFilter(o, e); }
QWidget * QwtLegend::find | ( | const QwtLegendItemManager * | plotItem ) | const |
Find the widget that represents a plot item
plotItem | Plot item |
Definition at line 470 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
Referenced by QwtPlotItem::attach(), QwtPlotPrintFilter::reset(), QwtPlotItem::updateLegend(), and QwtPlotCurve::updateLegend().
{ return d_data->map.find(plotItem); }
QwtLegendItemManager * QwtLegend::find | ( | const QWidget * | legendItem ) | const |
Find the widget that represents a plot item
legendItem | Legend item |
Definition at line 481 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
{ return d_data->map.find(legendItem); }
int QwtLegend::heightForWidth | ( | int | width ) | const [virtual] |
width | Width |
Definition at line 528 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
Referenced by QwtPlotLayout::LayoutData::init(), and QwtPlotLayout::minimumSizeHint().
{ width -= 2 * frameWidth(); int h = d_data->view->contentsWidget->heightForWidth(width); #if QT_VERSION < 0x040000 // Asking the layout is the default implementation in Qt4 if ( h <= 0 ) { QLayout *l = d_data->view->contentsWidget->layout(); if ( l && l->hasHeightForWidth() ) h = l->heightForWidth(width); } #endif if ( h >= 0 ) h += 2 * frameWidth(); return h; }
QScrollBar * QwtLegend::horizontalScrollBar | ( | ) | const |
Definition at line 367 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
Referenced by QwtPlotLayout::LayoutData::init().
{ return d_data->view->horizontalScrollBar(); }
int QwtLegend::identifierMode | ( | ) | const |
Default is ShowLine | ShowSymbol | ShowText.
Definition at line 349 of file qwt_legend.cpp.
References QwtLegend::PrivateData::identifierMode.
Referenced by QwtPlotCurve::updateLegend().
{ return d_data->identifierMode; }
void QwtLegend::insert | ( | const QwtLegendItemManager * | plotItem, |
QWidget * | legendItem | ||
) |
Insert a new item for a plot item
plotItem | Plot item |
legendItem | New legend item |
Definition at line 396 of file qwt_legend.cpp.
References contentsWidget(), layoutContents(), QwtLegend::PrivateData::map, and QwtLegend::PrivateData::view.
Referenced by QwtPlotItem::updateLegend().
{ if ( legendItem == NULL || plotItem == NULL ) return; QWidget *contentsWidget = d_data->view->contentsWidget; if ( legendItem->parent() != contentsWidget ) { #if QT_VERSION >= 0x040000 legendItem->setParent(contentsWidget); #else legendItem->reparent(contentsWidget, QPoint(0, 0)); #endif } legendItem->show(); d_data->map.insert(plotItem, legendItem); layoutContents(); if ( contentsWidget->layout() ) { #if QT_VERSION >= 0x040000 contentsWidget->layout()->addWidget(legendItem); #endif // set tab focus chain QWidget *w = NULL; #if QT_VERSION < 0x040000 QLayoutIterator layoutIterator = contentsWidget->layout()->iterator(); for ( QLayoutItem *item = layoutIterator.current(); item != 0; item = ++layoutIterator) { #else for (int i = 0; i < contentsWidget->layout()->count(); i++) { QLayoutItem *item = contentsWidget->layout()->itemAt(i); #endif if ( w && item->widget() ) { QWidget::setTabOrder(w, item->widget()); w = item->widget(); } } } if ( parentWidget() && parentWidget()->layout() == NULL ) { /* updateGeometry() doesn't post LayoutRequest in certain situations, like when we are hidden. But we want the parent widget notified, so it can show/hide the legend depending on its items. */ #if QT_VERSION < 0x040000 QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutHint)); #else QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); #endif } }
bool QwtLegend::isEmpty | ( | ) | const |
Return true, if there are no legend items.
Definition at line 626 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
Referenced by QwtPlotLayout::activate(), QwtPlotLayout::minimumSizeHint(), and QwtPlot::print().
{ return d_data->map.count() == 0; }
uint QwtLegend::itemCount | ( | ) | const |
Return the number of legend items.
Definition at line 632 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
{ return d_data->map.count(); }
QwtLegend::LegendItemMode QwtLegend::itemMode | ( | ) | const |
Definition at line 338 of file qwt_legend.cpp.
References QwtLegend::PrivateData::itemMode.
Referenced by QwtPlotItem::updateLegend().
{ return d_data->itemMode; }
void QwtLegend::layoutContents | ( | ) | [protected, virtual] |
Adjust contents widget and item layout to the size of the viewport().
Definition at line 553 of file qwt_legend.cpp.
References QwtDynGridLayout::heightForWidth(), int(), QwtDynGridLayout::maxItemWidth(), qwtMax, and QwtLegend::PrivateData::view.
Referenced by eventFilter(), and insert().
{ const QSize visibleSize = d_data->view->viewport()->size(); const QLayout *l = d_data->view->contentsWidget->layout(); if ( l && l->inherits("QwtDynGridLayout") ) { const QwtDynGridLayout *tl = (const QwtDynGridLayout *)l; const int minW = int(tl->maxItemWidth()) + 2 * tl->margin(); int w = qwtMax(visibleSize.width(), minW); int h = qwtMax(tl->heightForWidth(w), visibleSize.height()); const int vpWidth = d_data->view->viewportSize(w, h).width(); if ( w > vpWidth ) { w = qwtMax(vpWidth, minW); h = qwtMax(tl->heightForWidth(w), visibleSize.height()); } d_data->view->contentsWidget->resize(w, h); #if QT_VERSION < 0x040000 d_data->view->resizeContents(w, h); #endif } }
QValueList< QWidget * > QwtLegend::legendItems | ( | ) | const [virtual] |
Return a list of all legend items.
Definition at line 639 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().
{ const QMap<QWidget *, const QwtLegendItemManager *> &map = d_data->map.widgetMap(); #if QT_VERSION < 0x040000 QValueList<QWidget *> list; #else QList<QWidget *> list; #endif QMap<QWidget *, const QwtLegendItemManager *>::const_iterator it; for ( it = map.begin(); it != map.end(); ++it ) list += it.key(); return list; }
void QwtLegend::remove | ( | const QwtLegendItemManager * | plotItem ) |
Find the corresponding item for a plotItem and remove it from the item list.
plotItem | Plot item |
Definition at line 492 of file qwt_legend.cpp.
References QwtLegend::PrivateData::map.
void QwtLegend::resizeEvent | ( | QResizeEvent * | e ) | [protected, virtual] |
Resize event
e | Resize event |
Definition at line 664 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
{ QFrame::resizeEvent(e); d_data->view->setGeometry(contentsRect()); }
void QwtLegend::setDisplayPolicy | ( | LegendDisplayPolicy | policy, |
int | mode | ||
) |
Set the legend display policy to:
policy | Legend display policy |
mode | Identifier mode (or'd ShowLine, ShowSymbol, ShowText) |
Definition at line 298 of file qwt_legend.cpp.
References QwtLegend::PrivateData::displayPolicy, QwtLegend::PrivateData::identifierMode, QwtLegend::PrivateData::map, and QwtLegendItemManager::updateLegend().
{ d_data->displayPolicy = policy; if (-1 != mode) d_data->identifierMode = mode; QMap<QWidget *, const QwtLegendItemManager *> &map = d_data->map.widgetMap(); QMap<QWidget *, const QwtLegendItemManager *>::iterator it; for ( it = map.begin(); it != map.end(); ++it ) { #if QT_VERSION < 0x040000 QwtLegendItemManager *item = (QwtLegendItemManager *)it.data(); #else QwtLegendItemManager *item = (QwtLegendItemManager *)it.value(); #endif if ( item ) item->updateLegend(this); } }
void QwtLegend::setItemMode | ( | LegendItemMode | mode ) |
Definition at line 332 of file qwt_legend.cpp.
References QwtLegend::PrivateData::itemMode.
{ d_data->itemMode = mode; }
QSize QwtLegend::sizeHint | ( | ) | const [virtual] |
Return a size hint.
Definition at line 516 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
Referenced by QwtPlotLayout::LayoutData::init(), and QwtPlotLayout::minimumSizeHint().
{ QSize hint = d_data->view->contentsWidget->sizeHint(); hint += QSize(2 * frameWidth(), 2 * frameWidth()); return hint; }
QScrollBar * QwtLegend::verticalScrollBar | ( | ) | const |
Definition at line 376 of file qwt_legend.cpp.
References QwtLegend::PrivateData::view.
Referenced by QwtPlotLayout::LayoutData::init(), and QwtPlotLayout::minimumSizeHint().
{ return d_data->view->verticalScrollBar(); }