! \brief Insert a legend If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend the legend will be organized in one column from top to down. Otherwise the legend items will be placed in a table with a best fit number of columns from left to right. insertLegend() will set the plot widget as parent for the legend. The legend will be deleted in the destruct
| 925 | QwtPlotLayout::setLegendPosition() |
| 926 | */ |
| 927 | void QwtPlot::insertLegend( QwtAbstractLegend* legend, |
| 928 | QwtPlot::LegendPosition pos, double ratio ) |
| 929 | { |
| 930 | m_data->layout->setLegendPosition( pos, ratio ); |
| 931 | |
| 932 | if ( legend != m_data->legend ) |
| 933 | { |
| 934 | if ( m_data->legend && m_data->legend->parent() == this ) |
| 935 | delete m_data->legend; |
| 936 | |
| 937 | m_data->legend = legend; |
| 938 | |
| 939 | if ( m_data->legend ) |
| 940 | { |
| 941 | connect( |
| 942 | this, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)), |
| 943 | m_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>)) |
| 944 | ); |
| 945 | |
| 946 | if ( m_data->legend->parent() != this ) |
| 947 | m_data->legend->setParent( this ); |
| 948 | |
| 949 | qwtEnableLegendItems( this, false ); |
| 950 | updateLegend(); |
| 951 | qwtEnableLegendItems( this, true ); |
| 952 | |
| 953 | QwtLegend* lgd = qobject_cast< QwtLegend* >( legend ); |
| 954 | if ( lgd ) |
| 955 | { |
| 956 | switch ( m_data->layout->legendPosition() ) |
| 957 | { |
| 958 | case LeftLegend: |
| 959 | case RightLegend: |
| 960 | { |
| 961 | if ( lgd->maxColumns() == 0 ) |
| 962 | lgd->setMaxColumns( 1 ); // 1 column: align vertical |
| 963 | break; |
| 964 | } |
| 965 | case TopLegend: |
| 966 | case BottomLegend: |
| 967 | { |
| 968 | lgd->setMaxColumns( 0 ); // unlimited |
| 969 | break; |
| 970 | } |
| 971 | default: |
| 972 | break; |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | QWidget* previousInChain = NULL; |
| 977 | switch ( m_data->layout->legendPosition() ) |
| 978 | { |
| 979 | case LeftLegend: |
| 980 | { |
| 981 | const QwtAxisId axisId( QwtAxis::XTop ); |
| 982 | previousInChain = axisWidget( axisId ); |
| 983 | break; |
| 984 | } |
nothing calls this directly
no test coverage detected