Esempio n. 1
0
/*!
  \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.

  If pos != QwtPlot::ExternalLegend the plot widget will become 
  parent of the legend. It will be deleted when the plot is deleted, 
  or another legend is set with insertLegend().
       
  \param legend Legend
  \param pos The legend's position. For top/left position the number
             of colums will be limited to 1, otherwise it will be set to
             unlimited. 

  \param ratio Ratio between legend and the bounding rect
               of title, canvas and axes. The legend will be shrinked
               if it would need more space than the given ratio.
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
               it will be reset to the default ratio.
               The default vertical/horizontal ratio is 0.33/0.5.

  \sa legend(), QwtPlotLayout::legendPosition(), 
      QwtPlotLayout::setLegendPosition()
*/
void QwtPlot::insertLegend(QwtLegend *legend, 
    QwtPlot::LegendPosition pos, double ratio)
{
    d_data->layout->setLegendPosition(pos, ratio);

    if ( legend != d_data->legend )
    {
        if ( d_data->legend && d_data->legend->parent() == this )
            delete d_data->legend;

        d_data->legend = legend;

        if ( d_data->legend )
        {
            if ( pos != ExternalLegend )
            {
                if ( d_data->legend->parent() != this )
                {
#if QT_VERSION < 0x040000
                    d_data->legend->reparent(this, QPoint(0, 0));
#else
                    d_data->legend->setParent(this);
#endif
                }
            }

            const QwtPlotItemList& itmList = itemList();
            for ( QwtPlotItemIterator it = itmList.begin();
                it != itmList.end(); ++it )
            {
                (*it)->updateLegend(d_data->legend);
            }

            QLayout *l = d_data->legend->contentsWidget()->layout();
            if ( l && l->inherits("QwtDynGridLayout") )
            {
                QwtDynGridLayout *tl = (QwtDynGridLayout *)l;
                switch(d_data->layout->legendPosition())
                {
                    case LeftLegend:
                    case RightLegend:
                        tl->setMaxCols(1); // 1 column: align vertical
                        break;
                    case TopLegend:
                    case BottomLegend:
                        tl->setMaxCols(0); // unlimited
                        break;
                    case ExternalLegend:
                        break;
                }
            }
        }
        updateTabOrder();
    }

    updateLayout();
}
Esempio n. 2
0
/*!
  \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.

  If pos != QwtPlot::ExternalLegend the plot widget will become
  parent of the legend. It will be deleted when the plot is deleted,
  or another legend is set with insertLegend().

  \param legend Legend
  \param pos The legend's position. For top/left position the number
             of colums will be limited to 1, otherwise it will be set to
             unlimited.

  \param ratio Ratio between legend and the bounding rect
               of title, canvas and axes. The legend will be shrinked
               if it would need more space than the given ratio.
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
               it will be reset to the default ratio.
               The default vertical/horizontal ratio is 0.33/0.5.

  \sa legend(), QwtPlotLayout::legendPosition(),
      QwtPlotLayout::setLegendPosition()
*/
void QwtPlot::insertLegend( QwtLegend *legend,
    QwtPlot::LegendPosition pos, double ratio )
{
    d_data->layout->setLegendPosition( pos, ratio );

    if ( legend != d_data->legend )
    {
        if ( d_data->legend && d_data->legend->parent() == this )
            delete d_data->legend;

        d_data->legend = legend;

        if ( d_data->legend )
        {
            if ( pos != ExternalLegend )
            {
                if ( d_data->legend->parent() != this )
                    d_data->legend->setParent( this );
            }

            const QwtPlotItemList& itmList = itemList();
            for ( QwtPlotItemIterator it = itmList.begin();
                it != itmList.end(); ++it )
            {
                ( *it )->updateLegend( d_data->legend );
            }

            QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
                d_data->legend->contentsWidget()->layout() );
            if ( tl )
            {
                switch ( d_data->layout->legendPosition() )
                {
                    case LeftLegend:
                    case RightLegend:
                        tl->setMaxCols( 1 ); // 1 column: align vertical
                        break;
                    case TopLegend:
                    case BottomLegend:
                        tl->setMaxCols( 0 ); // unlimited
                        break;
                    case ExternalLegend:
                        break;
                }
            }
        }
        updateTabOrder();
    }

    updateLayout();
}
Esempio n. 3
0
/*!
  Specify the position of the legend within the widget.
  If the position legend is \c QwtPlot::Left or \c QwtPlot::Right
  the legend will be organized in one column from top to down. 
  Otherwise the legend items will be placed be placed in a table 
  with a best fit number of columns from left to right.
       
  \param pos The legend's position. Valid values are \c QwtPlot::Left,
           \c QwtPlot::Right, \c QwtPlot::Top, \c QwtPlot::Bottom.
  \param ratio Ratio between legend and the bounding rect
               of title, canvas and axes. The legend will be shrinked
               if it would need more space than the given ratio.
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
               it will be reset to the default ratio.
               The default vertical/horizontal ratio is 0.33/0.5.

  \sa QwtPlot::legendPosition(), QwtPlotLayout::setLegendPosition()
*/
void QwtPlot::setLegendPosition(QwtPlot::Position pos, double ratio)
{
    if (pos != d_layout->legendPosition())
    {
        d_layout->setLegendPosition(pos, ratio);

        QLayout *l = d_legend->contentsWidget()->layout();
        if ( l && l->inherits("QwtDynGridLayout") )
        {
            QwtDynGridLayout *tl = (QwtDynGridLayout *)l;
            if ( d_layout->legendPosition() == QwtPlot::Top ||
                d_layout->legendPosition() == QwtPlot::Bottom )
            {
                tl->setMaxCols(0); // unlimited
            }
            else
                tl->setMaxCols(1); // 1 column: align vertical
        }

        updateLayout();
        updateTabOrder();
    }
}