-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: dictionarygroup refactor in articleview (#1625)
* opt: refactor dictionary logic to seperate class --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fe2aa06
commit 932b88f
Showing
5 changed files
with
120 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Licensed under GPLv3 or later, see the LICENSE file */ | ||
|
||
|
||
#include "dictionary_group.hh" | ||
|
||
|
||
sptr< Dictionary::Class > DictionaryGroup::getDictionaryByName( QString const & dictName ) | ||
{ | ||
// Link to other dictionary | ||
for ( const auto & allDictionarie : allDictionaries ) { | ||
if ( dictName.compare( QString::fromUtf8( allDictionarie->getName().c_str() ) ) == 0 ) { | ||
return allDictionarie; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
const std::vector< sptr< Dictionary::Class > > * DictionaryGroup::getActiveDictionaries( unsigned currentGroup ) | ||
{ | ||
std::vector< sptr< Dictionary::Class > > const * activeDicts = nullptr; | ||
|
||
if ( !groups.empty() ) { | ||
for ( const auto & group : groups ) | ||
if ( group.id == currentGroup ) { | ||
activeDicts = &( group.dictionaries ); | ||
break; | ||
} | ||
} | ||
else | ||
activeDicts = &allDictionaries; | ||
|
||
return activeDicts; | ||
} | ||
|
||
|
||
sptr< Dictionary::Class > DictionaryGroup::getDictionaryById( const std::string & dictId ) | ||
{ | ||
|
||
for ( unsigned x = allDictionaries.size(); x--; ) { | ||
if ( allDictionaries[ x ]->getId() == dictId ) { | ||
return allDictionaries[ x ]; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
Instances::Group const * DictionaryGroup::getGroupById( unsigned groupId ) | ||
{ | ||
return groups.findGroup( groupId ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Licensed under GPLv3 or later, see the LICENSE file */ | ||
|
||
#ifndef DICTIONARYGROUP_HH_INCLUDED | ||
#define DICTIONARYGROUP_HH_INCLUDED | ||
|
||
#include "sptr.hh" | ||
#include "dict/dictionary.hh" | ||
#include "instances.hh" | ||
|
||
class DictionaryGroup | ||
{ | ||
public: | ||
DictionaryGroup( std::vector< sptr< Dictionary::Class > > const & allDictionaries_, | ||
Instances::Groups const & groups_ ): | ||
allDictionaries( allDictionaries_ ), | ||
groups( groups_ ) | ||
{ | ||
} | ||
|
||
sptr< Dictionary::Class > getDictionaryByName( QString const & dictionaryName ); | ||
|
||
const std::vector< sptr< Dictionary::Class > > * getActiveDictionaries( unsigned groupId ); | ||
|
||
sptr< Dictionary::Class > getDictionaryById( const std::string & dictId ); | ||
|
||
Instances::Group const * getGroupById( unsigned groupId ); | ||
|
||
|
||
private: | ||
std::vector< sptr< Dictionary::Class > > const & allDictionaries; | ||
Instances::Groups const & groups; | ||
}; | ||
|
||
#endif // DICTIONARYGROUP_HH_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters