예제 #1
0
 private function setupModelData(QStringList $lines, TreeItem $parent)
 {
     $parents = array();
     $indentations = array();
     array_push($parents, $parent);
     array_push($indentations, 0);
     $number = 0;
     while ($number < $lines->count()) {
         $position = 0;
         while ($position < $lines[$number]->length()) {
             if ($lines[$number]->mid($position, 1) != " ") {
                 break;
             }
             $position++;
         }
         $lineData = new QString($lines[$number]->mid($position)->trimmed());
         if (!$lineData->isEmpty()) {
             // Read the column data from the rest of the line.
             $columnStrings = $lineData->split("\t", QString::SkipEmptyParts);
             $columnData = array();
             for ($column = 0; $column < $columnStrings->count(); ++$column) {
                 array_push($columnData, $columnStrings[$column]);
             }
             if ($position > $indentations[count($indentations)]) {
                 // The last child of the current parent is now the new parent
                 // unless the current parent has no children.
                 if ($parents[count($parents)]->childCount() > 0) {
                     array_push($parent, $parents[count($parents)]->child($parents[count($parents)]->childCount() - 1));
                     array_push($indentations, $position);
                 }
             } else {
                 while ($position < $indentations[count($indentations)] && count($parents) > 0) {
                     array_pop($parents);
                     array_pop($indentations);
                 }
             }
             // Append a new item to the current parent's list of children.
             $parents[count($parents)]->appendChild(new TreeItem($columnData, $parents[count($parents)]));
         }
         $number++;
     }
 }