GridListLayout

Since: BlackBerry 10.0.0

#include <bb/cascades/GridListLayout>

A layout used with ListView to lay out items in a grid.

A GridListLayout with ten items

You can set GridListLayout using the ListView::layout property.

The orientation property determines the direction in which list items are added to the list (for example, when using TopToBottom, items are added row-by-row starting from the top).

All margin-properties on item visuals are ignored by GridListLayout.

For non-header items, the layout sets the size of the root node in the item visual to the size of a cell in the grid. All cells in the grid are of the same size, a size which is determined by a combination of the size of the ListView and the values of the GridListLayout properties orientation, columnCount, cellAspectRatio and either horizontalCellSpacing, ListView::leftPadding and ListView::rightPadding (for vertical lists), or verticalCellSpacing, ListView::topPadding and ListView::bottomPadding (for horizontal lists).

Header item visuals are given their preferred size, only limited by the width or height (minus padding) of the ListView (width is limited in vertical lists, height is limited in horizontal lists). Headers never share their row (column in horizontal lists) with any other item, even if the header only occupies a small portion of that row. Headers are placed on top of grid items when headerMode is Overlay or StickyOverlay, but that does not affect the placement of the grid items.

Here's an example in QML of a grid list containing photo thumbnails (without headers):

ListView {
    layout: GridListLayout {}
    dataModel: XmlDataModel {
        source: "flatmodel.xml"
    }

    listItemComponents: [
        ListItemComponent {
            type: "image"

            ImageView {
                imageSource: ListItemData
                scalingMethod: ScalingMethod.AspectFill
            }
        }
    ]
}


Overview

QML properties

cellAspectRatio: float
columnCount: int
headerMode: bb::cascades::ListHeaderMode::Type
horizontalCellSpacing: float
orientation: bb::cascades::LayoutOrientation::Type
spacingAfterHeader: float
spacingBeforeHeader: float
verticalCellSpacing: float
attachedObjects: QDeclarativeListProperty< QObject > [read-only]Inherited
objectName: QStringInherited
parent: QObject [read-only]Inherited
ui: bb::cascades::UIConfig [read-only]Inherited

Public Functions Index

GridListLayout ()
virtual ~GridListLayout ()
floatcellAspectRatio () const
intcolumnCount () const
bb::cascades::ListHeaderMode::TypeheaderMode () const
floathorizontalCellSpacing () const
bb::cascades::LayoutOrientation::Typeorientation () const
Q_SLOT voidresetCellAspectRatio ()
Q_SLOT voidresetColumnCount ()
Q_SLOT voidresetHeaderMode ()
Q_SLOT voidresetHorizontalCellSpacing ()
Q_SLOT voidresetOrientation ()
Q_SLOT voidresetSpacingAfterHeader ()
Q_SLOT voidresetSpacingBeforeHeader ()
Q_SLOT voidresetVerticalCellSpacing ()
Q_SLOT voidsetCellAspectRatio (float ratio)
Q_SLOT voidsetColumnCount (int columnCount)
Q_SLOT voidsetHeaderMode (bb::cascades::ListHeaderMode::Type newHeaderMode)
Q_SLOT voidsetHorizontalCellSpacing (float spacing)
Q_SLOT voidsetOrientation (bb::cascades::LayoutOrientation::Type orientation)
Q_SLOT voidsetSpacingAfterHeader (float spacing)
Q_SLOT voidsetSpacingBeforeHeader (float spacing)
Q_SLOT voidsetVerticalCellSpacing (float spacing)
floatspacingAfterHeader () const
floatspacingBeforeHeader () const
floatverticalCellSpacing () const
virtual boolevent (QEvent *event)Inherited
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited
Q_INVOKABLE bb::cascades::UIConfig *ui () const Inherited

Static Public Functions Index

Buildercreate ()

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited
virtual voidconnectNotify (const char *signal)Inherited
virtual voiddisconnectNotify (const char *signal)Inherited

Signals Index

voidcellAspectRatioChanged (float cellAspectRatio)
voidcolumnCountChanged (int columnCount)
voidheaderModeChanged (bb::cascades::ListHeaderMode::Type newHeaderMode)
voidhorizontalCellSpacingChanged (float horizontalCellSpacing)
voidorientationChanged (bb::cascades::LayoutOrientation::Type newOrientation)
voidspacingAfterHeaderChanged (float spacingAfterHeader)
voidspacingBeforeHeaderChanged (float spacingBeforeHeader)
voidverticalCellSpacingChanged (float verticalCellSpacing)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

float cellAspectRatio

The cell aspect ratio (cell width divided by cell height).

Since:

BlackBerry 10.0.0

int columnCount

The number of columns in the grid (or rows, depending on the orientation).

When the orientation is TopToBottom or BottomToTop, the columnCount property determines the number of columns in the grid. If orientation is LeftToRight or RightToLeft, this property instead determines the number of rows.

The default value is 3.

Since:

BlackBerry 10.0.0

bb::cascades::ListHeaderMode::Type headerMode

Determines if and how headers are shown by the GridListLayout.

If set to None, only one level of items from the DataModel is used. Otherwise the first level of items under the root item are used as headers, and their child items are placed in grids.

The default value is ListHeaderMode::None.

Since:

BlackBerry 10.0.0

float horizontalCellSpacing

The horizontal distance between cells.

The default value is 6.0.

Since:

BlackBerry 10.0.0

bb::cascades::LayoutOrientation::Type orientation

The orientation for the grid layout.

The orientation determines the direction in which list items are added to the list.

The default orientation is TopToBottom, but LeftToRight, RightToLeft, and BottomToTop can also be used.

TopToBottom and BottomToTop causes items to be layed out row-by-row. The value of the columnCount property determines the number of items in each row. Items are arranged from left to right in the rows. TopToBottom causes the first row to be placed at the top of the visible area in the ListView, while BottomToTop causes the first row to be placed at the bottom.

LeftToRight and RightToLeft causes items to be layed out column-by-column. The value of the columnCount property determines the number of items in each column. Items are arranged from top to bottom in the columns. LeftToRight causes the first column to be placed at the left border of the visible area in the ListView, while RightToLeft causes the first column to be placed at the right border.

Since:

BlackBerry 10.0.0

float spacingAfterHeader

The distance from a header to its grid section.

The default value is 6.0.

Since:

BlackBerry 10.0.0

float spacingBeforeHeader

The distance from the end of a grid section to the next header.

The default value is 8.0.

Since:

BlackBerry 10.0.0

float verticalCellSpacing

The vertical distance between cells.

The default value is 6.0.

Since:

BlackBerry 10.0.0

QDeclarativeListProperty< QObject > attachedObjectsInherited[read-only]

A hierarchical list of the UIObject's attached objects.

Since:

BlackBerry 10.0.0

QString objectNameInherited

This property is overridden from QObject.

See also:

QObject::objectName().

Since:

BlackBerry 10.0.0

QObject parentInherited[read-only]

A read-only property that represents this object's parent.

The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.

This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.

The default value of this property is 0.

Since:

BlackBerry 10.0.0

bb::cascades::UIConfig uiInherited[read-only]

An object that gives access to unit conversion routines.

QML use:
        // Size using design units
        Container {
            preferredWidth: ui.du(12)
            preferredHeight: ui.du(5)
        }

        // Size using design units, snap to whole pixels
        Container {
            preferredWidth: ui.sdu(13.5)
            preferredHeight: ui.sdu(7.5)
        }

        // Size using absolute pixel values
        Container {
            preferredWidth: ui.px(150)
            preferredHeight: ui.px(50)
        }
C++ use:
Container *container1 = Container::create().background(Color::Red);
UIConfig *ui = container1->ui();
container1->setPreferredWidth(ui->du(12));
container1->setPreferredHeight(ui->du(5));

Container *container2 = Container::create().background(Color::Green);
container2->setPreferredWidth(ui->sdu(13.5));
container2->setPreferredHeight(ui->sdu(7.5));

Container *container3 = Container::create().background(Color::Blue);
container3->setPreferredWidth(ui->px(150));
container3->setPreferredHeight(ui->sdu(50));
Since:

Blackberry 10.3.0

Public Functions

GridListLayout ()

Constructs a GridListLayout instance.

Since:

BlackBerry 10.0.0

virtual~GridListLayout ()

Destructor.

float cellAspectRatio ()

Returns the value of cellAspectRatio.

Return:

The cell aspect ratio (cell width divided by cell height).

Since:

BlackBerry 10.0.0

int columnCount ()

Returns the value of columnCount.

Return:

The number of columns in the grid when orientation is TopToBottom or BottomToTop. If orientation is LeftToRight or RightToLeft, this function instead returns the number of rows in the grid.

Since:

BlackBerry 10.0.0

bb::cascades::ListHeaderMode::Type headerMode ()

Returns the value of the headerMode property.

Return:

The value of the headerMode property.

Since:

BlackBerry 10.0.0

float horizontalCellSpacing ()

Returns the value of horizontalCellSpacing.

Return:

The horizontal distance between cells.

Since:

BlackBerry 10.0.0

bb::cascades::LayoutOrientation::Type orientation ()

Returns the orientation for the grid layout.

Return:

The orientation.

Since:

BlackBerry 10.0.0

Q_SLOT void resetCellAspectRatio ()

Resets the cellAspectRatio property to its default value of 1.0.

If the property value is changed, the cellAspectRatioChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetColumnCount ()

Resets the columnCount property to its default value of 3.

If the property value is changed, the columnCountChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetHeaderMode ()

Resets the headerMode property to its default value.

The default value is ListHeaderMode::None.

If the property value is changed, the headerModeChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetHorizontalCellSpacing ()

Resets the horizontalCellSpacing property to its default value of 6.0.

If the property value is changed, the horizontalCellSpacingChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetOrientation ()

Resets the orientation to its default.

The default orientation is LayoutOrientation::TopToBottom.

If the orientation is changed, the orientationChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetSpacingAfterHeader ()

Resets the spacingAfterHeader property to its default value of 6.0.

If the property value is changed, the spacingAfterHeaderChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetSpacingBeforeHeader ()

Resets the spacingBeforeHeader property to its default value of 8.0.

If the property value is changed, the spacingBeforeHeaderChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void resetVerticalCellSpacing ()

Resets the verticalCellSpacing property to its default value of 6.0.

If the property value is changed, the verticalCellSpacingChanged() signal is emitted.

Since:

BlackBerry 10.0.0

Q_SLOT void setCellAspectRatio (
  • floatratio)

Sets a value for cellAspectRatio.

If the property value is changed, the cellAspectRatioChanged() signal is emitted.

Parameters
ratio

The new cell aspect ratio (cell width divided by cell height).

Since:

BlackBerry 10.0.0

Q_SLOT void setColumnCount (
  • intcolumnCount)

Sets a value for columnCount.

If the property value is changed, the columnCountChanged() signal is emitted.

Parameters
columnCount

The number of columns the grid should have when orientation is TopToBottom or BottomToTop. Or the number of rows the grid should have, if orientation is LeftToRight or RightToLeft.

Since:

BlackBerry 10.0.0

Q_SLOT void setHeaderMode (

Sets a value on the headerMode property.

If the property value is changed, the headerModeChanged() signal is emitted.

Parameters
newHeaderMode

The value to set on the headerMode property.

Since:

BlackBerry 10.0.0

Q_SLOT void setHorizontalCellSpacing (
  • floatspacing)

Sets a value for horizontalCellSpacing.

If the property value is changed, the horizontalCellSpacingChanged() signal is emitted.

Parameters
spacing

The new horizontal distance between cells.

Since:

BlackBerry 10.0.0

Q_SLOT void setOrientation (

Sets the orientation for the grid layout.

If the orientation is changed, the orientationChanged() signal is emitted.

Parameters
orientation

The new orientation.

Since:

BlackBerry 10.0.0

Q_SLOT void setSpacingAfterHeader (
  • floatspacing)

Sets a value for spacingAfterHeader.

If the property value is changed, the spacingAfterHeaderChanged() signal is emitted.

Parameters
spacing

The new distance from a header to its grid section.

Since:

BlackBerry 10.0.0

Q_SLOT void setSpacingBeforeHeader (
  • floatspacing)

Sets a value for spacingBeforeHeader.

If the property value is changed, the spacingBeforeHeaderChanged() signal is emitted.

Parameters
spacing

The new distance from the end of a grid section to the next header.

Since:

BlackBerry 10.0.0

Q_SLOT void setVerticalCellSpacing (
  • floatspacing)

Sets a value for verticalCellSpacing.

If the property value is changed, the verticalCellSpacingChanged() signal is emitted.

Parameters
spacing

The new vertical distance between cells.

Since:

BlackBerry 10.0.0

float spacingAfterHeader ()

Returns the value of spacingAfterHeader.

Return:

Distance from a header to its grid section.

Since:

BlackBerry 10.0.0

float spacingBeforeHeader ()

Returns the value of spacingBeforeHeader.

Return:

Distance from the end of a grid section to the next header.

Since:

BlackBerry 10.0.0

float verticalCellSpacing ()

Returns the value of verticalCellSpacing.

Return:

The vertical distance between cells.

Since:

BlackBerry 10.0.0

virtual bool event (Inherited

Overloaded to implement the event mechanism in Cascades.

Warning!

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
event

The received event.

Return:

True if the received event was recognized and processed, false otherwise.

Since:

BlackBerry 10.0.0

void setObjectName (Inherited

Sets the objectName property.

Parameters
name

The new name for the object.

Since:

BlackBerry 10.0.0

virtual Q_INVOKABLE QString toDebugString ()Inherited

Returns a debug string representing this object.

Return:

A debug string for the object.

Since:

BlackBerry 10.0.0

Q_INVOKABLE bb::cascades::UIConfig * ui ()Inherited

Returns the UIConfig for this ui object.

The UIConfig can be used to perform unit conversions from design units (du) and snapped design units (sdu) to pixels.

Ownership remains with Cascades.

C++ use:
Container *container1 = Container::create().background(Color::Red);
UIConfig *ui = container1->ui();
container1->setPreferredWidth(ui->du(12));
container1->setPreferredHeight(ui->du(5));

Container *container2 = Container::create().background(Color::Green);
container2->setPreferredWidth(ui->sdu(13.5));
container2->setPreferredHeight(ui->sdu(7.5));

Container *container3 = Container::create().background(Color::Blue);
container3->setPreferredWidth(ui->px(150));
container3->setPreferredHeight(ui->sdu(50));
Return:

The UIConfig for this ui object.

Since:

BlackBerry 10.3.0

Static Public Functions

Builder create ()

Creates and returns a builder for constructing a grid list layout.

Using the builder to create a grid list layout:
GridListLayout* gridListLayout = GridListLayout::create()
        .orientation(LayoutOrientation::LeftToRight);
Return:

A builder used for constructing a grid list layout.

Since:

BlackBerry 10.0.0

Protected Functions

(Only has inherited protected functions)

BaseObject (Inherited

Constructs an instance of BaseObject's subclass.

Parameters
parent

An optional parent, defaults to 0.

Since:

BlackBerry 10.0.0

virtual void connectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The connected signal.

Since:

BlackBerry 10.0.0

virtual void disconnectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The disconnected signal.

Since:

BlackBerry 10.0.0

Signals

void cellAspectRatioChanged (
  • floatcellAspectRatio)

Emitted when the cellAspectRatio property has changed.

Parameters
cellAspectRatio

The new value for the cellAspectRatio property.

Since:

BlackBerry 10.0.0

void columnCountChanged (
  • intcolumnCount)

Emitted when the columnCount property has changed.

Parameters
columnCount

The new number of columns.

Since:

BlackBerry 10.0.0

void headerModeChanged (

Emitted when the headerMode property has changed.

Note:

Due to a workaround for a Qt Core issue with accessing enums from QML the argument of this signal doesn't follow naming convention for signals in which the signal arguments are typically named to match the associated property's name. Use the object's property to access current property value instead of the signal argument to avoid runtime errors (i.e. use headerMode instead of newHeaderMode).

Parameters
newHeaderMode

The new value for the headerMode property.

Since:

BlackBerry 10.0.0

void horizontalCellSpacingChanged (
  • floathorizontalCellSpacing)

Emitted when the horizontalCellSpacing property has changed.

Parameters
horizontalCellSpacing

The new value for the horizontalCellSpacing property.

Since:

BlackBerry 10.0.0

void orientationChanged (

Emitted when the orientation property has changed.

Note:

Due to a workaround for a Qt Core issue with accessing enums from QML the argument of this signal doesn't follow naming convention for signals in which the signal arguments are typically named to match the associated property's name. Use the object's property to access current property value instead of the signal argument to avoid runtime errors (i.e. use orientation instead of newOrientation).

Parameters
newOrientation

The new orientation.

Since:

BlackBerry 10.0.0

void spacingAfterHeaderChanged (
  • floatspacingAfterHeader)

Emitted when the spacingAfterHeader property has changed.

Parameters
spacingAfterHeader

The new value for the spacingAfterHeader property.

Since:

BlackBerry 10.0.0

void spacingBeforeHeaderChanged (
  • floatspacingBeforeHeader)

Emitted when the spacingBeforeHeader property has changed.

Parameters
spacingBeforeHeader

The new value for the spacingBeforeHeader property.

Since:

BlackBerry 10.0.0

void verticalCellSpacingChanged (
  • floatverticalCellSpacing)

Emitted when the verticalCellSpacing property has changed.

Parameters
verticalCellSpacing

The new value for the verticalCellSpacing property.

Since:

BlackBerry 10.0.0

void creationCompleted ()Inherited

Emitted when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class.

This signal indicates that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.

This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.

This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.

See also:

QmlDocument

Since:

BlackBerry 10.0.0

void objectNameChanged (Inherited

This signal is emitted when the objectName property is changed.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-29



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus