Load up the data from the database
| 233 | |
| 234 | // Load up the data from the database |
| 235 | void NNotebookView::loadData() { |
| 236 | NSqlQuery query(global.db); |
| 237 | NotebookTable notebookTable(global.db); |
| 238 | QList<qint32> closedLids; |
| 239 | notebookTable.getClosedNotebooks(closedLids); |
| 240 | |
| 241 | |
| 242 | QHash<qint32, NNotebookViewItem*>::iterator i1; |
| 243 | for (i1=dataStore.begin(); i1!=dataStore.end(); ++i1) { |
| 244 | if (i1.value() != NULL) |
| 245 | i1.value()->setHidden(true); |
| 246 | } |
| 247 | |
| 248 | QHash<QString, NNotebookViewItem*>::iterator i2; |
| 249 | for (i2=stackStore.begin(); i2!=stackStore.end(); ++i2) { |
| 250 | if (i2.value() != NULL) |
| 251 | i2.value()->setHidden(true); |
| 252 | } |
| 253 | |
| 254 | dataStore.clear(); |
| 255 | query.exec("Select lid, name, stack, username from NotebookModel order by username, name"); |
| 256 | while (query.next()) { |
| 257 | qint32 lid = query.value(0).toInt(); |
| 258 | if (!notebookTable.isDeleted(query.value(0).toInt())) { |
| 259 | NNotebookViewItem *newWidget = new NNotebookViewItem(lid); |
| 260 | newWidget->setData(NAME_POSITION, Qt::DisplayRole, query.value(1).toString()); |
| 261 | newWidget->setData(NAME_POSITION, Qt::UserRole, lid); |
| 262 | if (closedLids.contains(lid)) |
| 263 | newWidget->setHidden(true); |
| 264 | QString username = query.value(3).toString(); |
| 265 | if (username.trimmed() != "") |
| 266 | newWidget->stack = username; |
| 267 | else |
| 268 | newWidget->stack = query.value(2).toString(); |
| 269 | this->dataStore.insert(query.value(0).toInt(), newWidget); |
| 270 | root->addChild(newWidget); |
| 271 | |
| 272 | if (newWidget->stack != "" && !stackStore.contains(newWidget->stack)) { |
| 273 | NNotebookViewItem *stackWidget = new NNotebookViewItem(0); |
| 274 | stackWidget->setData(NAME_POSITION, Qt::DisplayRole, newWidget->stack); |
| 275 | stackWidget->setData(NAME_POSITION, Qt::UserRole, "STACK"); |
| 276 | if (username != "") |
| 277 | stackWidget->setType(NNotebookViewItem::LinkedStack); |
| 278 | stackStore.insert(newWidget->stack, stackWidget); |
| 279 | root->addChild(stackWidget); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | query.finish(); |
| 284 | this->rebuildTree(); |
| 285 | this->resetSize(); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | // Rebuild the notebook tree view |
no test coverage detected