From beeb68f7a66d9b88cd29f9b1c601855094e76884 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Tue, 6 Feb 2018 14:56:18 +0100 Subject: [PATCH] TabMruModel: Ignore moving already first index --- src/lib/tabwidget/tabmrumodel.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/tabwidget/tabmrumodel.cpp b/src/lib/tabwidget/tabmrumodel.cpp index c71f613e0..b1be6187e 100644 --- a/src/lib/tabwidget/tabmrumodel.cpp +++ b/src/lib/tabwidget/tabmrumodel.cpp @@ -151,16 +151,20 @@ TabMruModelItem *TabMruModel::item(const QModelIndex &index) const void TabMruModel::currentTabChanged(int index) { TabMruModelItem *it = item(mapFromSource(sourceModel()->index(index, 0))); - if (it) { - const int from = m_root->children.indexOf(it); - if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), 0)) { - qWarning() << "Invalid beginMoveRows" << from; - return; - } - m_root->children.removeAt(from); - m_root->children.insert(0, it); - endMoveRows(); + if (!it) { + return; } + const int from = m_root->children.indexOf(it); + if (from == 0) { + return; + } + if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), 0)) { + qWarning() << "Invalid beginMoveRows" << from; + return; + } + m_root->children.removeAt(from); + m_root->children.insert(0, it); + endMoveRows(); } void TabMruModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles)