Advertisement
peter9477

Mutual exclusion in Cascades ListView

Mar 3rd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ListView {
  2.     property variant selectedPath: []
  3.  
  4.     onSelectionChanged: {
  5.         if (selected)
  6.             selectedPath = indexPath;
  7.         else
  8.             selectedPath = [];
  9.     }
  10.  
  11.     onTriggered: {
  12.         if (equalPaths(selected(), indexPath)) {
  13.             select(indexPath, false);
  14.         }
  15.         else {
  16.             clearSelection();
  17.             select(indexPath, true);
  18.         }
  19.     }
  20.  
  21. //--------------------------------------
  22. // Compare two indexPaths as returned by ListView.selected()
  23. // and other routines, returning true only if they're identical.
  24. //
  25. function equalPaths(ip1, ip2) {
  26.     if (!ip1 || !ip2)
  27.         return false;
  28.  
  29.     if (ip1.length != ip2.length)
  30.         return false;
  31.  
  32.     for (var i = 0; i < ip1.length; i++)
  33.         if (ip1[i] != ip2[i])
  34.             return false;
  35.  
  36.     return true;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement