summaryrefslogtreecommitdiff
path: root/src/filetreemodel.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-02-07 13:39:35 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-07 13:39:35 -0500
commit2b0a720863a26faebdc240f4db29dd39c7a035b6 (patch)
treef920b0b442b790f2e6bc7d97d6574abfe5d2c5c6 /src/filetreemodel.cpp
parent1c8c1bb89b6d2103e146a54ae9f0dfdd50f7b835 (diff)
fixed sorting not emitting layout events and fixing persistent indexes
Diffstat (limited to 'src/filetreemodel.cpp')
-rw-r--r--src/filetreemodel.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/filetreemodel.cpp b/src/filetreemodel.cpp
index 01a10afc..40cded09 100644
--- a/src/filetreemodel.cpp
+++ b/src/filetreemodel.cpp
@@ -208,6 +208,7 @@ QModelIndex FileTreeModel::index(
{
if (auto* parentItem=itemFromIndex(parentIndex)) {
if (row < 0 || row >= parentItem->children().size()) {
+ log::error("row {} out of range for {}", row, parentItem->debugName());
return {};
}
@@ -378,13 +379,10 @@ Qt::ItemFlags FileTreeModel::flags(const QModelIndex& index) const
return f;
}
-void FileTreeModel::sort(int column, Qt::SortOrder order)
+void FileTreeModel::sortItem(FileTreeItem& item)
{
emit layoutAboutToBeChanged();
- m_sort.column = column;
- m_sort.order = order;
-
const auto oldList = persistentIndexList();
std::vector<std::pair<FileTreeItem*, int>> oldItems;
@@ -396,7 +394,7 @@ void FileTreeModel::sort(int column, Qt::SortOrder order)
oldItems.push_back({itemFromIndex(index), index.column()});
}
- m_root->sort(column, order);
+ item.sort(m_sort.column, m_sort.order);
QModelIndexList newList;
newList.reserve(itemCount);
@@ -411,6 +409,14 @@ void FileTreeModel::sort(int column, Qt::SortOrder order)
emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
}
+void FileTreeModel::sort(int column, Qt::SortOrder order)
+{
+ m_sort.column = column;
+ m_sort.order = order;
+
+ sortItem(*m_root);
+}
+
FileTreeItem* FileTreeModel::itemFromIndex(const QModelIndex& index) const
{
if (!index.isValid()) {