diff --git a/src/dict/loaddictionaries.cc b/src/dict/loaddictionaries.cc index fc4bb737..e369ac6e 100644 --- a/src/dict/loaddictionaries.cc +++ b/src/dict/loaddictionaries.cc @@ -224,7 +224,7 @@ void loadDictionaries( QWidget * parent, loadDicts.wait(); - if ( loadDicts.getExceptionText().size() ) { + if ( !loadDicts.getExceptionText().empty() ) { QMessageBox::critical( parent, QCoreApplication::translate( "LoadDictionaries", "Error loading dictionaries" ), QString::fromUtf8( loadDicts.getExceptionText().c_str() ) ); diff --git a/src/ui/editdictionaries.cc b/src/ui/editdictionaries.cc index 40d37a5a..103aa3a6 100644 --- a/src/ui/editdictionaries.cc +++ b/src/ui/editdictionaries.cc @@ -200,32 +200,28 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) #ifndef NO_TTS_SUPPORT cfg.voiceEngines = sources.getVoiceEngines(); #endif - ui.tabs->setUpdatesEnabled( false ); + setUpdatesEnabled( false ); // Those hold pointers to dictionaries, we need to free them. groupInstances.clear(); - groups.clear(); - orderAndProps.clear(); + // groups.clear(); + // orderAndProps.clear(); loadDictionaries( this, cfg, dictionaries, dictNetMgr ); - Instances::updateNames( savedGroups, dictionaries ); - Instances::updateNames( savedOrder, dictionaries ); - 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( savedOrder, savedInactive, dictionaries ); + groups->rebuild( 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 ); } - ui.tabs->setUpdatesEnabled( true ); + setUpdatesEnabled( true ); } EditDictionaries::~EditDictionaries() { diff --git a/src/ui/groups.cc b/src/ui/groups.cc index 09661f3b..15a49e12 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 ) +{ + this->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(); + this->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 8366f1e2..21224f19 100644 --- a/src/ui/groups.hh +++ b/src/ui/groups.hh @@ -19,7 +19,9 @@ public: std::vector< sptr< Dictionary::Class > > const &, Config::Groups const &, Config::Group const & order ); - + void rebuild( std::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 ); @@ -32,7 +34,7 @@ public: private: Ui::Groups ui; - std::vector< sptr< Dictionary::Class > > const & dicts; + std::vector< sptr< Dictionary::Class > > dicts; Config::Groups groups; QToolButton * groupsListButton; diff --git a/src/ui/orderandprops.cc b/src/ui/orderandprops.cc index be92334d..8aa90b84 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 dce11782..84ffa26d 100644 --- a/src/ui/orderandprops.hh +++ b/src/ui/orderandprops.hh @@ -18,7 +18,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;