Skip to content
Snippets Groups Projects
Commit e0855a9e authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2
Browse files

settings: prepare for hiding/disabling not relevant field in settings panel

Refs #75422

Change-Id: I1056e3a041479c18f01519616d2551f4d2923edb
parent 5d61a061
No related branches found
No related tags found
No related merge requests found
...@@ -49,18 +49,24 @@ static void avoidDuplicate(QWidget* w) ...@@ -49,18 +49,24 @@ static void avoidDuplicate(QWidget* w)
/** /**
* This check for some supported widgets and bind the widgets and property * This check for some supported widgets and bind the widgets and property
*/ */
static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& roles) static void setupWidget(QWidget* w,
Account* a,
const QHash<QByteArray, int>& roles)
{ {
if (w->objectName().left(LRC_CFG_LEN) == LRC_CFG) { if (w->objectName().left(LRC_CFG_LEN) == LRC_CFG) {
const QByteArray prop = w->objectName().mid(LRC_CFG_LEN, 999).toLatin1(); const QByteArray prop = w->objectName().mid(LRC_CFG_LEN, 999).toLatin1();
if (roles.contains(prop)) { if (roles.contains(prop)) {
const int role = roles[prop]; const int role = roles[prop];
auto roleState = a->roleState(static_cast<Account::Role>(role));
if (roleState == Account::RoleState::READ_WRITE
|| roleState == Account::RoleState::READ_ONLY) {
if (qobject_cast<QLineEdit*>(w)) { if (qobject_cast<QLineEdit*>(w)) {
QLineEdit* le = qobject_cast<QLineEdit*>(w); QLineEdit* le = qobject_cast<QLineEdit*>(w);
avoidDuplicate(le); avoidDuplicate(le);
le->setText(a->roleData(role).toString()); le->setText(a->roleData(role).toString());
ConnHolder* c = new ConnHolder { ConnHolder* c = new ConnHolder {
QObject::connect(le, &QLineEdit::textChanged, [a,role](const QString& text) { QObject::connect(le, &QLineEdit::textChanged,
[a,role](const QString& text) {
if (a->roleData(role) != text) if (a->roleData(role) != text)
a->setRoleData(role, text); a->setRoleData(role, text);
}) })
...@@ -72,7 +78,9 @@ static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& ro ...@@ -72,7 +78,9 @@ static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& ro
avoidDuplicate(sb); avoidDuplicate(sb);
sb->setValue(a->roleData(role).toInt()); sb->setValue(a->roleData(role).toInt());
ConnHolder* c = new ConnHolder { ConnHolder* c = new ConnHolder {
QObject::connect(sb, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [a,role](int value) { QObject::connect(sb, static_cast<void (QSpinBox::*)
(int)>(&QSpinBox::valueChanged),
[a,role](int value) {
if (a->roleData(role).toInt() != value) if (a->roleData(role).toInt() != value)
a->setRoleData(role, value); a->setRoleData(role, value);
}) })
...@@ -85,13 +93,19 @@ static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& ro ...@@ -85,13 +93,19 @@ static void setupWidget(QWidget* w, Account* a, const QHash<QByteArray, int>& ro
avoidDuplicate(b); avoidDuplicate(b);
b->setChecked(a->roleData(role).toBool()); b->setChecked(a->roleData(role).toBool());
ConnHolder* c = new ConnHolder { ConnHolder* c = new ConnHolder {
QObject::connect(b, &QAbstractButton::toggled,[a,role](bool c) { QObject::connect(b, &QAbstractButton::toggled,
[a,role](bool c) {
if (a->roleData(role).toBool() != c) if (a->roleData(role).toBool() != c)
a->setRoleData(role, c); a->setRoleData(role, c);
}) })
}; };
b->setProperty("lrcfgConn",QVariant::fromValue(c)); b->setProperty("lrcfgConn",QVariant::fromValue(c));
} }
w->setVisible(true);
w->setEnabled(roleState == Account::RoleState::READ_WRITE);
} else {
w->setVisible(false);
}
} }
else { else {
qWarning() << "Unknown config properties" << w->objectName(); qWarning() << "Unknown config properties" << w->objectName();
...@@ -106,7 +120,9 @@ static void clearConnections(QWidget* w) ...@@ -106,7 +120,9 @@ static void clearConnections(QWidget* w)
} }
} }
static void drill(QWidget* w, Account* a, const QHash<QByteArray, int>& roles, bool clear = false) static void drill(QWidget* w, Account* a,
const QHash<QByteArray, int>& roles,
bool clear = false)
{ {
for (QObject *object : w->children()) { for (QObject *object : w->children()) {
if (!object->isWidgetType()) if (!object->isWidgetType())
...@@ -122,7 +138,9 @@ static void drill(QWidget* w, Account* a, const QHash<QByteArray, int>& roles, b ...@@ -122,7 +138,9 @@ static void drill(QWidget* w, Account* a, const QHash<QByteArray, int>& roles, b
} }
} }
AccountSerializationAdapter::AccountSerializationAdapter(Account* a, QWidget* w) : QObject(w) AccountSerializationAdapter::AccountSerializationAdapter(Account* a,
QWidget* w)
: QObject(w)
{ {
static QHash<QByteArray, int> reverse; static QHash<QByteArray, int> reverse;
if (reverse.isEmpty()) { if (reverse.isEmpty()) {
...@@ -136,6 +154,4 @@ AccountSerializationAdapter::AccountSerializationAdapter(Account* a, QWidget* w) ...@@ -136,6 +154,4 @@ AccountSerializationAdapter::AccountSerializationAdapter(Account* a, QWidget* w)
} }
AccountSerializationAdapter::~AccountSerializationAdapter() AccountSerializationAdapter::~AccountSerializationAdapter()
{ {}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment