Index: trunk/BNC/qwt/qwt_dyngrid_layout.cpp
===================================================================
--- trunk/BNC/qwt/qwt_dyngrid_layout.cpp	(revision 4271)
+++ trunk/BNC/qwt/qwt_dyngrid_layout.cpp	(revision 8127)
@@ -10,5 +10,5 @@
 #include "qwt_dyngrid_layout.h"
 #include "qwt_math.h"
-#include <qwidget.h>
+#include <qvector.h>
 #include <qlist.h>
 
@@ -25,7 +25,7 @@
     mutable QList<QLayoutItem*> itemList;
 
-    uint maxCols;
+    uint maxColumns;
     uint numRows;
-    uint numCols;
+    uint numColumns;
 
     Qt::Orientations expanding;
@@ -82,5 +82,5 @@
 {
     d_data = new QwtDynGridLayout::PrivateData;
-    d_data->maxCols = d_data->numRows = d_data->numCols = 0;
+    d_data->maxColumns = d_data->numRows = d_data->numColumns = 0;
     d_data->expanding = 0;
 }
@@ -105,25 +105,29 @@
 /*!
   Limit the number of columns.
-  \param maxCols upper limit, 0 means unlimited
-  \sa maxCols()
-*/
-void QwtDynGridLayout::setMaxCols( uint maxCols )
-{
-    d_data->maxCols = maxCols;
-}
-
-/*!
-  Return the upper limit for the number of columns.
+  \param maxColumns upper limit, 0 means unlimited
+  \sa maxColumns()
+*/
+void QwtDynGridLayout::setMaxColumns( uint maxColumns )
+{
+    d_data->maxColumns = maxColumns;
+}
+
+/*!
+  \brief Return the upper limit for the number of columns.
+
   0 means unlimited, what is the default.
-  \sa setMaxCols()
-*/
-
-uint QwtDynGridLayout::maxCols() const
-{
-    return d_data->maxCols;
-}
-
-//! Adds item to the next free position.
-
+
+  \return Upper limit for the number of columns
+  \sa setMaxColumns()
+*/
+uint QwtDynGridLayout::maxColumns() const
+{
+    return d_data->maxColumns;
+}
+
+/*! 
+  \brief Add an item to the next free position.
+  \param item Layout item
+ */
 void QwtDynGridLayout::addItem( QLayoutItem *item )
 {
@@ -135,5 +139,4 @@
   \return true if this layout is empty.
 */
-
 bool QwtDynGridLayout::isEmpty() const
 {
@@ -144,5 +147,4 @@
   \return number of layout items
 */
-
 uint QwtDynGridLayout::itemCount() const
 {
@@ -151,7 +153,8 @@
 
 /*!
-  Find the item at a spcific index
+  Find the item at a specific index
 
   \param index Index
+  \return Item at a specific index
   \sa takeAt()
 */
@@ -165,7 +168,8 @@
 
 /*!
-  Find the item at a spcific index and remove it from the layout
+  Find the item at a specific index and remove it from the layout
 
   \param index Index
+  \return Layout item, removed from the layout
   \sa itemAt()
 */
@@ -200,8 +204,11 @@
 
 /*!
-  Returns whether this layout can make use of more space than sizeHint().
+  \brief Returns whether this layout can make use of more space than sizeHint().
+
   A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
   one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
   to grow in both dimensions.
+
+  \return Orientations, where the layout expands
   \sa setExpandingDirections()
 */
@@ -212,6 +219,6 @@
 
 /*!
-  Reorganizes columns and rows and resizes managed widgets within
-  the rectangle rect.
+  Reorganizes columns and rows and resizes managed items within
+  a rectangle.
 
   \param rect Layout geometry
@@ -224,10 +231,10 @@
         return;
 
-    d_data->numCols = columnsForWidth( rect.width() );
-    d_data->numRows = itemCount() / d_data->numCols;
-    if ( itemCount() % d_data->numCols )
+    d_data->numColumns = columnsForWidth( rect.width() );
+    d_data->numRows = itemCount() / d_data->numColumns;
+    if ( itemCount() % d_data->numColumns )
         d_data->numRows++;
 
-    QList<QRect> itemGeometries = layoutItems( rect, d_data->numCols );
+    QList<QRect> itemGeometries = layoutItems( rect, d_data->numColumns );
 
     int index = 0;
@@ -235,21 +242,20 @@
         it != d_data->itemList.end(); ++it )
     {
-        QWidget *w = ( *it )->widget();
-        if ( w )
-        {
-            w->setGeometry( itemGeometries[index] );
-            index++;
-        }
-    }
-}
-
-/*!
-  Calculate the number of columns for a given width. It tries to
-  use as many columns as possible (limited by maxCols())
+        ( *it )->setGeometry( itemGeometries[index] );
+        index++;
+    }
+}
+
+/*!
+  \brief Calculate the number of columns for a given width. 
+
+  The calculation tries to use as many columns as possible 
+  ( limited by maxColumns() )
 
   \param width Available width for all columns
-  \sa maxCols(), setMaxCols()
-*/
-
+  \return Number of columns for a given width
+
+  \sa maxColumns(), setMaxColumns()
+*/
 uint QwtDynGridLayout::columnsForWidth( int width ) const
 {
@@ -257,13 +263,16 @@
         return 0;
 
-    const int maxCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
-    if ( maxRowWidth( maxCols ) <= width )
-        return maxCols;
-
-    for ( int numCols = 2; numCols <= maxCols; numCols++ )
-    {
-        const int rowWidth = maxRowWidth( numCols );
+    uint maxColumns = itemCount();
+    if ( d_data->maxColumns > 0 ) 
+        maxColumns = qMin( d_data->maxColumns, maxColumns );
+
+    if ( maxRowWidth( maxColumns ) <= width )
+        return maxColumns;
+
+    for ( uint numColumns = 2; numColumns <= maxColumns; numColumns++ )
+    {
+        const int rowWidth = maxRowWidth( numColumns );
         if ( rowWidth > width )
-            return numCols - 1;
+            return numColumns - 1;
     }
 
@@ -275,13 +284,13 @@
   columns.
 
-  \param numCols Given number of columns
+  \param numColumns Given number of columns
   \param itemWidth Array of the width hints for all items
 */
-int QwtDynGridLayout::maxRowWidth( int numCols ) const
+int QwtDynGridLayout::maxRowWidth( int numColumns ) const
 {
     int col;
 
-    QVector<int> colWidth( numCols );
-    for ( col = 0; col < numCols; col++ )
+    QVector<int> colWidth( numColumns );
+    for ( col = 0; col < numColumns; col++ )
         colWidth[col] = 0;
 
@@ -292,11 +301,11 @@
         index < d_data->itemSizeHints.count(); index++ )
     {
-        col = index % numCols;
+        col = index % numColumns;
         colWidth[col] = qMax( colWidth[col],
             d_data->itemSizeHints[int( index )].width() );
     }
 
-    int rowWidth = 2 * margin() + ( numCols - 1 ) * spacing();
-    for ( col = 0; col < numCols; col++ )
+    int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing();
+    for ( col = 0; col < numColumns; col++ )
         rowWidth += colWidth[col];
 
@@ -328,26 +337,29 @@
 /*!
   Calculate the geometries of the layout items for a layout
-  with numCols columns and a given rect.
+  with numColumns columns and a given rectangle.
 
   \param rect Rect where to place the items
-  \param numCols Number of columns
+  \param numColumns Number of columns
   \return item geometries
 */
 
 QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
-    uint numCols ) const
+    uint numColumns ) const
 {
     QList<QRect> itemGeometries;
-    if ( numCols == 0 || isEmpty() )
+    if ( numColumns == 0 || isEmpty() )
         return itemGeometries;
 
-    uint numRows = itemCount() / numCols;
-    if ( numRows % itemCount() )
+    uint numRows = itemCount() / numColumns;
+    if ( numColumns % itemCount() )
         numRows++;
 
+    if ( numRows == 0 )
+        return itemGeometries;
+
     QVector<int> rowHeight( numRows );
-    QVector<int> colWidth( numCols );
-
-    layoutGrid( numCols, rowHeight, colWidth );
+    QVector<int> colWidth( numColumns );
+
+    layoutGrid( numColumns, rowHeight, colWidth );
 
     bool expandH, expandV;
@@ -356,15 +368,15 @@
 
     if ( expandH || expandV )
-        stretchGrid( rect, numCols, rowHeight, colWidth );
-
-    const int maxCols = d_data->maxCols;
-    d_data->maxCols = numCols;
+        stretchGrid( rect, numColumns, rowHeight, colWidth );
+
+    const int maxColumns = d_data->maxColumns;
+    d_data->maxColumns = numColumns;
     const QRect alignedRect = alignmentRect( rect );
-    d_data->maxCols = maxCols;
+    d_data->maxColumns = maxColumns;
 
     const int xOffset = expandH ? 0 : alignedRect.x();
     const int yOffset = expandV ? 0 : alignedRect.y();
 
-    QVector<int> colX( numCols );
+    QVector<int> colX( numColumns );
     QVector<int> rowY( numRows );
 
@@ -372,9 +384,9 @@
 
     rowY[0] = yOffset + margin();
-    for ( int r = 1; r < ( int )numRows; r++ )
+    for ( uint r = 1; r < numRows; r++ )
         rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;
 
     colX[0] = xOffset + margin();
-    for ( int c = 1; c < ( int )numCols; c++ )
+    for ( uint c = 1; c < numColumns; c++ )
         colX[c] = colX[c-1] + colWidth[c-1] + xySpace;
 
@@ -382,6 +394,6 @@
     for ( int i = 0; i < itemCount; i++ )
     {
-        const int row = i / numCols;
-        const int col = i % numCols;
+        const int row = i / numColumns;
+        const int col = i % numColumns;
 
         QRect itemGeometry( colX[col], rowY[row],
@@ -396,15 +408,15 @@
 /*!
   Calculate the dimensions for the columns and rows for a grid
-  of numCols columns.
-
-  \param numCols Number of columns.
+  of numColumns columns.
+
+  \param numColumns Number of columns.
   \param rowHeight Array where to fill in the calculated row heights.
   \param colWidth Array where to fill in the calculated column widths.
 */
 
-void QwtDynGridLayout::layoutGrid( uint numCols,
+void QwtDynGridLayout::layoutGrid( uint numColumns,
     QVector<int>& rowHeight, QVector<int>& colWidth ) const
 {
-    if ( numCols <= 0 )
+    if ( numColumns <= 0 )
         return;
 
@@ -412,9 +424,8 @@
         d_data->updateLayoutCache();
 
-    for ( uint index = 0;
-        index < ( uint )d_data->itemSizeHints.count(); index++ )
-    {
-        const int row = index / numCols;
-        const int col = index % numCols;
+    for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )
+    {
+        const int row = index / numColumns;
+        const int col = index % numColumns;
 
         const QSize &size = d_data->itemSizeHints[int( index )];
@@ -428,5 +439,5 @@
 
 /*!
-  \return true: QwtDynGridLayout implements heightForWidth.
+  \return true: QwtDynGridLayout implements heightForWidth().
   \sa heightForWidth()
 */
@@ -437,5 +448,5 @@
 
 /*!
-  \return The preferred height for this layout, given the width w.
+  \return The preferred height for this layout, given a width.
   \sa hasHeightForWidth()
 */
@@ -445,16 +456,16 @@
         return 0;
 
-    const uint numCols = columnsForWidth( width );
-    uint numRows = itemCount() / numCols;
-    if ( itemCount() % numCols )
+    const uint numColumns = columnsForWidth( width );
+    uint numRows = itemCount() / numColumns;
+    if ( itemCount() % numColumns )
         numRows++;
 
     QVector<int> rowHeight( numRows );
-    QVector<int> colWidth( numCols );
-
-    layoutGrid( numCols, rowHeight, colWidth );
+    QVector<int> colWidth( numColumns );
+
+    layoutGrid( numColumns, rowHeight, colWidth );
 
     int h = 2 * margin() + ( numRows - 1 ) * spacing();
-    for ( int row = 0; row < ( int )numRows; row++ )
+    for ( uint row = 0; row < numRows; row++ )
         h += rowHeight[row];
 
@@ -467,10 +478,15 @@
   rect. Rows and columns are stretched with the same factor.
 
+  \param rect Bounding rectangle
+  \param numColumns Number of columns
+  \param rowHeight Array to be filled with the calculated row heights
+  \param colWidth Array to be filled with the calculated column widths
+
   \sa setExpanding(), expanding()
 */
 void QwtDynGridLayout::stretchGrid( const QRect &rect,
-    uint numCols, QVector<int>& rowHeight, QVector<int>& colWidth ) const
-{
-    if ( numCols == 0 || isEmpty() )
+    uint numColumns, QVector<int>& rowHeight, QVector<int>& colWidth ) const
+{
+    if ( numColumns == 0 || isEmpty() )
         return;
 
@@ -481,13 +497,13 @@
     if ( expandH )
     {
-        int xDelta = rect.width() - 2 * margin() - ( numCols - 1 ) * spacing();
-        for ( int col = 0; col < ( int )numCols; col++ )
+        int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing();
+        for ( uint col = 0; col < numColumns; col++ )
             xDelta -= colWidth[col];
 
         if ( xDelta > 0 )
         {
-            for ( int col = 0; col < ( int )numCols; col++ )
+            for ( uint col = 0; col < numColumns; col++ )
             {
-                const int space = xDelta / ( numCols - col );
+                const int space = xDelta / ( numColumns - col );
                 colWidth[col] += space;
                 xDelta -= space;
@@ -498,15 +514,15 @@
     if ( expandV )
     {
-        uint numRows = itemCount() / numCols;
-        if ( itemCount() % numCols )
+        uint numRows = itemCount() / numColumns;
+        if ( itemCount() % numColumns )
             numRows++;
 
         int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();
-        for ( int row = 0; row < ( int )numRows; row++ )
+        for ( uint row = 0; row < numRows; row++ )
             yDelta -= rowHeight[row];
 
         if ( yDelta > 0 )
         {
-            for ( int row = 0; row < ( int )numRows; row++ )
+            for ( uint row = 0; row < numRows; row++ )
             {
                 const int space = yDelta / ( numRows - row );
@@ -519,9 +535,10 @@
 
 /*!
-   Return the size hint. If maxCols() > 0 it is the size for
-   a grid with maxCols() columns, otherwise it is the size for
+   Return the size hint. If maxColumns() > 0 it is the size for
+   a grid with maxColumns() columns, otherwise it is the size for
    a grid with only one row.
 
-   \sa maxCols(), setMaxCols()
+   \return Size hint
+   \sa maxColumns(), setMaxColumns()
 */
 QSize QwtDynGridLayout::sizeHint() const
@@ -530,20 +547,23 @@
         return QSize();
 
-    const uint numCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
-    uint numRows = itemCount() / numCols;
-    if ( itemCount() % numCols )
+    uint numColumns = itemCount();
+    if ( d_data->maxColumns > 0 )
+        numColumns = qMin( d_data->maxColumns, numColumns );
+
+    uint numRows = itemCount() / numColumns;
+    if ( itemCount() % numColumns )
         numRows++;
 
     QVector<int> rowHeight( numRows );
-    QVector<int> colWidth( numCols );
-
-    layoutGrid( numCols, rowHeight, colWidth );
+    QVector<int> colWidth( numColumns );
+
+    layoutGrid( numColumns, rowHeight, colWidth );
 
     int h = 2 * margin() + ( numRows - 1 ) * spacing();
-    for ( int row = 0; row < ( int )numRows; row++ )
+    for ( uint row = 0; row < numRows; row++ )
         h += rowHeight[row];
 
-    int w = 2 * margin() + ( numCols - 1 ) * spacing();
-    for ( int col = 0; col < ( int )numCols; col++ )
+    int w = 2 * margin() + ( numColumns - 1 ) * spacing();
+    for ( uint col = 0; col < numColumns; col++ )
         w += colWidth[col];
 
@@ -553,5 +573,5 @@
 /*!
   \return Number of rows of the current layout.
-  \sa numCols()
+  \sa numColumns()
   \warning The number of rows might change whenever the geometry changes
 */
@@ -566,6 +586,6 @@
   \warning The number of columns might change whenever the geometry changes
 */
-uint QwtDynGridLayout::numCols() const
-{
-    return d_data->numCols;
-}
+uint QwtDynGridLayout::numColumns() const
+{
+    return d_data->numColumns;
+}
