From b1ed33ac3fadb45875f71c6aaadab8f22a36d049 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 6 Jan 2015 15:17:29 +0000 Subject: [PATCH] Changed parts search to be just a simple substring search. --- common/lc_library.cpp | 37 +++++++++++++++++++++++++++++++----- common/lc_library.h | 3 ++- qt/lc_qpartstree.cpp | 6 ++---- qt/lc_qpreferencesdialog.cpp | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/common/lc_library.cpp b/common/lc_library.cpp index 07094170..5124d8bc 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -1887,13 +1887,10 @@ bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const String& CategoryKey void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) { - if (gCategories[CategoryIndex].Name == "Search Results") - GroupPieces = false; - - SearchPieces(gCategories[CategoryIndex].Keywords, GroupPieces, SinglePieces, GroupedPieces); + GetCategoryEntries(gCategories[CategoryIndex].Keywords, GroupPieces, SinglePieces, GroupedPieces); } -void lcPiecesLibrary::SearchPieces(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) +void lcPiecesLibrary::GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) { SinglePieces.RemoveAll(); GroupedPieces.RemoveAll(); @@ -1953,6 +1950,36 @@ void lcPiecesLibrary::SearchPieces(const String& CategoryKeywords, bool GroupPie } } +void lcPiecesLibrary::SearchPieces(const char* Keyword, lcArray& Pieces) const +{ + Pieces.RemoveAll(); + + String LowerKeyword = Keyword; + LowerKeyword.MakeLower(); + + for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) + { + PieceInfo* Info = mPieces[PieceIdx]; + + char LowerName[sizeof(Info->m_strName)]; + strcpy(LowerName, Info->m_strName); + strlwr(LowerName); + + if (strstr(LowerName, LowerKeyword)) + { + Pieces.Add(Info); + continue; + } + + char LowerDescription[sizeof(Info->m_strDescription)]; + strcpy(LowerDescription, Info->m_strDescription); + strlwr(LowerDescription); + + if (strstr(LowerDescription, LowerKeyword)) + Pieces.Add(Info); + } +} + void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray& Pieces) const { char Name[LC_PIECE_NAME_LEN]; diff --git a/common/lc_library.h b/common/lc_library.h index 33655b4d..4d4b22d9 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -130,8 +130,9 @@ public: void CloseCache(); bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const; - void SearchPieces(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); + void SearchPieces(const char* Keyword, lcArray& Pieces) const; void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); + void GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); void GetPatternedPieces(PieceInfo* Parent, lcArray& Pieces) const; void SetOfficialPieces() diff --git a/qt/lc_qpartstree.cpp b/qt/lc_qpartstree.cpp index e8680d6e..ade0f69c 100644 --- a/qt/lc_qpartstree.cpp +++ b/qt/lc_qpartstree.cpp @@ -117,10 +117,8 @@ void lcQPartsTree::searchParts(const QString& searchString) while (QTreeWidgetItem* Item = mSearchResultsItem->child(0)) delete Item; - lcPiecesLibrary* library = lcGetPiecesLibrary(); - lcArray singleParts, groupedParts; - - library->SearchPieces(searchString.toLocal8Bit().data(), false, singleParts, groupedParts); + lcArray singleParts; + lcGetPiecesLibrary()->SearchPieces(searchString.toLocal8Bit().data(), singleParts); singleParts.Sort(lcQPartsTreeSortFunc); for (int partIndex = 0; partIndex < singleParts.GetSize(); partIndex++) diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index 1fd3e9a5..cbaa71b6 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -244,7 +244,7 @@ void lcQPreferencesDialog::updateParts() { lcArray singleParts, groupedParts; - library->SearchPieces(options->Categories[categoryIndex].Keywords, false, singleParts, groupedParts); + library->GetCategoryEntries(options->Categories[categoryIndex].Keywords, false, singleParts, groupedParts); for (int partIndex = 0; partIndex < singleParts.GetSize(); partIndex++) {