QmlMaterial 0.1.0
Loading...
Searching...
No Matches
qt.hpp
1#pragma once
2
3#include <QList>
4#include <QObject>
5#include <QProperty>
6#include <Qt>
7#include <utility>
8
9namespace qml_material::utils
10{
11
12template<class Owner, class Value, auto Offset>
13void updateBoundValue(QObjectBindableProperty<Owner, Value, Offset>& property, const Value& value) {
14 // C++ state updates must keep the caller's binding installed.
15 // Owner callbacks must be detachable observers, not static property callbacks.
16 // Do not batch these updates: Qt skips QML observer notifications for a
17 // bound property manually notified inside a property update group.
18 if (property.valueBypassingBindings() == value) return;
19 property.setValueBypassingBindings(value);
20 property.notify();
21}
22
23inline void disconnectAll(QList<QMetaObject::Connection>& connections) {
24 for (const auto& connection : std::as_const(connections)) QObject::disconnect(connection);
25 connections.clear();
26}
27
28inline bool isKeyboardFocusReason(Qt::FocusReason reason) {
29 return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason ||
30 reason == Qt::ShortcutFocusReason;
31}
32
33} // namespace qml_material::utils