Remember previous selected piece when switching categories.

This commit is contained in:
Leonardo Zide 2024-12-19 15:02:10 -08:00
parent b9dc71d60e
commit 71c154bcaa
2 changed files with 27 additions and 1 deletions

View file

@ -540,6 +540,7 @@ lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent, lcPartSelectio
setWordWrap(false); setWordWrap(false);
setDragEnabled(true); setDragEnabled(true);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
setAutoScroll(false);
mListModel = new lcPartSelectionListModel(this); mListModel = new lcPartSelectionListModel(this);
setModel(mListModel); setModel(mListModel);
@ -585,6 +586,11 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index) void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
{ {
QModelIndex CurrentIndex = currentIndex();
if (CurrentIndex.isValid())
mLastCategoryRow[{mCategoryType, mCategoryIndex}] = CurrentIndex.row();
mCategoryType = Type; mCategoryType = Type;
mCategoryIndex = Index; mCategoryIndex = Index;
@ -610,7 +616,26 @@ void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
break; break;
} }
setCurrentIndex(mListModel->index(0, 0)); auto CurrentIt = mLastCategoryRow.find({mCategoryType, mCategoryIndex});
bool ScrollToTop = true;
if (CurrentIt != mLastCategoryRow.end())
{
CurrentIndex = mListModel->index(CurrentIt->second, 0);
if (!isRowHidden(CurrentIndex.row()))
{
scrollTo(CurrentIndex);
setCurrentIndex(CurrentIndex);
ScrollToTop = false;
}
}
if (ScrollToTop)
{
scrollToTop();
setCurrentIndex(indexAt(QPoint(0, 0)));
}
} }
void lcPartSelectionListView::SetCustomParts(const std::vector<PieceInfo*>& Parts) void lcPartSelectionListView::SetCustomParts(const std::vector<PieceInfo*>& Parts)

View file

@ -247,6 +247,7 @@ protected:
PieceInfo* mContextInfo = nullptr; PieceInfo* mContextInfo = nullptr;
lcPartCategoryType mCategoryType = lcPartCategoryType::AllParts; lcPartCategoryType mCategoryType = lcPartCategoryType::AllParts;
int mCategoryIndex = 0; int mCategoryIndex = 0;
std::map<std::pair<lcPartCategoryType, int>, int> mLastCategoryRow;
}; };
class lcPartSelectionWidget : public QWidget class lcPartSelectionWidget : public QWidget