mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Merge pull request #119 from xiaoyifang/fix/remove-dictmap
opt:remove dictMap parameter
This commit is contained in:
commit
e54b6e58d8
|
@ -11,19 +11,17 @@ using std::vector;
|
||||||
|
|
||||||
EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,
|
EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,
|
||||||
vector< sptr< Dictionary::Class > > & dictionaries_,
|
vector< sptr< Dictionary::Class > > & dictionaries_,
|
||||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap_,
|
|
||||||
Instances::Groups & groupInstances_,
|
Instances::Groups & groupInstances_,
|
||||||
QNetworkAccessManager & dictNetMgr_ ):
|
QNetworkAccessManager & dictNetMgr_ ):
|
||||||
QDialog( parent, Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint ),
|
QDialog( parent, Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint ),
|
||||||
cfg( cfg_ ),
|
cfg( cfg_ ),
|
||||||
dictionaries( dictionaries_ ),
|
dictionaries( dictionaries_ ),
|
||||||
dictMap(dictMap_),
|
|
||||||
groupInstances( groupInstances_ ),
|
groupInstances( groupInstances_ ),
|
||||||
dictNetMgr( dictNetMgr_ ),
|
dictNetMgr( dictNetMgr_ ),
|
||||||
origCfg( cfg ),
|
origCfg( cfg ),
|
||||||
sources( this, cfg ),
|
sources( this, cfg ),
|
||||||
orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries,
|
orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries,
|
||||||
dictionaries, dictMap ) ),
|
dictionaries ) ),
|
||||||
groups( new Groups( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ),
|
groups( new Groups( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ),
|
||||||
dictionariesChanged( false ),
|
dictionariesChanged( false ),
|
||||||
groupsChanged( false ),
|
groupsChanged( false ),
|
||||||
|
@ -216,7 +214,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
||||||
orderAndProps.clear();
|
orderAndProps.clear();
|
||||||
|
|
||||||
loadDictionaries( this, true, cfg, dictionaries, dictNetMgr );
|
loadDictionaries( this, true, cfg, dictionaries, dictNetMgr );
|
||||||
dictMap = Dictionary::dictToMap(dictionaries);
|
|
||||||
// If no changes to groups were made, update the original data
|
// If no changes to groups were made, update the original data
|
||||||
bool noGroupEdits = ( origCfg.groups == savedGroups );
|
bool noGroupEdits = ( origCfg.groups == savedGroups );
|
||||||
|
|
||||||
|
@ -241,7 +239,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
||||||
|
|
||||||
if ( rebuildGroups )
|
if ( rebuildGroups )
|
||||||
{
|
{
|
||||||
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries, dictMap );
|
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries );
|
||||||
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
||||||
|
|
||||||
ui.tabs->removeTab( 1 );
|
ui.tabs->removeTab( 1 );
|
||||||
|
|
|
@ -23,7 +23,6 @@ public:
|
||||||
|
|
||||||
EditDictionaries( QWidget * parent, Config::Class & cfg,
|
EditDictionaries( QWidget * parent, Config::Class & cfg,
|
||||||
std::vector< sptr< Dictionary::Class > > & dictionaries,
|
std::vector< sptr< Dictionary::Class > > & dictionaries,
|
||||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap_,
|
|
||||||
Instances::Groups & groupInstances, // We only clear those on rescan
|
Instances::Groups & groupInstances, // We only clear those on rescan
|
||||||
QNetworkAccessManager & dictNetMgr );
|
QNetworkAccessManager & dictNetMgr );
|
||||||
|
|
||||||
|
@ -78,7 +77,6 @@ private:
|
||||||
|
|
||||||
Config::Class & cfg;
|
Config::Class & cfg;
|
||||||
std::vector< sptr< Dictionary::Class > > & dictionaries;
|
std::vector< sptr< Dictionary::Class > > & dictionaries;
|
||||||
QMap<std::string, sptr< Dictionary::Class > > & dictMap;
|
|
||||||
Instances::Groups & groupInstances;
|
Instances::Groups & groupInstances;
|
||||||
QNetworkAccessManager & dictNetMgr;
|
QNetworkAccessManager & dictNetMgr;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ Groups::Groups( QWidget * parent,
|
||||||
// Populate the dictionaries' list
|
// Populate the dictionaries' list
|
||||||
|
|
||||||
ui.dictionaries->setAsSource();
|
ui.dictionaries->setAsSource();
|
||||||
ui.dictionaries->populate( Instances::Group( order, Dictionary::dictToMap(dicts), Config::Group() ).dictionaries,
|
ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries,
|
||||||
dicts );
|
dicts );
|
||||||
|
|
||||||
ui.searchLine->applyTo( ui.dictionaries );
|
ui.searchLine->applyTo( ui.dictionaries );
|
||||||
|
@ -87,13 +87,12 @@ void Groups::editGroup( unsigned id )
|
||||||
void Groups::updateDictionaryOrder( Config::Group const & order )
|
void Groups::updateDictionaryOrder( Config::Group const & order )
|
||||||
{
|
{
|
||||||
// Make sure it differs from what we have
|
// Make sure it differs from what we have
|
||||||
auto dictMap = Dictionary::dictToMap( dicts );
|
Instances::Group newOrder( order, dicts, Config::Group() );
|
||||||
Instances::Group newOrder( order, dictMap, Config::Group() );
|
|
||||||
|
|
||||||
if( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries )
|
if( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries )
|
||||||
{
|
{
|
||||||
// Repopulate
|
// Repopulate
|
||||||
ui.dictionaries->populate( Instances::Group( order, dictMap, Config::Group() ).dictionaries, dicts );
|
ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries, dicts );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,7 @@ DictGroupWidget::DictGroupWidget( QWidget * parent,
|
||||||
groupId( group.id )
|
groupId( group.id )
|
||||||
{
|
{
|
||||||
ui.setupUi( this );
|
ui.setupUi( this );
|
||||||
auto dictMap = Dictionary::dictToMap(dicts);
|
ui.dictionaries->populate( Instances::Group( group, dicts, Config::Group() ).dictionaries, dicts );
|
||||||
ui.dictionaries->populate( Instances::Group( group, dictMap, Config::Group() ).dictionaries, dicts );
|
|
||||||
|
|
||||||
// Populate icons' list
|
// Populate icons' list
|
||||||
|
|
||||||
|
@ -329,7 +328,7 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value,
|
||||||
|
|
||||||
g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
|
g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
|
||||||
|
|
||||||
Instances::Group i( g, Dictionary::dictToMap(*allDicts), Config::Group() );
|
Instances::Group i( g, *allDicts, Config::Group() );
|
||||||
|
|
||||||
if ( i.dictionaries.size() == 1 )
|
if ( i.dictionaries.size() == 1 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ using std::set;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
Group::Group( Config::Group const & cfgGroup,
|
Group::Group( Config::Group const & cfgGroup,
|
||||||
QMap<std::string, sptr< Dictionary::Class > > const & allDictionaries,
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
||||||
Config::Group const & inactiveGroup ):
|
Config::Group const & inactiveGroup ):
|
||||||
id( cfgGroup.id ),
|
id( cfgGroup.id ),
|
||||||
name( cfgGroup.name ),
|
name( cfgGroup.name ),
|
||||||
|
@ -24,13 +24,15 @@ Group::Group( Config::Group const & cfgGroup,
|
||||||
|
|
||||||
QMap<string, sptr< Dictionary::Class > > groupDicts;
|
QMap<string, sptr< Dictionary::Class > > groupDicts;
|
||||||
QVector<string> dictOrderList;
|
QVector<string> dictOrderList;
|
||||||
|
auto dictMap = Dictionary::dictToMap( allDictionaries );
|
||||||
|
|
||||||
for( unsigned x = 0; x < (unsigned)cfgGroup.dictionaries.size(); ++x )
|
for( unsigned x = 0; x < (unsigned)cfgGroup.dictionaries.size(); ++x )
|
||||||
{
|
{
|
||||||
std::string id = cfgGroup.dictionaries[ x ].id.toStdString();
|
std::string id = cfgGroup.dictionaries[ x ].id.toStdString();
|
||||||
|
|
||||||
if(allDictionaries.contains(id)){
|
if( dictMap.contains( id ) )
|
||||||
groupDicts.insert(id, allDictionaries[ id ] );
|
{
|
||||||
|
groupDicts.insert( id, dictMap[ id ] );
|
||||||
dictOrderList.push_back(id);
|
dictOrderList.push_back(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ struct Group
|
||||||
/// Instantiates the given group from its configuration. If some dictionary
|
/// Instantiates the given group from its configuration. If some dictionary
|
||||||
/// wasn't found, it just skips it.
|
/// wasn't found, it just skips it.
|
||||||
Group( Config::Group const & cfgGroup,
|
Group( Config::Group const & cfgGroup,
|
||||||
QMap<std::string, sptr< Dictionary::Class > > const & allDictionaries,
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
||||||
Config::Group const & inactiveGroup );
|
Config::Group const & inactiveGroup );
|
||||||
|
|
||||||
/// Creates an empty group.
|
/// Creates an empty group.
|
||||||
|
|
|
@ -1398,11 +1398,11 @@ void MainWindow::updateGroupList()
|
||||||
|
|
||||||
// Add dictionaryOrder first, as the 'All' group.
|
// Add dictionaryOrder first, as the 'All' group.
|
||||||
{
|
{
|
||||||
Instances::Group g( cfg.dictionaryOrder, dictMap, Config::Group() );
|
Instances::Group g( cfg.dictionaryOrder, dictionaries, Config::Group() );
|
||||||
|
|
||||||
// Add any missing entries to dictionary order
|
// Add any missing entries to dictionary order
|
||||||
Instances::complementDictionaryOrder( g,
|
Instances::complementDictionaryOrder( g,
|
||||||
Instances::Group( cfg.inactiveDictionaries, dictMap, Config::Group() ),
|
Instances::Group( cfg.inactiveDictionaries, dictionaries, Config::Group() ),
|
||||||
dictionaries );
|
dictionaries );
|
||||||
|
|
||||||
g.name = tr( "All" );
|
g.name = tr( "All" );
|
||||||
|
@ -1413,7 +1413,7 @@ void MainWindow::updateGroupList()
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int x = 0; x < cfg.groups.size(); ++x )
|
for( int x = 0; x < cfg.groups.size(); ++x )
|
||||||
groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictMap, cfg.inactiveDictionaries ) );
|
groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictionaries, cfg.inactiveDictionaries ) );
|
||||||
|
|
||||||
// Update names for dictionaries that are present, so that they could be
|
// Update names for dictionaries that are present, so that they could be
|
||||||
// found in case they got moved.
|
// found in case they got moved.
|
||||||
|
@ -2072,7 +2072,7 @@ void MainWindow::editDictionaries( unsigned editDictionaryGroup )
|
||||||
{ // Limit existence of newCfg
|
{ // Limit existence of newCfg
|
||||||
|
|
||||||
Config::Class newCfg = cfg;
|
Config::Class newCfg = cfg;
|
||||||
EditDictionaries dicts( this, newCfg, dictionaries, dictMap, groupInstances, dictNetMgr );
|
EditDictionaries dicts( this, newCfg, dictionaries, groupInstances, dictNetMgr );
|
||||||
|
|
||||||
connect( &dicts, SIGNAL( showDictionaryInfo( QString const & ) ),
|
connect( &dicts, SIGNAL( showDictionaryInfo( QString const & ) ),
|
||||||
this, SLOT( showDictionaryInfo( QString const & ) ) );
|
this, SLOT( showDictionaryInfo( QString const & ) ) );
|
||||||
|
|
|
@ -85,15 +85,12 @@ bool dictLessThan( sptr< Dictionary::Class > const & dict1,
|
||||||
OrderAndProps::OrderAndProps( QWidget * parent,
|
OrderAndProps::OrderAndProps( QWidget * parent,
|
||||||
Config::Group const & dictionaryOrder,
|
Config::Group const & dictionaryOrder,
|
||||||
Config::Group const & inactiveDictionaries,
|
Config::Group const & inactiveDictionaries,
|
||||||
std::vector< sptr< Dictionary::Class > > const &
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries):
|
||||||
allDictionaries ,
|
|
||||||
QMap<std::string, sptr< Dictionary::Class > > const & dictMap):
|
|
||||||
QWidget( parent )
|
QWidget( parent )
|
||||||
{
|
{
|
||||||
ui.setupUi( this );
|
ui.setupUi( this );
|
||||||
|
Instances::Group order( dictionaryOrder, allDictionaries, Config::Group() );
|
||||||
Instances::Group order( dictionaryOrder, dictMap, Config::Group() );
|
Instances::Group inactive( inactiveDictionaries, allDictionaries, Config::Group() );
|
||||||
Instances::Group inactive( inactiveDictionaries, dictMap, Config::Group() );
|
|
||||||
|
|
||||||
Instances::complementDictionaryOrder( order, inactive, allDictionaries );
|
Instances::complementDictionaryOrder( order, inactive, allDictionaries );
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ public:
|
||||||
|
|
||||||
OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder,
|
OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder,
|
||||||
Config::Group const & inactiveDictionaries,
|
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 getCurrentDictionaryOrder() const;
|
||||||
Config::Group getCurrentInactiveDictionaries() const;
|
Config::Group getCurrentInactiveDictionaries() const;
|
||||||
|
@ -35,7 +34,6 @@ private slots:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ui::OrderAndProps ui;
|
Ui::OrderAndProps ui;
|
||||||
|
|
||||||
void disableDictionaryDescription();
|
void disableDictionaryDescription();
|
||||||
void describeDictionary( DictListWidget *, QModelIndex const & );
|
void describeDictionary( DictListWidget *, QModelIndex const & );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue