fix: code smells

refactor the disabledType string build
This commit is contained in:
YiFang Xiao 2023-06-01 19:52:16 +08:00
parent 4b8c87a30d
commit 002f7a02f7
2 changed files with 28 additions and 88 deletions

View file

@ -11,9 +11,9 @@
#include <QWebEngineSettings>
Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
QDialog( parent ), prevInterfaceLanguage( 0 )
, cfg( cfg_ )
, helpAction( this )
QDialog( parent ),
cfg( cfg_ ),
helpAction( this )
{
Config::Preferences const & p = cfg_.preferences;
ui.setupUi( this );
@ -342,6 +342,16 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.maxDictionarySize->setValue( p.fts.maxDictionarySize );
}
void Preferences::buildDisabledTypes(QString & disabledTypes, bool is_checked, QString name )
{
if( !is_checked )
{
if ( !disabledTypes.isEmpty() )
disabledTypes += ',';
disabledTypes += name ;
}
}
Config::Preferences Preferences::getPreferences()
{
Config::Preferences p;
@ -463,89 +473,18 @@ Config::Preferences Preferences::getPreferences()
p.fts.enabled = ui.ftsGroupBox->isChecked();
p.fts.maxDictionarySize = ui.maxDictionarySize->value();
if( !ui.allowAard->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "AARD";
}
if( !ui.allowBGL->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "BGL";
}
if( !ui.allowDictD->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "DICTD";
}
if( !ui.allowDSL->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "DSL";
}
if( !ui.allowMDict->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "MDICT";
}
if( !ui.allowSDict->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "SDICT";
}
if( !ui.allowSlob->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "SLOB";
}
if( !ui.allowStardict->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "STARDICT";
}
if( !ui.allowXDXF->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "XDXF";
}
if( !ui.allowZim->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "ZIM";
}
if( !ui.allowEpwing->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "EPWING";
}
if( !ui.allowGls->isChecked() )
{
if( !p.fts.disabledTypes.isEmpty() )
p.fts.disabledTypes += ',';
p.fts.disabledTypes += "GLS";
}
buildDisabledTypes( p.fts.disabledTypes, ui.allowAard->isChecked(), "AARD" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowBGL->isChecked(), "BGL" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowDictD->isChecked(), "DICTD" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowDSL->isChecked(), "DSL" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowMDict->isChecked(), "MDICT" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowSDict->isChecked(), "SDICT" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowSlob->isChecked(), "SLOB" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowStardict->isChecked(), "STARDICT" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowXDXF->isChecked(), "XDXF" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowZim->isChecked(), "ZIM" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowEpwing->isChecked(), "EPWING" );
buildDisabledTypes( p.fts.disabledTypes, ui.allowGls->isChecked(), "GLS" );
return p;
}

View file

@ -11,7 +11,7 @@ class Preferences: public QDialog
{
Q_OBJECT
int prevInterfaceLanguage;
int prevInterfaceLanguage = 0;
QString prevWebFontFamily;
@ -21,7 +21,8 @@ class Preferences: public QDialog
public:
Preferences( QWidget * parent, Config::Class & cfg_ );
~Preferences() = default;
void buildDisabledTypes( QString & disabledTypes, bool is_checked, QString name );
~Preferences() override = default;
Config::Preferences getPreferences();