MCPcopy Create free account
hub / github.com/YACReader/yacreader / reload

Method reload

YACReaderLibrary/db/folder_model.cpp:188–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void 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
238void FolderModel::takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex &parentModelIndex, FolderItem *updated)
239{

Callers

nothing calls this directly

Calls 5

bindValueMethod · 0.80
execMethod · 0.80
QModelIndexClass · 0.50
containsMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected