Rebuild the notebook tree view
| 288 | |
| 289 | // Rebuild the notebook tree view |
| 290 | void NNotebookView::rebuildTree() { |
| 291 | if (!this->rebuildNotebookTreeNeeded) |
| 292 | return; |
| 293 | |
| 294 | // Go through all the widgets in the view. If |
| 295 | // it should be hidden (because the notebook is closed |
| 296 | // then hide it, othwise make it visible. If it has |
| 297 | // a stack, then save the stack name later so we can |
| 298 | // display stacks properly. |
| 299 | NotebookTable notebookTable(global.db); |
| 300 | QList<qint32> closedLids; |
| 301 | notebookTable.getClosedNotebooks(closedLids); |
| 302 | QHashIterator<qint32, NNotebookViewItem *> i(dataStore); |
| 303 | while (i.hasNext()) { |
| 304 | i.next(); |
| 305 | NNotebookViewItem *widget = i.value(); |
| 306 | if (widget != NULL) { |
| 307 | if (i.value()->stack != "") { |
| 308 | NNotebookViewItem *stackWidget = NULL; |
| 309 | if (stackStore.contains(i.value()->stack)) { |
| 310 | stackWidget = stackStore[i.value()->stack]; |
| 311 | } else { |
| 312 | NNotebookViewItem *stackWidget = new NNotebookViewItem(0); |
| 313 | stackWidget->setData(NAME_POSITION, Qt::DisplayRole, i.value()->stack); |
| 314 | stackWidget->setData(NAME_POSITION, Qt::UserRole, "STACK"); |
| 315 | stackStore.insert(widget->stack, stackWidget); |
| 316 | root->addChild(stackWidget); |
| 317 | } |
| 318 | i.value()->parent()->removeChild(i.value()); |
| 319 | stackWidget->childrenLids.append(i.key()); |
| 320 | stackWidget->addChild(i.value()); |
| 321 | } |
| 322 | if (closedLids.contains(widget->lid)) |
| 323 | widget->setHidden(true); |
| 324 | else |
| 325 | widget->setHidden(false); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Remove any empty stacks |
| 330 | QHashIterator<QString, NNotebookViewItem *> s(stackStore); |
| 331 | while (s.hasNext()) { |
| 332 | s.next(); |
| 333 | if (s.value()->childCount() == 0) { |
| 334 | root->removeChild(s.value()); |
| 335 | stackStore.remove(s.key()); |
| 336 | } else { |
| 337 | s.value()->setHidden(true); // hide by default. We'll unhide later when chirdren are found |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // unhide any empty stacks. They were hidden above but |
| 342 | // we look for any children that are visible. If they are |
| 343 | // visible we make the parent visible. This way, any stack |
| 344 | // that has all hidden chilren are visible, but others are |
| 345 | // hidden. |
| 346 | QHashIterator<qint32, NNotebookViewItem *> h(dataStore); |
| 347 | while (h.hasNext()) { |