diff --git a/src/creator/qml/Book.qml b/src/creator/qml/Book.qml --- a/src/creator/qml/Book.qml +++ b/src/creator/qml/Book.qml @@ -125,7 +125,7 @@ Kirigami.Action { text: i18nc("remove the page from the book", "Delete Page"); iconName: "list-remove" - onTriggered: {} + onTriggered: bookModel.removePage(model.index); }, Kirigami.Action { text: i18nc("add a page to the book after this one", "Add Page After This"); diff --git a/src/qtquick/ArchiveBookModel.h b/src/qtquick/ArchiveBookModel.h --- a/src/qtquick/ArchiveBookModel.h +++ b/src/qtquick/ArchiveBookModel.h @@ -141,6 +141,13 @@ * @param title The title of the page. This is shown in a table of contents. */ void addPage(QString url, QString title) override; + + /** + * @brief removePage + * remove the given page from the book by number. + * @param pageNumber the number of the page to remove. + */ + Q_INVOKABLE void removePage(int pageNumber) override; /** * Adds a new page to the book archive on disk, by copying in the file * passed to the function. Optionally this can be done at a specific diff --git a/src/qtquick/ArchiveBookModel.cpp b/src/qtquick/ArchiveBookModel.cpp --- a/src/qtquick/ArchiveBookModel.cpp +++ b/src/qtquick/ArchiveBookModel.cpp @@ -568,6 +568,33 @@ BookModel::addPage(url, title); } +void ArchiveBookModel::removePage(int pageNumber) +{ + if(!d->isLoading) + { + AdvancedComicBookFormat::Document* acbfDocument = qobject_cast(acbfData()); + if(!acbfDocument) + { + acbfDocument = d->createNewAcbfDocumentFromLegacyInformation(); + } + else + { + if(pageNumber == 0) + { + //Page no 0 is the cover page, when removed we'll take the next page. + AdvancedComicBookFormat::Page* page = acbfDocument->body()->page(0); + acbfDocument->metaData()->bookInfo()->setCoverpage(page); + acbfDocument->body()->removePage(page); + } + else { + AdvancedComicBookFormat::Page* page = acbfDocument->body()->page(pageNumber-1); + acbfDocument->body()->removePage(page); + } + } + } + BookModel::removePage(pageNumber); +} + // FIXME any metadata change sets dirty (as we need to replace the whole file in archive when saving) void ArchiveBookModel::addPageFromFile(QString fileUrl, int insertAfter) diff --git a/src/qtquick/BookModel.h b/src/qtquick/BookModel.h --- a/src/qtquick/BookModel.h +++ b/src/qtquick/BookModel.h @@ -116,6 +116,14 @@ * @param title The title of the page. This is shown in a table of contents. */ virtual void addPage(QString url, QString title); + + /** + * @brief removePage + * Remove this page from the book. + * @param index the index of the page to be removed. + */ + virtual void removePage(int pageNumber); + /** * \brief remove all pages from the book. */ diff --git a/src/qtquick/BookModel.cpp b/src/qtquick/BookModel.cpp --- a/src/qtquick/BookModel.cpp +++ b/src/qtquick/BookModel.cpp @@ -108,6 +108,15 @@ endInsertRows(); } +void BookModel::removePage(int pageNumber) +{ + QModelIndex index = createIndex(pageNumber, 0); + beginRemoveRows(QModelIndex(), index.row(), index.row()); + d->entries.removeAt(pageNumber); + emit pageCountChanged(); + endRemoveRows(); +} + void BookModel::clearPages() { beginResetModel();