| 109 | } |
| 110 | |
| 111 | void CFrmAddBookmark::loadFolder(int nCurrent) |
| 112 | { |
| 113 | if(!m_pDatabase || !m_pModelTree || !m_pPara) return; |
| 114 | |
| 115 | m_pModelTree->clear(); |
| 116 | m_folderItems.clear(); |
| 117 | |
| 118 | // 设置表头 |
| 119 | m_pModelTree->setHorizontalHeaderLabels(QStringList() << tr("Title")); |
| 120 | |
| 121 | QStandardItem* pCurrentItem = nullptr; |
| 122 | // 加载文件夹结构 |
| 123 | QList<BookmarkItem> folders = m_pDatabase->getAllFolders(); |
| 124 | |
| 125 | // 创建根节点 |
| 126 | QStandardItem *rootItem = m_pModelTree->invisibleRootItem(); |
| 127 | |
| 128 | if(0 == nCurrent) { |
| 129 | nCurrent = m_pPara->GetBookmarkCurrentFolder(); |
| 130 | auto item = m_pDatabase->getBookmarkByUrl(m_Url.toString()); |
| 131 | if(!item.isEmpty()) { |
| 132 | nCurrent = item[0].folderId; |
| 133 | ui->pbDelete->setVisible(true); |
| 134 | ui->pbDelete->setText(tr("Delete %1 bookmarks").arg(item.count())); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // 先添加顶级文件夹 |
| 139 | for (const auto &folder : folders) { |
| 140 | if (folder.folderId == 0) { // 顶级文件夹 |
| 141 | QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title); |
| 142 | if(!pFolderItem) continue; |
| 143 | pFolderItem->setData(folder.id, (int)Role::ID); |
| 144 | pFolderItem->setData(BookmarkType_Folder, (int)Role::Type); |
| 145 | rootItem->appendRow(pFolderItem); |
| 146 | m_folderItems[folder.id] = pFolderItem; |
| 147 | if(nCurrent == folder.id) |
| 148 | pCurrentItem = pFolderItem; |
| 149 | continue; |
| 150 | } |
| 151 | |
| 152 | auto it = m_folderItems.find(folder.folderId); |
| 153 | if(m_folderItems.end() == it) { |
| 154 | qWarning(log) << "The parent of folder is not find:" << folder.folderId; |
| 155 | continue; |
| 156 | } |
| 157 | QStandardItem *pFolderItem = new QStandardItem(folder.getIcon(), folder.title); |
| 158 | if(!pFolderItem) continue; |
| 159 | pFolderItem->setData(folder.id, (int)Role::ID); |
| 160 | pFolderItem->setData(BookmarkType_Folder, (int)Role::Type); |
| 161 | (*it)->appendRow(pFolderItem); |
| 162 | m_folderItems[folder.id] = pFolderItem; |
| 163 | if(nCurrent == folder.id) |
| 164 | pCurrentItem = pFolderItem; |
| 165 | } |
| 166 | |
| 167 | // Set current index |
| 168 | if(pCurrentItem) { |
nothing calls this directly
no test coverage detected