Update the flow view with new covers when the model adds rows

This commit is contained in:
Luis Ángel San Martín 2023-08-13 11:42:06 +02:00
parent 0024d9afda
commit b2d48a77ca
2 changed files with 11 additions and 0 deletions

View File

@ -135,6 +135,7 @@ void ClassicComicsView::setModel(ComicModel *model)
} else { } else {
connect(model, &QAbstractItemModel::dataChanged, this, &ClassicComicsView::applyModelChanges, Qt::UniqueConnection); connect(model, &QAbstractItemModel::dataChanged, this, &ClassicComicsView::applyModelChanges, Qt::UniqueConnection);
connect(model, &QAbstractItemModel::rowsRemoved, this, &ClassicComicsView::removeItemsFromFlow, Qt::UniqueConnection); connect(model, &QAbstractItemModel::rowsRemoved, this, &ClassicComicsView::removeItemsFromFlow, Qt::UniqueConnection);
connect(model, &QAbstractItemModel::rowsInserted, this, &ClassicComicsView::addItemsToFlow, Qt::UniqueConnection);
// TODO: Missing method resortCovers? // TODO: Missing method resortCovers?
connect(model, &ComicModel::resortedIndexes, comicFlow, &ComicFlowWidget::resortCovers, Qt::UniqueConnection); connect(model, &ComicModel::resortedIndexes, comicFlow, &ComicFlowWidget::resortCovers, Qt::UniqueConnection);
connect(model, &ComicModel::newSelectedIndex, this, &ClassicComicsView::setCurrentIndex, Qt::UniqueConnection); connect(model, &ComicModel::newSelectedIndex, this, &ClassicComicsView::setCurrentIndex, Qt::UniqueConnection);
@ -341,6 +342,15 @@ void ClassicComicsView::removeItemsFromFlow(const QModelIndex &parent, int from,
comicFlow->remove(i); comicFlow->remove(i);
} }
void ClassicComicsView::addItemsToFlow(const QModelIndex &parent, int from, int to)
{
Q_UNUSED(parent);
for (int i = from; i <= to; i++) {
auto coverPath = model->index(i, 0).data(ComicModel::CoverPathRole).toString();
comicFlow->add(coverPath.remove("file:"), i); // TODO: find a better way to get the path, file:+the_path is the way the URL is created for QML
}
}
void ClassicComicsView::closeEvent(QCloseEvent *event) void ClassicComicsView::closeEvent(QCloseEvent *event)
{ {
toolbar->removeAction(startSeparatorAction); toolbar->removeAction(startSeparatorAction);

View File

@ -42,6 +42,7 @@ public slots:
void saveSplitterStatus(); void saveSplitterStatus();
void applyModelChanges(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); void applyModelChanges(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void removeItemsFromFlow(const QModelIndex &parent, int from, int to); void removeItemsFromFlow(const QModelIndex &parent, int from, int to);
void addItemsToFlow(const QModelIndex &parent, int from, int to);
// ComicsView // ComicsView
void setShowMarks(bool show) override; void setShowMarks(bool show) override;
void selectAll() override; void selectAll() override;