diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index ed2abdc9..e1d9eb53 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -325,7 +325,32 @@ void ReadingListModel::addReadingList(const QString &name) void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &mi) { - //TODO + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + beginInsertRows(mi, 0, 0); //TODO calculate the right coordinates before inserting + + qulonglong id = DBHelper::insertReadingSubList(name,mi.data(IDRole).toULongLong(),db); + ReadingListItem * newItem; + ReadingListItem * readingListParent = static_cast(mi.internalPointer()); + readingListParent->appendChild(newItem = new ReadingListItem(QList() + << name + << id + << false + << true + << mi.data(IDRole).toULongLong())); + + + + items.insert(id, newItem); + + int pos = readingListParent->children().indexOf(newItem); + + pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0; + + + endInsertRows(); + + QSqlDatabase::removeDatabase(_databasePath); } bool ReadingListModel::isEditable(const QModelIndex &mi) diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 0c25983d..dbd6c0e2 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -472,6 +472,17 @@ qulonglong DBHelper::insertReadingList(const QString &name, QSqlDatabase &db) return query.lastInsertId().toULongLong(); } +qulonglong DBHelper::insertReadingSubList(const QString &name, qulonglong parentId, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO reading_list (name, parentId) " + "VALUES (:name, :parentId)"); + query.bindValue(":name", name); + query.bindValue(":parentId", parentId); + query.exec(); + return query.lastInsertId().toULongLong(); +} + void DBHelper::insertComicsInFavorites(const QList &comicsList, QSqlDatabase &db) { db.transaction(); diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 8d502762..55f58bd8 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -45,6 +45,7 @@ public: static qulonglong insert(ComicDB * comic, QSqlDatabase & db); static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db); static qulonglong insertReadingList(const QString & name, QSqlDatabase & db); + static qulonglong insertReadingSubList(const QString & name, qulonglong parentId, QSqlDatabase & db); static void insertComicsInFavorites(const QList & comicsList, QSqlDatabase & db); static void insertComicsInLabel(const QList & comicsList, qulonglong labelId, QSqlDatabase & db); static void insertComicsInReadingList(const QList & comicsList, qulonglong readingListId, QSqlDatabase & db);