From 4f19efcdb706c38083f6178acf6cd63150ff10a0 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 10:05:38 +0800 Subject: [PATCH 1/6] fix: remove some tabText() in groupWidget rename group --- src/ui/groups_widgets.cc | 21 ++++++++++++--------- src/ui/groups_widgets.hh | 9 +++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index c23975bf..a29def91 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -29,7 +29,8 @@ DictGroupWidget::DictGroupWidget( QWidget * parent, vector< sptr< Dictionary::Class > > const & dicts, Config::Group const & group ): QWidget( parent ), - groupId( group.id ) + groupId( group.id ), + groupName( group.name ) { ui.setupUi( this ); ui.dictionaries->populate( Instances::Group( group, dicts, Config::Group() ).dictionaries, dicts ); @@ -139,6 +140,7 @@ Config::Group DictGroupWidget::makeGroup() const g.favoritesFolder = ui.favoritesFolder->text().replace( '\\', '/' ); + g.name = groupName; return g.makeConfigGroup(); } @@ -558,8 +560,7 @@ void DictGroupsWidget::populate( Config::Groups const & groups, connect( gr, &DictGroupWidget::showDictionaryInfo, this, &DictGroupsWidget::showDictionaryInfo ); connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - QString toolTipStr = - "\"" + tabText( x ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( x ) ); + QString toolTipStr = tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( x ) ); setTabToolTip( x, toolTipStr ); } @@ -577,7 +578,6 @@ Config::Groups DictGroupsWidget::makeGroups() const for ( int x = 0; x < count(); ++x ) { result.push_back( dynamic_cast< DictGroupWidget & >( *widget( x ) ).makeGroup() ); - result.back().name = Utils::unescapeAmps( tabText( x ) ); } return result; @@ -655,8 +655,7 @@ int DictGroupsWidget::addNewGroup( QString const & name ) connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - const QString toolTipStr = - "\"" + tabText( idx ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( idx ) ); + const QString toolTipStr = tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( idx ) ); setTabToolTip( idx, toolTipStr ); return idx; } @@ -916,7 +915,9 @@ QString DictGroupsWidget::getCurrentGroupName() const const int current = currentIndex(); if ( current >= 0 ) { - return Utils::unescapeAmps( tabText( current ) ); + auto widget = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + + return widget.name(); } return {}; @@ -927,6 +928,8 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name ) const int current = currentIndex(); if ( current >= 0 ) { + auto widget = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + widget->setName( name ); setTabText( current, Utils::escapeAmps( name ) ); } } @@ -971,7 +974,7 @@ void DictGroupsWidget::combineGroups( int source, int target ) connect( model, &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - const QString toolTipStr = "\"" + tabText( target ) + "\"\n" + tr( "Dictionaries: " ) + const QString toolTipStr = tr( "Dictionaries: " ) + QString::number( model->getCurrentDictionaries().size() ); setTabToolTip( target, toolTipStr ); } @@ -1124,7 +1127,7 @@ void DictGroupsWidget::contextMenu( QPoint const & pos ) void DictGroupsWidget::tabDataChanged() { - const QString toolTipStr = "\"" + tabText( currentIndex() ) + "\"\n" + tr( "Dictionaries: " ) + const QString toolTipStr = tr( "Dictionaries: " ) + QString::number( getCurrentModel()->getCurrentDictionaries().size() ); setTabToolTip( currentIndex(), toolTipStr ); } diff --git a/src/ui/groups_widgets.hh b/src/ui/groups_widgets.hh index 4c28974a..efde6c81 100644 --- a/src/ui/groups_widgets.hh +++ b/src/ui/groups_widgets.hh @@ -136,6 +136,14 @@ public: return ui.dictionaries->selectionModel(); } + QString name(){ + return groupName; + } + + void setName( const QString & name ){ + groupName = name; + } + private slots: void groupIconActivated( int ); @@ -145,6 +153,7 @@ private slots: private: Ui::DictGroupWidget ui; unsigned groupId; + QString groupName; signals: void showDictionaryInfo( QString const & id ); From 1754ce2023676f05246e7080c831efb6e8aca574 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:36:03 +0000 Subject: [PATCH 2/6] [autofix.ci] apply automated fixes --- src/ui/groups_widgets.cc | 9 ++++----- src/ui/groups_widgets.hh | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index a29def91..dd07b7f3 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -916,7 +916,7 @@ QString DictGroupsWidget::getCurrentGroupName() const if ( current >= 0 ) { auto widget = dynamic_cast< DictGroupWidget & >( *widget( x ) ); - + return widget.name(); } @@ -974,8 +974,7 @@ void DictGroupsWidget::combineGroups( int source, int target ) connect( model, &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - const QString toolTipStr = tr( "Dictionaries: " ) - + QString::number( model->getCurrentDictionaries().size() ); + const QString toolTipStr = tr( "Dictionaries: " ) + QString::number( model->getCurrentDictionaries().size() ); setTabToolTip( target, toolTipStr ); } @@ -1127,8 +1126,8 @@ void DictGroupsWidget::contextMenu( QPoint const & pos ) void DictGroupsWidget::tabDataChanged() { - const QString toolTipStr = tr( "Dictionaries: " ) - + QString::number( getCurrentModel()->getCurrentDictionaries().size() ); + const QString toolTipStr = + tr( "Dictionaries: " ) + QString::number( getCurrentModel()->getCurrentDictionaries().size() ); setTabToolTip( currentIndex(), toolTipStr ); } diff --git a/src/ui/groups_widgets.hh b/src/ui/groups_widgets.hh index efde6c81..9d4fc099 100644 --- a/src/ui/groups_widgets.hh +++ b/src/ui/groups_widgets.hh @@ -136,11 +136,13 @@ public: return ui.dictionaries->selectionModel(); } - QString name(){ + QString name() + { return groupName; } - void setName( const QString & name ){ + void setName( const QString & name ) + { groupName = name; } From 6c0cedb3ec0ccbc209a9ef6e95a6c90b85a7c9b1 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 10:43:21 +0800 Subject: [PATCH 3/6] fix: remove some tabText() in groupWidget rename group --- src/ui/groups_widgets.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index dd07b7f3..b5d55a69 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -915,9 +915,9 @@ QString DictGroupsWidget::getCurrentGroupName() const const int current = currentIndex(); if ( current >= 0 ) { - auto widget = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + auto w = dynamic_cast< DictGroupWidget & >( *widget( x ) ); - return widget.name(); + return w.name(); } return {}; @@ -928,8 +928,8 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name ) const int current = currentIndex(); if ( current >= 0 ) { - auto widget = dynamic_cast< DictGroupWidget & >( *widget( x ) ); - widget->setName( name ); + auto w = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + w->setName( name ); setTabText( current, Utils::escapeAmps( name ) ); } } From 5ef4190b75d0f284f68eb375ed7892f94e00cf8a Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 10:51:57 +0800 Subject: [PATCH 4/6] fix: remove some tabText() in groupWidget rename group --- src/ui/groups_widgets.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index b5d55a69..824e9330 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -915,7 +915,7 @@ QString DictGroupsWidget::getCurrentGroupName() const const int current = currentIndex(); if ( current >= 0 ) { - auto w = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + auto w = dynamic_cast< DictGroupWidget & >( *widget( current ) ); return w.name(); } @@ -928,7 +928,7 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name ) const int current = currentIndex(); if ( current >= 0 ) { - auto w = dynamic_cast< DictGroupWidget & >( *widget( x ) ); + auto w = dynamic_cast< DictGroupWidget & >( *widget( current ) ); w->setName( name ); setTabText( current, Utils::escapeAmps( name ) ); } From 5954a5ce2a841c9c565e91cdad96edb9559edd13 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Mon, 4 Nov 2024 21:04:46 +0800 Subject: [PATCH 5/6] 1 --- src/ui/groups_widgets.cc | 9 ++++----- src/ui/groups_widgets.hh | 3 --- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index 824e9330..a50612f2 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -648,6 +648,7 @@ int DictGroupsWidget::addNewGroup( QString const & name ) Config::Group newGroup; newGroup.id = nextId++; + newGroup.name = name; const auto gr = new DictGroupWidget( this, *allDicts, newGroup ); const int idx = insertTab( currentIndex() + 1, gr, Utils::escapeAmps( name ) ); @@ -909,15 +910,13 @@ void DictGroupsWidget::groupsByMetadata() addGroupBasedOnMap( groupToDicts ); } - QString DictGroupsWidget::getCurrentGroupName() const { const int current = currentIndex(); if ( current >= 0 ) { - auto w = dynamic_cast< DictGroupWidget & >( *widget( current ) ); - - return w.name(); + auto * w = dynamic_cast< DictGroupWidget * >( widget( current ) ); + return w->name(); } return {}; @@ -928,7 +927,7 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name ) const int current = currentIndex(); if ( current >= 0 ) { - auto w = dynamic_cast< DictGroupWidget & >( *widget( current ) ); + auto * w = dynamic_cast< DictGroupWidget * >( widget( current ) ); w->setName( name ); setTabText( current, Utils::escapeAmps( name ) ); } diff --git a/src/ui/groups_widgets.hh b/src/ui/groups_widgets.hh index 9d4fc099..d41c6c59 100644 --- a/src/ui/groups_widgets.hh +++ b/src/ui/groups_widgets.hh @@ -121,9 +121,6 @@ class DictGroupWidget: public QWidget public: DictGroupWidget( QWidget * parent, std::vector< sptr< Dictionary::Class > > const &, Config::Group const & ); - /// Makes the group's configuration out of the data currently held. - /// Since the group's name is not part of the widget by design right now - /// (it is known by the containing tab widget only), it is returned as empty. Config::Group makeGroup() const; DictListModel * getModel() const From 488eda61e44e42f490f902536359798418de089d Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:40:47 +0800 Subject: [PATCH 6/6] Update src/ui/groups_widgets.cc Co-authored-by: shenleban tongying --- src/ui/groups_widgets.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index a50612f2..da311943 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -915,7 +915,7 @@ QString DictGroupsWidget::getCurrentGroupName() const const int current = currentIndex(); if ( current >= 0 ) { - auto * w = dynamic_cast< DictGroupWidget * >( widget( current ) ); + auto * w = qobject_cast< DictGroupWidget * >( widget( current ) ); return w->name(); }