| 186 | } |
| 187 | |
| 188 | void FolderModel::reload() |
| 189 | { |
| 190 | if (rootItem == nullptr) |
| 191 | return; |
| 192 | |
| 193 | if (!isSubfolder) { |
| 194 | auto newModelData = createModelData(_databasePath); |
| 195 | |
| 196 | takeUpdatedChildrenInfo(rootItem, QModelIndex(), newModelData.rootItem); |
| 197 | |
| 198 | // copy items from newModelData to this model that are not in this model |
| 199 | for (const auto key : newModelData.items.keys()) { |
| 200 | if (!items.contains(key)) { |
| 201 | items[key] = (newModelData.items[key]); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | delete newModelData.rootItem; |
| 206 | } else { |
| 207 | QString connectionName = ""; |
| 208 | { |
| 209 | QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); |
| 210 | |
| 211 | QSqlQuery selectQuery(db); |
| 212 | selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId and id <> 1"); |
| 213 | selectQuery.bindValue(":parentId", rootItem->id); |
| 214 | selectQuery.exec(); |
| 215 | |
| 216 | auto tempRoot = new FolderItem(rootItem->getData(), rootItem->parentItem); |
| 217 | tempRoot->id = rootItem->id; |
| 218 | auto newModelData = createModelData(selectQuery, tempRoot); |
| 219 | takeUpdatedChildrenInfo(rootItem, QModelIndex(), newModelData.rootItem); |
| 220 | |
| 221 | items = newModelData.items; |
| 222 | |
| 223 | // copy items from newModelData to this model that are not in this model |
| 224 | for (const auto key : newModelData.items.keys()) { |
| 225 | if (!items.contains(key)) { |
| 226 | items[key] = (newModelData.items[key]); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | delete newModelData.rootItem; |
| 231 | |
| 232 | connectionName = db.connectionName(); |
| 233 | } |
| 234 | QSqlDatabase::removeDatabase(connectionName); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | void FolderModel::takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex &parentModelIndex, FolderItem *updated) |
| 239 | { |
nothing calls this directly
no test coverage detected