opt: erase the need to removeTabs

This commit is contained in:
xiaoyifang 2024-11-02 16:45:13 +08:00 committed by xiaoyifang
parent 160402e1d0
commit 7c32cad65a
5 changed files with 56 additions and 10 deletions

View file

@ -214,16 +214,16 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
Instances::updateNames( savedInactive, dictionaries ); Instances::updateNames( savedInactive, dictionaries );
if ( rebuildGroups ) { 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 ); orderAndProps->rebuild( this, savedOrder, savedInactive, dictionaries );
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); groups->rebuild( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); // ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); // ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) );
connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo ); // connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo );
connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords ); // connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords );
} }
setUpdatesEnabled( true ); setUpdatesEnabled( true );
} }

View file

@ -64,6 +64,27 @@ Groups::Groups( QWidget * parent,
countChanged(); 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 ) void Groups::editGroup( unsigned id )
{ {
for ( int x = 0; x < groups.size(); ++x ) { for ( int x = 0; x < groups.size(); ++x ) {

View file

@ -18,7 +18,9 @@ public:
std::vector< sptr< Dictionary::Class > > const &, std::vector< sptr< Dictionary::Class > > const &,
Config::Groups const &, Config::Groups const &,
Config::Group const & order ); 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. /// Instructs the dialog to position itself on editing the given group.
void editGroup( unsigned id ); void editGroup( unsigned id );

View file

@ -133,6 +133,27 @@ OrderAndProps::OrderAndProps( QWidget * parent,
showDictNumbers(); 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 Config::Group OrderAndProps::getCurrentDictionaryOrder() const
{ {
Instances::Group g; Instances::Group g;

View file

@ -17,7 +17,9 @@ public:
Config::Group const & dictionaryOrder, Config::Group const & dictionaryOrder,
Config::Group const & inactiveDictionaries, Config::Group const & inactiveDictionaries,
std::vector< sptr< Dictionary::Class > > const & allDictionaries ); 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 getCurrentDictionaryOrder() const;
Config::Group getCurrentInactiveDictionaries() const; Config::Group getCurrentInactiveDictionaries() const;