Added 'All Parts' category.

This commit is contained in:
Leonardo Zide 2017-01-31 21:12:30 -08:00
parent e7fe26d2a4
commit e766f7892e
6 changed files with 37 additions and 6 deletions

View file

@ -2598,6 +2598,11 @@ void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>&
}
}
void lcPiecesLibrary::GetParts(lcArray<PieceInfo*>& Parts)
{
Parts = mPieces;
}
bool lcPiecesLibrary::LoadBuiltinPieces()
{
QResource Resource(":/resources/library.zip");

View file

@ -152,6 +152,7 @@ public:
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
void GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
void GetParts(lcArray<PieceInfo*>& Parts);
bool IsPrimitive(const char* Name) const
{

View file

@ -127,7 +127,10 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
lcPiecesLibrary* Library = lcGetPiecesLibrary();
lcArray<PieceInfo*> SingleParts, GroupedParts;
if (CategoryIndex != -1)
Library->GetCategoryEntries(CategoryIndex, false, SingleParts, GroupedParts);
else
Library->GetParts(SingleParts);
SingleParts.Sort(lcPartSortFunc);
mParts.resize(SingleParts.GetSize());
@ -481,7 +484,7 @@ void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)
}
lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
: QWidget(Parent)
: QWidget(Parent), mFilterAction(NULL)
{
mSplitter = new QSplitter(this);
@ -504,7 +507,8 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
mFilterWidget = new QLineEdit(PartsGroupWidget);
mFilterWidget->setPlaceholderText(tr("Search Parts"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
mFilterWidget->addAction(QIcon(":/resources/parts_search.png"), QLineEdit::LeadingPosition);
mFilterAction = mFilterWidget->addAction(QIcon(":/resources/parts_search.png"), QLineEdit::TrailingPosition);
connect(mFilterAction, SIGNAL(triggered()), this, SLOT(FilterTriggered()));
#endif
PartsLayout->addWidget(mFilterWidget);
@ -519,7 +523,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
setLayout(Layout);
connect(mPartsWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(PartChanged(const QModelIndex&, const QModelIndex&)));
connect(mFilterWidget, SIGNAL(textEdited(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*)));
UpdateCategories();
@ -537,9 +541,22 @@ void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event)
void lcPartSelectionWidget::FilterChanged(const QString& Text)
{
if (mFilterAction)
{
if (Text.isEmpty())
mFilterAction->setIcon(QIcon(":/resources/parts_search.png"));
else
mFilterAction->setIcon(QIcon(":/resources/parts_cancel.png"));
}
mPartsWidget->GetFilterModel()->SetFilter(Text);
}
void lcPartSelectionWidget::FilterTriggered()
{
mFilterWidget->clear();
}
void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous)
{
Q_UNUSED(Previous);
@ -549,8 +566,10 @@ void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidge
ListModel->SetModelsCategory();
else if (Current == mCurrentModelCategoryItem)
ListModel->SetCurrentModelCategory();
else if (Current == mAllPartsCategoryItem)
ListModel->SetCategory(-1);
else
ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current));
ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current) - 2);
mPartsWidget->setCurrentIndex(mPartsWidget->GetFilterModel()->index(0, 0));
}
@ -588,10 +607,12 @@ void lcPartSelectionWidget::UpdateCategories()
mCategoriesWidget->clear();
mAllPartsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("All Parts")));
mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use")));
for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++)
new QTreeWidgetItem(mCategoriesWidget, QStringList((const char*)gCategories[CategoryIdx].Name));
mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Current Model")));
mModelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Models")));
if (CurrentIndex != -1)

View file

@ -155,6 +155,7 @@ public:
protected slots:
void FilterChanged(const QString& Text);
void FilterTriggered();
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
@ -162,9 +163,11 @@ protected:
virtual void resizeEvent(QResizeEvent* Event);
QTreeWidget* mCategoriesWidget;
QTreeWidgetItem* mAllPartsCategoryItem;
QTreeWidgetItem* mCurrentModelCategoryItem;
QTreeWidgetItem* mModelsCategoryItem;
QLineEdit* mFilterWidget;
QAction* mFilterAction;
lcPartSelectionListView* mPartsWidget;
QSplitter* mSplitter;
};

View file

@ -89,6 +89,7 @@
<file>resources/piece_show_later.png</file>
<file>resources/time_add_keys.png</file>
<file>resources/parts_search.png</file>
<file>resources/parts_cancel.png</file>
<file>resources/library.zip</file>
<file>resources/minifig.ini</file>
<file>resources/leocad_fr.qm</file>

BIN
resources/parts_cancel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB