Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 0cbee5d69170b47b79913e14c408d3dc7a0df7c7 Mon Sep 17 00:00:00 2001
- From: Jean-Yves Avenard <jyavenard@mythtv.org>
- Date: Mon, 15 Jul 2013 05:05:42 +1000
- Subject: [PATCH] Add multiple UI object dependencies.
- Operator supported are & (AND) and | (OR); priority are strictly from left to right
- ---
- mythtv/libs/libmythui/mythuitype.cpp | 99 ++++++++++++++++++++++++++++--------
- mythtv/libs/libmythui/mythuitype.h | 12 ++++-
- 2 files changed, 87 insertions(+), 24 deletions(-)
- diff --git a/mythtv/libs/libmythui/mythuitype.cpp b/mythtv/libs/libmythui/mythuitype.cpp
- index 9accc45..25246c3 100644
- --- a/mythtv/libs/libmythui/mythuitype.cpp
- +++ b/mythtv/libs/libmythui/mythuitype.cpp
- @@ -47,7 +47,6 @@ MythUIType::MythUIType(QObject *parent, const QString &name)
- m_XYSpeed = QPoint(0, 0);
- m_deferload = false;
- m_IsDependDefault = false;
- - m_ReverseDepend = false;
- m_Parent = NULL;
- @@ -1037,13 +1036,47 @@ void MythUIType::Refresh(void)
- SetRedraw();
- }
- -void MythUIType::UpdateDependState(bool isDefault)
- +void MythUIType::UpdateDependState(MythUIType *dependee, bool isDefault)
- {
- - m_IsDependDefault = m_ReverseDepend ? !isDefault : isDefault;
- + bool reverse = m_ReverseDepend[dependee];
- + bool visible = reverse ? !isDefault : isDefault;
- + for (int i = 0; i < m_dependsValue.size(); i++)
- + {
- + if (m_dependsValue[i].first != dependee)
- + continue;
- + m_dependsValue[i].second = visible;
- + break;
- + }
- +
- + visible = m_dependsValue[0].second;
- + for (int i = 1; i < m_dependsValue.size(); i++)
- + {
- + bool v = m_dependsValue[i].second;
- +
- + if (m_dependOperator[i-1] == 1)
- + {
- + // OR operator
- + visible = visible && v;
- + }
- + else
- + {
- + // AND operator
- + visible = visible || v;
- + }
- + }
- +
- + m_IsDependDefault = visible;
- SetVisible(!m_IsDependDefault);
- }
- +void MythUIType::UpdateDependState(bool isDefault)
- +{
- + MythUIType *dependee = static_cast<MythUIType*>(sender());
- +
- + UpdateDependState(dependee, isDefault);
- +}
- +
- void MythUIType::SetVisible(bool visible)
- {
- if (visible == m_Visible)
- @@ -1159,7 +1192,6 @@ void MythUIType::CopyFrom(MythUIType *base)
- }
- m_dependsMap = base->m_dependsMap;
- - m_ReverseDepend = base->m_ReverseDepend;
- SetMinArea(base->m_MinArea);
- }
- @@ -1372,34 +1404,57 @@ void MythUIType::SetDependsMap(QMap<QString, QString> dependsMap)
- m_dependsMap = dependsMap;
- }
- -void MythUIType::SetReverseDependence(bool reverse)
- +void MythUIType::SetReverseDependence(MythUIType *dependee, bool reverse)
- {
- - m_ReverseDepend = reverse;
- + m_ReverseDepend.insert(dependee, reverse);
- }
- void MythUIType::ConnectDependants(bool recurse)
- {
- -
- - QMapIterator<QString, QString> i(m_dependsMap);
- - while(i.hasNext())
- + QMapIterator<QString, QString> it(m_dependsMap);
- + while(it.hasNext())
- {
- - i.next();
- - QString dependeeName = i.value();
- - bool reverse = false;
- - if (dependeeName.startsWith('!'))
- + it.next();
- + QStringList dependees;
- + QVector<int> operators;
- + QString name = it.value();
- + QStringList tmp1 = name.split("&");
- + for (int i = 0; i < tmp1.size(); i++)
- {
- - reverse = true;
- - dependeeName.remove(0,1);
- + QStringList tmp2 = tmp1[i].split("|");
- +
- + dependees.append(tmp2[0]);
- + for (int j = 1; j < tmp2.size(); j++)
- + {
- + dependees.append(tmp2[j]);
- + operators.append(1); // 1 is OR
- + }
- + operators.append(2); // 2 is AND
- }
- - MythUIType *dependee = GetChild(dependeeName);
- - MythUIType *dependant = GetChild(i.key());
- - if (dependee && dependant)
- + MythUIType *dependant = GetChild(it.key());
- + if (dependant)
- {
- - QObject::connect(dependee, SIGNAL(DependChanged(bool)),
- - dependant, SLOT(UpdateDependState(bool)));
- - dependant->SetReverseDependence(reverse);
- - dependant->UpdateDependState(true);
- + dependant->m_dependOperator = operators;
- + foreach (QString dependeeName, dependees)
- + {
- + bool reverse = false;
- + if (dependeeName.startsWith('!'))
- + {
- + reverse = true;
- + dependeeName.remove(0,1);
- + }
- + MythUIType *dependee = GetChild(dependeeName);
- +
- + if (dependee)
- + {
- + QObject::connect(dependee, SIGNAL(DependChanged(bool)),
- + dependant, SLOT(UpdateDependState(bool)));
- + dependant->SetReverseDependence(dependee, reverse);
- + dependant->m_dependsValue.append(QPair<MythUIType *, bool>(dependee, false));
- + dependant->UpdateDependState(dependee, true);
- + }
- + }
- }
- }
- diff --git a/mythtv/libs/libmythui/mythuitype.h b/mythtv/libs/libmythui/mythuitype.h
- index 82ce763..9bbcc41 100644
- --- a/mythtv/libs/libmythui/mythuitype.h
- +++ b/mythtv/libs/libmythui/mythuitype.h
- @@ -6,6 +6,8 @@
- #include <QMap>
- #include <QHash>
- #include <QList>
- +#include <QVector>
- +#include <QPair>
- #include <QFont>
- #include <QColor>
- @@ -174,7 +176,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
- void SetVerticalZoom(float zoom);
- void SetAngle(float angle);
- void SetDependIsDefault(bool isDefault);
- - void SetReverseDependence(bool reverse);
- + void SetReverseDependence(MythUIType *dependee, bool reverse);
- void SetDependsMap(QMap<QString, QString> dependsMap);
- QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
- @@ -190,6 +192,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
- void Show(void);
- void Refresh(void);
- void UpdateDependState(bool isDefault);
- + void UpdateDependState(MythUIType *dependee, bool isDefault);
- signals:
- void RequestUpdate();
- @@ -228,6 +231,11 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
- QList<MythUIType *> m_ChildrenList;
- QMap<QString, QString> m_dependsMap;
- + // the number of dependencies is assumed to be small (1 or 2 elements on average)
- + // so we use a QVector as we want the element ordered in the order they were defined
- + // and speed isn't going to be a factor
- + QVector< QPair<MythUIType *, bool> >m_dependsValue;
- + QVector<int> m_dependOperator;
- bool m_Visible;
- bool m_HasFocus;
- @@ -238,7 +246,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
- bool m_Vanish;
- bool m_Vanished;
- bool m_IsDependDefault;
- - bool m_ReverseDepend;
- + QMap<MythUIType *, bool> m_ReverseDepend;
- int m_focusOrder;
- --
- 1.8.2.1 (Apple Git-45)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement