mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix: code smell
This commit is contained in:
parent
60d26e0e0f
commit
837f8bcaf8
|
@ -86,7 +86,7 @@ class ArticleRequest: public Dictionary::DataRequest
|
|||
QMap< QString, QString > contexts;
|
||||
std::vector< sptr< Dictionary::Class > > activeDicts;
|
||||
|
||||
std::set< gd::wstring > alts; // Accumulated main forms
|
||||
std::set< gd::wstring, std::less<> > alts; // Accumulated main forms
|
||||
std::list< sptr< Dictionary::WordSearchRequest > > altSearches;
|
||||
std::list< sptr< Dictionary::DataRequest > > bodyRequests;
|
||||
bool altsDone{ false };
|
||||
|
|
|
@ -26,26 +26,26 @@ Group::Group( Config::Group const & cfgGroup,
|
|||
QVector<string> dictOrderList;
|
||||
auto dictMap = Dictionary::dictToMap( allDictionaries );
|
||||
|
||||
for( unsigned x = 0; x < (unsigned)cfgGroup.dictionaries.size(); ++x )
|
||||
for( auto const & dict: cfgGroup.dictionaries )
|
||||
{
|
||||
std::string id = cfgGroup.dictionaries[ x ].id.toStdString();
|
||||
std::string dictId = dict.id.toStdString();
|
||||
|
||||
if( dictMap.contains( id ) )
|
||||
if( dictMap.contains( dictId ) )
|
||||
{
|
||||
groupDicts.insert( id, dictMap[ id ] );
|
||||
dictOrderList.push_back(id);
|
||||
groupDicts.insert( dictId, dictMap[ dictId ] );
|
||||
dictOrderList.push_back(dictId);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove inactive dictionaries
|
||||
if( !inactiveGroup.dictionaries.isEmpty() )
|
||||
{
|
||||
set< string > inactiveSet;
|
||||
for( int i = 0; i < inactiveGroup.dictionaries.size(); i++ )
|
||||
set< string, std::less<> > inactiveSet;
|
||||
for(auto const & dict: inactiveGroup.dictionaries)
|
||||
{
|
||||
string id=inactiveGroup.dictionaries[ i ].id.toStdString();
|
||||
groupDicts.remove(id);
|
||||
dictOrderList.removeOne(id);
|
||||
string dictId = dict.id.toStdString();
|
||||
groupDicts.remove(dictId);
|
||||
dictOrderList.removeOne(dictId);
|
||||
}
|
||||
}
|
||||
for(const auto & dictId : dictOrderList)
|
||||
|
@ -81,10 +81,10 @@ Config::Group Group::makeConfigGroup()
|
|||
stream << iconData;
|
||||
}
|
||||
|
||||
for( unsigned x = 0; x < dictionaries.size(); ++x )
|
||||
for ( auto const & dict : dictionaries ) {
|
||||
result.dictionaries.push_back(
|
||||
Config::DictionaryRef( dictionaries[ x ]->getId().c_str(),
|
||||
QString::fromUtf8( dictionaries[ x ]->getName().c_str() ) ) );
|
||||
Config::DictionaryRef( dict->getId().c_str(), QString::fromUtf8( dict->getName().c_str() ) ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -104,9 +104,9 @@ void Group::checkMutedDictionaries( Config::MutedDictionaries * mutedDictionarie
|
|||
{
|
||||
Config::MutedDictionaries temp;
|
||||
|
||||
for( unsigned x = 0; x < dictionaries.size(); x++ )
|
||||
for ( auto const & dict : dictionaries )
|
||||
{
|
||||
QString id = QString::fromStdString( dictionaries[ x ]->getId() );
|
||||
QString id = QString::fromStdString( dict->getId() );
|
||||
if( mutedDictionaries->contains( id ) )
|
||||
temp.insert( id );
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ Group * Groups::findGroup( unsigned id )
|
|||
if ( operator [] ( x ).id == id )
|
||||
return &( operator [] ( x ) );
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Group const * Groups::findGroup( unsigned id ) const
|
||||
|
@ -128,14 +128,14 @@ Group const * Groups::findGroup( unsigned id ) const
|
|||
if ( operator [] ( x ).id == id )
|
||||
return &( operator [] ( x ) );
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void complementDictionaryOrder( Group & group,
|
||||
Group const & inactiveDictionaries,
|
||||
vector< sptr< Dictionary::Class > > const & dicts )
|
||||
{
|
||||
set< string > presentIds;
|
||||
set< string, std::less<> > presentIds;
|
||||
|
||||
for( unsigned x = group.dictionaries.size(); x--; )
|
||||
presentIds.insert( group.dictionaries[ x ]->getId());
|
||||
|
|
|
@ -33,7 +33,7 @@ struct Group
|
|||
Config::Group const & inactiveGroup );
|
||||
|
||||
/// Creates an empty group.
|
||||
Group( QString const & name_ );
|
||||
explicit Group( QString const & name_ );
|
||||
|
||||
Group(unsigned id, QString const & name_);
|
||||
|
||||
|
|
|
@ -59,10 +59,8 @@ protected:
|
|||
QString normalizedString;
|
||||
QVector< int > accentMarkPos;
|
||||
public:
|
||||
AccentMarkHandler()
|
||||
{}
|
||||
virtual ~AccentMarkHandler()
|
||||
{}
|
||||
AccentMarkHandler() = default;
|
||||
virtual ~AccentMarkHandler() = default;
|
||||
static QChar accentMark()
|
||||
{ return QChar( 0x301 ); }
|
||||
|
||||
|
@ -75,14 +73,12 @@ public:
|
|||
int pos = 0;
|
||||
QChar mark = accentMark();
|
||||
|
||||
for( int x = 0; x < baseString.length(); x++ )
|
||||
{
|
||||
if( baseString.at( x ) == mark )
|
||||
{
|
||||
for ( auto const & str : baseString ) {
|
||||
if ( str == mark ) {
|
||||
accentMarkPos.append( pos );
|
||||
continue;
|
||||
}
|
||||
normalizedString.append( baseString.at( x ) );
|
||||
normalizedString.append( str );
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
@ -95,9 +91,9 @@ public:
|
|||
int mirrorPosition( int const & pos ) const
|
||||
{
|
||||
int newPos = pos;
|
||||
for( int x = 0; x < accentMarkPos.size(); x++ )
|
||||
for( auto const accentPos: accentMarkPos)
|
||||
{
|
||||
if( accentMarkPos.at( x ) < pos )
|
||||
if ( accentPos < pos )
|
||||
newPos++;
|
||||
else
|
||||
break;
|
||||
|
@ -116,10 +112,8 @@ public:
|
|||
class DiacriticsHandler : public AccentMarkHandler
|
||||
{
|
||||
public:
|
||||
DiacriticsHandler()
|
||||
{}
|
||||
~DiacriticsHandler()
|
||||
{}
|
||||
DiacriticsHandler() = default;
|
||||
~DiacriticsHandler() = default;
|
||||
|
||||
/// Create text without diacriticss
|
||||
/// and store diacritic marks positions
|
||||
|
@ -241,10 +235,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
searchIsOpened( false ),
|
||||
dictionaryBarToggled( dictionaryBarToggled_ ),
|
||||
groupComboBox( groupComboBox_ ),
|
||||
translateLine( translateLine_ ),
|
||||
ftsSearchIsOpened( false ),
|
||||
ftsSearchMatchCase( false ),
|
||||
ftsPosition( 0 )
|
||||
translateLine( translateLine_ )
|
||||
{
|
||||
// setup GUI
|
||||
webview = new ArticleWebView( this );
|
||||
|
@ -299,7 +290,6 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
|
||||
connect( webview, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished );
|
||||
|
||||
connect( webview, &QWebEngineView::loadProgress, this, &ArticleView::loadProgress );
|
||||
connect( webview, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked );
|
||||
|
||||
connect( webview->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged );
|
||||
|
@ -607,9 +597,6 @@ void ArticleView::loadFinished( bool result )
|
|||
highlightFTSResults();
|
||||
}
|
||||
|
||||
void ArticleView::loadProgress(int ){
|
||||
}
|
||||
|
||||
void ArticleView::handleTitleChanged( QString const & title )
|
||||
{
|
||||
if( !title.isEmpty() ) // Qt 5.x WebKit raise signal titleChanges(QString()) while navigation within page
|
||||
|
@ -625,14 +612,13 @@ void ArticleView::handleUrlChanged( QUrl const & url )
|
|||
if ( group )
|
||||
{
|
||||
// Find the group's instance corresponding to the fragment value
|
||||
for( unsigned x = 0; x < groups.size(); ++x )
|
||||
if ( groups[ x ].id == group )
|
||||
{
|
||||
for ( auto const & g : groups ) {
|
||||
if ( g.id == group ) {
|
||||
// Found it
|
||||
|
||||
icon = groups[ x ].makeIcon();
|
||||
icon = g.makeIcon();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit iconChanged( this, icon );
|
||||
|
@ -740,7 +726,7 @@ void ArticleView::load( QUrl const & url ) { webview->load( url ); }
|
|||
|
||||
void ArticleView::cleanupTemp()
|
||||
{
|
||||
QSet< QString >::iterator it = desktopOpenedTempFiles.begin();
|
||||
auto it = desktopOpenedTempFiles.begin();
|
||||
while( it != desktopOpenedTempFiles.end() )
|
||||
{
|
||||
if( QFile::remove( *it ) )
|
||||
|
@ -942,7 +928,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
|
|||
if( group == Instances::Group::AllGroupId )
|
||||
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
||||
else
|
||||
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : 0;
|
||||
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
||||
if( !mutedDictionaries )
|
||||
return QString();
|
||||
|
||||
|
@ -978,7 +964,7 @@ QStringList ArticleView::getMutedDictionaries(unsigned group) {
|
|||
if (group == Instances::Group::AllGroupId)
|
||||
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
||||
else
|
||||
mutedDictionaries = grp ? (popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries) : 0;
|
||||
mutedDictionaries = grp ? (popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries) : nullptr;
|
||||
if (!mutedDictionaries)
|
||||
return QStringList();
|
||||
|
||||
|
|
|
@ -86,8 +86,9 @@ class ArticleView: public QWidget
|
|||
/// Search in results of full-text search
|
||||
QStringList allMatches;
|
||||
QStringList uniqueMatches;
|
||||
bool ftsSearchIsOpened, ftsSearchMatchCase;
|
||||
int ftsPosition;
|
||||
bool ftsSearchIsOpened = false;
|
||||
bool ftsSearchMatchCase = false;
|
||||
int ftsPosition=0;
|
||||
|
||||
QString delayedHighlightText;
|
||||
|
||||
|
@ -334,7 +335,6 @@ public slots:
|
|||
private slots:
|
||||
void inspectElement();
|
||||
void loadFinished( bool ok );
|
||||
void loadProgress(int);
|
||||
void handleTitleChanged( QString const & title );
|
||||
void handleUrlChanged( QUrl const & url );
|
||||
void attachWebChannelToHtml();
|
||||
|
|
|
@ -210,7 +210,7 @@ bool QtSingleApplication::sendMessage(const QString &message, int timeout)
|
|||
Returns the application identifier. Two processes with the same
|
||||
identifier will be regarded as instances of the same application.
|
||||
*/
|
||||
QString QtSingleApplication::id() const
|
||||
QString QtSingleApplication::appId() const
|
||||
{
|
||||
return peer->applicationId();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
QtSingleApplication(const QString &id, int &argc, char **argv);
|
||||
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
QString appId() const;
|
||||
|
||||
void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
|
||||
QWidget* activationWindow() const;
|
||||
|
|
Loading…
Reference in a new issue