mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Merge branch 'fix/populate-group-perf' into staged
This commit is contained in:
commit
687cd26c3a
|
@ -516,5 +516,14 @@ QString generateRandomDictionaryId()
|
|||
QCryptographicHash::Md5 ).toHex() );
|
||||
}
|
||||
|
||||
|
||||
QMap< std::string, sptr< Dictionary::Class > >
|
||||
dictToMap( std::vector< sptr< Dictionary::Class > > const & dicts )
|
||||
{
|
||||
QMap< std::string, sptr< Dictionary::Class > > dictMap;
|
||||
for( auto dict : dicts )
|
||||
{
|
||||
dictMap.insert( dict.get()->getId(), dict );
|
||||
}
|
||||
return dictMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -479,6 +479,9 @@ bool needToRebuildIndex( vector< string > const & dictionaryFiles,
|
|||
/// dictionaries.
|
||||
QString generateRandomDictionaryId();
|
||||
|
||||
QMap< std::string, sptr< Dictionary::Class > >
|
||||
dictToMap( std::vector< sptr< Dictionary::Class > > const & dicts );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,17 +11,19 @@ using std::vector;
|
|||
|
||||
EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,
|
||||
vector< sptr< Dictionary::Class > > & dictionaries_,
|
||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap_,
|
||||
Instances::Groups & groupInstances_,
|
||||
QNetworkAccessManager & dictNetMgr_ ):
|
||||
QDialog( parent, Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint ),
|
||||
cfg( cfg_ ),
|
||||
dictionaries( dictionaries_ ),
|
||||
dictMap(dictMap_),
|
||||
groupInstances( groupInstances_ ),
|
||||
dictNetMgr( dictNetMgr_ ),
|
||||
origCfg( cfg ),
|
||||
sources( this, cfg ),
|
||||
orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries,
|
||||
dictionaries ) ),
|
||||
dictionaries, dictMap ) ),
|
||||
groups( new Groups( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ),
|
||||
dictionariesChanged( false ),
|
||||
groupsChanged( false ),
|
||||
|
@ -244,7 +246,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
|||
|
||||
if ( rebuildGroups )
|
||||
{
|
||||
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries );
|
||||
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries, dictMap );
|
||||
ui.tabs->insertTab( 1, orderAndProps.get(), QIcon(":/icons/book.svg"), tr( "&Dictionaries" ) );
|
||||
|
||||
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
|
||||
EditDictionaries( QWidget * parent, Config::Class & cfg,
|
||||
std::vector< sptr< Dictionary::Class > > & dictionaries,
|
||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap_,
|
||||
Instances::Groups & groupInstances, // We only clear those on rescan
|
||||
QNetworkAccessManager & dictNetMgr );
|
||||
|
||||
|
@ -73,6 +74,7 @@ private:
|
|||
|
||||
Config::Class & cfg;
|
||||
std::vector< sptr< Dictionary::Class > > & dictionaries;
|
||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap;
|
||||
Instances::Groups & groupInstances;
|
||||
QNetworkAccessManager & dictNetMgr;
|
||||
|
||||
|
|
11
groups.cc
11
groups.cc
|
@ -20,7 +20,7 @@ Groups::Groups( QWidget * parent,
|
|||
// Populate the dictionaries' list
|
||||
|
||||
ui.dictionaries->setAsSource();
|
||||
ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries,
|
||||
ui.dictionaries->populate( Instances::Group( order, Dictionary::dictToMap(dicts), Config::Group() ).dictionaries,
|
||||
dicts );
|
||||
|
||||
ui.searchLine->applyTo( ui.dictionaries );
|
||||
|
@ -87,14 +87,13 @@ void Groups::editGroup( unsigned id )
|
|||
void Groups::updateDictionaryOrder( Config::Group const & order )
|
||||
{
|
||||
// Make sure it differs from what we have
|
||||
auto dictMap = Dictionary::dictToMap( dicts );
|
||||
Instances::Group newOrder( order, dictMap, Config::Group() );
|
||||
|
||||
Instances::Group newOrder( order, dicts, Config::Group() );
|
||||
|
||||
if ( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries )
|
||||
if( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries )
|
||||
{
|
||||
// Repopulate
|
||||
ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries,
|
||||
dicts );
|
||||
ui.dictionaries->populate( Instances::Group( order, dictMap, Config::Group() ).dictionaries, dicts );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ DictGroupWidget::DictGroupWidget( QWidget * parent,
|
|||
groupId( group.id )
|
||||
{
|
||||
ui.setupUi( this );
|
||||
ui.dictionaries->populate( Instances::Group( group, dicts, Config::Group() ).dictionaries, dicts );
|
||||
auto dictMap = Dictionary::dictToMap(dicts);
|
||||
ui.dictionaries->populate( Instances::Group( group, dictMap, Config::Group() ).dictionaries, dicts );
|
||||
|
||||
// Populate icons' list
|
||||
|
||||
|
@ -328,7 +329,7 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value,
|
|||
|
||||
g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
|
||||
|
||||
Instances::Group i( g, *allDicts, Config::Group() );
|
||||
Instances::Group i( g, Dictionary::dictToMap(*allDicts), Config::Group() );
|
||||
|
||||
if ( i.dictionaries.size() == 1 )
|
||||
{
|
||||
|
@ -584,8 +585,7 @@ void DictGroupsWidget::populate( Config::Groups const & groups,
|
|||
{
|
||||
DictGroupWidget *gr = new DictGroupWidget( this, *allDicts, groups[ x ] );
|
||||
addTab( gr, escapeAmps( groups[ x ].name ) );
|
||||
connect( gr, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SIGNAL( showDictionaryInfo( QString const & ) ) );
|
||||
// connect( gr, &DictGroupWidget::showDictionaryInfo,this, &DictGroupsWidget::showDictionaryInfo );
|
||||
connect( gr->getModel(), SIGNAL( contentChanged() ), this, SLOT( tabDataChanged() ) );
|
||||
|
||||
setCurrentIndex( x );
|
||||
|
|
65
instances.cc
65
instances.cc
|
@ -11,7 +11,7 @@ using std::set;
|
|||
using std::string;
|
||||
|
||||
Group::Group( Config::Group const & cfgGroup,
|
||||
vector< sptr< Dictionary::Class > > const & allDictionaries,
|
||||
QMap<std::string, sptr< Dictionary::Class > > const & allDictionaries,
|
||||
Config::Group const & inactiveGroup ):
|
||||
id( cfgGroup.id ),
|
||||
name( cfgGroup.name ),
|
||||
|
@ -22,70 +22,29 @@ Group::Group( Config::Group const & cfgGroup,
|
|||
if ( !cfgGroup.iconData.isEmpty() )
|
||||
iconData = iconFromData( cfgGroup.iconData );
|
||||
|
||||
vector< sptr< Dictionary::Class > > groupDicts;
|
||||
QMap<string, sptr< Dictionary::Class > > groupDicts;
|
||||
|
||||
for( unsigned x = 0; x < (unsigned)cfgGroup.dictionaries.size(); ++x )
|
||||
{
|
||||
std::string id = cfgGroup.dictionaries[ x ].id.toStdString();
|
||||
|
||||
bool added = false;
|
||||
|
||||
for( unsigned y = allDictionaries.size(); y--; )
|
||||
if ( allDictionaries[ y ]->getId() == id )
|
||||
{
|
||||
groupDicts.push_back( allDictionaries[ y ] );
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !added )
|
||||
{
|
||||
// Try matching by name instead
|
||||
QString qname = cfgGroup.dictionaries[ x ].name;
|
||||
std::string name = qname.toUtf8().data();
|
||||
|
||||
if ( !qname.isEmpty() )
|
||||
{
|
||||
|
||||
// To avoid duplicates in dictionaries list we don't add dictionary
|
||||
// if it with such name was already added or presented in rest of list
|
||||
|
||||
unsigned n;
|
||||
for( n = 0; n < groupDicts.size(); n++ )
|
||||
if( groupDicts[ n ]->getName() == name )
|
||||
break;
|
||||
if( n < groupDicts.size() )
|
||||
continue;
|
||||
|
||||
for( n = x + 1; n < (unsigned)cfgGroup.dictionaries.size(); n++ )
|
||||
if( cfgGroup.dictionaries[ n ].name == qname )
|
||||
break;
|
||||
if( n < (unsigned)cfgGroup.dictionaries.size() )
|
||||
continue;
|
||||
|
||||
for( unsigned y = 0; y < allDictionaries.size(); ++y )
|
||||
if ( allDictionaries[ y ]->getName() == name )
|
||||
{
|
||||
groupDicts.push_back( allDictionaries[ y ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(allDictionaries.contains(id)){
|
||||
groupDicts.insert(id, allDictionaries[ id ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Remove inactive dictionaries
|
||||
|
||||
if( inactiveGroup.dictionaries.isEmpty() )
|
||||
dictionaries = groupDicts;
|
||||
else
|
||||
if( !inactiveGroup.dictionaries.isEmpty() )
|
||||
{
|
||||
set< string > inactiveSet;
|
||||
for( int i = 0; i < inactiveGroup.dictionaries.size(); i++ )
|
||||
inactiveSet.insert( inactiveGroup.dictionaries[ i ].id.toStdString() );
|
||||
|
||||
for( unsigned i = 0; i < groupDicts.size(); i++ )
|
||||
if( inactiveSet.find( groupDicts[ i ]->getId() ) == inactiveSet.end() )
|
||||
dictionaries.push_back( groupDicts[ i ] );
|
||||
{
|
||||
groupDicts.remove(inactiveGroup.dictionaries[ i ].id.toStdString());
|
||||
}
|
||||
}
|
||||
for(const auto & dict : groupDicts)
|
||||
{
|
||||
dictionaries.push_back(dict);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ struct Group
|
|||
/// Instantiates the given group from its configuration. If some dictionary
|
||||
/// wasn't found, it just skips it.
|
||||
Group( Config::Group const & cfgGroup,
|
||||
vector< sptr< Dictionary::Class > > const & allDictionaries,
|
||||
QMap<std::string, sptr< Dictionary::Class > > const & allDictionaries,
|
||||
Config::Group const & inactiveGroup );
|
||||
|
||||
/// Creates an empty group.
|
||||
|
|
|
@ -1345,6 +1345,9 @@ void MainWindow::makeDictionaries()
|
|||
|
||||
loadDictionaries( this, isVisible(), cfg, dictionaries, dictNetMgr, false );
|
||||
|
||||
//create map
|
||||
dictMap = Dictionary::dictToMap(dictionaries);
|
||||
|
||||
for( unsigned x = 0; x < dictionaries.size(); x++ )
|
||||
{
|
||||
dictionaries[ x ]->setFTSParameters( cfg.preferences.fts );
|
||||
|
@ -1390,11 +1393,11 @@ void MainWindow::updateGroupList()
|
|||
|
||||
// Add dictionaryOrder first, as the 'All' group.
|
||||
{
|
||||
Instances::Group g( cfg.dictionaryOrder, dictionaries, Config::Group() );
|
||||
Instances::Group g( cfg.dictionaryOrder, dictMap, Config::Group() );
|
||||
|
||||
// Add any missing entries to dictionary order
|
||||
Instances::complementDictionaryOrder( g,
|
||||
Instances::Group( cfg.inactiveDictionaries, dictionaries, Config::Group() ),
|
||||
Instances::Group( cfg.inactiveDictionaries, dictMap, Config::Group() ),
|
||||
dictionaries );
|
||||
|
||||
g.name = tr( "All" );
|
||||
|
@ -1405,7 +1408,7 @@ void MainWindow::updateGroupList()
|
|||
}
|
||||
|
||||
for( int x = 0; x < cfg.groups.size(); ++x )
|
||||
groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictionaries, cfg.inactiveDictionaries ) );
|
||||
groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictMap, cfg.inactiveDictionaries ) );
|
||||
|
||||
// Update names for dictionaries that are present, so that they could be
|
||||
// found in case they got moved.
|
||||
|
@ -2051,7 +2054,7 @@ void MainWindow::editDictionaries( unsigned editDictionaryGroup )
|
|||
{ // Limit existence of newCfg
|
||||
|
||||
Config::Class newCfg = cfg;
|
||||
EditDictionaries dicts( this, newCfg, dictionaries, groupInstances, dictNetMgr );
|
||||
EditDictionaries dicts( this, newCfg, dictionaries, dictMap, groupInstances, dictNetMgr );
|
||||
|
||||
connect( &dicts, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||
this, SLOT( showDictionaryInfo( QString const & ) ) );
|
||||
|
|
|
@ -151,6 +151,7 @@ private:
|
|||
History history;
|
||||
DictionaryBar dictionaryBar;
|
||||
vector< sptr< Dictionary::Class > > dictionaries;
|
||||
QMap<std::string, sptr< Dictionary::Class > > dictMap;
|
||||
/// Here we store unmuted dictionaries when the dictionary bar is active
|
||||
vector< sptr< Dictionary::Class > > dictionariesUnmuted;
|
||||
Instances::Groups groupInstances;
|
||||
|
|
|
@ -86,13 +86,14 @@ OrderAndProps::OrderAndProps( QWidget * parent,
|
|||
Config::Group const & dictionaryOrder,
|
||||
Config::Group const & inactiveDictionaries,
|
||||
std::vector< sptr< Dictionary::Class > > const &
|
||||
allDictionaries ):
|
||||
allDictionaries ,
|
||||
QMap<std::string, sptr< Dictionary::Class > > const & dictMap):
|
||||
QWidget( parent )
|
||||
{
|
||||
ui.setupUi( this );
|
||||
|
||||
Instances::Group order( dictionaryOrder, allDictionaries, Config::Group() );
|
||||
Instances::Group inactive( inactiveDictionaries, allDictionaries, Config::Group() );
|
||||
Instances::Group order( dictionaryOrder, dictMap, Config::Group() );
|
||||
Instances::Group inactive( inactiveDictionaries, dictMap, Config::Group() );
|
||||
|
||||
Instances::complementDictionaryOrder( order, inactive, allDictionaries );
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ public:
|
|||
|
||||
OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder,
|
||||
Config::Group const & inactiveDictionaries,
|
||||
std::vector< sptr< Dictionary::Class > > const & allDictionaries );
|
||||
std::vector< sptr< Dictionary::Class > > const & allDictionaries ,
|
||||
QMap<std::string, sptr< Dictionary::Class > > const & dictMap);
|
||||
|
||||
Config::Group getCurrentDictionaryOrder() const;
|
||||
Config::Group getCurrentInactiveDictionaries() const;
|
||||
|
|
Loading…
Reference in a new issue