QSkinny 0.8.0
C++/Qt UI toolkit
|
#include <QskItem.h>
QskItem completes the C++ API of QQuickItem and re-establishs basic concepts like events. It also offers better control over the operations happening in the update cycle.
Public Types | |
enum | UpdateFlag { DeferredUpdate = 1 << 0 , DeferredPolish = 1 << 1 , DeferredLayout = 1 << 2 , CleanupOnVisibility = 1 << 3 , PreferRasterForTextures = 1 << 4 , DebugForceBackground = 1 << 7 } |
Public Slots | |
void | setGeometry (const QRectF &) |
void | show () |
void | hide () |
void | setHidden (bool) |
void | setDisabled (bool) |
void | resetImplicitSize () |
Signals | |
void | wheelEnabledChanged (bool) |
void | focusPolicyChanged (Qt::FocusPolicy) |
void | itemFlagsChanged () |
void | updateFlagsChanged (UpdateFlags) |
Public Member Functions | |
const char * | className () const |
bool | isVisibleTo (const QQuickItem *) const |
bool | isVisibleToParent () const |
bool | hasChildItems () const |
QRectF | rect () const |
QSizeF | implicitSize () const |
void | setGeometry (qreal x, qreal y, qreal width, qreal height) |
void | setGeometry (const QPointF &, const QSizeF &) |
QRectF | geometry () const |
void | setPosition (qreal x, qreal y) |
void | setSize (qreal width, qreal height) |
void | setPolishOnResize (bool) |
bool | polishOnResize () const |
void | setPolishOnParentResize (bool) |
bool | polishOnParentResize () const |
void | setFocusPolicy (Qt::FocusPolicy) |
Qt::FocusPolicy | focusPolicy () const |
void | setTabFence (bool) |
bool | isTabFence () const |
void | setWheelEnabled (bool) |
bool | isWheelEnabled () const |
void | setLayoutMirroring (bool on, bool childrenInherit=false) |
void | resetLayoutMirroring () |
bool | layoutMirroring () const |
void | resetUpdateFlags () |
UpdateFlags | updateFlags () const |
void | setUpdateFlag (UpdateFlag, bool on=true) |
void | resetUpdateFlag (UpdateFlag) |
bool | testUpdateFlag (UpdateFlag) const |
void | classBegin () override |
void | componentComplete () override |
void | releaseResources () override |
bool | isPolishScheduled () const |
bool | isUpdateNodeScheduled () const |
bool | isInitiallyPainted () const |
bool | maybeUnresized () const |
Protected Member Functions | |
QskItem (QskItemPrivate &, QQuickItem *=nullptr) | |
bool | event (QEvent *) override |
virtual void | changeEvent (QEvent *) |
virtual void | geometryChangeEvent (QskGeometryChangeEvent *) |
virtual void | windowChangeEvent (QskWindowChangeEvent *) |
void | mouseUngrabEvent () override |
void | touchUngrabEvent () override |
void | itemChange (ItemChange, const ItemChangeData &) override |
void | geometryChange (const QRectF &, const QRectF &) override |
virtual void | aboutToShow () |
Properties | |
QRectF | geometry |
QRectF | rect |
bool | tabFence |
bool | polishOnResize |
bool | polishOnParentResize |
Qt::FocusPolicy | focusPolicy |
bool | wheelEnabled |
bool | visibleToParent |
bool | hasChildItems |
bool | initiallyPainted |
UpdateFlags | updateFlags |
enum QskItem::UpdateFlag |
Qt/Quick classes have a tendency to update items too early and too often. To avoid processing of unwanted operations QskItem implements a couple of modifications, that can be en/disabled individually.
Enumerator | |
---|---|
DeferredUpdate | Creating of scene graph nodes is blocked when being invisible. The default implementation of Qt/Quick creates scene graph nodes for all items in the scene what might become a significant factor for the startup performance ( and memory footprint ) of large user interfaces. Instead of trying to work around these problems by asynchrounous instantiation strategies ( QQmlIncubator ) the DeferredUpdate flag offers a much simpler and obvious solution: don't instantiate before really needed. \saqt QQuickItem::isVisible()
|
DeferredPolish | Polishing an item is blocked when being invisible. F.e for all items being derived from QskControl the layout calculations happen during polishing. \saqt QQuickItem::updatePolish(), QQuickItem::polish() |
DeferredLayout | Recalculations of the implicitSize are blocked until being explicitly requested. When being enabled the item indicates layout relevant changes by sending a QEvent::LayoutRequest ( similar to QWidget ) to its parent item without recalculating the actual size hints ( f.e the implicitSize ). When having layout code that relies on binding the implicit width/height the QskItem::DeferredLayout flag needs to be disabled.
|
CleanupOnVisibility | Delete scene graph nodes, when the item becomes hidden. Enabling this mode will reduce the memory footprint, but comes at the cost of having to recreate nodes once the item gets shown again. \saqt QQuickItem::isVisible() |
PreferRasterForTextures | When creating textures from QskGraphic, prefer the raster paint engine over the OpenGL paint engine. |
DebugForceBackground | Always fill the background of the item with a random color.
|
|
override |
Definition at line 244 of file QskItem.cpp.
|
protected |
Sets the QQuickItem::ItemHasContents flag to true.
Definition at line 232 of file QskItem.cpp.
|
protectedvirtual |
A specific hook that is intended to be overloaded by controls that need to do some specific operations, when an item is painted the first time after becoming visible.
The default implementation is a no operation.
Reimplemented in QskMenu, QskPopup, and QskSlider.
Definition at line 1091 of file QskItem.cpp.
|
inlinefinaloverrideprivate |
|
protectedvirtual |
This event handler can be reimplemented to handle certain state changes:
- QEvent::StyleChange - QEvent::ContentsRectChange - QEvent::ReadOnlyChange - QEvent::EnabledChange - QEvent::LocaleChange - QEvent::ParentChange - QEvent::LayoutDirectionChange
event | Qt event |
Reimplemented in QskCheckBox, QskGraphicLabel, QskListView, QskPushButton, QskStatusIndicator, QskTabButton, QskTextLabel, and QskDialogButton.
Definition at line 859 of file QskItem.cpp.
|
override |
The QML engine initializes an item as being incomplete by explicitly calling classBegin(). Once the item has been constructed componentComplete() is called. This way temporary operations during the construction can be avoided.
In the C++ case the item indicates being complete from the beginning and both hooks are never called.
The overloaded version calls the base class and has no purpose beside being an entry point for debugging.
Definition at line 267 of file QskItem.cpp.
const char * QskItem::className | ( | ) | const |
A convenience wrapper for metaObject()->className()
Definition at line 262 of file QskItem.cpp.
|
override |
The QML engine initilizes an item as being incomplete by explicitly calling QQuickItem::classBegin(). Once the item has been constructed componentComplete() is called. This way temporary operations during the construction can be avoided.
In the C++ case the item indicates being complete from the beginning and both hooks are never called.
The overloaded does some sanity checks in debug mode and calls the base class.
Definition at line 272 of file QskItem.cpp.
|
overrideprotected |
QskItem handles the additional type of events.
For some reason the QQuick classes introduced proprietory notfier hooks instead of using the well established and powerful concept of events. QskItem tries to revert this decision by mapping notifications to events, when possible.
The following notification events are added by QSkinny - usually with a very similar to how they are used known for Qt/Widgets:
Furthermore events derived from QskEvent are used.
event | Qt event |
Definition at line 736 of file QskItem.cpp.
Qt::FocusPolicy QskItem::focusPolicy | ( | ) | const |
Definition at line 446 of file QskItem.cpp.
QRectF QskItem::geometry | ( | ) | const |
Definition at line 394 of file QskItem.cpp.
|
overrideprotected |
This overloaded notifier calls QQuickItem::polish() depending on the polishOnResize() flag and forwards the notification to the event queue.
Definition at line 1024 of file QskItem.cpp.
|
protectedvirtual |
For no known reason QQuickItem propagates changes of position and size by calling QQuickItem::geometryChange(), instead of using events.
QskItem reestablished the more powerful concept of events by sending/posting events, that can be preprocessed by event filtering.
event | Event indicating the geometry change |
Reimplemented in QskGraphicLabel, QskScrollBox, QskSubWindowArea, QskGridBox, and QskLinearBox.
Definition at line 855 of file QskItem.cpp.
|
inline |
|
slot |
An alternative way to call setVisible( false ). Useful for signal/slot connections
Definition at line 315 of file QskItem.cpp.
|
inline |
Qt/Quick offers an oversimplified layout system that is based on the property bindings of implicit width and height. QSkinny restablishs a layout system that can compete with what is available in the Qt/Widgets or Qt/Graphics technologies.
In the QSkinny layout system the implicitSize is a synonym for what is also known as sizeHint or preferredSize.
bool QskItem::isInitiallyPainted | ( | ) | const |
Definition at line 578 of file QskItem.cpp.
bool QskItem::isPolishScheduled | ( | ) | const |
Definition at line 565 of file QskItem.cpp.
bool QskItem::isTabFence | ( | ) | const |
Definition at line 410 of file QskItem.cpp.
bool QskItem::isUpdateNodeScheduled | ( | ) | const |
Definition at line 570 of file QskItem.cpp.
bool QskItem::isVisibleTo | ( | const QQuickItem * | ancestor | ) | const |
The true case occurs if neither the item itself nor any parent up to but excluding ancestor has been explicitly hidden.
ancestor | Ancestor is the parentItem() hierarchy |
Definition at line 320 of file QskItem.cpp.
bool QskItem::isVisibleToParent | ( | ) | const |
An item might be invisible because it has been explicitly hidden or one of its ancestors has been hidden. isVisibleToParent() indicates the first situation.
Definition at line 325 of file QskItem.cpp.
bool QskItem::isWheelEnabled | ( | ) | const |
Definition at line 465 of file QskItem.cpp.
|
overrideprotected |
For no obvious reason Qt/Quick has introduced an additional callback mechanism beside events and signals.
change | Indicator, to identify what has changed |
changeData | Extra information relating to the change |
Definition at line 863 of file QskItem.cpp.
|
signal |
Signal indicating that at least one if the following attributes has changed:
bool QskItem::layoutMirroring | ( | ) | const |
Direction how the content is layed out horizontally.
If no value has been explicitly assigned it is inherited from the closest ancestor, where the attribute has been assigned with the childrenInherit parameter. If such an ancestor does not exists layoutMirroring is false.
Definition at line 511 of file QskItem.cpp.
bool QskItem::maybeUnresized | ( | ) | const |
Flag indicating a potential state, where the item is waiting to be sized by the layout system.
Unfortunately the list of items to-be-polished is not processed in top/down order and a container might be requested to calculate the geometries for its children before having a proper size itself.
Some of these situations can be avoided by ignoring these requests depending on the maybeUnresized flag.
Definition at line 583 of file QskItem.cpp.
|
overrideprotected |
Notification, that is overloaded for debuging purposes, without doing anything beside calling the base class.
\saqt QQuickItem::mouseUngrabEvent
Definition at line 1044 of file QskItem.cpp.
bool QskItem::polishOnParentResize | ( | ) | const |
Definition at line 506 of file QskItem.cpp.
bool QskItem::polishOnResize | ( | ) | const |
Definition at line 482 of file QskItem.cpp.
QRectF QskItem::rect | ( | ) | const |
Definition at line 388 of file QskItem.cpp.
|
override |
This specific hook is called, when the item is about to be removed from the window it was previously rendering to.
The implementation stores the values needed for the following QskWindowChangeEvent.
Definition at line 287 of file QskItem.cpp.
|
slot |
Notifies the layout system that attributes affecting the layout system have changed.
If the QskItem::DeferredLayout flag is enabled ( = default ) the cached implicitSize() gets invalidated and a QEvent::LayoutRequest is sent to the parent item ( like QWidget::updateGeometry ).
Otherwise the implicitSize() gets recalculated and layout updates can be executed using property bindings.
Definition at line 721 of file QskItem.cpp.
void QskItem::resetLayoutMirroring | ( | ) |
Clear the layoutMirroring property
Definition at line 553 of file QskItem.cpp.
void QskItem::resetUpdateFlag | ( | UpdateFlag | flag | ) |
Reset the value for flag to the default settings from QskSetup. Future changes of the corresponding bit with QskSetup::setItemUpdateFlag() will affect the behaviour of this item.
flag | Flag affecting the item update process |
Definition at line 630 of file QskItem.cpp.
void QskItem::resetUpdateFlags | ( | ) |
Reset all flags to the default settings
Definition at line 608 of file QskItem.cpp.
|
slot |
Convenience function, equivalent to setEnabled( !on ). \saqt QQuickItem::setEnabled()
Definition at line 300 of file QskItem.cpp.
void QskItem::setFocusPolicy | ( | Qt::FocusPolicy | policy | ) |
Definition at line 415 of file QskItem.cpp.
|
inline |
|
inlineslot |
Set the position and the size of an item
rect | Geometry relative to the parent item |
void QskItem::setGeometry | ( | qreal | x, |
qreal | y, | ||
qreal | width, | ||
qreal | height | ||
) |
Set the position and the size of an item
x | X ( = left ) coordinate relative to the parent item |
y | Y ( = top ) coordinate relative to the parent item |
width | Width |
height | Height |
Definition at line 330 of file QskItem.cpp.
|
slot |
Convenience function, equivalent to setVisible( !on ).
Definition at line 305 of file QskItem.cpp.
void QskItem::setLayoutMirroring | ( | bool | on, |
bool | childrenInherit = false |
||
) |
Change the direction how the content is laid out horizontally.
on | True enables layoutMirroring |
childrenInherit | If true the mirroring behavior is propagated to all child items as well. |
Changes of this property will be indicated by a QEvent::LayoutDirectionChange.
Definition at line 525 of file QskItem.cpp.
void QskItem::setPolishOnParentResize | ( | bool | on | ) |
Definition at line 487 of file QskItem.cpp.
void QskItem::setPolishOnResize | ( | bool | on | ) |
Set or clear the polishOnResize flag.
Definition at line 470 of file QskItem.cpp.
|
inline |
void QskItem::setTabFence | ( | bool | on | ) |
void QskItem::setUpdateFlag | ( | UpdateFlag | flag, |
bool | on = true |
||
) |
QskItem offers several tweaks to the Qt/Quick update cycle, that can be en/disables individually.
The default settings for these flags are taken from QskSetup::itemUpdateFlags() When calling setUpdateFlag() the value for the particular flag is decoupled from the corresponding default bit - even if both bits have the same value. This can be reverted by calling resetUpdateFlag()
flag | Flag affecting the item update process |
on | En/Disable the behaviour related to the flag |
Definition at line 617 of file QskItem.cpp.
void QskItem::setWheelEnabled | ( | bool | on | ) |
Definition at line 455 of file QskItem.cpp.
|
slot |
An alternative way to call setVisible( true ). Useful for signal/slot connections
Definition at line 310 of file QskItem.cpp.
bool QskItem::testUpdateFlag | ( | UpdateFlag | flag | ) | const |
Flag | affecting the item update process |
Definition at line 645 of file QskItem.cpp.
|
overrideprotected |
Notification, that is overloaded for debuging purposes, without doing anything beside calling the base class.
\saqt QQuickItem::touchUngrabEvent
Definition at line 1049 of file QskItem.cpp.
QskItem::UpdateFlags QskItem::updateFlags | ( | ) | const |
Definition at line 603 of file QskItem.cpp.
|
signal |
Signal indicating, that the effective update flags have changed
flags | Effective flags, might be derived in parts from QskSetup::itemUpdateFlags() |
|
privatevirtual |
Definition at line 1133 of file QskItem.cpp.
|
privatevirtual |
Definition at line 1095 of file QskItem.cpp.
|
finaloverrideprivate |
Definition at line 1099 of file QskItem.cpp.
|
finaloverrideprivate |
Definition at line 1063 of file QskItem.cpp.
|
protectedvirtual |
This event handler can be reimplemented to handle situations, where an item is added, removed or transferred between windows. It corresponds to the QQuickItem::ItemSceneChange notification, but is more convenient:
event | Event with the old/new windows |
Reimplemented in QskFocusIndicator, QskPopup, and QskScrollBox.
Definition at line 851 of file QskItem.cpp.
|
readwrite |
This property holds the geometry of the item relative to its parent item. When changing the geometry, the item receives a QskEvent::GeometryChange event.
|
read |
|
read |
Status flag indicating that there has already been a call of QQuickItem::updatePaintNode() since the item has become visible.
Before each initial call of updatePaintNode() the specific hook aboutToShow() is called, that is intended to be overloaded.
|
readwrite |
When polishOnResize is set QQuickItem::polish() will be called automatically whenever the size of the item has been changed. This is usually necessary when the item is a container and the layout of its children depends on the size of the container.
|
read |
This property returns the internal geometry of the item. It equals QRect(0, 0, width(), height() ).
|
readwrite |
The tabFence flag can be used to create local tab focus chains. It is usually used in combination with QQuickItem::ItemIsFocusScope.
QskPopup is an example where the focus tab chain is expected to continue with the first child instead of leaving the popup, when reaching its end.
|
read |
QskItem offers several tweaks to the Qt/Quick update cycle, that can be en/disabled individually.
The flags are a combination from bits that have been explicitly set by setUpdateFlag() and those being derived from the aapplication wide default settings, that can be set with QskSetup.
|
read |
Flag indicating if an item would become visible if its parentItem() is shown. The implementation relies on the internal explicitVisible flag, that has not been exposed by the public API of QQuickItem.
In many situations it is important to know if an item has been explicitly hidden because of a setVisible( false ) or it is a child of an item, that is in an invisible state. F,e for calculating the size hint for a hidden container it is necessary to know which children would stay hidden when the container becomes visible.