From 44349b0a37cf83d2c1ffd78a51825a9ffebf63db Mon Sep 17 00:00:00 2001 From: Adam Higerd Date: Mon, 14 Apr 2025 10:03:06 -0500 Subject: [PATCH] Qt: fix blank rows in library rendering --- src/platform/qt/library/LibraryModel.cpp | 22 +++++++++++++++++++++- src/platform/qt/library/LibraryModel.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/platform/qt/library/LibraryModel.cpp b/src/platform/qt/library/LibraryModel.cpp index cf4cb58ca..6c09025b7 100644 --- a/src/platform/qt/library/LibraryModel.cpp +++ b/src/platform/qt/library/LibraryModel.cpp @@ -336,6 +336,26 @@ QVariant LibraryModel::folderData(const QModelIndex& index, int role) const { return QVariant(); } +bool LibraryModel::validateIndex(const QModelIndex& index) const +{ + if (index.model() != this || index.row() < 0 || index.column() < 0 || index.column() > MAX_COLUMN) { + // Obviously invalid index + return false; + } + + if (index.parent().isValid() && !validateIndex(index.parent())) { + // Parent index is invalid + return false; + } + + if (index.row() >= rowCount(index.parent())) { + // Row is out of bounds for this level of hierarchy + return false; + } + + return true; +} + QVariant LibraryModel::data(const QModelIndex& index, int role) const { switch (role) { case Qt::DisplayRole: @@ -357,7 +377,7 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const { return QVariant(); } - if (index.model() != this || index.row() < 0 || index.row() > rowCount() || index.column() < 0 || index.column() > columnCount()) { + if (!validateIndex(index)) { return QVariant(); } diff --git a/src/platform/qt/library/LibraryModel.h b/src/platform/qt/library/LibraryModel.h index dd78026c8..651bbe7b3 100644 --- a/src/platform/qt/library/LibraryModel.h +++ b/src/platform/qt/library/LibraryModel.h @@ -70,6 +70,8 @@ private: QVariant folderData(const QModelIndex& index, int role = Qt::DisplayRole) const; + bool validateIndex(const QModelIndex& index) const; + void addEntriesList(const QList& items); void addEntriesTree(const QList& items); void addEntryInternal(const LibraryEntry& item);