opt: extract GroupBackup structure to store the old group info (#1883)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run

* opt: backup group info

* opt: remove updateNames condtion

* opt: rename variable origCfg to a more friendly name

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2024-11-01 10:52:45 +08:00 committed by GitHub
parent 8a92cbf34a
commit 6b33178829
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 40 deletions

View file

@ -827,6 +827,13 @@ enum class ToolbarsIconSize : std::uint8_t {
Large = 2,
};
struct GroupBackup
{
Group dictionaryOrder;
Group inactiveDictionaries;
Groups groups;
};
struct Class
{
Paths paths;

View file

@ -19,7 +19,6 @@ EditDictionaries::EditDictionaries( QWidget * parent,
dictionaries( dictionaries_ ),
groupInstances( groupInstances_ ),
dictNetMgr( dictNetMgr_ ),
origCfg( cfg ),
sources( this, cfg ),
orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries, dictionaries ) ),
groups( new Groups( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ),
@ -31,9 +30,9 @@ EditDictionaries::EditDictionaries( QWidget * parent,
// would like to preserve them if no edits were done. To that end, we save
// the initial group readings so that if no edits were really done, we won't
// be changing groups.
origCfg.groups = groups->getGroups();
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
origGroups.groups = groups->getGroups();
origGroups.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
origGroups.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
ui.setupUi( this );
@ -94,8 +93,8 @@ void EditDictionaries::save( bool rebuildGroups )
acceptChangedSources( rebuildGroups );
}
if ( origCfg.groups != newGroups || origCfg.dictionaryOrder != newOrder
|| origCfg.inactiveDictionaries != newInactive ) {
if ( origGroups.groups != newGroups || origGroups.dictionaryOrder != newOrder
|| origGroups.inactiveDictionaries != newInactive ) {
groupsChanged = true;
cfg.groups = newGroups;
cfg.dictionaryOrder = newOrder;
@ -210,29 +209,8 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
loadDictionaries( this, cfg, dictionaries, dictNetMgr );
// If no changes to groups were made, update the original data
const bool noGroupEdits = ( origCfg.groups == savedGroups );
if ( noGroupEdits ) {
savedGroups = cfg.groups;
}
Instances::updateNames( savedGroups, dictionaries );
const bool noOrderEdits = ( origCfg.dictionaryOrder == savedOrder );
if ( noOrderEdits ) {
savedOrder = cfg.dictionaryOrder;
}
Instances::updateNames( savedOrder, dictionaries );
const bool noInactiveEdits = ( origCfg.inactiveDictionaries == savedInactive );
if ( noInactiveEdits ) {
savedInactive = cfg.inactiveDictionaries;
}
Instances::updateNames( savedInactive, dictionaries );
if ( rebuildGroups ) {
@ -246,18 +224,6 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
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 );
if ( noGroupEdits ) {
origCfg.groups = groups->getGroups();
}
if ( noOrderEdits ) {
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
}
if ( noInactiveEdits ) {
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
}
}
ui.tabs->setUpdatesEnabled( true );
}

View file

@ -79,7 +79,7 @@ private:
QNetworkAccessManager & dictNetMgr;
// Backed up to decide later if something was changed or not
Config::Class origCfg;
Config::GroupBackup origGroups;
Ui::EditDictionaries ui;
Sources sources;