From 7b21d4af0be6f6343f972ebe5ed6219a3a5e6c91 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 7 Dec 2019 11:23:50 -0800 Subject: [PATCH] Fixed Qt4 errors. --- common/lc_partselectionwidget.cpp | 49 ++++++++++++++++++++----------- common/lc_partselectionwidget.h | 3 ++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index efdd4793..7b2bb690 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -195,6 +195,13 @@ void lcPartSelectionListModel::SetFavoritesCategory() std::vector Favorites = lcGetPiecesLibrary()->GetFavorites(); + auto lcPartSortFunc = [](const PieceInfo* a, const PieceInfo* b) + { + return strcmp(a->m_strDescription, b->m_strDescription) < 0; + }; + + std::sort(Favorites.begin(), Favorites.end(), lcPartSortFunc); + mParts.reserve(Favorites.size()); for (PieceInfo* Favorite : Favorites) @@ -495,29 +502,22 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos) { QMenu* Menu = new QMenu(this); + mContextInfo = nullptr; QModelIndex Index = indexAt(Pos); + if (Index.isValid()) { - PieceInfo* Info = mListModel->GetPieceInfo(Index.row()); - lcPiecesLibrary* Library = lcGetPiecesLibrary(); + mContextInfo = mListModel->GetPieceInfo(Index.row()); - if (!Library->IsFavorite(Info)) + if (mContextInfo) { - Menu->addAction(tr("Add to Favorites"), [Library, Info]() - { - Library->AddToFavorites(Info); - }); - } - else - { - Menu->addAction(tr("Remove from Favorites"), [this, Library, Info]() - { - Library->RemoveFromFavorites(Info); - emit FavoriteRemoved(); - }); - } + if (!lcGetPiecesLibrary()->IsFavorite(mContextInfo)) + Menu->addAction(tr("Add to Favorites"), this, SLOT(AddToFavorites())); + else + Menu->addAction(tr("Remove from Favorites"), this, SLOT(RemoveFromFavorites())); - Menu->addSeparator(); + Menu->addSeparator(); + } } if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT) @@ -638,6 +638,21 @@ void lcPartSelectionListView::ToggleFixedColor() mListModel->ToggleColorLocked(); } +void lcPartSelectionListView::AddToFavorites() +{ + if (mContextInfo) + lcGetPiecesLibrary()->AddToFavorites(mContextInfo); +} + +void lcPartSelectionListView::RemoveFromFavorites() +{ + if (mContextInfo) + { + lcGetPiecesLibrary()->RemoveFromFavorites(mContextInfo); + emit FavoriteRemoved(); + } +} + void lcPartSelectionListView::UpdateViewMode() { setViewMode(mListModel->GetIconSize() && !mListModel->IsListMode() ? QListView::IconMode : QListView::ListMode); diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index f712f43e..79e69d57 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -147,11 +147,14 @@ public slots: void TogglePartAliases(); void ToggleListMode(); void ToggleFixedColor(); + void AddToFavorites(); + void RemoveFromFavorites(); protected: void SetIconSize(int Size); lcPartSelectionListModel* mListModel; + PieceInfo* mContextInfo; }; class lcPartSelectionWidget : public QWidget