mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Added favorite parts category.
This commit is contained in:
parent
9fe520c56a
commit
17a230c52a
6 changed files with 137 additions and 3 deletions
|
@ -1827,7 +1827,7 @@ void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcPiecesLibrary::GetParts(lcArray<PieceInfo*>& Parts)
|
void lcPiecesLibrary::GetParts(lcArray<PieceInfo*>& Parts) const
|
||||||
{
|
{
|
||||||
Parts.SetSize(0);
|
Parts.SetSize(0);
|
||||||
Parts.AllocGrow(mPieces.size());
|
Parts.AllocGrow(mPieces.size());
|
||||||
|
@ -1836,6 +1836,72 @@ void lcPiecesLibrary::GetParts(lcArray<PieceInfo*>& Parts)
|
||||||
Parts.Add(PartIt.second);
|
Parts.Add(PartIt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<PieceInfo*> lcPiecesLibrary::GetFavorites() const
|
||||||
|
{
|
||||||
|
QStringList Favorites = lcGetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES);
|
||||||
|
std::vector<PieceInfo*> Parts;
|
||||||
|
Parts.reserve(Favorites.size());
|
||||||
|
|
||||||
|
for (const QString& Favorite : Favorites)
|
||||||
|
{
|
||||||
|
std::map<std::string, PieceInfo*>::const_iterator PartIt = mPieces.find(Favorite.toStdString());
|
||||||
|
|
||||||
|
if (PartIt != mPieces.end())
|
||||||
|
Parts.push_back(PartIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lcPiecesLibrary::IsFavorite(const PieceInfo* Info) const
|
||||||
|
{
|
||||||
|
std::map<std::string, PieceInfo*>::const_iterator PartIt = std::find_if(mPieces.begin(), mPieces.end(), [Info](const std::pair<std::string, PieceInfo*>& PartIt)
|
||||||
|
{
|
||||||
|
return PartIt.second == Info;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (PartIt == mPieces.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QStringList Favorites = lcGetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES);
|
||||||
|
|
||||||
|
return Favorites.contains(QString::fromStdString(PartIt->first));
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcPiecesLibrary::AddToFavorites(const PieceInfo* Info) const
|
||||||
|
{
|
||||||
|
std::map<std::string, PieceInfo*>::const_iterator PartIt = std::find_if(mPieces.begin(), mPieces.end(), [Info](const std::pair<std::string, PieceInfo*>& PartIt)
|
||||||
|
{
|
||||||
|
return PartIt.second == Info;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (PartIt == mPieces.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList Favorites = lcGetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES);
|
||||||
|
|
||||||
|
Favorites.append(QString::fromStdString(PartIt->first));
|
||||||
|
|
||||||
|
lcSetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES, Favorites);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcPiecesLibrary::RemoveFromFavorites(const PieceInfo* Info) const
|
||||||
|
{
|
||||||
|
std::map<std::string, PieceInfo*>::const_iterator PartIt = std::find_if(mPieces.begin(), mPieces.end(), [Info](const std::pair<std::string, PieceInfo*>& PartIt)
|
||||||
|
{
|
||||||
|
return PartIt.second == Info;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (PartIt == mPieces.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList Favorites = lcGetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES);
|
||||||
|
|
||||||
|
Favorites.removeOne(QString::fromStdString(PartIt->first));
|
||||||
|
|
||||||
|
lcSetProfileStringList(LC_PROFILE_LIBRARY_FAVORITES, Favorites);
|
||||||
|
}
|
||||||
|
|
||||||
bool lcPiecesLibrary::LoadBuiltinPieces()
|
bool lcPiecesLibrary::LoadBuiltinPieces()
|
||||||
{
|
{
|
||||||
QResource Resource(":/resources/library.zip");
|
QResource Resource(":/resources/library.zip");
|
||||||
|
|
|
@ -101,7 +101,12 @@ public:
|
||||||
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
||||||
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
||||||
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
|
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
|
||||||
void GetParts(lcArray<PieceInfo*>& Parts);
|
void GetParts(lcArray<PieceInfo*>& Parts) const;
|
||||||
|
|
||||||
|
std::vector<PieceInfo*> GetFavorites() const;
|
||||||
|
bool IsFavorite(const PieceInfo* Info) const;
|
||||||
|
void AddToFavorites(const PieceInfo* Info) const;
|
||||||
|
void RemoveFromFavorites(const PieceInfo* Info) const;
|
||||||
|
|
||||||
void GetPrimitiveFile(lcLibraryPrimitive* Primitive, std::function<void(lcFile& File)> Callback);
|
void GetPrimitiveFile(lcLibraryPrimitive* Primitive, std::function<void(lcFile& File)> Callback);
|
||||||
void GetPieceFile(const char* FileName, std::function<void(lcFile& File)> Callback);
|
void GetPieceFile(const char* FileName, std::function<void(lcFile& File)> Callback);
|
||||||
|
|
|
@ -185,6 +185,26 @@ void lcPartSelectionListModel::SetModelsCategory()
|
||||||
SetFilter(mFilter);
|
SetFilter(mFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcPartSelectionListModel::SetFavoritesCategory()
|
||||||
|
{
|
||||||
|
ClearRequests();
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
|
mParts.clear();
|
||||||
|
|
||||||
|
std::vector<PieceInfo*> Favorites = lcGetPiecesLibrary()->GetFavorites();
|
||||||
|
|
||||||
|
mParts.reserve(Favorites.size());
|
||||||
|
|
||||||
|
for (PieceInfo* Favorite : Favorites)
|
||||||
|
mParts.emplace_back(QPair<PieceInfo*, QPixmap>(Favorite, QPixmap()));
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
|
||||||
|
SetFilter(mFilter);
|
||||||
|
}
|
||||||
|
|
||||||
void lcPartSelectionListModel::SetCurrentModelCategory()
|
void lcPartSelectionListModel::SetCurrentModelCategory()
|
||||||
{
|
{
|
||||||
ClearRequests();
|
ClearRequests();
|
||||||
|
@ -475,6 +495,31 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
|
||||||
{
|
{
|
||||||
QMenu* Menu = new QMenu(this);
|
QMenu* Menu = new QMenu(this);
|
||||||
|
|
||||||
|
QModelIndex Index = indexAt(Pos);
|
||||||
|
if (Index.isValid())
|
||||||
|
{
|
||||||
|
PieceInfo* Info = mListModel->GetPieceInfo(Index.row());
|
||||||
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||||
|
|
||||||
|
if (!Library->IsFavorite(Info))
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu->addSeparator();
|
||||||
|
}
|
||||||
|
|
||||||
if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT)
|
if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT)
|
||||||
{
|
{
|
||||||
QActionGroup* IconGroup = new QActionGroup(Menu);
|
QActionGroup* IconGroup = new QActionGroup(Menu);
|
||||||
|
@ -672,6 +717,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
|
||||||
Layout->addWidget(mSplitter);
|
Layout->addWidget(mSplitter);
|
||||||
setLayout(Layout);
|
setLayout(Layout);
|
||||||
|
|
||||||
|
connect(mPartsWidget, SIGNAL(FavoriteRemoved()), this, SLOT(FavoriteRemoved()));
|
||||||
connect(mPartsWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(PartChanged(const QModelIndex&, const QModelIndex&)));
|
connect(mPartsWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(PartChanged(const QModelIndex&, const QModelIndex&)));
|
||||||
connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&)));
|
connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&)));
|
||||||
connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
|
connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
|
||||||
|
@ -787,10 +833,12 @@ void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidge
|
||||||
ListModel->SetModelsCategory();
|
ListModel->SetModelsCategory();
|
||||||
else if (Current == mCurrentModelCategoryItem)
|
else if (Current == mCurrentModelCategoryItem)
|
||||||
ListModel->SetCurrentModelCategory();
|
ListModel->SetCurrentModelCategory();
|
||||||
|
else if (Current == mFavoritesCategoryItem)
|
||||||
|
ListModel->SetFavoritesCategory();
|
||||||
else if (Current == mAllPartsCategoryItem)
|
else if (Current == mAllPartsCategoryItem)
|
||||||
ListModel->SetCategory(-1);
|
ListModel->SetCategory(-1);
|
||||||
else
|
else
|
||||||
ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current) - 2);
|
ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current) - 3);
|
||||||
|
|
||||||
mPartsWidget->setCurrentIndex(ListModel->index(0, 0));
|
mPartsWidget->setCurrentIndex(ListModel->index(0, 0));
|
||||||
}
|
}
|
||||||
|
@ -803,6 +851,12 @@ void lcPartSelectionWidget::PartChanged(const QModelIndex& Current, const QModel
|
||||||
gMainWindow->SetCurrentPieceInfo(mPartsWidget->GetCurrentPart());
|
gMainWindow->SetCurrentPieceInfo(mPartsWidget->GetCurrentPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcPartSelectionWidget::FavoriteRemoved()
|
||||||
|
{
|
||||||
|
if (mCategoriesWidget->currentItem() == mFavoritesCategoryItem)
|
||||||
|
mPartsWidget->GetListModel()->SetFavoritesCategory();
|
||||||
|
}
|
||||||
|
|
||||||
void lcPartSelectionWidget::Redraw()
|
void lcPartSelectionWidget::Redraw()
|
||||||
{
|
{
|
||||||
mPartsWidget->GetListModel()->Redraw();
|
mPartsWidget->GetListModel()->Redraw();
|
||||||
|
@ -829,6 +883,7 @@ void lcPartSelectionWidget::UpdateCategories()
|
||||||
mCategoriesWidget->clear();
|
mCategoriesWidget->clear();
|
||||||
|
|
||||||
mAllPartsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("All Parts")));
|
mAllPartsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("All Parts")));
|
||||||
|
mFavoritesCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Favorites")));
|
||||||
mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use")));
|
mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use")));
|
||||||
|
|
||||||
for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++)
|
for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++)
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
void ToggleListMode();
|
void ToggleListMode();
|
||||||
void SetCategory(int CategoryIndex);
|
void SetCategory(int CategoryIndex);
|
||||||
void SetModelsCategory();
|
void SetModelsCategory();
|
||||||
|
void SetFavoritesCategory();
|
||||||
void SetCurrentModelCategory();
|
void SetCurrentModelCategory();
|
||||||
void SetFilter(const QString& Filter);
|
void SetFilter(const QString& Filter);
|
||||||
void RequestPreview(int InfoIndex);
|
void RequestPreview(int InfoIndex);
|
||||||
|
@ -131,6 +132,9 @@ public:
|
||||||
|
|
||||||
void UpdateViewMode();
|
void UpdateViewMode();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void FavoriteRemoved();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void CustomContextMenuRequested(QPoint Pos);
|
void CustomContextMenuRequested(QPoint Pos);
|
||||||
void SetNoIcons();
|
void SetNoIcons();
|
||||||
|
@ -176,6 +180,7 @@ protected slots:
|
||||||
void FilterTriggered();
|
void FilterTriggered();
|
||||||
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
|
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
|
||||||
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
|
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
|
||||||
|
void FavoriteRemoved();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void resizeEvent(QResizeEvent* Event);
|
virtual void resizeEvent(QResizeEvent* Event);
|
||||||
|
@ -183,6 +188,7 @@ protected:
|
||||||
|
|
||||||
QTreeWidget* mCategoriesWidget;
|
QTreeWidget* mCategoriesWidget;
|
||||||
QTreeWidgetItem* mAllPartsCategoryItem;
|
QTreeWidgetItem* mAllPartsCategoryItem;
|
||||||
|
QTreeWidgetItem* mFavoritesCategoryItem;
|
||||||
QTreeWidgetItem* mCurrentModelCategoryItem;
|
QTreeWidgetItem* mCurrentModelCategoryItem;
|
||||||
QTreeWidgetItem* mModelsCategoryItem;
|
QTreeWidgetItem* mModelsCategoryItem;
|
||||||
QLineEdit* mFilterWidget;
|
QLineEdit* mFilterWidget;
|
||||||
|
|
|
@ -77,6 +77,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
|
||||||
lcProfileEntry("Settings", "CheckUpdates", 1), // LC_PROFILE_CHECK_UPDATES
|
lcProfileEntry("Settings", "CheckUpdates", 1), // LC_PROFILE_CHECK_UPDATES
|
||||||
lcProfileEntry("Settings", "ProjectsPath", ""), // LC_PROFILE_PROJECTS_PATH
|
lcProfileEntry("Settings", "ProjectsPath", ""), // LC_PROFILE_PROJECTS_PATH
|
||||||
lcProfileEntry("Settings", "PartsLibrary", ""), // LC_PROFILE_PARTS_LIBRARY
|
lcProfileEntry("Settings", "PartsLibrary", ""), // LC_PROFILE_PARTS_LIBRARY
|
||||||
|
lcProfileEntry("Settings", "LibraryFavorites", QStringList()), // LC_PROFILE_LIBRARY_FAVORITES
|
||||||
lcProfileEntry("Settings", "MinifigSettings", ""), // LC_PROFILE_MINIFIG_SETTINGS
|
lcProfileEntry("Settings", "MinifigSettings", ""), // LC_PROFILE_MINIFIG_SETTINGS
|
||||||
lcProfileEntry("Settings", "ColorConfig", ""), // LC_PROFILE_COLOR_CONFIG
|
lcProfileEntry("Settings", "ColorConfig", ""), // LC_PROFILE_COLOR_CONFIG
|
||||||
lcProfileEntry("Settings", "Shortcuts"), // LC_PROFILE_KEYBOARD_SHORTCUTS
|
lcProfileEntry("Settings", "Shortcuts"), // LC_PROFILE_KEYBOARD_SHORTCUTS
|
||||||
|
|
|
@ -25,6 +25,7 @@ enum LC_PROFILE_KEY
|
||||||
LC_PROFILE_CHECK_UPDATES,
|
LC_PROFILE_CHECK_UPDATES,
|
||||||
LC_PROFILE_PROJECTS_PATH,
|
LC_PROFILE_PROJECTS_PATH,
|
||||||
LC_PROFILE_PARTS_LIBRARY,
|
LC_PROFILE_PARTS_LIBRARY,
|
||||||
|
LC_PROFILE_LIBRARY_FAVORITES,
|
||||||
LC_PROFILE_MINIFIG_SETTINGS,
|
LC_PROFILE_MINIFIG_SETTINGS,
|
||||||
LC_PROFILE_COLOR_CONFIG,
|
LC_PROFILE_COLOR_CONFIG,
|
||||||
LC_PROFILE_KEYBOARD_SHORTCUTS,
|
LC_PROFILE_KEYBOARD_SHORTCUTS,
|
||||||
|
|
Loading…
Reference in a new issue