mirror of
https://github.com/leozide/leocad
synced 2025-01-13 08:01:38 +01:00
Merge pull request #852 from trevorsandy/FILTER_CATEGORIES
Filter categories
This commit is contained in:
commit
b72248c6a7
5 changed files with 75 additions and 1 deletions
|
@ -727,11 +727,40 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
|
|||
mSplitter->setOrientation(Qt::Vertical);
|
||||
mSplitter->setChildrenCollapsible(false);
|
||||
|
||||
QWidget* CategoriesGroupWidget = new QWidget(mSplitter);
|
||||
|
||||
QVBoxLayout* CategoriesLayout = new QVBoxLayout();
|
||||
CategoriesLayout->setContentsMargins(0, 0, 0, 0);
|
||||
CategoriesGroupWidget->setLayout(CategoriesLayout);
|
||||
|
||||
QHBoxLayout* FilterCategoriesLayout = new QHBoxLayout();
|
||||
FilterCategoriesLayout->setContentsMargins(0, 0, 0, 0);
|
||||
CategoriesLayout->addLayout(FilterCategoriesLayout);
|
||||
|
||||
mFilterCategoriesWidget = new QLineEdit(CategoriesGroupWidget);
|
||||
mFilterCategoriesWidget->setPlaceholderText(tr("Filter Categories"));
|
||||
mFilterCategoriesAction = mFilterCategoriesWidget->addAction(QIcon(":/resources/filter.png"), QLineEdit::TrailingPosition);
|
||||
connect(mFilterCategoriesAction, SIGNAL(triggered()), this, SLOT(FilterCategoriesTriggered()));
|
||||
FilterCategoriesLayout->addWidget(mFilterCategoriesWidget);
|
||||
|
||||
mFilterCaseAction = new QAction();
|
||||
mFilterCaseAction->setIcon(QIcon(":/resources/case.png"));
|
||||
mFilterCaseAction->setToolTip(tr("Match Case"));
|
||||
mFilterCaseAction->setCheckable(true);
|
||||
mFilterCaseAction->setChecked(false);
|
||||
connect(mFilterCaseAction, SIGNAL(triggered()), this, SLOT(FilterCaseTriggered()));
|
||||
|
||||
QToolButton* FilterCaseButton = new QToolButton();
|
||||
FilterCaseButton->setDefaultAction(mFilterCaseAction);
|
||||
FilterCategoriesLayout->addWidget(FilterCaseButton);
|
||||
|
||||
mCategoriesWidget = new QTreeWidget(mSplitter);
|
||||
mCategoriesWidget->setHeaderHidden(true);
|
||||
mCategoriesWidget->setUniformRowHeights(true);
|
||||
mCategoriesWidget->setRootIsDecorated(false);
|
||||
|
||||
CategoriesLayout->addWidget(mCategoriesWidget);
|
||||
|
||||
QWidget* PartsGroupWidget = new QWidget(mSplitter);
|
||||
|
||||
QVBoxLayout* PartsLayout = new QVBoxLayout();
|
||||
|
@ -769,6 +798,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
|
|||
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(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
|
||||
connect(mFilterCategoriesWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterCategoriesChanged(const QString&)));
|
||||
|
||||
LoadPartPalettes();
|
||||
UpdateCategories();
|
||||
|
@ -855,6 +885,31 @@ void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event)
|
|||
QWidget::resizeEvent(Event);
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterCategoriesChanged(const QString& Text)
|
||||
{
|
||||
if (mFilterCategoriesAction)
|
||||
{
|
||||
if (Text.isEmpty())
|
||||
mFilterCategoriesAction->setIcon(QIcon(":/resources/filter.png"));
|
||||
else
|
||||
mFilterCategoriesAction->setIcon(QIcon(":/resources/parts_cancel.png"));
|
||||
}
|
||||
|
||||
bool Hide = true;
|
||||
Qt::CaseSensitivity MatchCase = mFilterCaseAction->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
|
||||
mCategoriesWidget->setUpdatesEnabled(false);
|
||||
for (int CategoryIdx = 0; CategoryIdx < mCategoriesWidget->topLevelItemCount(); CategoryIdx++)
|
||||
{
|
||||
QTreeWidgetItem* CategoryItem = mCategoriesWidget->topLevelItem(CategoryIdx);
|
||||
Hide = false;
|
||||
if (!CategoryItem->text(0).contains(Text, MatchCase))
|
||||
Hide = true;
|
||||
CategoryItem->setHidden(Hide);
|
||||
}
|
||||
mCategoriesWidget->setUpdatesEnabled(true);
|
||||
mCategoriesWidget->update();
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterChanged(const QString& Text)
|
||||
{
|
||||
if (mFilterAction)
|
||||
|
@ -868,6 +923,17 @@ void lcPartSelectionWidget::FilterChanged(const QString& Text)
|
|||
mPartsWidget->GetListModel()->SetFilter(Text);
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterCategoriesTriggered()
|
||||
{
|
||||
mFilterCategoriesWidget->clear();
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterCaseTriggered()
|
||||
{
|
||||
if (!mFilterCategoriesWidget->text().isEmpty())
|
||||
FilterCategoriesChanged(mFilterCategoriesWidget->text());
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterTriggered()
|
||||
{
|
||||
mFilterWidget->clear();
|
||||
|
|
|
@ -230,7 +230,10 @@ public slots:
|
|||
protected slots:
|
||||
void DockLocationChanged(Qt::DockWidgetArea Area);
|
||||
void FilterChanged(const QString& Text);
|
||||
void FilterCategoriesChanged(const QString& Text);
|
||||
void FilterTriggered();
|
||||
void FilterCaseTriggered();
|
||||
void FilterCategoriesTriggered();
|
||||
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
|
||||
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
|
||||
void OptionsMenuAboutToShow();
|
||||
|
@ -244,6 +247,9 @@ protected:
|
|||
bool event(QEvent* Event) override;
|
||||
|
||||
QTreeWidget* mCategoriesWidget;
|
||||
QLineEdit* mFilterCategoriesWidget;
|
||||
QAction* mFilterCategoriesAction;
|
||||
QAction* mFilterCaseAction;
|
||||
QLineEdit* mFilterWidget;
|
||||
QAction* mFilterAction;
|
||||
lcPartSelectionListView* mPartsWidget;
|
||||
|
|
|
@ -134,7 +134,9 @@
|
|||
<file>resources/shaders/unlit_vertex_color_vs.glsl</file>
|
||||
<file>resources/shaders/unlit_view_sphere_ps.glsl</file>
|
||||
<file>resources/shaders/unlit_view_sphere_vs.glsl</file>
|
||||
<file>resources/gear_in.png</file>
|
||||
<file>resources/case.png</file>
|
||||
<file>resources/filter.png</file>
|
||||
<file>resources/flexible.png</file>
|
||||
<file>resources/gear_in.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
BIN
resources/case.png
Normal file
BIN
resources/case.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 KiB |
BIN
resources/filter.png
Normal file
BIN
resources/filter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in a new issue