Advertisement
Guest User

Untitled

a guest
Jul 14th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 KB | None | 0 0
  1. From 0cbee5d69170b47b79913e14c408d3dc7a0df7c7 Mon Sep 17 00:00:00 2001
  2. From: Jean-Yves Avenard <jyavenard@mythtv.org>
  3. Date: Mon, 15 Jul 2013 05:05:42 +1000
  4. Subject: [PATCH] Add multiple UI object dependencies.
  5.  
  6. Operator supported are & (AND) and | (OR); priority are strictly from left to right
  7. ---
  8. mythtv/libs/libmythui/mythuitype.cpp | 99 ++++++++++++++++++++++++++++--------
  9. mythtv/libs/libmythui/mythuitype.h | 12 ++++-
  10. 2 files changed, 87 insertions(+), 24 deletions(-)
  11.  
  12. diff --git a/mythtv/libs/libmythui/mythuitype.cpp b/mythtv/libs/libmythui/mythuitype.cpp
  13. index 9accc45..25246c3 100644
  14. --- a/mythtv/libs/libmythui/mythuitype.cpp
  15. +++ b/mythtv/libs/libmythui/mythuitype.cpp
  16. @@ -47,7 +47,6 @@ MythUIType::MythUIType(QObject *parent, const QString &name)
  17. m_XYSpeed = QPoint(0, 0);
  18. m_deferload = false;
  19. m_IsDependDefault = false;
  20. - m_ReverseDepend = false;
  21.  
  22. m_Parent = NULL;
  23.  
  24. @@ -1037,13 +1036,47 @@ void MythUIType::Refresh(void)
  25. SetRedraw();
  26. }
  27.  
  28. -void MythUIType::UpdateDependState(bool isDefault)
  29. +void MythUIType::UpdateDependState(MythUIType *dependee, bool isDefault)
  30. {
  31. - m_IsDependDefault = m_ReverseDepend ? !isDefault : isDefault;
  32. + bool reverse = m_ReverseDepend[dependee];
  33. + bool visible = reverse ? !isDefault : isDefault;
  34. + for (int i = 0; i < m_dependsValue.size(); i++)
  35. + {
  36. + if (m_dependsValue[i].first != dependee)
  37. + continue;
  38. + m_dependsValue[i].second = visible;
  39. + break;
  40. + }
  41. +
  42. + visible = m_dependsValue[0].second;
  43. + for (int i = 1; i < m_dependsValue.size(); i++)
  44. + {
  45. + bool v = m_dependsValue[i].second;
  46. +
  47. + if (m_dependOperator[i-1] == 1)
  48. + {
  49. + // OR operator
  50. + visible = visible && v;
  51. + }
  52. + else
  53. + {
  54. + // AND operator
  55. + visible = visible || v;
  56. + }
  57. + }
  58. +
  59. + m_IsDependDefault = visible;
  60.  
  61. SetVisible(!m_IsDependDefault);
  62. }
  63.  
  64. +void MythUIType::UpdateDependState(bool isDefault)
  65. +{
  66. + MythUIType *dependee = static_cast<MythUIType*>(sender());
  67. +
  68. + UpdateDependState(dependee, isDefault);
  69. +}
  70. +
  71. void MythUIType::SetVisible(bool visible)
  72. {
  73. if (visible == m_Visible)
  74. @@ -1159,7 +1192,6 @@ void MythUIType::CopyFrom(MythUIType *base)
  75. }
  76.  
  77. m_dependsMap = base->m_dependsMap;
  78. - m_ReverseDepend = base->m_ReverseDepend;
  79.  
  80. SetMinArea(base->m_MinArea);
  81. }
  82. @@ -1372,34 +1404,57 @@ void MythUIType::SetDependsMap(QMap<QString, QString> dependsMap)
  83. m_dependsMap = dependsMap;
  84. }
  85.  
  86. -void MythUIType::SetReverseDependence(bool reverse)
  87. +void MythUIType::SetReverseDependence(MythUIType *dependee, bool reverse)
  88. {
  89. - m_ReverseDepend = reverse;
  90. + m_ReverseDepend.insert(dependee, reverse);
  91. }
  92.  
  93. void MythUIType::ConnectDependants(bool recurse)
  94. {
  95. -
  96. - QMapIterator<QString, QString> i(m_dependsMap);
  97. - while(i.hasNext())
  98. + QMapIterator<QString, QString> it(m_dependsMap);
  99. + while(it.hasNext())
  100. {
  101. - i.next();
  102. - QString dependeeName = i.value();
  103. - bool reverse = false;
  104. - if (dependeeName.startsWith('!'))
  105. + it.next();
  106. + QStringList dependees;
  107. + QVector<int> operators;
  108. + QString name = it.value();
  109. + QStringList tmp1 = name.split("&");
  110. + for (int i = 0; i < tmp1.size(); i++)
  111. {
  112. - reverse = true;
  113. - dependeeName.remove(0,1);
  114. + QStringList tmp2 = tmp1[i].split("|");
  115. +
  116. + dependees.append(tmp2[0]);
  117. + for (int j = 1; j < tmp2.size(); j++)
  118. + {
  119. + dependees.append(tmp2[j]);
  120. + operators.append(1); // 1 is OR
  121. + }
  122. + operators.append(2); // 2 is AND
  123. }
  124. - MythUIType *dependee = GetChild(dependeeName);
  125. - MythUIType *dependant = GetChild(i.key());
  126.  
  127. - if (dependee && dependant)
  128. + MythUIType *dependant = GetChild(it.key());
  129. + if (dependant)
  130. {
  131. - QObject::connect(dependee, SIGNAL(DependChanged(bool)),
  132. - dependant, SLOT(UpdateDependState(bool)));
  133. - dependant->SetReverseDependence(reverse);
  134. - dependant->UpdateDependState(true);
  135. + dependant->m_dependOperator = operators;
  136. + foreach (QString dependeeName, dependees)
  137. + {
  138. + bool reverse = false;
  139. + if (dependeeName.startsWith('!'))
  140. + {
  141. + reverse = true;
  142. + dependeeName.remove(0,1);
  143. + }
  144. + MythUIType *dependee = GetChild(dependeeName);
  145. +
  146. + if (dependee)
  147. + {
  148. + QObject::connect(dependee, SIGNAL(DependChanged(bool)),
  149. + dependant, SLOT(UpdateDependState(bool)));
  150. + dependant->SetReverseDependence(dependee, reverse);
  151. + dependant->m_dependsValue.append(QPair<MythUIType *, bool>(dependee, false));
  152. + dependant->UpdateDependState(dependee, true);
  153. + }
  154. + }
  155. }
  156. }
  157.  
  158. diff --git a/mythtv/libs/libmythui/mythuitype.h b/mythtv/libs/libmythui/mythuitype.h
  159. index 82ce763..9bbcc41 100644
  160. --- a/mythtv/libs/libmythui/mythuitype.h
  161. +++ b/mythtv/libs/libmythui/mythuitype.h
  162. @@ -6,6 +6,8 @@
  163. #include <QMap>
  164. #include <QHash>
  165. #include <QList>
  166. +#include <QVector>
  167. +#include <QPair>
  168. #include <QFont>
  169. #include <QColor>
  170.  
  171. @@ -174,7 +176,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
  172. void SetVerticalZoom(float zoom);
  173. void SetAngle(float angle);
  174. void SetDependIsDefault(bool isDefault);
  175. - void SetReverseDependence(bool reverse);
  176. + void SetReverseDependence(MythUIType *dependee, bool reverse);
  177. void SetDependsMap(QMap<QString, QString> dependsMap);
  178. QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
  179.  
  180. @@ -190,6 +192,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
  181. void Show(void);
  182. void Refresh(void);
  183. void UpdateDependState(bool isDefault);
  184. + void UpdateDependState(MythUIType *dependee, bool isDefault);
  185.  
  186. signals:
  187. void RequestUpdate();
  188. @@ -228,6 +231,11 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
  189.  
  190. QList<MythUIType *> m_ChildrenList;
  191. QMap<QString, QString> m_dependsMap;
  192. + // the number of dependencies is assumed to be small (1 or 2 elements on average)
  193. + // so we use a QVector as we want the element ordered in the order they were defined
  194. + // and speed isn't going to be a factor
  195. + QVector< QPair<MythUIType *, bool> >m_dependsValue;
  196. + QVector<int> m_dependOperator;
  197.  
  198. bool m_Visible;
  199. bool m_HasFocus;
  200. @@ -238,7 +246,7 @@ class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
  201. bool m_Vanish;
  202. bool m_Vanished;
  203. bool m_IsDependDefault;
  204. - bool m_ReverseDepend;
  205. + QMap<MythUIType *, bool> m_ReverseDepend;
  206.  
  207. int m_focusOrder;
  208.  
  209. --
  210. 1.8.2.1 (Apple Git-45)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement