Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lengyijun committed Feb 18, 2025
1 parent 7202407 commit 87032fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ui/favoritespanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,20 @@ TreeItem * FavoritesModel::findFolderByName( TreeItem * parent, const QString &
return nullptr;
}

bool FavoritesModel::findWordByNameRec( TreeItem * parent, const QString & name)
{
for ( int i = 0; i < parent->childCount(); i++ ) {
TreeItem * child = parent->child( i );
if ( child->type() == TreeItem::Word && child->data().toString() == name ) {
return true;
}
if ( child->type() == TreeItem::Folder && findWordByNameRec(child, name)) {
return true;
}
}
return false;
}

TreeItem * FavoritesModel::getItem( const QModelIndex & index ) const
{
if ( index.isValid() ) {
Expand Down Expand Up @@ -1065,6 +1079,11 @@ bool FavoritesModel::isHeadwordPresent( const QString & path, const QString & he
{
QModelIndex idx;

if (path.isEmpty()) {
// `all`
return findWordByNameRec(getItem(idx), headword);
}

// Find target folder

QStringList folders = path.split( "/", Qt::SkipEmptyParts );
Expand Down
2 changes: 2 additions & 0 deletions src/ui/favoritespanewidget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ protected:
// Find item in folder
QModelIndex findItemInFolder( QString const & itemName, TreeItem::Type itemType, QModelIndex const & parentIdx );

bool findWordByNameRec( TreeItem * parent, const QString & name);

TreeItem * getItem( const QModelIndex & index ) const;

// Find folder with given name or create it if folder not exist
Expand Down

0 comments on commit 87032fd

Please sign in to comment.