| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | /*! | - |
| 43 | \class QGraphicsAnchorLayout | - |
| 44 | \brief The QGraphicsAnchorLayout class provides a layout where one can anchor widgets | - |
| 45 | together in Graphics View. | - |
| 46 | \since 4.6 | - |
| 47 | \ingroup appearance | - |
| 48 | \ingroup geomanagement | - |
| 49 | \ingroup graphicsview-api | - |
| 50 | \inmodule QtWidgets | - |
| 51 | | - |
| 52 | The anchor layout allows developers to specify how widgets should be placed relative to | - |
| 53 | each other, and to the layout itself. The specification is made by adding anchors to the | - |
| 54 | layout by calling addAnchor(), addAnchors() or addCornerAnchors(). | - |
| 55 | | - |
| 56 | Existing anchors in the layout can be accessed with the anchor() function. | - |
| 57 | Items that are anchored are automatically added to the layout, and if items | - |
| 58 | are removed, all their anchors will be automatically removed. | - |
| 59 | | - |
| 60 | \div {class="float-left"} | - |
| 61 | \inlineimage simpleanchorlayout-example.png Using an anchor layout to align simple colored widgets. | - |
| 62 | \enddiv | - |
| 63 | | - |
| 64 | Anchors are always set up between edges of an item, where the "center" is also considered to | - |
| 65 | be an edge. Consider the following example: | - |
| 66 | | - |
| 67 | \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors | - |
| 68 | | - |
| 69 | Here, the right edge of item \c a is anchored to the left edge of item \c b and the bottom | - |
| 70 | edge of item \c a is anchored to the top edge of item \c b, with the result that | - |
| 71 | item \c b will be placed diagonally to the right and below item \c b. | - |
| 72 | | - |
| 73 | The addCornerAnchors() function provides a simpler way of anchoring the corners | - |
| 74 | of two widgets than the two individual calls to addAnchor() shown in the code | - |
| 75 | above. Here, we see how a widget can be anchored to the top-left corner of the enclosing | - |
| 76 | layout: | - |
| 77 | | - |
| 78 | \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor | - |
| 79 | | - |
| 80 | In cases where anchors are used to match the widths or heights of widgets, it is | - |
| 81 | convenient to use the addAnchors() function. As with the other functions for specifying | - |
| 82 | anchors, it can also be used to anchor a widget to a layout. | - |
| 83 | | - |
| 84 | \section1 Size Hints and Size Policies in an Anchor Layout | - |
| 85 | | - |
| 86 | QGraphicsAnchorLayout respects each item's size hints and size policies. | - |
| 87 | Note that there are some properties of QSizePolicy that are \l{Known issues}{not respected}. | - |
| 88 | | - |
| 89 | \section1 Spacing within an Anchor Layout | - |
| 90 | | - |
| 91 | The layout may distribute some space between the items. If the spacing has not been | - |
| 92 | explicitly specified, the actual amount of space will usually be 0. | - |
| 93 | | - |
| 94 | However, if the first edge is the \e opposite of the second edge (e.g., the right edge | - |
| 95 | of the first widget is anchored to the left edge of the second widget), the size of the | - |
| 96 | anchor will be queried from the style through a pixel metric: | - |
| 97 | \l{QStyle::}{PM_LayoutHorizontalSpacing} for horizontal anchors and | - |
| 98 | \l{QStyle::}{PM_LayoutVerticalSpacing} for vertical anchors. | - |
| 99 | | - |
| 100 | If the spacing is negative, the items will overlap to some extent. | - |
| 101 | | - |
| 102 | | - |
| 103 | \section1 Known issues | - |
| 104 | There are some features that QGraphicsAnchorLayout currently does not support. | - |
| 105 | This might change in the future, so avoid using these features if you want to | - |
| 106 | avoid any future regressions in behaviour: | - |
| 107 | \list | - |
| 108 | | - |
| 109 | \li Stretch factors are not respected. | - |
| 110 | | - |
| 111 | \li QSizePolicy::ExpandFlag is not respected. | - |
| 112 | | - |
| 113 | \li Height for width is not respected. | - |
| 114 | | - |
| 115 | \endlist | - |
| 116 | | - |
| 117 | \sa QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayout | - |
| 118 | */ | - |
| 119 | | - |
| 120 | /*! | - |
| 121 | \class QGraphicsAnchor | - |
| 122 | \brief The QGraphicsAnchor class represents an anchor between two items in a | - |
| 123 | QGraphicsAnchorLayout. | - |
| 124 | \since 4.6 | - |
| 125 | \ingroup appearance | - |
| 126 | \ingroup geomanagement | - |
| 127 | \ingroup graphicsview-api | - |
| 128 | \inmodule QtWidgets | - |
| 129 | | - |
| 130 | The graphics anchor provides an API that enables you to query and manipulate the | - |
| 131 | properties an anchor has. When an anchor is added to the layout with | - |
| 132 | QGraphicsAnchorLayout::addAnchor(), a QGraphicsAnchor instance is returned where the properties | - |
| 133 | are initialized to their default values. The properties can then be further changed, and they | - |
| 134 | will be picked up the next time the layout is activated. | - |
| 135 | | - |
| 136 | \sa QGraphicsAnchorLayout::anchor() | - |
| 137 | | - |
| 138 | */ | - |
| 139 | #include "qgraphicsanchorlayout_p.h" | - |
| 140 | #ifndef QT_NO_GRAPHICSVIEW | - |
| 141 | QT_BEGIN_NAMESPACE | - |
| 142 | | - |
| 143 | QGraphicsAnchor::QGraphicsAnchor(QGraphicsAnchorLayout *parentLayout) | - |
| 144 | : QObject(*(new QGraphicsAnchorPrivate)) | - |
| 145 | { | - |
| 146 | Q_D(QGraphicsAnchor); never executed (the execution status of this line is deduced): QGraphicsAnchorPrivate * const d = d_func(); | - |
| 147 | Q_ASSERT(parentLayout); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 148 | d->layoutPrivate = parentLayout->d_func(); never executed (the execution status of this line is deduced): d->layoutPrivate = parentLayout->d_func(); | - |
| 149 | } | 0 |
| 150 | | - |
| 151 | /*! | - |
| 152 | Removes the QGraphicsAnchor object from the layout and destroys it. | - |
| 153 | */ | - |
| 154 | QGraphicsAnchor::~QGraphicsAnchor() | - |
| 155 | { | - |
| 156 | } | - |
| 157 | | - |
| 158 | /*! | - |
| 159 | \property QGraphicsAnchor::sizePolicy | - |
| 160 | \brief the size policy for the QGraphicsAnchor. | - |
| 161 | | - |
| 162 | By setting the size policy on an anchor you can configure how the anchor can resize itself | - |
| 163 | from its preferred spacing. For instance, if the anchor has the size policy | - |
| 164 | QSizePolicy::Minimum, the spacing is the minimum size of the anchor. However, its size | - |
| 165 | can grow up to the anchors maximum size. If the default size policy is QSizePolicy::Fixed, | - |
| 166 | the anchor can neither grow or shrink, which means that the only size the anchor can have | - |
| 167 | is the spacing. QSizePolicy::Fixed is the default size policy. | - |
| 168 | QGraphicsAnchor always has a minimum spacing of 0 and a very large maximum spacing. | - |
| 169 | | - |
| 170 | \sa QGraphicsAnchor::spacing | - |
| 171 | */ | - |
| 172 | | - |
| 173 | void QGraphicsAnchor::setSizePolicy(QSizePolicy::Policy policy) | - |
| 174 | { | - |
| 175 | Q_D(QGraphicsAnchor); never executed (the execution status of this line is deduced): QGraphicsAnchorPrivate * const d = d_func(); | - |
| 176 | d->setSizePolicy(policy); never executed (the execution status of this line is deduced): d->setSizePolicy(policy); | - |
| 177 | } | 0 |
| 178 | | - |
| 179 | QSizePolicy::Policy QGraphicsAnchor::sizePolicy() const | - |
| 180 | { | - |
| 181 | Q_D(const QGraphicsAnchor); never executed (the execution status of this line is deduced): const QGraphicsAnchorPrivate * const d = d_func(); | - |
| 182 | return d->sizePolicy; never executed: return d->sizePolicy; | 0 |
| 183 | } | - |
| 184 | | - |
| 185 | /*! | - |
| 186 | \property QGraphicsAnchor::spacing | - |
| 187 | \brief the preferred space between items in the QGraphicsAnchorLayout. | - |
| 188 | | - |
| 189 | Depending on the anchor type, the default spacing is either | - |
| 190 | 0 or a value returned from the style. | - |
| 191 | | - |
| 192 | \sa QGraphicsAnchorLayout::addAnchor() | - |
| 193 | */ | - |
| 194 | void QGraphicsAnchor::setSpacing(qreal spacing) | - |
| 195 | { | - |
| 196 | Q_D(QGraphicsAnchor); never executed (the execution status of this line is deduced): QGraphicsAnchorPrivate * const d = d_func(); | - |
| 197 | d->setSpacing(spacing); never executed (the execution status of this line is deduced): d->setSpacing(spacing); | - |
| 198 | } | 0 |
| 199 | | - |
| 200 | qreal QGraphicsAnchor::spacing() const | - |
| 201 | { | - |
| 202 | Q_D(const QGraphicsAnchor); never executed (the execution status of this line is deduced): const QGraphicsAnchorPrivate * const d = d_func(); | - |
| 203 | return d->spacing(); never executed: return d->spacing(); | 0 |
| 204 | } | - |
| 205 | | - |
| 206 | void QGraphicsAnchor::unsetSpacing() | - |
| 207 | { | - |
| 208 | Q_D(QGraphicsAnchor); never executed (the execution status of this line is deduced): QGraphicsAnchorPrivate * const d = d_func(); | - |
| 209 | d->unsetSpacing(); never executed (the execution status of this line is deduced): d->unsetSpacing(); | - |
| 210 | } | 0 |
| 211 | | - |
| 212 | /*! | - |
| 213 | Constructs a QGraphicsAnchorLayout instance. \a parent is passed to | - |
| 214 | QGraphicsLayout's constructor. | - |
| 215 | */ | - |
| 216 | QGraphicsAnchorLayout::QGraphicsAnchorLayout(QGraphicsLayoutItem *parent) | - |
| 217 | : QGraphicsLayout(*new QGraphicsAnchorLayoutPrivate(), parent) | - |
| 218 | { | - |
| 219 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 220 | d->createLayoutEdges(); never executed (the execution status of this line is deduced): d->createLayoutEdges(); | - |
| 221 | } | 0 |
| 222 | | - |
| 223 | /*! | - |
| 224 | Destroys the QGraphicsAnchorLayout object. | - |
| 225 | */ | - |
| 226 | QGraphicsAnchorLayout::~QGraphicsAnchorLayout() | - |
| 227 | { | - |
| 228 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 229 | | - |
| 230 | for (int i = count() - 1; i >= 0; --i) { | 0 |
| 231 | QGraphicsLayoutItem *item = d->items.at(i); never executed (the execution status of this line is deduced): QGraphicsLayoutItem *item = d->items.at(i); | - |
| 232 | removeAt(i); never executed (the execution status of this line is deduced): removeAt(i); | - |
| 233 | if (item) { | 0 |
| 234 | if (item->ownedByLayout()) never evaluated: item->ownedByLayout() | 0 |
| 235 | delete item; never executed: delete item; | 0 |
| 236 | } | 0 |
| 237 | } | 0 |
| 238 | | - |
| 239 | d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Horizontal); never executed (the execution status of this line is deduced): d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Horizontal); | - |
| 240 | d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Vertical); never executed (the execution status of this line is deduced): d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Vertical); | - |
| 241 | d->deleteLayoutEdges(); never executed (the execution status of this line is deduced): d->deleteLayoutEdges(); | - |
| 242 | | - |
| 243 | Q_ASSERT(d->itemCenterConstraints[0].isEmpty()); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 244 | Q_ASSERT(d->itemCenterConstraints[1].isEmpty()); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 245 | Q_ASSERT(d->items.isEmpty()); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 246 | Q_ASSERT(d->m_vertexList.isEmpty()); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 247 | } | 0 |
| 248 | | - |
| 249 | /*! | - |
| 250 | Creates an anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge | - |
| 251 | of item \a secondItem. The spacing of the anchor is picked up from the style. Anchors | - |
| 252 | between a layout edge and an item edge will have a size of 0. | - |
| 253 | If there is already an anchor between the edges, the new anchor will replace the old one. | - |
| 254 | | - |
| 255 | \a firstItem and \a secondItem are automatically added to the layout if they are not part | - |
| 256 | of the layout. This means that count() can increase by up to 2. | - |
| 257 | | - |
| 258 | The spacing an anchor will get depends on the type of anchor. For instance, anchors from the | - |
| 259 | Right edge of one item to the Left edge of another (or vice versa) will use the default | - |
| 260 | horizontal spacing. The same behaviour applies to Bottom to Top anchors, (but they will use | - |
| 261 | the default vertical spacing). For all other anchor combinations, the spacing will be 0. | - |
| 262 | All anchoring functions will follow this rule. | - |
| 263 | | - |
| 264 | The spacing can also be set manually by using QGraphicsAnchor::setSpacing() method. | - |
| 265 | | - |
| 266 | Calling this function where \a firstItem or \a secondItem are ancestors of the layout have | - |
| 267 | undefined behaviour. | - |
| 268 | | - |
| 269 | \sa addAnchors(), addCornerAnchors() | - |
| 270 | */ | - |
| 271 | QGraphicsAnchor * | - |
| 272 | QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, | - |
| 273 | QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) | - |
| 274 | { | - |
| 275 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 276 | QGraphicsAnchor *a = d->addAnchor(firstItem, firstEdge, secondItem, secondEdge); never executed (the execution status of this line is deduced): QGraphicsAnchor *a = d->addAnchor(firstItem, firstEdge, secondItem, secondEdge); | - |
| 277 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 278 | return a; never executed: return a; | 0 |
| 279 | } | - |
| 280 | | - |
| 281 | /*! | - |
| 282 | Returns the anchor between the anchor points defined by \a firstItem and \a firstEdge and | - |
| 283 | \a secondItem and \a secondEdge. If there is no such anchor, the function will return 0. | - |
| 284 | */ | - |
| 285 | QGraphicsAnchor * | - |
| 286 | QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, | - |
| 287 | QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) | - |
| 288 | { | - |
| 289 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 290 | return d->getAnchor(firstItem, firstEdge, secondItem, secondEdge); never executed: return d->getAnchor(firstItem, firstEdge, secondItem, secondEdge); | 0 |
| 291 | } | - |
| 292 | | - |
| 293 | /*! | - |
| 294 | Creates two anchors between \a firstItem and \a secondItem specified by the corners, | - |
| 295 | \a firstCorner and \a secondCorner, where one is for the horizontal edge and another | - |
| 296 | one for the vertical edge. | - |
| 297 | | - |
| 298 | This is a convenience function, since anchoring corners can be expressed as anchoring | - |
| 299 | two edges. For instance: | - |
| 300 | | - |
| 301 | \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor in two steps | - |
| 302 | | - |
| 303 | This can also be achieved with the following line of code: | - |
| 304 | | - |
| 305 | \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor | - |
| 306 | | - |
| 307 | If there is already an anchor between the edge pairs, it will be replaced by the anchors that | - |
| 308 | this function specifies. | - |
| 309 | | - |
| 310 | \a firstItem and \a secondItem are automatically added to the layout if they are not part of the | - |
| 311 | layout. This means that count() can increase by up to 2. | - |
| 312 | | - |
| 313 | \sa addAnchor(), addAnchors() | - |
| 314 | */ | - |
| 315 | void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem, | - |
| 316 | Qt::Corner firstCorner, | - |
| 317 | QGraphicsLayoutItem *secondItem, | - |
| 318 | Qt::Corner secondCorner) | - |
| 319 | { | - |
| 320 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 321 | | - |
| 322 | // Horizontal anchor | - |
| 323 | Qt::AnchorPoint firstEdge = (firstCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft); never evaluated: firstCorner & 1 | 0 |
| 324 | Qt::AnchorPoint secondEdge = (secondCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft); never evaluated: secondCorner & 1 | 0 |
| 325 | if (d->addAnchor(firstItem, firstEdge, secondItem, secondEdge)) { never evaluated: d->addAnchor(firstItem, firstEdge, secondItem, secondEdge) | 0 |
| 326 | // Vertical anchor | - |
| 327 | firstEdge = (firstCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop); never evaluated: firstCorner & 2 | 0 |
| 328 | secondEdge = (secondCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop); never evaluated: secondCorner & 2 | 0 |
| 329 | d->addAnchor(firstItem, firstEdge, secondItem, secondEdge); never executed (the execution status of this line is deduced): d->addAnchor(firstItem, firstEdge, secondItem, secondEdge); | - |
| 330 | | - |
| 331 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 332 | } | 0 |
| 333 | } | 0 |
| 334 | | - |
| 335 | /*! | - |
| 336 | Anchors two or four edges of \a firstItem with the corresponding | - |
| 337 | edges of \a secondItem, so that \a firstItem has the same size as | - |
| 338 | \a secondItem in the dimensions specified by \a orientations. | - |
| 339 | | - |
| 340 | For example, the following example anchors the left and right edges of two items | - |
| 341 | to match their widths: | - |
| 342 | | - |
| 343 | \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps | - |
| 344 | | - |
| 345 | This can also be achieved using the following line of code: | - |
| 346 | | - |
| 347 | \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes | - |
| 348 | | - |
| 349 | \sa addAnchor(), addCornerAnchors() | - |
| 350 | */ | - |
| 351 | void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem, | - |
| 352 | QGraphicsLayoutItem *secondItem, | - |
| 353 | Qt::Orientations orientations) | - |
| 354 | { | - |
| 355 | bool ok = true; never executed (the execution status of this line is deduced): bool ok = true; | - |
| 356 | if (orientations & Qt::Horizontal) { never evaluated: orientations & Qt::Horizontal | 0 |
| 357 | // Currently, if the first is ok, then the rest of the calls should be ok | - |
| 358 | ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != 0; never executed (the execution status of this line is deduced): ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != 0; | - |
| 359 | if (ok) | 0 |
| 360 | addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight); never executed: addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight); | 0 |
| 361 | } | 0 |
| 362 | if (orientations & Qt::Vertical && ok) { never evaluated: orientations & Qt::Vertical never evaluated: ok | 0 |
| 363 | addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop); never executed (the execution status of this line is deduced): addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop); | - |
| 364 | addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom); never executed (the execution status of this line is deduced): addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom); | - |
| 365 | } | 0 |
| 366 | } | 0 |
| 367 | | - |
| 368 | /*! | - |
| 369 | Sets the default horizontal spacing for the anchor layout to \a spacing. | - |
| 370 | | - |
| 371 | \sa horizontalSpacing(), setVerticalSpacing(), setSpacing() | - |
| 372 | */ | - |
| 373 | void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing) | - |
| 374 | { | - |
| 375 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 376 | | - |
| 377 | d->spacings[0] = spacing; never executed (the execution status of this line is deduced): d->spacings[0] = spacing; | - |
| 378 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 379 | } | 0 |
| 380 | | - |
| 381 | /*! | - |
| 382 | Sets the default vertical spacing for the anchor layout to \a spacing. | - |
| 383 | | - |
| 384 | \sa verticalSpacing(), setHorizontalSpacing(), setSpacing() | - |
| 385 | */ | - |
| 386 | void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing) | - |
| 387 | { | - |
| 388 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 389 | | - |
| 390 | d->spacings[1] = spacing; never executed (the execution status of this line is deduced): d->spacings[1] = spacing; | - |
| 391 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 392 | } | 0 |
| 393 | | - |
| 394 | /*! | - |
| 395 | Sets the default horizontal and the default vertical spacing for the anchor layout to \a spacing. | - |
| 396 | | - |
| 397 | If an item is anchored with no spacing associated with the anchor, it will use the default | - |
| 398 | spacing. | - |
| 399 | | - |
| 400 | QGraphicsAnchorLayout does not support negative spacings. Setting a negative value will unset the | - |
| 401 | previous spacing and make the layout use the spacing provided by the current widget style. | - |
| 402 | | - |
| 403 | \sa setHorizontalSpacing(), setVerticalSpacing() | - |
| 404 | */ | - |
| 405 | void QGraphicsAnchorLayout::setSpacing(qreal spacing) | - |
| 406 | { | - |
| 407 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 408 | | - |
| 409 | d->spacings[0] = d->spacings[1] = spacing; never executed (the execution status of this line is deduced): d->spacings[0] = d->spacings[1] = spacing; | - |
| 410 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 411 | } | 0 |
| 412 | | - |
| 413 | /*! | - |
| 414 | Returns the default horizontal spacing for the anchor layout. | - |
| 415 | | - |
| 416 | \sa verticalSpacing(), setHorizontalSpacing() | - |
| 417 | */ | - |
| 418 | qreal QGraphicsAnchorLayout::horizontalSpacing() const | - |
| 419 | { | - |
| 420 | Q_D(const QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): const QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 421 | return d->styleInfo().defaultSpacing(Qt::Horizontal); never executed: return d->styleInfo().defaultSpacing(Qt::Horizontal); | 0 |
| 422 | } | - |
| 423 | | - |
| 424 | /*! | - |
| 425 | Returns the default vertical spacing for the anchor layout. | - |
| 426 | | - |
| 427 | \sa horizontalSpacing(), setVerticalSpacing() | - |
| 428 | */ | - |
| 429 | qreal QGraphicsAnchorLayout::verticalSpacing() const | - |
| 430 | { | - |
| 431 | Q_D(const QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): const QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 432 | return d->styleInfo().defaultSpacing(Qt::Vertical); never executed: return d->styleInfo().defaultSpacing(Qt::Vertical); | 0 |
| 433 | } | - |
| 434 | | - |
| 435 | /*! | - |
| 436 | \reimp | - |
| 437 | */ | - |
| 438 | void QGraphicsAnchorLayout::setGeometry(const QRectF &geom) | - |
| 439 | { | - |
| 440 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 441 | | - |
| 442 | QGraphicsLayout::setGeometry(geom); never executed (the execution status of this line is deduced): QGraphicsLayout::setGeometry(geom); | - |
| 443 | d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal); never executed (the execution status of this line is deduced): d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal); | - |
| 444 | d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical); never executed (the execution status of this line is deduced): d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical); | - |
| 445 | d->setItemsGeometries(geom); never executed (the execution status of this line is deduced): d->setItemsGeometries(geom); | - |
| 446 | } | 0 |
| 447 | | - |
| 448 | /*! | - |
| 449 | Removes the layout item at \a index without destroying it. Ownership of | - |
| 450 | the item is transferred to the caller. | - |
| 451 | | - |
| 452 | Removing an item will also remove any of the anchors associated with it. | - |
| 453 | | - |
| 454 | \sa itemAt(), count() | - |
| 455 | */ | - |
| 456 | void QGraphicsAnchorLayout::removeAt(int index) | - |
| 457 | { | - |
| 458 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 459 | QGraphicsLayoutItem *item = d->items.value(index); never executed (the execution status of this line is deduced): QGraphicsLayoutItem *item = d->items.value(index); | - |
| 460 | | - |
| 461 | if (!item) | 0 |
| 462 | return; | 0 |
| 463 | | - |
| 464 | // Removing an item affects both horizontal and vertical graphs | - |
| 465 | d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Horizontal); never executed (the execution status of this line is deduced): d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Horizontal); | - |
| 466 | d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Vertical); never executed (the execution status of this line is deduced): d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Vertical); | - |
| 467 | d->removeAnchors(item); never executed (the execution status of this line is deduced): d->removeAnchors(item); | - |
| 468 | d->items.remove(index); never executed (the execution status of this line is deduced): d->items.remove(index); | - |
| 469 | | - |
| 470 | item->setParentLayoutItem(0); never executed (the execution status of this line is deduced): item->setParentLayoutItem(0); | - |
| 471 | invalidate(); never executed (the execution status of this line is deduced): invalidate(); | - |
| 472 | } | 0 |
| 473 | | - |
| 474 | /*! | - |
| 475 | \reimp | - |
| 476 | */ | - |
| 477 | int QGraphicsAnchorLayout::count() const | - |
| 478 | { | - |
| 479 | Q_D(const QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): const QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 480 | return d->items.size(); never executed: return d->items.size(); | 0 |
| 481 | } | - |
| 482 | | - |
| 483 | /*! | - |
| 484 | \reimp | - |
| 485 | */ | - |
| 486 | QGraphicsLayoutItem *QGraphicsAnchorLayout::itemAt(int index) const | - |
| 487 | { | - |
| 488 | Q_D(const QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): const QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 489 | return d->items.value(index); never executed: return d->items.value(index); | 0 |
| 490 | } | - |
| 491 | | - |
| 492 | /*! | - |
| 493 | \reimp | - |
| 494 | */ | - |
| 495 | void QGraphicsAnchorLayout::invalidate() | - |
| 496 | { | - |
| 497 | Q_D(QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 498 | QGraphicsLayout::invalidate(); never executed (the execution status of this line is deduced): QGraphicsLayout::invalidate(); | - |
| 499 | d->calculateGraphCacheDirty = true; never executed (the execution status of this line is deduced): d->calculateGraphCacheDirty = true; | - |
| 500 | d->styleInfoDirty = true; never executed (the execution status of this line is deduced): d->styleInfoDirty = true; | - |
| 501 | } | 0 |
| 502 | | - |
| 503 | /*! | - |
| 504 | \reimp | - |
| 505 | */ | - |
| 506 | QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | - |
| 507 | { | - |
| 508 | Q_UNUSED(constraint); never executed (the execution status of this line is deduced): (void)constraint;; | - |
| 509 | Q_D(const QGraphicsAnchorLayout); never executed (the execution status of this line is deduced): const QGraphicsAnchorLayoutPrivate * const d = d_func(); | - |
| 510 | | - |
| 511 | // Some setup calculations are delayed until the information is | - |
| 512 | // actually needed, avoiding unnecessary recalculations when | - |
| 513 | // adding multiple anchors. | - |
| 514 | | - |
| 515 | // sizeHint() / effectiveSizeHint() already have a cache | - |
| 516 | // mechanism, using invalidate() to force recalculation. However | - |
| 517 | // sizeHint() is called three times after invalidation (for max, | - |
| 518 | // min and pref), but we just need do our setup once. | - |
| 519 | | - |
| 520 | const_cast<QGraphicsAnchorLayoutPrivate *>(d)->calculateGraphs(); never executed (the execution status of this line is deduced): const_cast<QGraphicsAnchorLayoutPrivate *>(d)->calculateGraphs(); | - |
| 521 | | - |
| 522 | // ### apply constraint! | - |
| 523 | QSizeF engineSizeHint( never executed (the execution status of this line is deduced): QSizeF engineSizeHint( | - |
| 524 | d->sizeHints[QGraphicsAnchorLayoutPrivate::Horizontal][which], never executed (the execution status of this line is deduced): d->sizeHints[QGraphicsAnchorLayoutPrivate::Horizontal][which], | - |
| 525 | d->sizeHints[QGraphicsAnchorLayoutPrivate::Vertical][which]); never executed (the execution status of this line is deduced): d->sizeHints[QGraphicsAnchorLayoutPrivate::Vertical][which]); | - |
| 526 | | - |
| 527 | qreal left, top, right, bottom; never executed (the execution status of this line is deduced): qreal left, top, right, bottom; | - |
| 528 | getContentsMargins(&left, &top, &right, &bottom); never executed (the execution status of this line is deduced): getContentsMargins(&left, &top, &right, &bottom); | - |
| 529 | | - |
| 530 | return engineSizeHint + QSizeF(left + right, top + bottom); never executed: return engineSizeHint + QSizeF(left + right, top + bottom); | 0 |
| 531 | } | - |
| 532 | | - |
| 533 | QT_END_NAMESPACE | - |
| 534 | #endif //QT_NO_GRAPHICSVIEW | - |
| 535 | | - |
| | |