| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicslinearlayout.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | /*! | - | ||||||||||||
| 35 | \class QGraphicsLinearLayout | - | ||||||||||||
| 36 | \brief The QGraphicsLinearLayout class provides a horizontal or vertical | - | ||||||||||||
| 37 | layout for managing widgets in Graphics View. | - | ||||||||||||
| 38 | \since 4.4 | - | ||||||||||||
| 39 | \ingroup graphicsview-api | - | ||||||||||||
| 40 | \inmodule QtWidgets | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | The default orientation for a linear layout is Qt::Horizontal. You can | - | ||||||||||||
| 43 | choose a vertical orientation either by calling setOrientation(), or by | - | ||||||||||||
| 44 | passing Qt::Vertical to QGraphicsLinearLayout's constructor. | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | The most common way to use QGraphicsLinearLayout is to construct an object | - | ||||||||||||
| 47 | on the heap with no parent, add widgets and layouts by calling addItem(), | - | ||||||||||||
| 48 | and finally assign the layout to a widget by calling | - | ||||||||||||
| 49 | QGraphicsWidget::setLayout(). | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | \snippet code/src_gui_graphicsview_qgraphicslinearlayout.cpp 0 | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | You can add widgets, layouts, stretches (addStretch(), insertStretch() or | - | ||||||||||||
| 54 | setStretchFactor()), and spacings (setItemSpacing()) to a linear | - | ||||||||||||
| 55 | layout. The layout takes ownership of the items. In some cases when the layout | - | ||||||||||||
| 56 | item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a | - | ||||||||||||
| 57 | ambiguity in ownership because the layout item belongs to two ownership hierarchies. | - | ||||||||||||
| 58 | See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle | - | ||||||||||||
| 59 | this. | - | ||||||||||||
| 60 | You can access each item in the layout by calling count() and itemAt(). Calling | - | ||||||||||||
| 61 | removeAt() or removeItem() will remove an item from the layout, without | - | ||||||||||||
| 62 | destroying it. | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | \section1 Size Hints and Size Policies in QGraphicsLinearLayout | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | QGraphicsLinearLayout respects each item's size hints and size policies, | - | ||||||||||||
| 67 | and when the layout contains more space than the items can fill, each item | - | ||||||||||||
| 68 | is arranged according to the layout's alignment for that item. You can set | - | ||||||||||||
| 69 | an alignment for each item by calling setAlignment(), and check the | - | ||||||||||||
| 70 | alignment for any item by calling alignment(). By default, items are | - | ||||||||||||
| 71 | aligned to the top left. | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | \section1 Spacing within QGraphicsLinearLayout | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | Between the items, the layout distributes some space. The actual amount of | - | ||||||||||||
| 76 | space depends on the managed widget's current style, but the common | - | ||||||||||||
| 77 | spacing is 4. You can also set your own spacing by calling setSpacing(), | - | ||||||||||||
| 78 | and get the current spacing value by calling spacing(). If you want to | - | ||||||||||||
| 79 | configure individual spacing for your items, you can call setItemSpacing(). | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | \section1 Stretch Factor in QGraphicsLinearLayout | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | You can assign a stretch factor to each item to control how much space it | - | ||||||||||||
| 84 | will get compared to the other items. By default, two identical widgets | - | ||||||||||||
| 85 | arranged in a linear layout will have the same size, but if the first | - | ||||||||||||
| 86 | widget has a stretch factor of 1 and the second widget has a stretch | - | ||||||||||||
| 87 | factor of 2, the first widget will get 1/3 of the available space, and the | - | ||||||||||||
| 88 | second will get 2/3. | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | QGraphicsLinearLayout calculates the distribution of sizes by adding up | - | ||||||||||||
| 91 | the stretch factors of all items, and then dividing the available space | - | ||||||||||||
| 92 | accordingly. The default stretch factor is 0 for all items; a factor of 0 | - | ||||||||||||
| 93 | means the item does not have any defined stretch factor; effectively this | - | ||||||||||||
| 94 | is the same as setting the stretch factor to 1. The stretch factor only | - | ||||||||||||
| 95 | applies to the available space in the lengthwise direction of the layout | - | ||||||||||||
| 96 | (following its orientation). If you want to control both the item's | - | ||||||||||||
| 97 | horizontal and vertical stretch, you can use QGraphicsGridLayout instead. | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | \section1 QGraphicsLinearLayout Compared to Other Layouts | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | QGraphicsLinearLayout is very similar to QVBoxLayout and QHBoxLayout, but | - | ||||||||||||
| 102 | in contrast to these classes, it is used to manage QGraphicsWidget and | - | ||||||||||||
| 103 | QGraphicsLayout instead of QWidget and QLayout. | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | \sa QGraphicsGridLayout, QGraphicsWidget | - | ||||||||||||
| 106 | */ | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | #include "qapplication.h" | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | #include "qwidget.h" | - | ||||||||||||
| 113 | #include "qgraphicslayout_p.h" | - | ||||||||||||
| 114 | #include "qgraphicslayoutitem.h" | - | ||||||||||||
| 115 | #include "qgraphicslinearlayout.h" | - | ||||||||||||
| 116 | #include "qgraphicswidget.h" | - | ||||||||||||
| 117 | #include "qgraphicsgridlayoutengine_p.h" | - | ||||||||||||
| 118 | #include "qgraphicslayoutstyleinfo_p.h" | - | ||||||||||||
| 119 | #include "qscopedpointer.h" | - | ||||||||||||
| 120 | #ifdef QT_DEBUG | - | ||||||||||||
| 121 | #include <QtCore/qdebug.h> | - | ||||||||||||
| 122 | #endif | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 125 | - | |||||||||||||
| 126 | class QGraphicsLinearLayoutPrivate : public QGraphicsLayoutPrivate | - | ||||||||||||
| 127 | { | - | ||||||||||||
| 128 | public: | - | ||||||||||||
| 129 | QGraphicsLinearLayoutPrivate(Qt::Orientation orientation) | - | ||||||||||||
| 130 | : orientation(orientation) | - | ||||||||||||
| 131 |     { } never executed:  end of block | 0 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | void removeGridItem(QGridLayoutItem *gridItem); | - | ||||||||||||
| 134 | QGraphicsLayoutStyleInfo *styleInfo() const; | - | ||||||||||||
| 135 | void fixIndex(int *index) const; | - | ||||||||||||
| 136 | int gridRow(int index) const; | - | ||||||||||||
| 137 | int gridColumn(int index) const; | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | Qt::Orientation orientation; | - | ||||||||||||
| 140 | mutable QScopedPointer<QGraphicsLayoutStyleInfo> m_styleInfo; | - | ||||||||||||
| 141 | QGraphicsGridLayoutEngine engine; | - | ||||||||||||
| 142 | }; | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | void QGraphicsLinearLayoutPrivate::removeGridItem(QGridLayoutItem *gridItem) | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | int index = gridItem->firstRow(orientation); | - | ||||||||||||
| 147 | engine.removeItem(gridItem); | - | ||||||||||||
| 148 | engine.removeRows(index, 1, orientation); | - | ||||||||||||
| 149 | } never executed:  end of block | 0 | ||||||||||||
| 150 | - | |||||||||||||
| 151 | void QGraphicsLinearLayoutPrivate::fixIndex(int *index) const | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | int count = engine.rowCount(orientation); | - | ||||||||||||
| 154 |     if (uint(*index) > uint(count))
  | 0 | ||||||||||||
| 155 |         *index = count; never executed:  *index = count; | 0 | ||||||||||||
| 156 | } never executed:  end of block | 0 | ||||||||||||
| 157 | - | |||||||||||||
| 158 | int QGraphicsLinearLayoutPrivate::gridRow(int index) const | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 |     if (orientation == Qt::Horizontal)
  | 0 | ||||||||||||
| 161 |         return 0; never executed:  return 0; | 0 | ||||||||||||
| 162 |     return int(qMin(uint(index), uint(engine.rowCount()))); never executed:  return int(qMin(uint(index), uint(engine.rowCount()))); | 0 | ||||||||||||
| 163 | } | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | int QGraphicsLinearLayoutPrivate::gridColumn(int index) const | - | ||||||||||||
| 166 | { | - | ||||||||||||
| 167 |     if (orientation == Qt::Vertical)
  | 0 | ||||||||||||
| 168 |         return 0; never executed:  return 0; | 0 | ||||||||||||
| 169 |     return int(qMin(uint(index), uint(engine.columnCount()))); never executed:  return int(qMin(uint(index), uint(engine.columnCount()))); | 0 | ||||||||||||
| 170 | } | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | QGraphicsLayoutStyleInfo *QGraphicsLinearLayoutPrivate::styleInfo() const | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 |     if (!m_styleInfo)
  | 0 | ||||||||||||
| 175 |         m_styleInfo.reset(new QGraphicsLayoutStyleInfo(this)); never executed:  m_styleInfo.reset(new QGraphicsLayoutStyleInfo(this)); | 0 | ||||||||||||
| 176 |     return m_styleInfo.data(); never executed:  return m_styleInfo.data(); | 0 | ||||||||||||
| 177 | } | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | /*! | - | ||||||||||||
| 180 | Constructs a QGraphicsLinearLayout instance. You can pass the | - | ||||||||||||
| 181 | \a orientation for the layout, either horizontal or vertical, and | - | ||||||||||||
| 182 | \a parent is passed to QGraphicsLayout's constructor. | - | ||||||||||||
| 183 | */ | - | ||||||||||||
| 184 | QGraphicsLinearLayout::QGraphicsLinearLayout(Qt::Orientation orientation, QGraphicsLayoutItem *parent) | - | ||||||||||||
| 185 | : QGraphicsLayout(*new QGraphicsLinearLayoutPrivate(orientation), parent) | - | ||||||||||||
| 186 | { | - | ||||||||||||
| 187 | } never executed:  end of block | 0 | ||||||||||||
| 188 | - | |||||||||||||
| 189 | /*! | - | ||||||||||||
| 190 | Constructs a QGraphicsLinearLayout instance using Qt::Horizontal | - | ||||||||||||
| 191 | orientation. \a parent is passed to QGraphicsLayout's constructor. | - | ||||||||||||
| 192 | */ | - | ||||||||||||
| 193 | QGraphicsLinearLayout::QGraphicsLinearLayout(QGraphicsLayoutItem *parent) | - | ||||||||||||
| 194 | : QGraphicsLayout(*new QGraphicsLinearLayoutPrivate(Qt::Horizontal), parent) | - | ||||||||||||
| 195 | { | - | ||||||||||||
| 196 | } never executed:  end of block | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | /*! | - | ||||||||||||
| 199 | Destroys the QGraphicsLinearLayout object. | - | ||||||||||||
| 200 | */ | - | ||||||||||||
| 201 | QGraphicsLinearLayout::~QGraphicsLinearLayout() | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 |     for (int i = count() - 1; i >= 0; --i) {
  | 0 | ||||||||||||
| 204 | QGraphicsLayoutItem *item = itemAt(i); | - | ||||||||||||
| 205 | // The following lines can be removed, but this removes the item | - | ||||||||||||
| 206 | // from the layout more efficiently than the implementation of | - | ||||||||||||
| 207 | // ~QGraphicsLayoutItem. | - | ||||||||||||
| 208 | removeAt(i); | - | ||||||||||||
| 209 |         if (item) {
  | 0 | ||||||||||||
| 210 | item->setParentLayoutItem(0); | - | ||||||||||||
| 211 |             if (item->ownedByLayout())
  | 0 | ||||||||||||
| 212 |                 delete item; never executed:  delete item; | 0 | ||||||||||||
| 213 |         } never executed:  end of block | 0 | ||||||||||||
| 214 |     } never executed:  end of block | 0 | ||||||||||||
| 215 | } never executed:  end of block | 0 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | /*! | - | ||||||||||||
| 218 | Change the layout orientation to \a orientation. Changing the layout | - | ||||||||||||
| 219 | orientation will automatically invalidate the layout. | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | \sa orientation() | - | ||||||||||||
| 222 | */ | - | ||||||||||||
| 223 | void QGraphicsLinearLayout::setOrientation(Qt::Orientation orientation) | - | ||||||||||||
| 224 | { | - | ||||||||||||
| 225 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 226 |     if (orientation != d->orientation) {
  | 0 | ||||||||||||
| 227 | d->engine.transpose(); | - | ||||||||||||
| 228 | d->orientation = orientation; | - | ||||||||||||
| 229 | invalidate(); | - | ||||||||||||
| 230 |     } never executed:  end of block | 0 | ||||||||||||
| 231 | } never executed:  end of block | 0 | ||||||||||||
| 232 | - | |||||||||||||
| 233 | /*! | - | ||||||||||||
| 234 | Returns the layout orientation. | - | ||||||||||||
| 235 | \sa setOrientation() | - | ||||||||||||
| 236 | */ | - | ||||||||||||
| 237 | Qt::Orientation QGraphicsLinearLayout::orientation() const | - | ||||||||||||
| 238 | { | - | ||||||||||||
| 239 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 240 |     return d->orientation; never executed:  return d->orientation; | 0 | ||||||||||||
| 241 | } | - | ||||||||||||
| 242 | - | |||||||||||||
| 243 | /*! | - | ||||||||||||
| 244 | \fn void QGraphicsLinearLayout::addItem(QGraphicsLayoutItem *item) | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | This convenience function is equivalent to calling | - | ||||||||||||
| 247 | insertItem(-1, \a item). | - | ||||||||||||
| 248 | */ | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | /*! | - | ||||||||||||
| 251 | \fn void QGraphicsLinearLayout::addStretch(int stretch) | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | This convenience function is equivalent to calling | - | ||||||||||||
| 254 | insertStretch(-1, \a stretch). | - | ||||||||||||
| 255 | */ | - | ||||||||||||
| 256 | - | |||||||||||||
| 257 | /*! | - | ||||||||||||
| 258 | Inserts \a item into the layout at \a index, or before any item that is | - | ||||||||||||
| 259 | currently at \a index. | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | \sa addItem(), itemAt(), insertStretch(), setItemSpacing() | - | ||||||||||||
| 262 | */ | - | ||||||||||||
| 263 | void QGraphicsLinearLayout::insertItem(int index, QGraphicsLayoutItem *item) | - | ||||||||||||
| 264 | { | - | ||||||||||||
| 265 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 266 |     if (!item) {
  | 0 | ||||||||||||
| 267 | qWarning("QGraphicsLinearLayout::insertItem: cannot insert null item"); | - | ||||||||||||
| 268 |         return; never executed:  return; | 0 | ||||||||||||
| 269 | } | - | ||||||||||||
| 270 |     if (item == this) {
  | 0 | ||||||||||||
| 271 | qWarning("QGraphicsLinearLayout::insertItem: cannot insert itself"); | - | ||||||||||||
| 272 |         return; never executed:  return; | 0 | ||||||||||||
| 273 | } | - | ||||||||||||
| 274 | d->addChildLayoutItem(item); | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | Q_ASSERT(item); | - | ||||||||||||
| 277 | d->fixIndex(&index); | - | ||||||||||||
| 278 | d->engine.insertRow(index, d->orientation); | - | ||||||||||||
| 279 | QGraphicsGridLayoutEngineItem *gridEngineItem = new QGraphicsGridLayoutEngineItem(item, d->gridRow(index), d->gridColumn(index), 1, 1, 0); | - | ||||||||||||
| 280 | d->engine.insertItem(gridEngineItem, index); | - | ||||||||||||
| 281 | invalidate(); | - | ||||||||||||
| 282 | } never executed:  end of block | 0 | ||||||||||||
| 283 | - | |||||||||||||
| 284 | /*! | - | ||||||||||||
| 285 | Inserts a stretch of \a stretch at \a index, or before any item that is | - | ||||||||||||
| 286 | currently at \a index. | - | ||||||||||||
| 287 | - | |||||||||||||
| 288 | \sa addStretch(), setStretchFactor(), setItemSpacing(), insertItem() | - | ||||||||||||
| 289 | */ | - | ||||||||||||
| 290 | void QGraphicsLinearLayout::insertStretch(int index, int stretch) | - | ||||||||||||
| 291 | { | - | ||||||||||||
| 292 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 293 | d->fixIndex(&index); | - | ||||||||||||
| 294 | d->engine.insertRow(index, d->orientation); | - | ||||||||||||
| 295 | d->engine.setRowStretchFactor(index, stretch, d->orientation); | - | ||||||||||||
| 296 | invalidate(); | - | ||||||||||||
| 297 | } never executed:  end of block | 0 | ||||||||||||
| 298 | - | |||||||||||||
| 299 | /*! | - | ||||||||||||
| 300 | Removes \a item from the layout without destroying it. Ownership of | - | ||||||||||||
| 301 | \a item is transferred to the caller. | - | ||||||||||||
| 302 | - | |||||||||||||
| 303 | \sa removeAt(), insertItem() | - | ||||||||||||
| 304 | */ | - | ||||||||||||
| 305 | void QGraphicsLinearLayout::removeItem(QGraphicsLayoutItem *item) | - | ||||||||||||
| 306 | { | - | ||||||||||||
| 307 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 308 |     if (QGraphicsGridLayoutEngineItem *gridItem = d->engine.findLayoutItem(item)) {
  | 0 | ||||||||||||
| 309 | item->setParentLayoutItem(0); | - | ||||||||||||
| 310 | d->removeGridItem(gridItem); | - | ||||||||||||
| 311 | delete gridItem; | - | ||||||||||||
| 312 | invalidate(); | - | ||||||||||||
| 313 |     } never executed:  end of block | 0 | ||||||||||||
| 314 | } never executed:  end of block | 0 | ||||||||||||
| 315 | - | |||||||||||||
| 316 | /*! | - | ||||||||||||
| 317 | Removes the item at \a index without destroying it. Ownership of the item | - | ||||||||||||
| 318 | is transferred to the caller. | - | ||||||||||||
| 319 | - | |||||||||||||
| 320 | \sa removeItem(), insertItem() | - | ||||||||||||
| 321 | */ | - | ||||||||||||
| 322 | void QGraphicsLinearLayout::removeAt(int index) | - | ||||||||||||
| 323 | { | - | ||||||||||||
| 324 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 325 |     if (index < 0 || index >= d->engine.itemCount()) {
 
  | 0 | ||||||||||||
| 326 | qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index); | - | ||||||||||||
| 327 |         return; never executed:  return; | 0 | ||||||||||||
| 328 | } | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 |     if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) {
  | 0 | ||||||||||||
| 331 |         if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
  | 0 | ||||||||||||
| 332 |             layoutItem->setParentLayoutItem(0); never executed:  layoutItem->setParentLayoutItem(0); | 0 | ||||||||||||
| 333 | d->removeGridItem(gridItem); | - | ||||||||||||
| 334 | delete gridItem; | - | ||||||||||||
| 335 | invalidate(); | - | ||||||||||||
| 336 |     } never executed:  end of block | 0 | ||||||||||||
| 337 | } never executed:  end of block | 0 | ||||||||||||
| 338 | - | |||||||||||||
| 339 | /*! | - | ||||||||||||
| 340 | Sets the layout's spacing to \a spacing. Spacing refers to the | - | ||||||||||||
| 341 | vertical and horizontal distances between items. | - | ||||||||||||
| 342 | - | |||||||||||||
| 343 | \sa setItemSpacing(), setStretchFactor(), QGraphicsGridLayout::setSpacing() | - | ||||||||||||
| 344 | */ | - | ||||||||||||
| 345 | void QGraphicsLinearLayout::setSpacing(qreal spacing) | - | ||||||||||||
| 346 | { | - | ||||||||||||
| 347 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 348 |     if (spacing < 0) {
  | 0 | ||||||||||||
| 349 | qWarning("QGraphicsLinearLayout::setSpacing: invalid spacing %g", spacing); | - | ||||||||||||
| 350 |         return; never executed:  return; | 0 | ||||||||||||
| 351 | } | - | ||||||||||||
| 352 | d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical); | - | ||||||||||||
| 353 | invalidate(); | - | ||||||||||||
| 354 | } never executed:  end of block | 0 | ||||||||||||
| 355 | - | |||||||||||||
| 356 | /*! | - | ||||||||||||
| 357 | Returns the layout's spacing. Spacing refers to the | - | ||||||||||||
| 358 | vertical and horizontal distances between items. | - | ||||||||||||
| 359 | - | |||||||||||||
| 360 | \sa setSpacing() | - | ||||||||||||
| 361 | */ | - | ||||||||||||
| 362 | qreal QGraphicsLinearLayout::spacing() const | - | ||||||||||||
| 363 | { | - | ||||||||||||
| 364 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 365 |     return d->engine.spacing(d->orientation, d->styleInfo()); never executed:  return d->engine.spacing(d->orientation, d->styleInfo()); | 0 | ||||||||||||
| 366 | } | - | ||||||||||||
| 367 | - | |||||||||||||
| 368 | /*! | - | ||||||||||||
| 369 | Sets the spacing after item at \a index to \a spacing. | - | ||||||||||||
| 370 | */ | - | ||||||||||||
| 371 | void QGraphicsLinearLayout::setItemSpacing(int index, qreal spacing) | - | ||||||||||||
| 372 | { | - | ||||||||||||
| 373 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 374 | d->engine.setRowSpacing(index, spacing, d->orientation); | - | ||||||||||||
| 375 | invalidate(); | - | ||||||||||||
| 376 | } never executed:  end of block | 0 | ||||||||||||
| 377 | /*! | - | ||||||||||||
| 378 | Returns the spacing after item at \a index. | - | ||||||||||||
| 379 | */ | - | ||||||||||||
| 380 | qreal QGraphicsLinearLayout::itemSpacing(int index) const | - | ||||||||||||
| 381 | { | - | ||||||||||||
| 382 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 383 |     return d->engine.rowSpacing(index, d->orientation); never executed:  return d->engine.rowSpacing(index, d->orientation); | 0 | ||||||||||||
| 384 | } | - | ||||||||||||
| 385 | - | |||||||||||||
| 386 | /*! | - | ||||||||||||
| 387 | Sets the stretch factor for \a item to \a stretch. If an item's stretch | - | ||||||||||||
| 388 | factor changes, this function will invalidate the layout. | - | ||||||||||||
| 389 | - | |||||||||||||
| 390 | Setting \a stretch to 0 removes the stretch factor from the item, and is | - | ||||||||||||
| 391 | effectively equivalent to setting \a stretch to 1. | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | \sa stretchFactor() | - | ||||||||||||
| 394 | */ | - | ||||||||||||
| 395 | void QGraphicsLinearLayout::setStretchFactor(QGraphicsLayoutItem *item, int stretch) | - | ||||||||||||
| 396 | { | - | ||||||||||||
| 397 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 398 |     if (!item) {
  | 0 | ||||||||||||
| 399 | qWarning("QGraphicsLinearLayout::setStretchFactor: cannot assign" | - | ||||||||||||
| 400 | " a stretch factor to a null item"); | - | ||||||||||||
| 401 |         return; never executed:  return; | 0 | ||||||||||||
| 402 | } | - | ||||||||||||
| 403 |     if (stretchFactor(item) == stretch)
  | 0 | ||||||||||||
| 404 |         return; never executed:  return; | 0 | ||||||||||||
| 405 | d->engine.setStretchFactor(item, stretch, d->orientation); | - | ||||||||||||
| 406 | invalidate(); | - | ||||||||||||
| 407 | } never executed:  end of block | 0 | ||||||||||||
| 408 | - | |||||||||||||
| 409 | /*! | - | ||||||||||||
| 410 | Returns the stretch factor for \a item. The default stretch factor is 0, | - | ||||||||||||
| 411 | meaning that the item has no assigned stretch factor. | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | \sa setStretchFactor() | - | ||||||||||||
| 414 | */ | - | ||||||||||||
| 415 | int QGraphicsLinearLayout::stretchFactor(QGraphicsLayoutItem *item) const | - | ||||||||||||
| 416 | { | - | ||||||||||||
| 417 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 418 |     if (!item) {
  | 0 | ||||||||||||
| 419 | qWarning("QGraphicsLinearLayout::setStretchFactor: cannot return" | - | ||||||||||||
| 420 | " a stretch factor for a null item"); | - | ||||||||||||
| 421 |         return 0; never executed:  return 0; | 0 | ||||||||||||
| 422 | } | - | ||||||||||||
| 423 |     return d->engine.stretchFactor(item, d->orientation); never executed:  return d->engine.stretchFactor(item, d->orientation); | 0 | ||||||||||||
| 424 | } | - | ||||||||||||
| 425 | - | |||||||||||||
| 426 | /*! | - | ||||||||||||
| 427 | Sets the alignment of \a item to \a alignment. If \a item's alignment | - | ||||||||||||
| 428 | changes, the layout is automatically invalidated. | - | ||||||||||||
| 429 | - | |||||||||||||
| 430 | \sa alignment(), invalidate() | - | ||||||||||||
| 431 | */ | - | ||||||||||||
| 432 | void QGraphicsLinearLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) | - | ||||||||||||
| 433 | { | - | ||||||||||||
| 434 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 435 |     if (this->alignment(item) == alignment)
  | 0 | ||||||||||||
| 436 |         return; never executed:  return; | 0 | ||||||||||||
| 437 | d->engine.setAlignment(item, alignment); | - | ||||||||||||
| 438 | invalidate(); | - | ||||||||||||
| 439 | } never executed:  end of block | 0 | ||||||||||||
| 440 | - | |||||||||||||
| 441 | /*! | - | ||||||||||||
| 442 | Returns the alignment for \a item. The default alignment is | - | ||||||||||||
| 443 | Qt::AlignTop | Qt::AlignLeft. | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | The alignment decides how the item is positioned within its assigned space | - | ||||||||||||
| 446 | in the case where there's more space available in the layout than the | - | ||||||||||||
| 447 | widgets can occupy. | - | ||||||||||||
| 448 | - | |||||||||||||
| 449 | \sa setAlignment() | - | ||||||||||||
| 450 | */ | - | ||||||||||||
| 451 | Qt::Alignment QGraphicsLinearLayout::alignment(QGraphicsLayoutItem *item) const | - | ||||||||||||
| 452 | { | - | ||||||||||||
| 453 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 454 |     return d->engine.alignment(item); never executed:  return d->engine.alignment(item); | 0 | ||||||||||||
| 455 | } | - | ||||||||||||
| 456 | - | |||||||||||||
| 457 | #if 0 // ### | - | ||||||||||||
| 458 | QSizePolicy::ControlTypes QGraphicsLinearLayout::controlTypes(LayoutSide side) const | - | ||||||||||||
| 459 | { | - | ||||||||||||
| 460 | return d->engine.controlTypes(side); | - | ||||||||||||
| 461 | } | - | ||||||||||||
| 462 | #endif | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | /*! | - | ||||||||||||
| 465 | \reimp | - | ||||||||||||
| 466 | */ | - | ||||||||||||
| 467 | int QGraphicsLinearLayout::count() const | - | ||||||||||||
| 468 | { | - | ||||||||||||
| 469 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 470 |     return d->engine.itemCount(); never executed:  return d->engine.itemCount(); | 0 | ||||||||||||
| 471 | } | - | ||||||||||||
| 472 | - | |||||||||||||
| 473 | /*! | - | ||||||||||||
| 474 | \reimp | - | ||||||||||||
| 475 | When iterating from 0 and up, it will return the items in the visual arranged order. | - | ||||||||||||
| 476 | */ | - | ||||||||||||
| 477 | QGraphicsLayoutItem *QGraphicsLinearLayout::itemAt(int index) const | - | ||||||||||||
| 478 | { | - | ||||||||||||
| 479 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 480 |     if (index < 0 || index >= d->engine.itemCount()) {
 
  | 0 | ||||||||||||
| 481 | qWarning("QGraphicsLinearLayout::itemAt: invalid index %d", index); | - | ||||||||||||
| 482 |         return 0; never executed:  return 0; | 0 | ||||||||||||
| 483 | } | - | ||||||||||||
| 484 | QGraphicsLayoutItem *item = 0; | - | ||||||||||||
| 485 |     if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem *>(d->engine.itemAt(index)))
  | 0 | ||||||||||||
| 486 |         item = gridItem->layoutItem(); never executed:  item = gridItem->layoutItem(); | 0 | ||||||||||||
| 487 |     return item; never executed:  return item; | 0 | ||||||||||||
| 488 | } | - | ||||||||||||
| 489 | - | |||||||||||||
| 490 | /*! | - | ||||||||||||
| 491 | \reimp | - | ||||||||||||
| 492 | */ | - | ||||||||||||
| 493 | void QGraphicsLinearLayout::setGeometry(const QRectF &rect) | - | ||||||||||||
| 494 | { | - | ||||||||||||
| 495 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 496 | QGraphicsLayout::setGeometry(rect); | - | ||||||||||||
| 497 | QRectF effectiveRect = geometry(); | - | ||||||||||||
| 498 | qreal left, top, right, bottom; | - | ||||||||||||
| 499 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||
| 500 | Qt::LayoutDirection visualDir = d->visualDirection(); | - | ||||||||||||
| 501 | d->engine.setVisualDirection(visualDir); | - | ||||||||||||
| 502 |     if (visualDir == Qt::RightToLeft)
  | 0 | ||||||||||||
| 503 |         qSwap(left, right); never executed:  qSwap(left, right); | 0 | ||||||||||||
| 504 | effectiveRect.adjust(+left, +top, -right, -bottom); | - | ||||||||||||
| 505 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||
| 506 | if (qt_graphicsLayoutDebug()) { | - | ||||||||||||
| 507 | static int counter = 0; | - | ||||||||||||
| 508 | qDebug() << counter++ << "QGraphicsLinearLayout::setGeometry - " << rect; | - | ||||||||||||
| 509 | dump(1); | - | ||||||||||||
| 510 | } | - | ||||||||||||
| 511 | #endif | - | ||||||||||||
| 512 | d->engine.setGeometries(effectiveRect, d->styleInfo()); | - | ||||||||||||
| 513 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||
| 514 | if (qt_graphicsLayoutDebug()) { | - | ||||||||||||
| 515 | qDebug("post dump"); | - | ||||||||||||
| 516 | dump(1); | - | ||||||||||||
| 517 | } | - | ||||||||||||
| 518 | #endif | - | ||||||||||||
| 519 | } never executed:  end of block | 0 | ||||||||||||
| 520 | - | |||||||||||||
| 521 | /*! | - | ||||||||||||
| 522 | \reimp | - | ||||||||||||
| 523 | */ | - | ||||||||||||
| 524 | QSizeF QGraphicsLinearLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | - | ||||||||||||
| 525 | { | - | ||||||||||||
| 526 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 527 | qreal left, top, right, bottom; | - | ||||||||||||
| 528 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||
| 529 | const QSizeF extraMargins(left + right, top + bottom); | - | ||||||||||||
| 530 |     return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins; never executed:  return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins; | 0 | ||||||||||||
| 531 | } | - | ||||||||||||
| 532 | - | |||||||||||||
| 533 | /*! | - | ||||||||||||
| 534 | \reimp | - | ||||||||||||
| 535 | */ | - | ||||||||||||
| 536 | void QGraphicsLinearLayout::invalidate() | - | ||||||||||||
| 537 | { | - | ||||||||||||
| 538 | Q_D(QGraphicsLinearLayout); | - | ||||||||||||
| 539 | d->engine.invalidate(); | - | ||||||||||||
| 540 |     if (d->m_styleInfo)
  | 0 | ||||||||||||
| 541 |         d->m_styleInfo->invalidate(); never executed:  d->m_styleInfo->invalidate(); | 0 | ||||||||||||
| 542 | QGraphicsLayout::invalidate(); | - | ||||||||||||
| 543 | } never executed:  end of block | 0 | ||||||||||||
| 544 | - | |||||||||||||
| 545 | /*! | - | ||||||||||||
| 546 | \internal | - | ||||||||||||
| 547 | */ | - | ||||||||||||
| 548 | void QGraphicsLinearLayout::dump(int indent) const | - | ||||||||||||
| 549 | { | - | ||||||||||||
| 550 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||
| 551 | if (qt_graphicsLayoutDebug()) { | - | ||||||||||||
| 552 | Q_D(const QGraphicsLinearLayout); | - | ||||||||||||
| 553 | qDebug("%*s%s layout", indent, "", | - | ||||||||||||
| 554 | d->orientation == Qt::Horizontal ? "Horizontal" : "Vertical"); | - | ||||||||||||
| 555 | d->engine.dump(indent + 1); | - | ||||||||||||
| 556 | } | - | ||||||||||||
| 557 | #else | - | ||||||||||||
| 558 | Q_UNUSED(indent); | - | ||||||||||||
| 559 | #endif | - | ||||||||||||
| 560 | } never executed:  end of block | 0 | ||||||||||||
| 561 | - | |||||||||||||
| 562 | QT_END_NAMESPACE | - | ||||||||||||
| 563 | - | |||||||||||||
| 564 | #endif //QT_NO_GRAPHICSVIEW | - | ||||||||||||
| Source code | Switch to Preprocessed file |