mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
opt: extract GroupBackup structure to store the old group info (#1883)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
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:
parent
8a92cbf34a
commit
6b33178829
|
@ -827,6 +827,13 @@ enum class ToolbarsIconSize : std::uint8_t {
|
|||
Large = 2,
|
||||
};
|
||||
|
||||
struct GroupBackup
|
||||
{
|
||||
Group dictionaryOrder;
|
||||
Group inactiveDictionaries;
|
||||
Groups groups;
|
||||
};
|
||||
|
||||
struct Class
|
||||
{
|
||||
Paths paths;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue