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

Method addFolderAtParent

YACReaderLibrary/db/folder_model.cpp:878–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

876}
877
878QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent)
879{
880 FolderItem *parentItem;
881
882 if (parent.isValid())
883 parentItem = static_cast<FolderItem *>(parent.internalPointer());
884 else
885 parentItem = rootItem;
886
887 Folder newFolder;
888 newFolder.name = folderName;
889 newFolder.parentId = parentItem->id;
890 newFolder.path = parentItem->data(Columns::Path).toString() + "/" + folderName;
891 newFolder.type = parentItem->data(Columns::Type).value<YACReader::FileType>();
892
893 QString connectionName = "";
894 {
895 QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
896 newFolder.id = DBHelper::insert(&newFolder, db);
897 DBHelper::updateChildrenInfo(parentItem->id, db);
898 connectionName = db.connectionName();
899 }
900 QSqlDatabase::removeDatabase(connectionName);
901
902 int destRow = 0;
903
904 QList<QVariant> data;
905 data << newFolder.name;
906 data << newFolder.path;
907 data << false; // finished
908 data << true; // completed
909 data << 0; // numChildren
910 data << QVariant(); // first child hash, new folder is empty
911 data << QVariant(); // custom cover
912 data << QVariant::fromValue(newFolder.type);
913 data << newFolder.added;
914 data << newFolder.updated;
915
916 auto item = new FolderItem(data);
917 item->id = newFolder.id;
918
919 beginInsertRows(parent, 0, 0); // TODO calculate the destRow before inserting the new child
920
921 parentItem->appendChild(item);
922 destRow = parentItem->children().indexOf(item); // TODO optimize this, appendChild should return the index of the new item
923 items.insert(item->id, item);
924
925 endInsertRows();
926
927 return index(destRow, 0, parent);
928}
929
930QUrl FolderModel::getCoverUrlPathForComicHash(const QString &hash) const
931{

Callers 1

Calls 6

toStringMethod · 0.80
isValidMethod · 0.45
dataMethod · 0.45
appendChildMethod · 0.45
childrenMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected