diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-11 18:24:18 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-12 12:44:07 +0000 |
commit | 244cc6eec931f0b46e3d2b8ea32f03b32cb1023e (patch) | |
tree | bd590e8e4b98e82ba6b820d8543b486f4082fb4c /src/templates | |
parent | 8d5a8ee53d089cea7543040ecb11d165ab34c506 (diff) |
Templates: follow the Qt coding style
Return early to keep the indentation low. This style was already used
in many areas, so now the same style is consistently used everywhere.
Change-Id: Ibc7c05147fdcf226ad1cbdd26cd70e1da89108af
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates')
30 files changed, 1012 insertions, 886 deletions
diff --git a/src/templates/qquickabstractbutton.cpp b/src/templates/qquickabstractbutton.cpp index 546eecb3..016c6d5a 100644 --- a/src/templates/qquickabstractbutton.cpp +++ b/src/templates/qquickabstractbutton.cpp @@ -246,11 +246,12 @@ QString QQuickAbstractButton::text() const void QQuickAbstractButton::setText(const QString &text) { Q_D(QQuickAbstractButton); - if (d->text != text) { - d->text = text; - setAccessibleName(text); - emit textChanged(); - } + if (d->text == text) + return; + + d->text = text; + setAccessibleName(text); + emit textChanged(); } /*! @@ -267,11 +268,12 @@ bool QQuickAbstractButton::isPressed() const void QQuickAbstractButton::setPressed(bool isPressed) { Q_D(QQuickAbstractButton); - if (d->pressed != isPressed) { - d->pressed = isPressed; - setAccessibleProperty("pressed", isPressed); - emit pressedChanged(); - } + if (d->pressed == isPressed) + return; + + d->pressed = isPressed; + setAccessibleProperty("pressed", isPressed); + emit pressedChanged(); } /*! @@ -288,15 +290,16 @@ bool QQuickAbstractButton::isChecked() const void QQuickAbstractButton::setChecked(bool checked) { Q_D(QQuickAbstractButton); + if (d->checked == checked) + return; + if (checked && !d->checkable) setCheckable(true); - if (d->checked != checked) { - d->checked = checked; - setAccessibleProperty("checked", checked); - checkStateSet(); - emit checkedChanged(); - } + d->checked = checked; + setAccessibleProperty("checked", checked); + checkStateSet(); + emit checkedChanged(); } /*! @@ -313,11 +316,12 @@ bool QQuickAbstractButton::isCheckable() const void QQuickAbstractButton::setCheckable(bool checkable) { Q_D(QQuickAbstractButton); - if (d->checkable != checkable) { - d->checkable = checkable; - setAccessibleProperty("checkable", checkable); - emit checkableChanged(); - } + if (d->checkable == checkable) + return; + + d->checkable = checkable; + setAccessibleProperty("checkable", checkable); + emit checkableChanged(); } /*! @@ -339,10 +343,11 @@ bool QQuickAbstractButton::isHighlighted() const void QQuickAbstractButton::setHighlighted(bool highlighted) { Q_D(QQuickAbstractButton); - if (highlighted != d->highlighted) { - d->highlighted = highlighted; - emit highlightedChanged(); - } + if (highlighted == d->highlighted) + return; + + d->highlighted = highlighted; + emit highlightedChanged(); } /*! @@ -368,10 +373,11 @@ bool QQuickAbstractButton::autoExclusive() const void QQuickAbstractButton::setAutoExclusive(bool exclusive) { Q_D(QQuickAbstractButton); - if (d->autoExclusive != exclusive) { - d->autoExclusive = exclusive; - emit autoExclusiveChanged(); - } + if (d->autoExclusive == exclusive) + return; + + d->autoExclusive = exclusive; + emit autoExclusiveChanged(); } /*! @@ -391,11 +397,12 @@ bool QQuickAbstractButton::autoRepeat() const void QQuickAbstractButton::setAutoRepeat(bool repeat) { Q_D(QQuickAbstractButton); - if (d->autoRepeat != repeat) { - d->stopPressRepeat(); - d->autoRepeat = repeat; - emit autoRepeatChanged(); - } + if (d->autoRepeat == repeat) + return; + + d->stopPressRepeat(); + d->autoRepeat = repeat; + emit autoRepeatChanged(); } /*! @@ -412,16 +419,17 @@ QQuickItem *QQuickAbstractButton::indicator() const void QQuickAbstractButton::setIndicator(QQuickItem *indicator) { Q_D(QQuickAbstractButton); - if (d->indicator != indicator) { - delete d->indicator; - d->indicator = indicator; - if (indicator) { - if (!indicator->parentItem()) - indicator->setParentItem(this); - indicator->setAcceptedMouseButtons(Qt::LeftButton); - } - emit indicatorChanged(); + if (d->indicator == indicator) + return; + + delete d->indicator; + d->indicator = indicator; + if (indicator) { + if (!indicator->parentItem()) + indicator->setParentItem(this); + indicator->setAcceptedMouseButtons(Qt::LeftButton); } + emit indicatorChanged(); } /*! diff --git a/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp index d2bbcd79..12d8133d 100644 --- a/src/templates/qquickapplicationwindow.cpp +++ b/src/templates/qquickapplicationwindow.cpp @@ -246,25 +246,26 @@ QQuickItem *QQuickApplicationWindow::header() const void QQuickApplicationWindow::setHeader(QQuickItem *header) { Q_D(QQuickApplicationWindow); - if (d->header != header) { - if (d->header) - QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - d->header = header; - if (header) { - header->setParentItem(contentItem()); - QQuickItemPrivate *p = QQuickItemPrivate::get(header); - p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - if (qFuzzyIsNull(header->z())) - header->setZ(1); - if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header)) - toolBar->setPosition(QQuickToolBar::Header); - else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header)) - tabBar->setPosition(QQuickTabBar::Header); - if (isComponentComplete()) - d->relayout(); - } - emit headerChanged(); + if (d->header == header) + return; + + if (d->header) + QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->header = header; + if (header) { + header->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(header); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(header->z())) + header->setZ(1); + if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header)) + toolBar->setPosition(QQuickToolBar::Header); + else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header)) + tabBar->setPosition(QQuickTabBar::Header); + if (isComponentComplete()) + d->relayout(); } + emit headerChanged(); } /*! @@ -287,25 +288,26 @@ QQuickItem *QQuickApplicationWindow::footer() const void QQuickApplicationWindow::setFooter(QQuickItem *footer) { Q_D(QQuickApplicationWindow); - if (d->footer != footer) { - if (d->footer) - QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - d->footer = footer; - if (footer) { - footer->setParentItem(contentItem()); - QQuickItemPrivate *p = QQuickItemPrivate::get(footer); - p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - if (qFuzzyIsNull(footer->z())) - footer->setZ(1); - if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer)) - toolBar->setPosition(QQuickToolBar::Footer); - else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer)) - tabBar->setPosition(QQuickTabBar::Footer); - if (isComponentComplete()) - d->relayout(); - } - emit footerChanged(); + if (d->footer == footer) + return; + + if (d->footer) + QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->footer = footer; + if (footer) { + footer->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(footer); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(footer->z())) + footer->setZ(1); + if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer)) + toolBar->setPosition(QQuickToolBar::Footer); + else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer)) + tabBar->setPosition(QQuickTabBar::Footer); + if (isComponentComplete()) + d->relayout(); } + emit footerChanged(); } /*! diff --git a/src/templates/qquickbusyindicator.cpp b/src/templates/qquickbusyindicator.cpp index d4e07d44..3cfd96cb 100644 --- a/src/templates/qquickbusyindicator.cpp +++ b/src/templates/qquickbusyindicator.cpp @@ -98,10 +98,11 @@ bool QQuickBusyIndicator::isRunning() const void QQuickBusyIndicator::setRunning(bool running) { Q_D(QQuickBusyIndicator); - if (d->running != running) { - d->running = running; - emit runningChanged(); - } + if (d->running == running) + return; + + d->running = running; + emit runningChanged(); } #ifndef QT_NO_ACCESSIBILITY diff --git a/src/templates/qquickbuttongroup.cpp b/src/templates/qquickbuttongroup.cpp index da282250..5f0ec6b1 100644 --- a/src/templates/qquickbuttongroup.cpp +++ b/src/templates/qquickbuttongroup.cpp @@ -221,14 +221,15 @@ QQuickAbstractButton *QQuickButtonGroup::checkedButton() const void QQuickButtonGroup::setCheckedButton(QQuickAbstractButton *checkedButton) { Q_D(QQuickButtonGroup); - if (d->checkedButton != checkedButton) { - if (d->checkedButton) - d->checkedButton->setChecked(false); - d->checkedButton = checkedButton; - if (checkedButton) - checkedButton->setChecked(true); - emit checkedButtonChanged(); - } + if (d->checkedButton == checkedButton) + return; + + if (d->checkedButton) + d->checkedButton->setChecked(false); + d->checkedButton = checkedButton; + if (checkedButton) + checkedButton->setChecked(true); + emit checkedButtonChanged(); } /*! @@ -366,14 +367,15 @@ QQuickButtonGroup *QQuickButtonGroupAttached::group() const void QQuickButtonGroupAttached::setGroup(QQuickButtonGroup *group) { Q_D(QQuickButtonGroupAttached); - if (d->group != group) { - if (d->group) - d->group->removeButton(qobject_cast<QQuickAbstractButton*>(parent())); - d->group = group; - if (group) - group->addButton(qobject_cast<QQuickAbstractButton*>(parent())); - emit groupChanged(); - } + if (d->group == group) + return; + + if (d->group) + d->group->removeButton(qobject_cast<QQuickAbstractButton*>(parent())); + d->group = group; + if (group) + group->addButton(qobject_cast<QQuickAbstractButton*>(parent())); + emit groupChanged(); } QT_END_NAMESPACE diff --git a/src/templates/qquickcheckbox.cpp b/src/templates/qquickcheckbox.cpp index 1272a271..945fbc42 100644 --- a/src/templates/qquickcheckbox.cpp +++ b/src/templates/qquickcheckbox.cpp @@ -121,10 +121,11 @@ bool QQuickCheckBox::isTristate() const void QQuickCheckBox::setTristate(bool tristate) { Q_D(QQuickCheckBox); - if (d->tristate != tristate) { - d->tristate = tristate; - emit tristateChanged(); - } + if (d->tristate == tristate) + return; + + d->tristate = tristate; + emit tristateChanged(); } /*! @@ -148,16 +149,18 @@ Qt::CheckState QQuickCheckBox::checkState() const void QQuickCheckBox::setCheckState(Qt::CheckState state) { Q_D(QQuickCheckBox); + if (d->checkState == state) + return; + if (!d->tristate && state == Qt::PartiallyChecked) setTristate(true); - if (d->checkState != state) { - bool wasChecked = isChecked(); - d->checked = state != Qt::Unchecked; - d->checkState = state; - emit checkStateChanged(); - if (d->checked != wasChecked) - emit checkedChanged(); - } + + bool wasChecked = isChecked(); + d->checked = state != Qt::Unchecked; + d->checkState = state; + emit checkStateChanged(); + if (d->checked != wasChecked) + emit checkedChanged(); } QFont QQuickCheckBox::defaultFont() const diff --git a/src/templates/qquickcombobox.cpp b/src/templates/qquickcombobox.cpp index f51b301f..210239b0 100644 --- a/src/templates/qquickcombobox.cpp +++ b/src/templates/qquickcombobox.cpp @@ -302,10 +302,11 @@ void QQuickComboBoxPrivate::decrease() void QQuickComboBoxPrivate::setHighlightedIndex(int index) { Q_Q(QQuickComboBox); - if (highlightedIndex != index) { - highlightedIndex = index; - emit q->highlightedIndexChanged(); - } + if (highlightedIndex == index) + return; + + highlightedIndex = index; + emit q->highlightedIndexChanged(); } void QQuickComboBoxPrivate::createDelegateModel() @@ -403,15 +404,16 @@ void QQuickComboBox::setModel(const QVariant& m) if (model.userType() == qMetaTypeId<QJSValue>()) model = model.value<QJSValue>().toVariant(); - if (d->model != model) { - d->model = model; - d->createDelegateModel(); - if (isComponentComplete()) { - setCurrentIndex(count() > 0 ? 0 : -1); - d->updateCurrentText(); - } - emit modelChanged(); + if (d->model == model) + return; + + d->model = model; + d->createDelegateModel(); + if (isComponentComplete()) { + setCurrentIndex(count() > 0 ? 0 : -1); + d->updateCurrentText(); } + emit modelChanged(); } /*! @@ -440,10 +442,11 @@ bool QQuickComboBox::isPressed() const void QQuickComboBox::setPressed(bool pressed) { Q_D(QQuickComboBox); - if (d->pressed != pressed) { - d->pressed = pressed; - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + emit pressedChanged(); } /*! @@ -476,12 +479,13 @@ int QQuickComboBox::currentIndex() const void QQuickComboBox::setCurrentIndex(int index) { Q_D(QQuickComboBox); - if (d->currentIndex != index) { - d->currentIndex = index; - emit currentIndexChanged(); - if (isComponentComplete()) - d->updateCurrentText(); - } + if (d->currentIndex == index) + return; + + d->currentIndex = index; + emit currentIndexChanged(); + if (isComponentComplete()) + d->updateCurrentText(); } /*! @@ -527,19 +531,21 @@ void QQuickComboBox::setDisplayText(const QString &text) { Q_D(QQuickComboBox); d->hasDisplayText = true; - if (d->displayText != text) { - d->displayText = text; - emit displayTextChanged(); - } + if (d->displayText == text) + return; + + d->displayText = text; + emit displayTextChanged(); } void QQuickComboBox::resetDisplayText() { Q_D(QQuickComboBox); - if (d->hasDisplayText) { - d->hasDisplayText = false; - d->updateCurrentText(); - } + if (!d->hasDisplayText) + return; + + d->hasDisplayText = false; + d->updateCurrentText(); } /*! @@ -558,12 +564,13 @@ QString QQuickComboBox::textRole() const void QQuickComboBox::setTextRole(const QString &role) { Q_D(QQuickComboBox); - if (d->textRole != role) { - d->textRole = role; - if (isComponentComplete()) - d->updateCurrentText(); - emit textRoleChanged(); - } + if (d->textRole == role) + return; + + d->textRole = role; + if (isComponentComplete()) + d->updateCurrentText(); + emit textRoleChanged(); } /*! @@ -582,14 +589,15 @@ QQmlComponent *QQuickComboBox::delegate() const void QQuickComboBox::setDelegate(QQmlComponent* delegate) { Q_D(QQuickComboBox); - if (d->delegate != delegate) { - delete d->delegate; - d->delegate = delegate; - QQmlDelegateModel *delegateModel = qobject_cast<QQmlDelegateModel*>(d->delegateModel); - if (delegateModel) - delegateModel->setDelegate(d->delegate); - emit delegateChanged(); - } + if (d->delegate == delegate) + return; + + delete d->delegate; + d->delegate = delegate; + QQmlDelegateModel *delegateModel = qobject_cast<QQmlDelegateModel*>(d->delegateModel); + if (delegateModel) + delegateModel->setDelegate(d->delegate); + emit delegateChanged(); } /*! @@ -608,13 +616,14 @@ QQuickPopup *QQuickComboBox::popup() const void QQuickComboBox::setPopup(QQuickPopup *popup) { Q_D(QQuickComboBox); - if (d->popup != popup) { - delete d->popup; - if (popup) - popup->setClosePolicy(QQuickPopup::OnEscape | QQuickPopup::OnPressOutsideParent); - d->popup = popup; - emit popupChanged(); - } + if (d->popup == popup) + return; + + delete d->popup; + if (popup) + popup->setClosePolicy(QQuickPopup::OnEscape | QQuickPopup::OnPressOutsideParent); + d->popup = popup; + emit popupChanged(); } /*! diff --git a/src/templates/qquickcontainer.cpp b/src/templates/qquickcontainer.cpp index d5c387fb..12b330f6 100644 --- a/src/templates/qquickcontainer.cpp +++ b/src/templates/qquickcontainer.cpp @@ -442,11 +442,12 @@ int QQuickContainer::currentIndex() const void QQuickContainer::setCurrentIndex(int index) { Q_D(QQuickContainer); - if (d->currentIndex != index) { - d->currentIndex = index; - emit currentIndexChanged(); - emit currentItemChanged(); - } + if (d->currentIndex == index) + return; + + d->currentIndex = index; + emit currentIndexChanged(); + emit currentItemChanged(); } /*! diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp index a8235492..5bf42da0 100644 --- a/src/templates/qquickcontrol.cpp +++ b/src/templates/qquickcontrol.cpp @@ -746,10 +746,11 @@ Qt::FocusReason QQuickControl::focusReason() const void QQuickControl::setFocusReason(Qt::FocusReason reason) { Q_D(QQuickControl); - if (d->focusReason != reason) { - d->focusReason = reason; - emit focusReasonChanged(); - } + if (d->focusReason == reason) + return; + + d->focusReason = reason; + emit focusReasonChanged(); } /*! @@ -770,18 +771,19 @@ QQuickItem *QQuickControl::background() const void QQuickControl::setBackground(QQuickItem *background) { Q_D(QQuickControl); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } /*! @@ -800,18 +802,19 @@ QQuickItem *QQuickControl::contentItem() const void QQuickControl::setContentItem(QQuickItem *item) { Q_D(QQuickControl); - if (d->contentItem != item) { - contentItemChange(item, d->contentItem); - delete d->contentItem; - d->contentItem = item; - if (item) { - if (!item->parentItem()) - item->setParentItem(this); - if (isComponentComplete()) - d->resizeContent(); - } - emit contentItemChanged(); + if (d->contentItem == item) + return; + + contentItemChange(item, d->contentItem); + delete d->contentItem; + d->contentItem = item; + if (item) { + if (!item->parentItem()) + item->setParentItem(this); + if (isComponentComplete()) + d->resizeContent(); } + emit contentItemChanged(); } void QQuickControl::componentComplete() diff --git a/src/templates/qquickdial.cpp b/src/templates/qquickdial.cpp index cdd7c60b..e1083b35 100644 --- a/src/templates/qquickdial.cpp +++ b/src/templates/qquickdial.cpp @@ -143,14 +143,15 @@ void QQuickDialPrivate::setPosition(qreal pos) { Q_Q(QQuickDial); pos = qBound<qreal>(0.0, pos, 1.0); - if (!qFuzzyCompare(position, pos)) { - position = pos; + if (qFuzzyCompare(position, pos)) + return; - angle = startAngle + position * qAbs(endAngle - startAngle); + position = pos; - emit q->positionChanged(); - emit q->angleChanged(); - } + angle = startAngle + position * qAbs(endAngle - startAngle); + + emit q->positionChanged(); + emit q->angleChanged(); } void QQuickDialPrivate::updatePosition() @@ -184,13 +185,14 @@ qreal QQuickDial::from() const void QQuickDial::setFrom(qreal from) { Q_D(QQuickDial); - if (!qFuzzyCompare(d->from, from)) { - d->from = from; - emit fromChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } + if (qFuzzyCompare(d->from, from)) + return; + + d->from = from; + emit fromChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); } } @@ -211,13 +213,14 @@ qreal QQuickDial::to() const void QQuickDial::setTo(qreal to) { Q_D(QQuickDial); - if (!qFuzzyCompare(d->to, to)) { - d->to = to; - emit toChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } + if (qFuzzyCompare(d->to, to)) + return; + + d->to = to; + emit toChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); } } @@ -245,11 +248,12 @@ void QQuickDial::setValue(qreal value) if (isComponentComplete()) value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); - if (!qFuzzyCompare(d->value, value)) { - d->value = value; - d->updatePosition(); - emit valueChanged(); - } + if (qFuzzyCompare(d->value, value)) + return; + + d->value = value; + d->updatePosition(); + emit valueChanged(); } /*! @@ -304,10 +308,11 @@ qreal QQuickDial::stepSize() const void QQuickDial::setStepSize(qreal step) { Q_D(QQuickDial); - if (!qFuzzyCompare(d->stepSize, step)) { - d->stepSize = step; - emit stepSizeChanged(); - } + if (qFuzzyCompare(d->stepSize, step)) + return; + + d->stepSize = step; + emit stepSizeChanged(); } /*! @@ -334,10 +339,11 @@ QQuickDial::SnapMode QQuickDial::snapMode() const void QQuickDial::setSnapMode(SnapMode mode) { Q_D(QQuickDial); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } + if (d->snapMode == mode) + return; + + d->snapMode = mode; + emit snapModeChanged(); } /*! @@ -367,11 +373,12 @@ bool QQuickDial::isPressed() const void QQuickDial::setPressed(bool pressed) { Q_D(QQuickDial); - if (d->pressed != pressed) { - d->pressed = pressed; - setAccessibleProperty("pressed", pressed); - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + setAccessibleProperty("pressed", pressed); + emit pressedChanged(); } /*! @@ -420,12 +427,13 @@ QQuickItem *QQuickDial::handle() const void QQuickDial::setHandle(QQuickItem *handle) { Q_D(QQuickDial); - if (handle != d->handle) { - d->handle = handle; - if (d->handle && !d->handle->parentItem()) - d->handle->setParentItem(this); - emit handleChanged(); - } + if (handle == d->handle) + return; + + d->handle = handle; + if (d->handle && !d->handle->parentItem()) + d->handle->setParentItem(this); + emit handleChanged(); } void QQuickDial::keyPressEvent(QKeyEvent *event) diff --git a/src/templates/qquickdrawer.cpp b/src/templates/qquickdrawer.cpp index 33e0ff8f..a28d11a6 100644 --- a/src/templates/qquickdrawer.cpp +++ b/src/templates/qquickdrawer.cpp @@ -290,12 +290,13 @@ Qt::Edge QQuickDrawer::edge() const void QQuickDrawer::setEdge(Qt::Edge edge) { Q_D(QQuickDrawer); - if (d->edge != edge) { - d->edge = edge; - if (isComponentComplete()) - d->updateContent(); - emit edgeChanged(); - } + if (d->edge == edge) + return; + + d->edge = edge; + if (isComponentComplete()) + d->updateContent(); + emit edgeChanged(); } /*! @@ -315,12 +316,13 @@ void QQuickDrawer::setPosition(qreal position) { Q_D(QQuickDrawer); position = qBound<qreal>(0.0, position, 1.0); - if (!qFuzzyCompare(d->position, position)) { - d->position = position; - if (isComponentComplete()) - d->updateContent(); - emit positionChanged(); - } + if (qFuzzyCompare(d->position, position)) + return; + + d->position = position; + if (isComponentComplete()) + d->updateContent(); + emit positionChanged(); } @@ -338,20 +340,21 @@ QQuickItem *QQuickDrawer::contentItem() const void QQuickDrawer::setContentItem(QQuickItem *item) { Q_D(QQuickDrawer); - if (d->content != item) { - if (d->content) { - QQuickItemPrivate::get(d->content)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - delete d->content; - } - d->content = item; - if (item) { - item->setParentItem(this); - QQuickItemPrivate::get(item)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - if (isComponentComplete()) - d->updateContent(); - } - emit contentItemChanged(); + if (d->content == item) + return; + + if (d->content) { + QQuickItemPrivate::get(d->content)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + delete d->content; } + d->content = item; + if (item) { + item->setParentItem(this); + QQuickItemPrivate::get(item)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + if (isComponentComplete()) + d->updateContent(); + } + emit contentItemChanged(); } /*! @@ -371,15 +374,16 @@ QQuickPropertyAnimation *QQuickDrawer::animation() const void QQuickDrawer::setAnimation(QQuickPropertyAnimation *animation) { Q_D(QQuickDrawer); - if (d->animation != animation) { - delete d->animation; - d->animation = animation; - if (animation) { - animation->setTargetObject(this); - animation->setProperty(QStringLiteral("position")); - } - emit animationChanged(); + if (d->animation == animation) + return; + + delete d->animation; + d->animation = animation; + if (animation) { + animation->setTargetObject(this); + animation->setProperty(QStringLiteral("position")); } + emit animationChanged(); } /*! diff --git a/src/templates/qquickgroupbox.cpp b/src/templates/qquickgroupbox.cpp index 1dba509b..33f7c672 100644 --- a/src/templates/qquickgroupbox.cpp +++ b/src/templates/qquickgroupbox.cpp @@ -108,10 +108,11 @@ QString QQuickGroupBox::title() const void QQuickGroupBox::setTitle(const QString &title) { Q_D(QQuickGroupBox); - if (d->title != title) { - d->title = title; - emit titleChanged(); - } + if (d->title == title) + return; + + d->title = title; + emit titleChanged(); } /*! @@ -130,13 +131,14 @@ QQuickItem *QQuickGroupBox::label() const void QQuickGroupBox::setLabel(QQuickItem *label) { Q_D(QQuickGroupBox); - if (d->label != label) { - delete d->label; - d->label = label; - if (label && !label->parentItem()) - label->setParentItem(this); - emit labelChanged(); - } + if (d->label == label) + return; + + delete d->label; + d->label = label; + if (label && !label->parentItem()) + label->setParentItem(this); + emit labelChanged(); } QFont QQuickGroupBox::defaultFont() const diff --git a/src/templates/qquicklabel.cpp b/src/templates/qquicklabel.cpp index 92969d4f..e9fb274d 100644 --- a/src/templates/qquicklabel.cpp +++ b/src/templates/qquicklabel.cpp @@ -195,16 +195,17 @@ QQuickItem *QQuickLabel::background() const void QQuickLabel::setBackground(QQuickItem *background) { Q_D(QQuickLabel); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); } + emit backgroundChanged(); } void QQuickLabel::classBegin() diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp index 1b411efe..b20088ba 100644 --- a/src/templates/qquickoverlay.cpp +++ b/src/templates/qquickoverlay.cpp @@ -132,19 +132,20 @@ QQuickItem *QQuickOverlay::background() const void QQuickOverlay::setBackground(QQuickItem *background) { Q_D(QQuickOverlay); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setOpacity(0.0); - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setOpacity(0.0); + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) diff --git a/src/templates/qquickpage.cpp b/src/templates/qquickpage.cpp index 8bafb2b9..bf1fc42d 100644 --- a/src/templates/qquickpage.cpp +++ b/src/templates/qquickpage.cpp @@ -164,25 +164,26 @@ QQuickItem *QQuickPage::header() const void QQuickPage::setHeader(QQuickItem *header) { Q_D(QQuickPage); - if (d->header != header) { - if (d->header) - QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - d->header = header; - if (header) { - header->setParentItem(this); - QQuickItemPrivate *p = QQuickItemPrivate::get(header); - p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - if (qFuzzyIsNull(header->z())) - header->setZ(1); - if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header)) - toolBar->setPosition(QQuickToolBar::Header); - else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header)) - tabBar->setPosition(QQuickTabBar::Header); - if (isComponentComplete()) - d->relayout(); - } - emit headerChanged(); + if (d->header == header) + return; + + if (d->header) + QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->header = header; + if (header) { + header->setParentItem(this); + QQuickItemPrivate *p = QQuickItemPrivate::get(header); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(header->z())) + header->setZ(1); + if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header)) + toolBar->setPosition(QQuickToolBar::Header); + else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header)) + tabBar->setPosition(QQuickTabBar::Header); + if (isComponentComplete()) + d->relayout(); } + emit headerChanged(); } /*! @@ -205,25 +206,26 @@ QQuickItem *QQuickPage::footer() const void QQuickPage::setFooter(QQuickItem *footer) { Q_D(QQuickPage); - if (d->footer != footer) { - if (d->footer) - QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - d->footer = footer; - if (footer) { - footer->setParentItem(this); - QQuickItemPrivate *p = QQuickItemPrivate::get(footer); - p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); - if (qFuzzyIsNull(footer->z())) - footer->setZ(1); - if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer)) - toolBar->setPosition(QQuickToolBar::Footer); - else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer)) - tabBar->setPosition(QQuickTabBar::Footer); - if (isComponentComplete()) - d->relayout(); - } - emit footerChanged(); + if (d->footer == footer) + return; + + if (d->footer) + QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->footer = footer; + if (footer) { + footer->setParentItem(this); + QQuickItemPrivate *p = QQuickItemPrivate::get(footer); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(footer->z())) + footer->setZ(1); + if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer)) + toolBar->setPosition(QQuickToolBar::Footer); + else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer)) + tabBar->setPosition(QQuickTabBar::Footer); + if (isComponentComplete()) + d->relayout(); } + emit footerChanged(); } /*! diff --git a/src/templates/qquickpageindicator.cpp b/src/templates/qquickpageindicator.cpp index ea50371d..1035085e 100644 --- a/src/templates/qquickpageindicator.cpp +++ b/src/templates/qquickpageindicator.cpp @@ -165,10 +165,11 @@ int QQuickPageIndicator::count() const void QQuickPageIndicator::setCount(int count) { Q_D(QQuickPageIndicator); - if (d->count != count) { - d->count = count; - emit countChanged(); - } + if (d->count == count) + return; + + d->count = count; + emit countChanged(); } /*! @@ -185,10 +186,11 @@ int QQuickPageIndicator::currentIndex() const void QQuickPageIndicator::setCurrentIndex(int index) { Q_D(QQuickPageIndicator); - if (d->currentIndex != index) { - d->currentIndex = index; - emit currentIndexChanged(); - } + if (d->currentIndex == index) + return; + + d->currentIndex = index; + emit currentIndexChanged(); } /*! @@ -209,11 +211,12 @@ bool QQuickPageIndicator::isInteractive() const void QQuickPageIndicator::setInteractive(bool interactive) { Q_D(QQuickPageIndicator); - if (d->interactive != interactive) { - d->interactive = interactive; - setAcceptedMouseButtons(interactive ? Qt::LeftButton : Qt::NoButton); - emit interactiveChanged(); - } + if (d->interactive == interactive) + return; + + d->interactive = interactive; + setAcceptedMouseButtons(interactive ? Qt::LeftButton : Qt::NoButton); + emit interactiveChanged(); } /*! @@ -236,10 +239,11 @@ QQmlComponent *QQuickPageIndicator::delegate() const void QQuickPageIndicator::setDelegate(QQmlComponent *delegate) { Q_D(QQuickPageIndicator); - if (d->delegate != delegate) { - d->delegate = delegate; - emit delegateChanged(); - } + if (d->delegate == delegate) + return; + + d->delegate = delegate; + emit delegateChanged(); } void QQuickPageIndicator::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) diff --git a/src/templates/qquickpane.cpp b/src/templates/qquickpane.cpp index a9428002..e8eeccdb 100644 --- a/src/templates/qquickpane.cpp +++ b/src/templates/qquickpane.cpp @@ -101,10 +101,11 @@ qreal QQuickPane::contentWidth() const void QQuickPane::setContentWidth(qreal width) { Q_D(QQuickPane); - if (d->contentWidth != width) { - d->contentWidth = width; - emit contentWidthChanged(); - } + if (qFuzzyCompare(d->contentWidth, width)) + return; + + d->contentWidth = width; + emit contentWidthChanged(); } /*! @@ -125,10 +126,11 @@ qreal QQuickPane::contentHeight() const void QQuickPane::setContentHeight(qreal height) { Q_D(QQuickPane); - if (d->contentHeight != height) { - d->contentHeight = height; - emit contentHeightChanged(); - } + if (qFuzzyCompare(d->contentHeight, height)) + return; + + d->contentHeight = height; + emit contentHeightChanged(); } /*! diff --git a/src/templates/qquickpopup.cpp b/src/templates/qquickpopup.cpp index 0fed8109..8214df8a 100644 --- a/src/templates/qquickpopup.cpp +++ b/src/templates/qquickpopup.cpp @@ -430,11 +430,12 @@ qreal QQuickPopupPositioner::x() const void QQuickPopupPositioner::setX(qreal x) { - if (m_x != x) { - m_x = x; - if (m_popup->popupItem->isVisible()) - repositionPopup(); - } + if (m_x == x) + return; + + m_x = x; + if (m_popup->popupItem->isVisible()) + repositionPopup(); } qreal QQuickPopupPositioner::y() const @@ -444,11 +445,12 @@ qreal QQuickPopupPositioner::y() const void QQuickPopupPositioner::setY(qreal y) { - if (m_y != y) { - m_y = y; - if (m_popup->popupItem->isVisible()) - repositionPopup(); - } + if (m_y == y) + return; + + m_y = y; + if (m_popup->popupItem->isVisible()) + repositionPopup(); } QQuickItem *QQuickPopupPositioner::parentItem() const @@ -851,10 +853,11 @@ qreal QQuickPopup::contentWidth() const void QQuickPopup::setContentWidth(qreal width) { Q_D(QQuickPopup); - if (d->contentWidth != width) { - d->contentWidth = width; - emit contentWidthChanged(); - } + if (qFuzzyCompare(d->contentWidth, width)) + return; + + d->contentWidth = width; + emit contentWidthChanged(); } /*! @@ -875,10 +878,11 @@ qreal QQuickPopup::contentHeight() const void QQuickPopup::setContentHeight(qreal height) { Q_D(QQuickPopup); - if (d->contentHeight != height) { - d->contentHeight = height; - emit contentHeightChanged(); - } + if (qFuzzyCompare(d->contentHeight, height)) + return; + + d->contentHeight = height; + emit contentHeightChanged(); } /*! @@ -1223,12 +1227,13 @@ QQuickItem *QQuickPopup::parentItem() const void QQuickPopup::setParentItem(QQuickItem *parent) { Q_D(QQuickPopup); - if (d->parentItem != parent) { - d->parentItem = parent; - if (d->positioner.parentItem()) - d->positioner.setParentItem(parent); - emit parentChanged(); - } + if (d->parentItem == parent) + return; + + d->parentItem = parent; + if (d->positioner.parentItem()) + d->positioner.setParentItem(parent); + emit parentChanged(); } /*! @@ -1249,18 +1254,19 @@ QQuickItem *QQuickPopup::background() const void QQuickPopup::setBackground(QQuickItem *background) { Q_D(QQuickPopup); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setParentItem(d->popupItem); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setParentItem(d->popupItem); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } /*! @@ -1282,17 +1288,18 @@ QQuickItem *QQuickPopup::contentItem() const void QQuickPopup::setContentItem(QQuickItem *item) { Q_D(QQuickPopup); - if (d->contentItem != item) { - contentItemChange(item, d->contentItem); - delete d->contentItem; - d->contentItem = item; - if (item) { - item->setParentItem(d->popupItem); - if (isComponentComplete()) - d->resizeContent(); - } - emit contentItemChanged(); + if (d->contentItem == item) + return; + + contentItemChange(item, d->contentItem); + delete d->contentItem; + d->contentItem = item; + if (item) { + item->setParentItem(d->popupItem); + if (isComponentComplete()) + d->resizeContent(); } + emit contentItemChanged(); } /*! diff --git a/src/templates/qquickprogressbar.cpp b/src/templates/qquickprogressbar.cpp index 62ad15f8..8596128f 100644 --- a/src/templates/qquickprogressbar.cpp +++ b/src/templates/qquickprogressbar.cpp @@ -102,14 +102,15 @@ qreal QQuickProgressBar::from() const void QQuickProgressBar::setFrom(qreal from) { Q_D(QQuickProgressBar); - if (!qFuzzyCompare(d->from, from)) { - d->from = from; - emit fromChanged(); - emit positionChanged(); - emit visualPositionChanged(); - if (isComponentComplete()) - setValue(d->value); - } + if (qFuzzyCompare(d->from, from)) + return; + + d->from = from; + emit fromChanged(); + emit positionChanged(); + emit visualPositionChanged(); + if (isComponentComplete()) + setValue(d->value); } /*! @@ -128,14 +129,15 @@ qreal QQuickProgressBar::to() const void QQuickProgressBar::setTo(qreal to) { Q_D(QQuickProgressBar); - if (!qFuzzyCompare(d->to, to)) { - d->to = to; - emit toChanged(); - emit positionChanged(); - emit visualPositionChanged(); - if (isComponentComplete()) - setValue(d->value); - } + if (qFuzzyCompare(d->to, to)) + return; + + d->to = to; + emit toChanged(); + emit positionChanged(); + emit visualPositionChanged(); + if (isComponentComplete()) + setValue(d->value); } /*! @@ -157,12 +159,13 @@ void QQuickProgressBar::setValue(qreal value) if (isComponentComplete()) value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); - if (!qFuzzyCompare(d->value, value)) { - d->value = value; - emit valueChanged(); - emit positionChanged(); - emit visualPositionChanged(); - } + if (qFuzzyCompare(d->value, value)) + return; + + d->value = value; + emit valueChanged(); + emit positionChanged(); + emit visualPositionChanged(); } /*! @@ -219,10 +222,11 @@ bool QQuickProgressBar::isIndeterminate() const void QQuickProgressBar::setIndeterminate(bool indeterminate) { Q_D(QQuickProgressBar); - if (d->indeterminate != indeterminate) { - d->indeterminate = indeterminate; - emit indeterminateChanged(); - } + if (d->indeterminate == indeterminate) + return; + + d->indeterminate = indeterminate; + emit indeterminateChanged(); } /*! @@ -241,13 +245,14 @@ QQuickItem *QQuickProgressBar::indicator() const void QQuickProgressBar::setIndicator(QQuickItem *indicator) { Q_D(QQuickProgressBar); - if (d->indicator != indicator) { - delete d->indicator; - d->indicator = indicator; - if (indicator && !indicator->parentItem()) - indicator->setParentItem(this); - emit indicatorChanged(); - } + if (d->indicator == indicator) + return; + + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); } void QQuickProgressBar::mirrorChange() diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 11069757..1ca4fbed 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -224,35 +224,36 @@ QQuickItem *QQuickRangeSliderNode::handle() const void QQuickRangeSliderNode::setHandle(QQuickItem *handle) { Q_D(QQuickRangeSliderNode); - if (d->handle != handle) { - delete d->handle; - d->handle = handle; - if (handle) { - if (!handle->parentItem()) - handle->setParentItem(d->slider); - - QQuickItem *firstHandle = d->slider->first()->handle(); - QQuickItem *secondHandle = d->slider->second()->handle(); - if (firstHandle && secondHandle) { - // The order of property assignments in QML is undefined, - // but we need the first handle to be before the second due - // to focus order constraints, so check for that here. - const QList<QQuickItem *> childItems = d->slider->childItems(); - const int firstIndex = childItems.indexOf(firstHandle); - const int secondIndex = childItems.indexOf(secondHandle); - if (firstIndex != -1 && secondIndex != -1 && firstIndex > secondIndex) { - firstHandle->stackBefore(secondHandle); - // Ensure we have some way of knowing which handle is above - // the other when it comes to mouse presses, and also that - // they are rendered in the correct order. - secondHandle->setZ(secondHandle->z() + 1); - } - } + if (d->handle == handle) + return; - handle->setActiveFocusOnTab(true); + delete d->handle; + d->handle = handle; + if (handle) { + if (!handle->parentItem()) + handle->setParentItem(d->slider); + + QQuickItem *firstHandle = d->slider->first()->handle(); + QQuickItem *secondHandle = d->slider->second()->handle(); + if (firstHandle && secondHandle) { + // The order of property assignments in QML is undefined, + // but we need the first handle to be before the second due + // to focus order constraints, so check for that here. + const QList<QQuickItem *> childItems = d->slider->childItems(); + const int firstIndex = childItems.indexOf(firstHandle); + const int secondIndex = childItems.indexOf(secondHandle); + if (firstIndex != -1 && secondIndex != -1 && firstIndex > secondIndex) { + firstHandle->stackBefore(secondHandle); + // Ensure we have some way of knowing which handle is above + // the other when it comes to mouse presses, and also that + // they are rendered in the correct order. + secondHandle->setZ(secondHandle->z() + 1); + } } - emit handleChanged(); + + handle->setActiveFocusOnTab(true); } + emit handleChanged(); } bool QQuickRangeSliderNode::isPressed() const @@ -264,11 +265,12 @@ bool QQuickRangeSliderNode::isPressed() const void QQuickRangeSliderNode::setPressed(bool pressed) { Q_D(QQuickRangeSliderNode); - if (d->pressed != pressed) { - d->pressed = pressed; - d->slider->setAccessibleProperty("pressed", pressed || d->slider->second()->isPressed()); - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + d->slider->setAccessibleProperty("pressed", pressed || d->slider->second()->isPressed()); + emit pressedChanged(); } void QQuickRangeSliderNode::increase() @@ -552,10 +554,11 @@ qreal QQuickRangeSlider::stepSize() const void QQuickRangeSlider::setStepSize(qreal step) { Q_D(QQuickRangeSlider); - if (!qFuzzyCompare(d->stepSize, step)) { - d->stepSize = step; - emit stepSizeChanged(); - } + if (qFuzzyCompare(d->stepSize, step)) + return; + + d->stepSize = step; + emit stepSizeChanged(); } /*! @@ -579,10 +582,11 @@ QQuickRangeSlider::SnapMode QQuickRangeSlider::snapMode() const void QQuickRangeSlider::setSnapMode(SnapMode mode) { Q_D(QQuickRangeSlider); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } + if (d->snapMode == mode) + return; + + d->snapMode = mode; + emit snapModeChanged(); } /*! @@ -603,10 +607,11 @@ Qt::Orientation QQuickRangeSlider::orientation() const void QQuickRangeSlider::setOrientation(Qt::Orientation orientation) { Q_D(QQuickRangeSlider); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -625,13 +630,14 @@ QQuickItem *QQuickRangeSlider::track() const void QQuickRangeSlider::setTrack(QQuickItem *track) { Q_D(QQuickRangeSlider); - if (d->track != track) { - delete d->track; - d->track = track; - if (track && !track->parentItem()) - track->setParentItem(this); - emit trackChanged(); - } + if (d->track == track) + return; + + delete d->track; + d->track = track; + if (track && !track->parentItem()) + track->setParentItem(this); + emit trackChanged(); } /*! diff --git a/src/templates/qquickscrollbar.cpp b/src/templates/qquickscrollbar.cpp index ad7b0a6d..a99a409e 100644 --- a/src/templates/qquickscrollbar.cpp +++ b/src/templates/qquickscrollbar.cpp @@ -135,10 +135,11 @@ qreal QQuickScrollBar::size() const void QQuickScrollBar::setSize(qreal size) { Q_D(QQuickScrollBar); - if (!qFuzzyCompare(d->size, size)) { - d->size = size; - emit sizeChanged(); - } + if (qFuzzyCompare(d->size, size)) + return; + + d->size = size; + emit sizeChanged(); } /*! @@ -157,10 +158,11 @@ qreal QQuickScrollBar::position() const void QQuickScrollBar::setPosition(qreal position) { Q_D(QQuickScrollBar); - if (!qFuzzyCompare(d->position, position)) { - d->position = position; - emit positionChanged(); - } + if (qFuzzyCompare(d->position, position)) + return; + + d->position = position; + emit positionChanged(); } /*! @@ -178,10 +180,11 @@ bool QQuickScrollBar::isActive() const void QQuickScrollBar::setActive(bool active) { Q_D(QQuickScrollBar); - if (d->active != active) { - d->active = active; - emit activeChanged(); - } + if (d->active == active) + return; + + d->active = active; + emit activeChanged(); } /*! @@ -198,12 +201,13 @@ bool QQuickScrollBar::isPressed() const void QQuickScrollBar::setPressed(bool pressed) { Q_D(QQuickScrollBar); - if (d->pressed != pressed) { - d->pressed = pressed; - setAccessibleProperty("pressed", pressed); - setActive(d->pressed || d->moving); - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + setAccessibleProperty("pressed", pressed); + setActive(d->pressed || d->moving); + emit pressedChanged(); } /*! @@ -224,10 +228,11 @@ Qt::Orientation QQuickScrollBar::orientation() const void QQuickScrollBar::setOrientation(Qt::Orientation orientation) { Q_D(QQuickScrollBar); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -246,13 +251,14 @@ QQuickItem *QQuickScrollBar::handle() const void QQuickScrollBar::setHandle(QQuickItem *handle) { Q_D(QQuickScrollBar); - if (d->handle != handle) { - delete d->handle; - d->handle = handle; - if (handle && !handle->parentItem()) - handle->setParentItem(this); - emit handleChanged(); - } + if (d->handle == handle) + return; + + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); } void QQuickScrollBar::mousePressEvent(QMouseEvent *event) @@ -436,40 +442,41 @@ QQuickScrollBar *QQuickScrollBarAttached::horizontal() const void QQuickScrollBarAttached::setHorizontal(QQuickScrollBar *horizontal) { Q_D(QQuickScrollBarAttached); - if (d->horizontal != horizontal) { - if (d->horizontal) { - QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); - } - - d->horizontal = horizontal; - - if (horizontal) { - if (!horizontal->parentItem()) - horizontal->setParentItem(d->flickable); - horizontal->setOrientation(Qt::Horizontal); - - QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); - connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); - - d->layoutHorizontal(); - horizontal->setSize(area->property("widthRatio").toReal()); - horizontal->setPosition(area->property("xPosition").toReal()); - } - emit horizontalChanged(); + if (d->horizontal == horizontal) + return; + + if (d->horizontal) { + QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + d->layoutHorizontal(); + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); } /*! @@ -493,40 +500,41 @@ QQuickScrollBar *QQuickScrollBarAttached::vertical() const void QQuickScrollBarAttached::setVertical(QQuickScrollBar *vertical) { Q_D(QQuickScrollBarAttached); - if (d->vertical != vertical) { - if (d->vertical) { - QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); - } - - d->vertical = vertical; - - if (vertical) { - if (!vertical->parentItem()) - vertical->setParentItem(d->flickable); - vertical->setOrientation(Qt::Vertical); - - QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); - connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); - - d->layoutVertical(); - vertical->setSize(area->property("heightRatio").toReal()); - vertical->setPosition(area->property("yPosition").toReal()); - } - emit verticalChanged(); + if (d->vertical == vertical) + return; + + if (d->vertical) { + QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + d->layoutVertical(); + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); } + emit verticalChanged(); } QT_END_NAMESPACE diff --git a/src/templates/qquickscrollindicator.cpp b/src/templates/qquickscrollindicator.cpp index 5e210f09..2aba3c89 100644 --- a/src/templates/qquickscrollindicator.cpp +++ b/src/templates/qquickscrollindicator.cpp @@ -124,10 +124,11 @@ qreal QQuickScrollIndicator::size() const void QQuickScrollIndicator::setSize(qreal size) { Q_D(QQuickScrollIndicator); - if (!qFuzzyCompare(d->size, size)) { - d->size = size; - emit sizeChanged(); - } + if (qFuzzyCompare(d->size, size)) + return; + + d->size = size; + emit sizeChanged(); } /*! @@ -146,10 +147,11 @@ qreal QQuickScrollIndicator::position() const void QQuickScrollIndicator::setPosition(qreal position) { Q_D(QQuickScrollIndicator); - if (!qFuzzyCompare(d->position, position)) { - d->position = position; - emit positionChanged(); - } + if (qFuzzyCompare(d->position, position)) + return; + + d->position = position; + emit positionChanged(); } /*! @@ -167,10 +169,11 @@ bool QQuickScrollIndicator::isActive() const void QQuickScrollIndicator::setActive(bool active) { Q_D(QQuickScrollIndicator); - if (d->active != active) { - d->active = active; - emit activeChanged(); - } + if (d->active == active) + return; + + d->active = active; + emit activeChanged(); } /*! @@ -191,10 +194,11 @@ Qt::Orientation QQuickScrollIndicator::orientation() const void QQuickScrollIndicator::setOrientation(Qt::Orientation orientation) { Q_D(QQuickScrollIndicator); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -213,13 +217,14 @@ QQuickItem *QQuickScrollIndicator::indicator() const void QQuickScrollIndicator::setIndicator(QQuickItem *indicator) { Q_D(QQuickScrollIndicator); - if (d->indicator != indicator) { - delete d->indicator; - d->indicator = indicator; - if (indicator && !indicator->parentItem()) - indicator->setParentItem(this); - emit indicatorChanged(); - } + if (d->indicator == indicator) + return; + + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); } class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener @@ -318,38 +323,39 @@ QQuickScrollIndicator *QQuickScrollIndicatorAttached::horizontal() const void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizontal) { Q_D(QQuickScrollIndicatorAttached); - if (d->horizontal != horizontal) { - if (d->horizontal) { - QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); - } - - d->horizontal = horizontal; - - if (horizontal) { - if (!horizontal->parentItem()) - horizontal->setParentItem(d->flickable); - horizontal->setOrientation(Qt::Horizontal); - - QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); - connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); - - d->layoutHorizontal(); - horizontal->setSize(area->property("widthRatio").toReal()); - horizontal->setPosition(area->property("xPosition").toReal()); - } - emit horizontalChanged(); + if (d->horizontal == horizontal) + return; + + if (d->horizontal) { + QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QQuickItemPrivate::get(horizontal)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + d->layoutHorizontal(); + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); } /*! @@ -373,38 +379,39 @@ QQuickScrollIndicator *QQuickScrollIndicatorAttached::vertical() const void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical) { Q_D(QQuickScrollIndicatorAttached); - if (d->vertical != vertical) { - if (d->vertical) { - QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); - disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); - } - - d->vertical = vertical; - - if (vertical) { - if (!vertical->parentItem()) - vertical->setParentItem(d->flickable); - vertical->setOrientation(Qt::Vertical); - - QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); - QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); - - // TODO: export QQuickFlickableVisibleArea - QObject *area = d->flickable->property("visibleArea").value<QObject *>(); - connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); - connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); - - d->layoutVertical(); - vertical->setSize(area->property("heightRatio").toReal()); - vertical->setPosition(area->property("yPosition").toReal()); - } - emit verticalChanged(); + if (d->vertical == vertical) + return; + + if (d->vertical) { + QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QQuickItemPrivate::get(vertical)->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + d->layoutVertical(); + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); } + emit verticalChanged(); } #ifndef QT_NO_ACCESSIBILITY diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp index a4165c3f..261c1577 100644 --- a/src/templates/qquickslider.cpp +++ b/src/templates/qquickslider.cpp @@ -147,11 +147,12 @@ void QQuickSliderPrivate::setPosition(qreal pos) { Q_Q(QQuickSlider); pos = qBound<qreal>(0.0, pos, 1.0); - if (!qFuzzyCompare(position, pos)) { - position = pos; - emit q->positionChanged(); - emit q->visualPositionChanged(); - } + if (qFuzzyCompare(position, pos)) + return; + + position = pos; + emit q->positionChanged(); + emit q->visualPositionChanged(); } void QQuickSliderPrivate::updatePosition() @@ -185,13 +186,14 @@ qreal QQuickSlider::from() const void QQuickSlider::setFrom(qreal from) { Q_D(QQuickSlider); - if (!qFuzzyCompare(d->from, from)) { - d->from = from; - emit fromChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } + if (qFuzzyCompare(d->from, from)) + return; + + d->from = from; + emit fromChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); } } @@ -211,13 +213,14 @@ qreal QQuickSlider::to() const void QQuickSlider::setTo(qreal to) { Q_D(QQuickSlider); - if (!qFuzzyCompare(d->to, to)) { - d->to = to; - emit toChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } + if (qFuzzyCompare(d->to, to)) + return; + + d->to = to; + emit toChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); } } @@ -244,11 +247,12 @@ void QQuickSlider::setValue(qreal value) if (isComponentComplete()) value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); - if (!qFuzzyCompare(d->value, value)) { - d->value = value; - d->updatePosition(); - emit valueChanged(); - } + if (qFuzzyCompare(d->value, value)) + return; + + d->value = value; + d->updatePosition(); + emit valueChanged(); } /*! @@ -307,10 +311,11 @@ qreal QQuickSlider::stepSize() const void QQuickSlider::setStepSize(qreal step) { Q_D(QQuickSlider); - if (!qFuzzyCompare(d->stepSize, step)) { - d->stepSize = step; - emit stepSizeChanged(); - } + if (qFuzzyCompare(d->stepSize, step)) + return; + + d->stepSize = step; + emit stepSizeChanged(); } /*! @@ -334,10 +339,11 @@ QQuickSlider::SnapMode QQuickSlider::snapMode() const void QQuickSlider::setSnapMode(SnapMode mode) { Q_D(QQuickSlider); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } + if (d->snapMode == mode) + return; + + d->snapMode = mode; + emit snapModeChanged(); } /*! @@ -354,11 +360,12 @@ bool QQuickSlider::isPressed() const void QQuickSlider::setPressed(bool pressed) { Q_D(QQuickSlider); - if (d->pressed != pressed) { - d->pressed = pressed; - setAccessibleProperty("pressed", pressed); - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + setAccessibleProperty("pressed", pressed); + emit pressedChanged(); } /*! @@ -379,10 +386,11 @@ Qt::Orientation QQuickSlider::orientation() const void QQuickSlider::setOrientation(Qt::Orientation orientation) { Q_D(QQuickSlider); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -401,13 +409,14 @@ QQuickItem *QQuickSlider::handle() const void QQuickSlider::setHandle(QQuickItem *handle) { Q_D(QQuickSlider); - if (d->handle != handle) { - delete d->handle; - d->handle = handle; - if (handle && !handle->parentItem()) - handle->setParentItem(this); - emit handleChanged(); - } + if (d->handle == handle) + return; + + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); } /*! @@ -426,13 +435,14 @@ QQuickItem *QQuickSlider::track() const void QQuickSlider::setTrack(QQuickItem *track) { Q_D(QQuickSlider); - if (d->track != track) { - delete d->track; - d->track = track; - if (track && !track->parentItem()) - track->setParentItem(this); - emit trackChanged(); - } + if (d->track == track) + return; + + delete d->track; + d->track = track; + if (track && !track->parentItem()) + track->setParentItem(this); + emit trackChanged(); } /*! diff --git a/src/templates/qquickspinbox.cpp b/src/templates/qquickspinbox.cpp index 6046d2e4..240b5a9b 100644 --- a/src/templates/qquickspinbox.cpp +++ b/src/templates/qquickspinbox.cpp @@ -260,12 +260,13 @@ int QQuickSpinBox::from() const void QQuickSpinBox::setFrom(int from) { Q_D(QQuickSpinBox); - if (d->from != from) { - d->from = from; - emit fromChanged(); - if (isComponentComplete()) - setValue(d->value); - } + if (d->from == from) + return; + + d->from = from; + emit fromChanged(); + if (isComponentComplete()) + setValue(d->value); } /*! @@ -284,12 +285,13 @@ int QQuickSpinBox::to() const void QQuickSpinBox::setTo(int to) { Q_D(QQuickSpinBox); - if (d->to != to) { - d->to = to; - emit toChanged(); - if (isComponentComplete()) - setValue(d->value); - } + if (d->to == to) + return; + + d->to = to; + emit toChanged(); + if (isComponentComplete()) + setValue(d->value); } /*! @@ -309,10 +311,11 @@ void QQuickSpinBox::setValue(int value) if (isComponentComplete()) value = d->boundValue(value); - if (d->value != value) { - d->value = value; - emit valueChanged(); - } + if (d->value == value) + return; + + d->value = value; + emit valueChanged(); } /*! @@ -331,10 +334,11 @@ int QQuickSpinBox::stepSize() const void QQuickSpinBox::setStepSize(int step) { Q_D(QQuickSpinBox); - if (d->stepSize != step) { - d->stepSize = step; - emit stepSizeChanged(); - } + if (d->stepSize == step) + return; + + d->stepSize = step; + emit stepSizeChanged(); } /*! @@ -356,10 +360,11 @@ QValidator *QQuickSpinBox::validator() const void QQuickSpinBox::setValidator(QValidator *validator) { Q_D(QQuickSpinBox); - if (d->validator != validator) { - d->validator = validator; - emit validatorChanged(); - } + if (d->validator == validator) + return; + + d->validator = validator; + emit validatorChanged(); } /*! @@ -641,10 +646,11 @@ bool QQuickSpinButton::isPressed() const void QQuickSpinButton::setPressed(bool pressed) { Q_D(QQuickSpinButton); - if (d->pressed != pressed) { - d->pressed = pressed; - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + emit pressedChanged(); } QQuickItem *QQuickSpinButton::indicator() const @@ -656,16 +662,17 @@ QQuickItem *QQuickSpinButton::indicator() const void QQuickSpinButton::setIndicator(QQuickItem *indicator) { Q_D(QQuickSpinButton); - if (d->indicator != indicator) { - delete d->indicator; - d->indicator = indicator; - if (indicator) { - if (!indicator->parentItem()) - indicator->setParentItem(static_cast<QQuickItem *>(parent())); - indicator->setAcceptedMouseButtons(Qt::LeftButton); - } - emit indicatorChanged(); + if (d->indicator == indicator) + return; + + delete d->indicator; + d->indicator = indicator; + if (indicator) { + if (!indicator->parentItem()) + indicator->setParentItem(static_cast<QQuickItem *>(parent())); + indicator->setAcceptedMouseButtons(Qt::LeftButton); } + emit indicatorChanged(); } QT_END_NAMESPACE diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp index e60e2dfd..8b48e687 100644 --- a/src/templates/qquickstackview.cpp +++ b/src/templates/qquickstackview.cpp @@ -711,10 +711,11 @@ void QQuickStackView::setPopEnter(QQuickTransition *enter) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->removeDisplacedTransition != enter) { - d->transitioner->removeDisplacedTransition = enter; - emit popEnterChanged(); - } + if (d->transitioner->removeDisplacedTransition == enter) + return; + + d->transitioner->removeDisplacedTransition = enter; + emit popEnterChanged(); } /*! @@ -737,10 +738,11 @@ void QQuickStackView::setPopExit(QQuickTransition *exit) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->removeTransition != exit) { - d->transitioner->removeTransition = exit; - emit popExitChanged(); - } + if (d->transitioner->removeTransition == exit) + return; + + d->transitioner->removeTransition = exit; + emit popExitChanged(); } /*! @@ -763,10 +765,11 @@ void QQuickStackView::setPushEnter(QQuickTransition *enter) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->addTransition != enter) { - d->transitioner->addTransition = enter; - emit pushEnterChanged(); - } + if (d->transitioner->addTransition == enter) + return; + + d->transitioner->addTransition = enter; + emit pushEnterChanged(); } /*! @@ -789,10 +792,11 @@ void QQuickStackView::setPushExit(QQuickTransition *exit) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->addDisplacedTransition != exit) { - d->transitioner->addDisplacedTransition = exit; - emit pushExitChanged(); - } + if (d->transitioner->addDisplacedTransition == exit) + return; + + d->transitioner->addDisplacedTransition = exit; + emit pushExitChanged(); } /*! @@ -815,10 +819,11 @@ void QQuickStackView::setReplaceEnter(QQuickTransition *enter) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->moveTransition != enter) { - d->transitioner->moveTransition = enter; - emit replaceEnterChanged(); - } + if (d->transitioner->moveTransition == enter) + return; + + d->transitioner->moveTransition = enter; + emit replaceEnterChanged(); } /*! @@ -841,10 +846,11 @@ void QQuickStackView::setReplaceExit(QQuickTransition *exit) { Q_D(QQuickStackView); d->ensureTransitioner(); - if (d->transitioner->moveDisplacedTransition != exit) { - d->transitioner->moveDisplacedTransition = exit; - emit replaceExitChanged(); - } + if (d->transitioner->moveDisplacedTransition == exit) + return; + + d->transitioner->moveDisplacedTransition = exit; + emit replaceExitChanged(); } void QQuickStackView::componentComplete() diff --git a/src/templates/qquickstackview_p.cpp b/src/templates/qquickstackview_p.cpp index 5d967a0e..63cc1800 100644 --- a/src/templates/qquickstackview_p.cpp +++ b/src/templates/qquickstackview_p.cpp @@ -187,32 +187,35 @@ void QQuickStackElement::initialize() void QQuickStackElement::setIndex(int value) { - if (index != value) { - index = value; - QQuickStackAttached *attached = attachedStackObject(this); - if (attached) - emit attached->indexChanged(); - } + if (index == value) + return; + + index = value; + QQuickStackAttached *attached = attachedStackObject(this); + if (attached) + emit attached->indexChanged(); } void QQuickStackElement::setView(QQuickStackView *value) { - if (view != value) { - view = value; - QQuickStackAttached *attached = attachedStackObject(this); - if (attached) - emit attached->viewChanged(); - } + if (view == value) + return; + + view = value; + QQuickStackAttached *attached = attachedStackObject(this); + if (attached) + emit attached->viewChanged(); } void QQuickStackElement::setStatus(QQuickStackView::Status value) { - if (status != value) { - status = value; - QQuickStackAttached *attached = attachedStackObject(this); - if (attached) - emit attached->statusChanged(); - } + if (status == value) + return; + + status = value; + QQuickStackAttached *attached = attachedStackObject(this); + if (attached) + emit attached->statusChanged(); } void QQuickStackElement::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget) @@ -251,12 +254,13 @@ QQuickStackViewPrivate::QQuickStackViewPrivate() : busy(false), currentItem(null void QQuickStackViewPrivate::setCurrentItem(QQuickItem *item) { Q_Q(QQuickStackView); - if (currentItem != item) { - currentItem = item; - if (item) - item->setVisible(true); - emit q->currentItemChanged(); - } + if (currentItem == item) + return; + + currentItem = item; + if (item) + item->setVisible(true); + emit q->currentItemChanged(); } static bool initProperties(QQuickStackElement *element, const QV4::Value &props, QQmlV4Function *args) @@ -528,11 +532,12 @@ void QQuickStackViewPrivate::viewItemTransitionFinished(QQuickItemViewTransition void QQuickStackViewPrivate::setBusy(bool b) { Q_Q(QQuickStackView); - if (busy != b) { - busy = b; - q->setFiltersChildMouseEvents(busy); - emit q->busyChanged(); - } + if (busy == b) + return; + + busy = b; + q->setFiltersChildMouseEvents(busy); + emit q->busyChanged(); } QT_END_NAMESPACE diff --git a/src/templates/qquickswipeview.cpp b/src/templates/qquickswipeview.cpp index 41091930..3fb27b31 100644 --- a/src/templates/qquickswipeview.cpp +++ b/src/templates/qquickswipeview.cpp @@ -241,20 +241,22 @@ void QQuickSwipeViewAttachedPrivate::setView(QQuickSwipeView *view) void QQuickSwipeViewAttachedPrivate::setIsCurrent(bool current) { - if (current != isCurrent) { - isCurrent = current; - Q_Q(QQuickSwipeViewAttached); - emit q->isCurrentItemChanged(); - } + if (current == isCurrent) + return; + + isCurrent = current; + Q_Q(QQuickSwipeViewAttached); + emit q->isCurrentItemChanged(); } void QQuickSwipeViewAttachedPrivate::setIndex(int i) { - if (i != index) { - index = i; - Q_Q(QQuickSwipeViewAttached); - emit q->indexChanged(); - } + if (i == index) + return; + + index = i; + Q_Q(QQuickSwipeViewAttached); + emit q->indexChanged(); } void QQuickSwipeViewAttachedPrivate::updateView(QQuickItem *parent) diff --git a/src/templates/qquickswitch.cpp b/src/templates/qquickswitch.cpp index 9acbc0f8..79d9735c 100644 --- a/src/templates/qquickswitch.cpp +++ b/src/templates/qquickswitch.cpp @@ -188,11 +188,12 @@ void QQuickSwitch::setPosition(qreal position) { Q_D(QQuickSwitch); position = qBound<qreal>(0.0, position, 1.0); - if (d->position != position) { - d->position = position; - emit positionChanged(); - emit visualPositionChanged(); - } + if (qFuzzyCompare(d->position, position)) + return; + + d->position = position; + emit positionChanged(); + emit visualPositionChanged(); } /*! diff --git a/src/templates/qquicktextarea.cpp b/src/templates/qquicktextarea.cpp index e83f8bf1..85e1a9ec 100644 --- a/src/templates/qquicktextarea.cpp +++ b/src/templates/qquicktextarea.cpp @@ -249,18 +249,19 @@ QQuickItem *QQuickTextArea::background() const void QQuickTextArea::setBackground(QQuickItem *background) { Q_D(QQuickTextArea); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } /*! @@ -277,14 +278,15 @@ QString QQuickTextArea::placeholderText() const void QQuickTextArea::setPlaceholderText(const QString &text) { Q_D(QQuickTextArea); - if (d->placeholder != text) { - d->placeholder = text; + if (d->placeholder == text) + return; + + d->placeholder = text; #ifndef QT_NO_ACCESSIBILITY - if (d->accessibleAttached) - d->accessibleAttached->setDescription(text); + if (d->accessibleAttached) + d->accessibleAttached->setDescription(text); #endif - emit placeholderTextChanged(); - } + emit placeholderTextChanged(); } /*! @@ -315,10 +317,11 @@ Qt::FocusReason QQuickTextArea::focusReason() const void QQuickTextArea::setFocusReason(Qt::FocusReason reason) { Q_D(QQuickTextArea); - if (d->focusReason != reason) { - d->focusReason = reason; - emit focusReasonChanged(); - } + if (d->focusReason == reason) + return; + + d->focusReason = reason; + emit focusReasonChanged(); } void QQuickTextArea::classBegin() diff --git a/src/templates/qquicktextfield.cpp b/src/templates/qquicktextfield.cpp index 782ff148..6efc0a66 100644 --- a/src/templates/qquicktextfield.cpp +++ b/src/templates/qquicktextfield.cpp @@ -274,18 +274,19 @@ QQuickItem *QQuickTextField::background() const void QQuickTextField::setBackground(QQuickItem *background) { Q_D(QQuickTextField); - if (d->background != background) { - delete d->background; - d->background = background; - if (background) { - background->setParentItem(this); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } - emit backgroundChanged(); + if (d->background == background) + return; + + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } + emit backgroundChanged(); } /*! @@ -302,14 +303,15 @@ QString QQuickTextField::placeholderText() const void QQuickTextField::setPlaceholderText(const QString &text) { Q_D(QQuickTextField); - if (d->placeholder != text) { - d->placeholder = text; + if (d->placeholder == text) + return; + + d->placeholder = text; #ifndef QT_NO_ACCESSIBILITY - if (d->accessibleAttached) - d->accessibleAttached->setDescription(text); + if (d->accessibleAttached) + d->accessibleAttached->setDescription(text); #endif - emit placeholderTextChanged(); - } + emit placeholderTextChanged(); } /*! @@ -340,10 +342,11 @@ Qt::FocusReason QQuickTextField::focusReason() const void QQuickTextField::setFocusReason(Qt::FocusReason reason) { Q_D(QQuickTextField); - if (d->focusReason != reason) { - d->focusReason = reason; - emit focusReasonChanged(); - } + if (d->focusReason == reason) + return; + + d->focusReason = reason; + emit focusReasonChanged(); } void QQuickTextField::classBegin() diff --git a/src/templates/qquicktumbler.cpp b/src/templates/qquicktumbler.cpp index 2735ef9f..38447f6b 100644 --- a/src/templates/qquicktumbler.cpp +++ b/src/templates/qquicktumbler.cpp @@ -213,10 +213,11 @@ QVariant QQuickTumbler::model() const void QQuickTumbler::setModel(const QVariant &model) { Q_D(QQuickTumbler); - if (model != d->model) { - d->model = model; - emit modelChanged(); - } + if (model == d->model) + return; + + d->model = model; + emit modelChanged(); } /*! @@ -274,10 +275,11 @@ QQmlComponent *QQuickTumbler::delegate() const void QQuickTumbler::setDelegate(QQmlComponent *delegate) { Q_D(QQuickTumbler); - if (delegate != d->delegate) { - d->delegate = delegate; - emit delegateChanged(); - } + if (delegate == d->delegate) + return; + + d->delegate = delegate; + emit delegateChanged(); } /*! @@ -295,11 +297,12 @@ int QQuickTumbler::visibleItemCount() const void QQuickTumbler::setVisibleItemCount(int visibleItemCount) { Q_D(QQuickTumbler); - if (visibleItemCount != d->visibleItemCount) { - d->visibleItemCount = visibleItemCount; - d->_q_updateItemHeights(); - emit visibleItemCountChanged(); - } + if (visibleItemCount == d->visibleItemCount) + return; + + d->visibleItemCount = visibleItemCount; + d->_q_updateItemHeights(); + emit visibleItemCountChanged(); } QQuickTumblerAttached *QQuickTumbler::qmlAttachedProperties(QObject *object) |