| 188 | } |
| 189 | |
| 190 | void CFrmBookmark::loadBookmarks() |
| 191 | { |
| 192 | if(!m_pDatabase || !m_pModel || !m_pTreeView) return; |
| 193 | m_pModel->clear(); |
| 194 | m_folderItems.clear(); |
| 195 | |
| 196 | // 设置表头 |
| 197 | m_pModel->setHorizontalHeaderLabels(QStringList() << tr("Title")); |
| 198 | |
| 199 | // 加载文件夹结构 |
| 200 | QList<BookmarkItem> folders = m_pDatabase->getAllFolders(); |
| 201 | |
| 202 | // 创建根节点 |
| 203 | QStandardItem *rootItem = m_pModel->invisibleRootItem(); |
| 204 | |
| 205 | int nCurrent = m_pPara->GetBookmarkCurrentFolder(); |
| 206 | QStandardItem* pCurrentItem = nullptr; |
| 207 | |
| 208 | // 先添加顶级文件夹 |
| 209 | for (const auto &folder : folders) { |
| 210 | if (folder.folderId == 0) { // 顶级文件夹 |
| 211 | QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title); |
| 212 | if(!pFolderItem) continue; |
| 213 | pFolderItem->setData(folder.id, ID); |
| 214 | pFolderItem->setData(BookmarkType_Folder, Type); |
| 215 | rootItem->appendRow(pFolderItem); |
| 216 | m_folderItems[folder.id] = pFolderItem; |
| 217 | if(folder.id == nCurrent) |
| 218 | pCurrentItem = pFolderItem; |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | auto it = m_folderItems.find(folder.folderId); |
| 223 | if(m_folderItems.end() == it) { |
| 224 | qWarning(log) << "The parent of folder is not find:" << folder.folderId; |
| 225 | continue; |
| 226 | } |
| 227 | QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title); |
| 228 | if(!pFolderItem) continue; |
| 229 | pFolderItem->setData(folder.id, ID); |
| 230 | pFolderItem->setData(BookmarkType_Folder, Type); |
| 231 | (*it)->appendRow(pFolderItem); |
| 232 | m_folderItems[folder.id] = pFolderItem; |
| 233 | if(folder.id == nCurrent) |
| 234 | pCurrentItem = pFolderItem; |
| 235 | } |
| 236 | |
| 237 | // Set current index |
| 238 | if(pCurrentItem) { |
| 239 | auto index = m_pModel->indexFromItem(pCurrentItem); |
| 240 | m_pTreeView->setCurrentIndex(index); |
| 241 | } |
| 242 | |
| 243 | // 添加书签到对应的文件夹 |
| 244 | QList<BookmarkItem> bookmarks = m_pDatabase->getAllBookmarks(-1); |
| 245 | for (const auto &bookmark : bookmarks) { |
| 246 | QStandardItem *pParentItem = nullptr; |
| 247 |
nothing calls this directly
no test coverage detected