mirror of
https://github.com/leozide/leocad
synced 2024-12-25 21:58:23 +01:00
Remember previous selected piece when switching categories.
This commit is contained in:
parent
b9dc71d60e
commit
71c154bcaa
2 changed files with 27 additions and 1 deletions
|
@ -540,6 +540,7 @@ lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent, lcPartSelectio
|
|||
setWordWrap(false);
|
||||
setDragEnabled(true);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
setAutoScroll(false);
|
||||
|
||||
mListModel = new lcPartSelectionListModel(this);
|
||||
setModel(mListModel);
|
||||
|
@ -585,6 +586,11 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
|
|||
|
||||
void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
|
||||
{
|
||||
QModelIndex CurrentIndex = currentIndex();
|
||||
|
||||
if (CurrentIndex.isValid())
|
||||
mLastCategoryRow[{mCategoryType, mCategoryIndex}] = CurrentIndex.row();
|
||||
|
||||
mCategoryType = Type;
|
||||
mCategoryIndex = Index;
|
||||
|
||||
|
@ -610,7 +616,26 @@ void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
|
|||
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)
|
||||
|
|
|
@ -247,6 +247,7 @@ protected:
|
|||
PieceInfo* mContextInfo = nullptr;
|
||||
lcPartCategoryType mCategoryType = lcPartCategoryType::AllParts;
|
||||
int mCategoryIndex = 0;
|
||||
std::map<std::pair<lcPartCategoryType, int>, int> mLastCategoryRow;
|
||||
};
|
||||
|
||||
class lcPartSelectionWidget : public QWidget
|
||||
|
|
Loading…
Reference in a new issue