From 3db496d1eff99df36e99dcc53258498827f5a069 Mon Sep 17 00:00:00 2001 From: Trevor SANDY Date: Tue, 18 Apr 2023 00:59:12 +0200 Subject: [PATCH 1/2] Filter categories --- common/lc_partselectionwidget.cpp | 48 ++++++++++++++++++++++++++++++ common/lc_partselectionwidget.h | 4 +++ leocad.qrc | 1 + resources/filter.png | Bin 0 -> 1642 bytes 4 files changed, 53 insertions(+) create mode 100644 resources/filter.png diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 4f984317..9b9efbc6 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -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(); diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 6bba9189..1f97ab4b 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -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; diff --git a/leocad.qrc b/leocad.qrc index 0a3567ec..75d84a9d 100644 --- a/leocad.qrc +++ b/leocad.qrc @@ -78,6 +78,7 @@ resources/file_print.png resources/file_print_preview.png resources/file_save.png + resources/filter.png resources/time_first.png resources/time_last.png resources/time_next.png diff --git a/resources/filter.png b/resources/filter.png new file mode 100644 index 0000000000000000000000000000000000000000..dc486c4401583131e9cd9ce18549a120840e0fbf GIT binary patch literal 1642 zcmV-w29^1VP)jFOf~ zTd2@L`4MnQi~VCQ-EK>}J3Bi+*K_a8mTjT1Z9;GM?A)2Td(L;x`Odj_8Rr~~F%%58 z^^-%}I8*Crx(14}hI1BU3ag=|cOFcB{NeFF#`p+0k282zJli^CeDV58dNV}}3jiov zKl=4$greWY%EFb^u_$U{rKqkbMM+3StW-xV8YZ0_9{pZw@I1N?w6VN02KqpuuT6%#K1@zgQF%!)42q!iT7GQf2~Pq(E=c07A`xu>xH!_i)c7AFotBthH*ZD zkftFqVZ(ufu&yH%(&(9va7c&-m8r~P8)y1cNM~(~n*Cc^7DK+}h>V(|JfhHh9m z-8&*ZzM3>)k|!Sd0*TQK-rc%t3U9SS26M?R4`Zf>ix%aPyijGB34}@j9G5&L zv0XTBFn7e*e!hME#A3@flb-&1}QpA5GE zq|qcVJ|`6Ds^G{?(E|~wU@|CNR*g=nD=hnb1h_kqG=A*3R{zyYEAiq=4Od283}rn0 zmvKRS!Z>~99O3|xE=k@L_5`6%DG*6U;)IB1jv_N*+SuK&N=EU^!+%2`Pa64tknaQK zG+*`9`}_CRKHX6N&XyHeMn%%vXQ5_+Pw|Qp1tu9zlR}fylg^Q1%f)!sA<5we85yIx zw``FHQI0Mwv5sW><_BaN_x*7hdTPLE`{wOkq_l@*JP$xbVj;#D&&oqv=#1DO2(2VjVeGUvm3-KR z=c+FcE-EE@Go1M6I+9l|lJV^`8ZWGZ+ik9ba}|P^n|2@Av;LW9>z}BtBGnveQDU;u z_ z&40ESt*7x^4INM@A!C^=HpV=h>b#6|?QJcyG4A)^yPmVAaAFb3hRq)z=Ho8spB*3L z+kc7k-jOt~`}BxVv>{ld7OPZ4@gpCJh#>6^8$NmIlgv1IA`cbq`7BZ}9fTzs4YmDX zhZN^OTW&(~-7JjH1;FHw#+_hqCrO#kOr?Bp0Ej{7)XD8voPOCH^~@~-yJ0b%QS6pg!F4=1=cVQgK)#cTzgQ(f oWYXf;I6F!gzZcw-@xK5A02AOnNFlAraR2}S07*qoM6N<$g4pH&>;M1& literal 0 HcmV?d00001 From 7908800e149d0bed5c1f83e2f43937a39abd46d4 Mon Sep 17 00:00:00 2001 From: Trevor SANDY Date: Wed, 19 Apr 2023 13:07:46 +0200 Subject: [PATCH 2/2] Add match case button --- common/lc_partselectionwidget.cpp | 22 ++++++++++++++++++++-- common/lc_partselectionwidget.h | 2 ++ leocad.qrc | 5 +++-- resources/case.png | Bin 0 -> 1031 bytes 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 resources/case.png diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 9b9efbc6..51570adc 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -734,7 +734,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) CategoriesGroupWidget->setLayout(CategoriesLayout); QHBoxLayout* FilterCategoriesLayout = new QHBoxLayout(); - FilterCategoriesLayout->setContentsMargins(0, 0, 6, 0); + FilterCategoriesLayout->setContentsMargins(0, 0, 0, 0); CategoriesLayout->addLayout(FilterCategoriesLayout); mFilterCategoriesWidget = new QLineEdit(CategoriesGroupWidget); @@ -743,6 +743,17 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) 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); @@ -885,12 +896,13 @@ void lcPartSelectionWidget::FilterCategoriesChanged(const QString& Text) } 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, Qt::CaseInsensitive)) + if (!CategoryItem->text(0).contains(Text, MatchCase)) Hide = true; CategoryItem->setHidden(Hide); } @@ -916,6 +928,12 @@ void lcPartSelectionWidget::FilterCategoriesTriggered() mFilterCategoriesWidget->clear(); } +void lcPartSelectionWidget::FilterCaseTriggered() +{ + if (!mFilterCategoriesWidget->text().isEmpty()) + FilterCategoriesChanged(mFilterCategoriesWidget->text()); +} + void lcPartSelectionWidget::FilterTriggered() { mFilterWidget->clear(); diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 1f97ab4b..bda09014 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -232,6 +232,7 @@ protected slots: 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); @@ -248,6 +249,7 @@ protected: QTreeWidget* mCategoriesWidget; QLineEdit* mFilterCategoriesWidget; QAction* mFilterCategoriesAction; + QAction* mFilterCaseAction; QLineEdit* mFilterWidget; QAction* mFilterAction; lcPartSelectionListView* mPartsWidget; diff --git a/leocad.qrc b/leocad.qrc index 75d84a9d..c5ebff8f 100644 --- a/leocad.qrc +++ b/leocad.qrc @@ -78,7 +78,6 @@ resources/file_print.png resources/file_print_preview.png resources/file_save.png - resources/filter.png resources/time_first.png resources/time_last.png resources/time_next.png @@ -135,7 +134,9 @@ resources/shaders/unlit_vertex_color_vs.glsl resources/shaders/unlit_view_sphere_ps.glsl resources/shaders/unlit_view_sphere_vs.glsl - resources/gear_in.png + resources/case.png + resources/filter.png resources/flexible.png + resources/gear_in.png diff --git a/resources/case.png b/resources/case.png new file mode 100644 index 0000000000000000000000000000000000000000..9c24a2d44dc1ac43eab9db75065fc2e5aa8e2f07 GIT binary patch literal 1031 zcmV+i1o-=jP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1Dr`jK~z{r?NwW7 zR7V(|bLO1vg_@0pCIx9h1BHmU286!#!Paaet%BfP0>zgiB^VKeK9<^-ltuBWAU082 zrM{@BMDf9=AjV4(L9&YRW!+{sn{3YJT=sIN-#?j+i9LGaL&(d1@GGXNnY{s^k<2cN+N{i$`Dy1_#bskm(DQ;fd#YB-t8_J$KPJ4TBkmk%HY9jYcquF>dfX zn06KA=wGp-S(c2zIhS%1so$0Cmfu550JOvFDKcV}N@b4Kd3~Y>RZuRL&*!@KAL!{% zBwEz;#UoIGbAx}#7SQs!oTw{6Y8a-;49=wj8#Zp7b<(ususf^Os)@v6=uhG^%}YQP zU+3K7x~_e_HMv*$QzH?Wz8`ouH|Fh38dT zQS$GjxG6EH1i$TNukx814@6iA4uKaC=p^l&q{mgnE_pXLa~We7!8kb*@O_IAem{QK zlq?RQ_yLOas^LHcmSCyzUWah0(MX_y29_C&{Rbtp?-txem=yp3002ovPDHLkV1fYA B^m+gQ literal 0 HcmV?d00001