From 7c32cad65af00d7d5ca6a1f4398c20f8533e1b13 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sat, 2 Nov 2024 16:45:13 +0800 Subject: [PATCH] opt: erase the need to removeTabs --- src/ui/editdictionaries.cc | 16 ++++++++-------- src/ui/groups.cc | 21 +++++++++++++++++++++ src/ui/groups.hh | 4 +++- src/ui/orderandprops.cc | 21 +++++++++++++++++++++ src/ui/orderandprops.hh | 4 +++- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/ui/editdictionaries.cc b/src/ui/editdictionaries.cc index 01af97e4..9675e031 100644 --- a/src/ui/editdictionaries.cc +++ b/src/ui/editdictionaries.cc @@ -214,16 +214,16 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) Instances::updateNames( savedInactive, dictionaries ); if ( rebuildGroups ) { - ui.tabs->removeTab( 1 ); - ui.tabs->removeTab( 1 ); + // ui.tabs->removeTab( 1 ); + // ui.tabs->removeTab( 1 ); - orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries ); - groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); + orderAndProps->rebuild( this, savedOrder, savedInactive, dictionaries ); + groups->rebuild( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); - ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); - ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); - connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo ); - connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords ); + // ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); + // ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); + // connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo ); + // connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords ); } setUpdatesEnabled( true ); } diff --git a/src/ui/groups.cc b/src/ui/groups.cc index 09661f3b..ada9cd36 100644 --- a/src/ui/groups.cc +++ b/src/ui/groups.cc @@ -64,6 +64,27 @@ Groups::Groups( QWidget * parent, countChanged(); } +void Groups::rebuild( vector< sptr< Dictionary::Class > > const & dicts_, + Config::Groups const & groups_, + Config::Group const & order ){ + + setUpdatesEnabled( false ); + dicts = dicts_; + groups = groups_; + + ui.dictionaries->setAsSource(); + ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries, dicts ); + + ui.searchLine->applyTo( ui.dictionaries ); + + // Populate groups' widget + + ui.groups->populate( groups, dicts, ui.dictionaries->getCurrentDictionaries() ); + + countChanged(); + setUpdatesEnabled( true ); +} + void Groups::editGroup( unsigned id ) { for ( int x = 0; x < groups.size(); ++x ) { diff --git a/src/ui/groups.hh b/src/ui/groups.hh index b6bbac08..4431afad 100644 --- a/src/ui/groups.hh +++ b/src/ui/groups.hh @@ -18,7 +18,9 @@ public: std::vector< sptr< Dictionary::Class > > const &, Config::Groups const &, Config::Group const & order ); - + void rebuild( vector< sptr< Dictionary::Class > > const & dicts_, + Config::Groups const & groups_, + Config::Group const & order ); /// Instructs the dialog to position itself on editing the given group. void editGroup( unsigned id ); diff --git a/src/ui/orderandprops.cc b/src/ui/orderandprops.cc index 08e5a898..2f28a555 100644 --- a/src/ui/orderandprops.cc +++ b/src/ui/orderandprops.cc @@ -133,6 +133,27 @@ OrderAndProps::OrderAndProps( QWidget * parent, showDictNumbers(); } +void OrderAndProps::rebuild( Config::Group const & dictionaryOrder, + Config::Group const & inactiveDictionaries, + std::vector< sptr< Dictionary::Class > > const & allDictionaries ) +{ + Instances::Group order( dictionaryOrder, allDictionaries, Config::Group() ); + Instances::Group inactive( inactiveDictionaries, allDictionaries, Config::Group() ); + + Instances::complementDictionaryOrder( order, inactive, allDictionaries ); + + setUpdatesEnabled( false ); + ui.dictionaryOrder->populate( order.dictionaries, allDictionaries ); + ui.inactiveDictionaries->populate( inactive.dictionaries, allDictionaries ); + + ui.searchLine->applyTo( ui.dictionaryOrder ); + + disableDictionaryDescription(); + + showDictNumbers(); + setUpdatesEnabled( true ); +} + Config::Group OrderAndProps::getCurrentDictionaryOrder() const { Instances::Group g; diff --git a/src/ui/orderandprops.hh b/src/ui/orderandprops.hh index 99c154e8..8e9bb938 100644 --- a/src/ui/orderandprops.hh +++ b/src/ui/orderandprops.hh @@ -17,7 +17,9 @@ public: Config::Group const & dictionaryOrder, Config::Group const & inactiveDictionaries, std::vector< sptr< Dictionary::Class > > const & allDictionaries ); - + void rebuild( Config::Group const & dictionaryOrder, + Config::Group const & inactiveDictionaries, + std::vector< sptr< Dictionary::Class > > const & allDictionaries ); Config::Group getCurrentDictionaryOrder() const; Config::Group getCurrentInactiveDictionaries() const;