qwt_dyngrid_layout.cpp 14.1 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#include "qwt_dyngrid_layout.h"
#include "qwt_math.h"
Bryant's avatar
Bryant committed
12
#include <qvector.h>
pixhawk's avatar
pixhawk committed
13 14 15 16 17 18
#include <qlist.h>

class QwtDynGridLayout::PrivateData
{
public:
    PrivateData():
Bryant's avatar
Bryant committed
19 20
        isDirty( true )
    {
pixhawk's avatar
pixhawk committed
21 22
    }

Bryant's avatar
Bryant committed
23
    void updateLayoutCache();
pixhawk's avatar
pixhawk committed
24

Bryant's avatar
Bryant committed
25
    mutable QList<QLayoutItem*> itemList;
pixhawk's avatar
pixhawk committed
26

Bryant's avatar
Bryant committed
27
    uint maxColumns;
pixhawk's avatar
pixhawk committed
28
    uint numRows;
Bryant's avatar
Bryant committed
29
    uint numColumns;
pixhawk's avatar
pixhawk committed
30 31 32 33

    Qt::Orientations expanding;

    bool isDirty;
Bryant's avatar
Bryant committed
34
    QVector<QSize> itemSizeHints;
pixhawk's avatar
pixhawk committed
35 36
};

Bryant's avatar
Bryant committed
37 38 39
void QwtDynGridLayout::PrivateData::updateLayoutCache()
{
    itemSizeHints.resize( itemList.count() );
pixhawk's avatar
pixhawk committed
40

Bryant's avatar
Bryant committed
41
    int index = 0;
pixhawk's avatar
pixhawk committed
42

Bryant's avatar
Bryant committed
43 44 45 46 47
    for ( QList<QLayoutItem*>::iterator it = itemList.begin();
        it != itemList.end(); ++it, index++ )
    {
        itemSizeHints[ index ] = ( *it )->sizeHint();
    }
pixhawk's avatar
pixhawk committed
48

Bryant's avatar
Bryant committed
49
    isDirty = false;
pixhawk's avatar
pixhawk committed
50 51 52 53
}

/*!
  \param parent Parent widget
Bryant's avatar
Bryant committed
54
  \param margin Margin
pixhawk's avatar
pixhawk committed
55 56
  \param spacing Spacing
*/
Bryant's avatar
Bryant committed
57 58 59 60

QwtDynGridLayout::QwtDynGridLayout( QWidget *parent,
        int margin, int spacing ):
    QLayout( parent )
pixhawk's avatar
pixhawk committed
61 62
{
    init();
Bryant's avatar
Bryant committed
63 64 65

    setSpacing( spacing );
    setMargin( margin );
pixhawk's avatar
pixhawk committed
66 67 68 69 70 71
}

/*!
  \param spacing Spacing
*/

Bryant's avatar
Bryant committed
72
QwtDynGridLayout::QwtDynGridLayout( int spacing )
pixhawk's avatar
pixhawk committed
73 74
{
    init();
Bryant's avatar
Bryant committed
75
    setSpacing( spacing );
pixhawk's avatar
pixhawk committed
76 77 78 79 80 81 82 83
}

/*!
  Initialize the layout with default values.
*/
void QwtDynGridLayout::init()
{
    d_data = new QwtDynGridLayout::PrivateData;
Bryant's avatar
Bryant committed
84
    d_data->maxColumns = d_data->numRows = d_data->numColumns = 0;
pixhawk's avatar
pixhawk committed
85 86 87 88 89 90 91
    d_data->expanding = 0;
}

//! Destructor

QwtDynGridLayout::~QwtDynGridLayout()
{
Bryant's avatar
Bryant committed
92 93
    for ( int i = 0; i < d_data->itemList.size(); i++ )
        delete d_data->itemList[i];
pixhawk's avatar
pixhawk committed
94 95 96 97

    delete d_data;
}

Bryant's avatar
Bryant committed
98
//! Invalidate all internal caches
pixhawk's avatar
pixhawk committed
99 100 101 102 103 104 105 106
void QwtDynGridLayout::invalidate()
{
    d_data->isDirty = true;
    QLayout::invalidate();
}

/*!
  Limit the number of columns.
Bryant's avatar
Bryant committed
107 108
  \param maxColumns upper limit, 0 means unlimited
  \sa maxColumns()
pixhawk's avatar
pixhawk committed
109
*/
Bryant's avatar
Bryant committed
110
void QwtDynGridLayout::setMaxColumns( uint maxColumns )
pixhawk's avatar
pixhawk committed
111
{
Bryant's avatar
Bryant committed
112
    d_data->maxColumns = maxColumns;
pixhawk's avatar
pixhawk committed
113 114 115
}

/*!
Bryant's avatar
Bryant committed
116 117
  \brief Return the upper limit for the number of columns.

pixhawk's avatar
pixhawk committed
118 119
  0 means unlimited, what is the default.

Bryant's avatar
Bryant committed
120 121 122 123
  \return Upper limit for the number of columns
  \sa setMaxColumns()
*/
uint QwtDynGridLayout::maxColumns() const
124
{
Bryant's avatar
Bryant committed
125
    return d_data->maxColumns;
pixhawk's avatar
pixhawk committed
126 127
}

Bryant's avatar
Bryant committed
128 129 130 131 132
/*! 
  \brief Add an item to the next free position.
  \param item Layout item
 */
void QwtDynGridLayout::addItem( QLayoutItem *item )
pixhawk's avatar
pixhawk committed
133
{
Bryant's avatar
Bryant committed
134
    d_data->itemList.append( item );
pixhawk's avatar
pixhawk committed
135 136 137
    invalidate();
}

138 139
/*!
  \return true if this layout is empty.
pixhawk's avatar
pixhawk committed
140 141 142 143 144 145
*/
bool QwtDynGridLayout::isEmpty() const
{
    return d_data->itemList.isEmpty();
}

146
/*!
pixhawk's avatar
pixhawk committed
147 148 149 150 151 152 153
  \return number of layout items
*/
uint QwtDynGridLayout::itemCount() const
{
    return d_data->itemList.count();
}

154
/*!
Bryant's avatar
Bryant committed
155
  Find the item at a specific index
pixhawk's avatar
pixhawk committed
156

Bryant's avatar
Bryant committed
157 158 159
  \param index Index
  \return Item at a specific index
  \sa takeAt()
pixhawk's avatar
pixhawk committed
160 161 162 163 164 165
*/
QLayoutItem *QwtDynGridLayout::itemAt( int index ) const
{
    if ( index < 0 || index >= d_data->itemList.count() )
        return NULL;

Bryant's avatar
Bryant committed
166
    return d_data->itemList.at( index );
pixhawk's avatar
pixhawk committed
167
}
168

Bryant's avatar
Bryant committed
169 170 171 172 173 174 175
/*!
  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()
*/
pixhawk's avatar
pixhawk committed
176 177 178 179
QLayoutItem *QwtDynGridLayout::takeAt( int index )
{
    if ( index < 0 || index >= d_data->itemList.count() )
        return NULL;
180

pixhawk's avatar
pixhawk committed
181
    d_data->isDirty = true;
Bryant's avatar
Bryant committed
182
    return d_data->itemList.takeAt( index );
pixhawk's avatar
pixhawk committed
183 184
}

Bryant's avatar
Bryant committed
185
//! \return Number of items in the layout
pixhawk's avatar
pixhawk committed
186 187 188 189 190
int QwtDynGridLayout::count() const
{
    return d_data->itemList.count();
}

Bryant's avatar
Bryant committed
191 192 193 194 195 196 197 198 199 200
/*!
  Set 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. The default value is 0.

  \param expanding Or'd orientations
  \sa expandingDirections()
*/
void QwtDynGridLayout::setExpandingDirections( Qt::Orientations expanding )
pixhawk's avatar
pixhawk committed
201 202 203 204
{
    d_data->expanding = expanding;
}

Bryant's avatar
Bryant committed
205 206 207 208 209 210 211 212 213 214
/*!
  \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()
*/
pixhawk's avatar
pixhawk committed
215 216 217 218 219 220
Qt::Orientations QwtDynGridLayout::expandingDirections() const
{
    return d_data->expanding;
}

/*!
Bryant's avatar
Bryant committed
221 222
  Reorganizes columns and rows and resizes managed items within
  a rectangle.
pixhawk's avatar
pixhawk committed
223

Bryant's avatar
Bryant committed
224 225 226
  \param rect Layout geometry
*/
void QwtDynGridLayout::setGeometry( const QRect &rect )
pixhawk's avatar
pixhawk committed
227
{
Bryant's avatar
Bryant committed
228
    QLayout::setGeometry( rect );
pixhawk's avatar
pixhawk committed
229 230 231 232

    if ( isEmpty() )
        return;

Bryant's avatar
Bryant committed
233 234 235
    d_data->numColumns = columnsForWidth( rect.width() );
    d_data->numRows = itemCount() / d_data->numColumns;
    if ( itemCount() % d_data->numColumns )
pixhawk's avatar
pixhawk committed
236 237
        d_data->numRows++;

Bryant's avatar
Bryant committed
238
    QList<QRect> itemGeometries = layoutItems( rect, d_data->numColumns );
pixhawk's avatar
pixhawk committed
239 240

    int index = 0;
Bryant's avatar
Bryant committed
241 242 243 244 245
    for ( QList<QLayoutItem*>::iterator it = d_data->itemList.begin();
        it != d_data->itemList.end(); ++it )
    {
        ( *it )->setGeometry( itemGeometries[index] );
        index++;
pixhawk's avatar
pixhawk committed
246 247 248
    }
}

249
/*!
Bryant's avatar
Bryant committed
250 251 252 253
  \brief Calculate the number of columns for a given width. 

  The calculation tries to use as many columns as possible 
  ( limited by maxColumns() )
pixhawk's avatar
pixhawk committed
254 255

  \param width Available width for all columns
Bryant's avatar
Bryant committed
256
  \return Number of columns for a given width
pixhawk's avatar
pixhawk committed
257

Bryant's avatar
Bryant committed
258 259 260
  \sa maxColumns(), setMaxColumns()
*/
uint QwtDynGridLayout::columnsForWidth( int width ) const
pixhawk's avatar
pixhawk committed
261 262 263 264
{
    if ( isEmpty() )
        return 0;

Bryant's avatar
Bryant committed
265 266 267 268 269 270
    uint maxColumns = itemCount();
    if ( d_data->maxColumns > 0 ) 
        maxColumns = qMin( d_data->maxColumns, maxColumns );

    if ( maxRowWidth( maxColumns ) <= width )
        return maxColumns;
pixhawk's avatar
pixhawk committed
271

Bryant's avatar
Bryant committed
272 273 274
    for ( uint numColumns = 2; numColumns <= maxColumns; numColumns++ )
    {
        const int rowWidth = maxRowWidth( numColumns );
pixhawk's avatar
pixhawk committed
275
        if ( rowWidth > width )
Bryant's avatar
Bryant committed
276
            return numColumns - 1;
pixhawk's avatar
pixhawk committed
277 278 279 280 281
    }

    return 1; // At least 1 column
}

282
/*!
pixhawk's avatar
pixhawk committed
283 284 285
  Calculate the width of a layout for a given number of
  columns.

Bryant's avatar
Bryant committed
286
  \param numColumns Given number of columns
pixhawk's avatar
pixhawk committed
287 288
  \param itemWidth Array of the width hints for all items
*/
Bryant's avatar
Bryant committed
289
int QwtDynGridLayout::maxRowWidth( int numColumns ) const
pixhawk's avatar
pixhawk committed
290 291 292
{
    int col;

Bryant's avatar
Bryant committed
293 294
    QVector<int> colWidth( numColumns );
    for ( col = 0; col < numColumns; col++ )
pixhawk's avatar
pixhawk committed
295 296 297
        colWidth[col] = 0;

    if ( d_data->isDirty )
Bryant's avatar
Bryant committed
298
        d_data->updateLayoutCache();
pixhawk's avatar
pixhawk committed
299

Bryant's avatar
Bryant committed
300 301 302 303 304 305
    for ( int index = 0;
        index < d_data->itemSizeHints.count(); index++ )
    {
        col = index % numColumns;
        colWidth[col] = qMax( colWidth[col],
            d_data->itemSizeHints[int( index )].width() );
pixhawk's avatar
pixhawk committed
306 307
    }

Bryant's avatar
Bryant committed
308 309
    int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing();
    for ( col = 0; col < numColumns; col++ )
pixhawk's avatar
pixhawk committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323
        rowWidth += colWidth[col];

    return rowWidth;
}

/*!
  \return the maximum width of all layout items
*/
int QwtDynGridLayout::maxItemWidth() const
{
    if ( isEmpty() )
        return 0;

    if ( d_data->isDirty )
Bryant's avatar
Bryant committed
324
        d_data->updateLayoutCache();
pixhawk's avatar
pixhawk committed
325 326

    int w = 0;
Bryant's avatar
Bryant committed
327 328 329
    for ( int i = 0; i < d_data->itemSizeHints.count(); i++ )
    {
        const int itemW = d_data->itemSizeHints[i].width();
pixhawk's avatar
pixhawk committed
330 331 332 333 334 335 336 337 338
        if ( itemW > w )
            w = itemW;
    }

    return w;
}

/*!
  Calculate the geometries of the layout items for a layout
Bryant's avatar
Bryant committed
339 340
  with numColumns columns and a given rectangle.

pixhawk's avatar
pixhawk committed
341
  \param rect Rect where to place the items
Bryant's avatar
Bryant committed
342
  \param numColumns Number of columns
pixhawk's avatar
pixhawk committed
343 344 345
  \return item geometries
*/

Bryant's avatar
Bryant committed
346 347
QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
    uint numColumns ) const
pixhawk's avatar
pixhawk committed
348 349
{
    QList<QRect> itemGeometries;
Bryant's avatar
Bryant committed
350
    if ( numColumns == 0 || isEmpty() )
pixhawk's avatar
pixhawk committed
351 352
        return itemGeometries;

Bryant's avatar
Bryant committed
353 354
    uint numRows = itemCount() / numColumns;
    if ( numColumns % itemCount() )
pixhawk's avatar
pixhawk committed
355
        numRows++;
356

Bryant's avatar
Bryant committed
357 358 359 360 361
    if ( numRows == 0 )
        return itemGeometries;

    QVector<int> rowHeight( numRows );
    QVector<int> colWidth( numColumns );
362

Bryant's avatar
Bryant committed
363
    layoutGrid( numColumns, rowHeight, colWidth );
pixhawk's avatar
pixhawk committed
364 365 366 367 368 369

    bool expandH, expandV;
    expandH = expandingDirections() & Qt::Horizontal;
    expandV = expandingDirections() & Qt::Vertical;

    if ( expandH || expandV )
Bryant's avatar
Bryant committed
370
        stretchGrid( rect, numColumns, rowHeight, colWidth );
pixhawk's avatar
pixhawk committed
371

Bryant's avatar
Bryant committed
372 373 374 375
    const int maxColumns = d_data->maxColumns;
    d_data->maxColumns = numColumns;
    const QRect alignedRect = alignmentRect( rect );
    d_data->maxColumns = maxColumns;
pixhawk's avatar
pixhawk committed
376 377 378 379

    const int xOffset = expandH ? 0 : alignedRect.x();
    const int yOffset = expandV ? 0 : alignedRect.y();

Bryant's avatar
Bryant committed
380 381
    QVector<int> colX( numColumns );
    QVector<int> rowY( numRows );
pixhawk's avatar
pixhawk committed
382 383 384 385

    const int xySpace = spacing();

    rowY[0] = yOffset + margin();
Bryant's avatar
Bryant committed
386
    for ( uint r = 1; r < numRows; r++ )
pixhawk's avatar
pixhawk committed
387 388 389
        rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;

    colX[0] = xOffset + margin();
Bryant's avatar
Bryant committed
390
    for ( uint c = 1; c < numColumns; c++ )
pixhawk's avatar
pixhawk committed
391
        colX[c] = colX[c-1] + colWidth[c-1] + xySpace;
392

pixhawk's avatar
pixhawk committed
393
    const int itemCount = d_data->itemList.size();
Bryant's avatar
Bryant committed
394 395 396 397
    for ( int i = 0; i < itemCount; i++ )
    {
        const int row = i / numColumns;
        const int col = i % numColumns;
pixhawk's avatar
pixhawk committed
398

Bryant's avatar
Bryant committed
399 400 401
        QRect itemGeometry( colX[col], rowY[row],
            colWidth[col], rowHeight[row] );
        itemGeometries.append( itemGeometry );
pixhawk's avatar
pixhawk committed
402 403 404 405 406 407 408 409
    }

    return itemGeometries;
}


/*!
  Calculate the dimensions for the columns and rows for a grid
Bryant's avatar
Bryant committed
410 411 412
  of numColumns columns.

  \param numColumns Number of columns.
pixhawk's avatar
pixhawk committed
413 414 415 416
  \param rowHeight Array where to fill in the calculated row heights.
  \param colWidth Array where to fill in the calculated column widths.
*/

Bryant's avatar
Bryant committed
417 418
void QwtDynGridLayout::layoutGrid( uint numColumns,
    QVector<int>& rowHeight, QVector<int>& colWidth ) const
pixhawk's avatar
pixhawk committed
419
{
Bryant's avatar
Bryant committed
420
    if ( numColumns <= 0 )
pixhawk's avatar
pixhawk committed
421 422 423
        return;

    if ( d_data->isDirty )
Bryant's avatar
Bryant committed
424
        d_data->updateLayoutCache();
pixhawk's avatar
pixhawk committed
425

Bryant's avatar
Bryant committed
426 427 428 429
    for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )
    {
        const int row = index / numColumns;
        const int col = index % numColumns;
pixhawk's avatar
pixhawk committed
430

Bryant's avatar
Bryant committed
431
        const QSize &size = d_data->itemSizeHints[int( index )];
pixhawk's avatar
pixhawk committed
432

Bryant's avatar
Bryant committed
433 434 435 436
        rowHeight[row] = ( col == 0 )
            ? size.height() : qMax( rowHeight[row], size.height() );
        colWidth[col] = ( row == 0 )
            ? size.width() : qMax( colWidth[col], size.width() );
pixhawk's avatar
pixhawk committed
437 438 439 440
    }
}

/*!
Bryant's avatar
Bryant committed
441 442
  \return true: QwtDynGridLayout implements heightForWidth().
  \sa heightForWidth()
pixhawk's avatar
pixhawk committed
443 444 445 446 447 448 449
*/
bool QwtDynGridLayout::hasHeightForWidth() const
{
    return true;
}

/*!
Bryant's avatar
Bryant committed
450 451
  \return The preferred height for this layout, given a width.
  \sa hasHeightForWidth()
pixhawk's avatar
pixhawk committed
452
*/
Bryant's avatar
Bryant committed
453
int QwtDynGridLayout::heightForWidth( int width ) const
pixhawk's avatar
pixhawk committed
454 455 456 457
{
    if ( isEmpty() )
        return 0;

Bryant's avatar
Bryant committed
458 459 460
    const uint numColumns = columnsForWidth( width );
    uint numRows = itemCount() / numColumns;
    if ( itemCount() % numColumns )
pixhawk's avatar
pixhawk committed
461 462
        numRows++;

Bryant's avatar
Bryant committed
463 464
    QVector<int> rowHeight( numRows );
    QVector<int> colWidth( numColumns );
pixhawk's avatar
pixhawk committed
465

Bryant's avatar
Bryant committed
466
    layoutGrid( numColumns, rowHeight, colWidth );
pixhawk's avatar
pixhawk committed
467

Bryant's avatar
Bryant committed
468 469
    int h = 2 * margin() + ( numRows - 1 ) * spacing();
    for ( uint row = 0; row < numRows; row++ )
pixhawk's avatar
pixhawk committed
470 471 472 473 474 475 476 477 478 479
        h += rowHeight[row];

    return h;
}

/*!
  Stretch columns in case of expanding() & QSizePolicy::Horizontal and
  rows in case of expanding() & QSizePolicy::Vertical to fill the entire
  rect. Rows and columns are stretched with the same factor.

Bryant's avatar
Bryant committed
480 481 482 483 484 485 486 487 488
  \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 numColumns, QVector<int>& rowHeight, QVector<int>& colWidth ) const
pixhawk's avatar
pixhawk committed
489
{
Bryant's avatar
Bryant committed
490
    if ( numColumns == 0 || isEmpty() )
pixhawk's avatar
pixhawk committed
491 492 493 494 495
        return;

    bool expandH, expandV;
    expandH = expandingDirections() & Qt::Horizontal;
    expandV = expandingDirections() & Qt::Vertical;
Bryant's avatar
Bryant committed
496 497 498 499 500

    if ( expandH )
    {
        int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing();
        for ( uint col = 0; col < numColumns; col++ )
pixhawk's avatar
pixhawk committed
501 502
            xDelta -= colWidth[col];

Bryant's avatar
Bryant committed
503 504 505 506 507
        if ( xDelta > 0 )
        {
            for ( uint col = 0; col < numColumns; col++ )
            {
                const int space = xDelta / ( numColumns - col );
pixhawk's avatar
pixhawk committed
508 509 510 511 512 513
                colWidth[col] += space;
                xDelta -= space;
            }
        }
    }

Bryant's avatar
Bryant committed
514 515 516 517
    if ( expandV )
    {
        uint numRows = itemCount() / numColumns;
        if ( itemCount() % numColumns )
pixhawk's avatar
pixhawk committed
518 519
            numRows++;

Bryant's avatar
Bryant committed
520 521
        int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();
        for ( uint row = 0; row < numRows; row++ )
pixhawk's avatar
pixhawk committed
522 523
            yDelta -= rowHeight[row];

Bryant's avatar
Bryant committed
524 525 526 527 528
        if ( yDelta > 0 )
        {
            for ( uint row = 0; row < numRows; row++ )
            {
                const int space = yDelta / ( numRows - row );
pixhawk's avatar
pixhawk committed
529 530 531 532 533 534 535 536
                rowHeight[row] += space;
                yDelta -= space;
            }
        }
    }
}

/*!
Bryant's avatar
Bryant committed
537 538
   Return the size hint. If maxColumns() > 0 it is the size for
   a grid with maxColumns() columns, otherwise it is the size for
pixhawk's avatar
pixhawk committed
539 540
   a grid with only one row.

Bryant's avatar
Bryant committed
541 542 543
   \return Size hint
   \sa maxColumns(), setMaxColumns()
*/
pixhawk's avatar
pixhawk committed
544 545 546 547 548
QSize QwtDynGridLayout::sizeHint() const
{
    if ( isEmpty() )
        return QSize();

Bryant's avatar
Bryant committed
549 550 551 552 553 554
    uint numColumns = itemCount();
    if ( d_data->maxColumns > 0 )
        numColumns = qMin( d_data->maxColumns, numColumns );

    uint numRows = itemCount() / numColumns;
    if ( itemCount() % numColumns )
pixhawk's avatar
pixhawk committed
555 556
        numRows++;

Bryant's avatar
Bryant committed
557 558
    QVector<int> rowHeight( numRows );
    QVector<int> colWidth( numColumns );
pixhawk's avatar
pixhawk committed
559

Bryant's avatar
Bryant committed
560
    layoutGrid( numColumns, rowHeight, colWidth );
pixhawk's avatar
pixhawk committed
561

Bryant's avatar
Bryant committed
562 563
    int h = 2 * margin() + ( numRows - 1 ) * spacing();
    for ( uint row = 0; row < numRows; row++ )
pixhawk's avatar
pixhawk committed
564 565
        h += rowHeight[row];

Bryant's avatar
Bryant committed
566 567
    int w = 2 * margin() + ( numColumns - 1 ) * spacing();
    for ( uint col = 0; col < numColumns; col++ )
pixhawk's avatar
pixhawk committed
568 569
        w += colWidth[col];

Bryant's avatar
Bryant committed
570
    return QSize( w, h );
pixhawk's avatar
pixhawk committed
571 572 573 574
}

/*!
  \return Number of rows of the current layout.
Bryant's avatar
Bryant committed
575
  \sa numColumns()
pixhawk's avatar
pixhawk committed
576 577
  \warning The number of rows might change whenever the geometry changes
*/
578 579 580
uint QwtDynGridLayout::numRows() const
{
    return d_data->numRows;
pixhawk's avatar
pixhawk committed
581 582 583 584
}

/*!
  \return Number of columns of the current layout.
Bryant's avatar
Bryant committed
585
  \sa numRows()
pixhawk's avatar
pixhawk committed
586 587
  \warning The number of columns might change whenever the geometry changes
*/
Bryant's avatar
Bryant committed
588
uint QwtDynGridLayout::numColumns() const
589
{
Bryant's avatar
Bryant committed
590
    return d_data->numColumns;
pixhawk's avatar
pixhawk committed
591
}