mirror of
https://github.com/leozide/leocad
synced 2024-12-25 21:58:23 +01:00
Filter categories
This commit is contained in:
parent
697e89b129
commit
3db496d1ef
4 changed files with 53 additions and 0 deletions
|
@ -727,11 +727,29 @@ 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, 6, 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);
|
||||
|
||||
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 +787,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 +874,30 @@ 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;
|
||||
mCategoriesWidget->setUpdatesEnabled(false);
|
||||
for (int CategoryIdx = 0; CategoryIdx < mCategoriesWidget->topLevelItemCount(); CategoryIdx++)
|
||||
{
|
||||
QTreeWidgetItem* CategoryItem = mCategoriesWidget->topLevelItem(CategoryIdx);
|
||||
Hide = false;
|
||||
if (!CategoryItem->text(0).contains(Text, Qt::CaseInsensitive))
|
||||
Hide = true;
|
||||
CategoryItem->setHidden(Hide);
|
||||
}
|
||||
mCategoriesWidget->setUpdatesEnabled(true);
|
||||
mCategoriesWidget->update();
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterChanged(const QString& Text)
|
||||
{
|
||||
if (mFilterAction)
|
||||
|
@ -868,6 +911,11 @@ void lcPartSelectionWidget::FilterChanged(const QString& Text)
|
|||
mPartsWidget->GetListModel()->SetFilter(Text);
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterCategoriesTriggered()
|
||||
{
|
||||
mFilterCategoriesWidget->clear();
|
||||
}
|
||||
|
||||
void lcPartSelectionWidget::FilterTriggered()
|
||||
{
|
||||
mFilterWidget->clear();
|
||||
|
|
|
@ -230,7 +230,9 @@ public slots:
|
|||
protected slots:
|
||||
void DockLocationChanged(Qt::DockWidgetArea Area);
|
||||
void FilterChanged(const QString& Text);
|
||||
void FilterCategoriesChanged(const QString& Text);
|
||||
void FilterTriggered();
|
||||
void FilterCategoriesTriggered();
|
||||
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
|
||||
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
|
||||
void OptionsMenuAboutToShow();
|
||||
|
@ -244,6 +246,8 @@ protected:
|
|||
bool event(QEvent* Event) override;
|
||||
|
||||
QTreeWidget* mCategoriesWidget;
|
||||
QLineEdit* mFilterCategoriesWidget;
|
||||
QAction* mFilterCategoriesAction;
|
||||
QLineEdit* mFilterWidget;
|
||||
QAction* mFilterAction;
|
||||
lcPartSelectionListView* mPartsWidget;
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
<file>resources/file_print.png</file>
|
||||
<file>resources/file_print_preview.png</file>
|
||||
<file>resources/file_save.png</file>
|
||||
<file>resources/filter.png</file>
|
||||
<file>resources/time_first.png</file>
|
||||
<file>resources/time_last.png</file>
|
||||
<file>resources/time_next.png</file>
|
||||
|
|
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