Utils: Introduce a BaseAspect::setEnabler(BoolAspect *)

A convenience method to tie the enabled state of an aspect to some
other bool aspect, to be used e.g. when settings item availability
depends on some check box.

Makes it harder to miss one of the three necessary steps.

Change-Id: I8c120bb6846aea2a503614f7c73fa57a149cab41
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-04-12 13:43:24 +02:00
parent ef108d7a06
commit 38b4536090
6 changed files with 22 additions and 25 deletions

View File

@@ -309,6 +309,17 @@ void BaseAspect::setEnabled(bool enabled)
}
}
/*!
Makes the enabled state of this aspect depend on the checked state of \a checker.
*/
void BaseAspect::setEnabler(BoolAspect *checker)
{
QTC_ASSERT(checker, return);
setEnabled(checker->value());
connect(checker, &BoolAspect::volatileValueChanged, this, &BaseAspect::setEnabled);
connect(checker, &BoolAspect::valueChanged, this, &BaseAspect::setEnabled);
}
bool BaseAspect::isReadOnly() const
{
return d->m_readOnly;