mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Reduce allocations and time spent creating delegates by half
This commit is contained in:
parent
7cfb7dcea4
commit
b847623fbe
2 changed files with 9 additions and 7 deletions
|
@ -53,6 +53,7 @@ DelegateChooser::setRoleValue(const QVariant &value)
|
||||||
{
|
{
|
||||||
if (value != roleValue_) {
|
if (value != roleValue_) {
|
||||||
roleValue_ = value;
|
roleValue_ = value;
|
||||||
|
if (isComponentComplete())
|
||||||
recalcChild();
|
recalcChild();
|
||||||
emit roleValueChanged();
|
emit roleValueChanged();
|
||||||
}
|
}
|
||||||
|
@ -96,8 +97,8 @@ void
|
||||||
DelegateChooser::recalcChild()
|
DelegateChooser::recalcChild()
|
||||||
{
|
{
|
||||||
for (const auto choice : qAsConst(choices_)) {
|
for (const auto choice : qAsConst(choices_)) {
|
||||||
auto choiceValue = choice->roleValue();
|
const auto &choiceValue = choice->roleValueRef();
|
||||||
if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
|
if (choiceValue == roleValue_ || (!choiceValue.isValid() && !roleValue_.isValid())) {
|
||||||
if (child_) {
|
if (child_) {
|
||||||
child_->setParentItem(nullptr);
|
child_->setParentItem(nullptr);
|
||||||
child_ = nullptr;
|
child_ = nullptr;
|
||||||
|
|
|
@ -25,10 +25,11 @@ public:
|
||||||
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
||||||
Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
|
Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
|
||||||
|
|
||||||
QQmlComponent *delegate() const;
|
[[nodiscard]] QQmlComponent *delegate() const;
|
||||||
void setDelegate(QQmlComponent *delegate);
|
void setDelegate(QQmlComponent *delegate);
|
||||||
|
|
||||||
QVariant roleValue() const;
|
[[nodiscard]] QVariant roleValue() const;
|
||||||
|
[[nodiscard]] const QVariant &roleValueRef() const { return roleValue_; }
|
||||||
void setRoleValue(const QVariant &value);
|
void setRoleValue(const QVariant &value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -53,10 +54,10 @@ public:
|
||||||
|
|
||||||
QQmlListProperty<DelegateChoice> choices();
|
QQmlListProperty<DelegateChoice> choices();
|
||||||
|
|
||||||
QVariant roleValue() const;
|
[[nodiscard]] QVariant roleValue() const;
|
||||||
void setRoleValue(const QVariant &value);
|
void setRoleValue(const QVariant &value);
|
||||||
|
|
||||||
QQuickItem *child() const { return child_; }
|
[[nodiscard]] QQuickItem *child() const { return child_; }
|
||||||
|
|
||||||
void recalcChild();
|
void recalcChild();
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
|
Loading…
Reference in a new issue