| 75 | } |
| 76 | |
| 77 | QModelIndex |
| 78 | MonitorDataModel::index( TreeNode* node, int column) const |
| 79 | { |
| 80 | // Treat null nodes as the root. |
| 81 | if( !node) node = this->root_; |
| 82 | |
| 83 | // We have to reach the root before we can start forming indices. |
| 84 | // Retain the row information for the entire path as we traverse it. |
| 85 | QList<int> list; |
| 86 | for( ; node->parent(); node = node->parent()) { |
| 87 | list.append( node->row()); |
| 88 | } |
| 89 | |
| 90 | // Form the index of the tree root to start from. Use the topmost |
| 91 | // non-null node that we found as the root. |
| 92 | QModelIndex index = this->QAbstractItemModel::createIndex( 0, column, node); |
| 93 | |
| 94 | // Now we can form index values all the way back to the node of |
| 95 | // interest. |
| 96 | while( !list.isEmpty()) { |
| 97 | index = this->index( list.takeLast(), column, index); |
| 98 | } |
| 99 | return index; |
| 100 | } |
| 101 | |
| 102 | TreeNode* |
| 103 | MonitorDataModel::getNode( const QModelIndex &index, bool defaultToRoot) const |