mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
Some more groups combining
This commit is contained in:
parent
c6ea89e179
commit
6fd4b33ad3
|
@ -778,6 +778,21 @@ void DictGroupsWidget::removeAllGroups()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DictGroupsWidget::combineGroups( int source, int target )
|
||||||
|
{
|
||||||
|
if( source < 0 || source >= count() || target < 0 || target >= count() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
setCurrentIndex( source );
|
||||||
|
vector< sptr< Dictionary::Class > > const & dicts = getCurrentModel()->getCurrentDictionaries();
|
||||||
|
|
||||||
|
setCurrentIndex( target );
|
||||||
|
DictListModel *model = getCurrentModel();
|
||||||
|
|
||||||
|
for( unsigned i = 0; i < dicts.size(); i++ )
|
||||||
|
model->addRow( QModelIndex(), dicts[ i ] );
|
||||||
|
}
|
||||||
|
|
||||||
void DictGroupsWidget::contextMenu( QPoint const & pos )
|
void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
{
|
{
|
||||||
int clickedGroup = tabBar()->tabAt( pos );
|
int clickedGroup = tabBar()->tabAt( pos );
|
||||||
|
@ -792,10 +807,13 @@ void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
QAction *combineSourceAction = new QAction( QString( tr( "Combine groups by source language to \"%1->\"" ) )
|
QAction *combineSourceAction = new QAction( QString( tr( "Combine groups by source language to \"%1->\"" ) )
|
||||||
.arg( name.left( 2 ) ), &menu );
|
.arg( name.left( 2 ) ), &menu );
|
||||||
combineSourceAction->setEnabled( false );
|
combineSourceAction->setEnabled( false );
|
||||||
|
|
||||||
|
QString grLeft = name.left( 2 );
|
||||||
|
QString grRight = name.right( 2 );
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
QString str = tabText( i );
|
QString str = tabText( i );
|
||||||
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " && str.startsWith( name.left( 2 ) ) )
|
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " && str.startsWith( grLeft ) )
|
||||||
{
|
{
|
||||||
combineSourceAction->setEnabled( true );
|
combineSourceAction->setEnabled( true );
|
||||||
break;
|
break;
|
||||||
|
@ -806,10 +824,11 @@ void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
QAction *combineTargetAction = new QAction( QString( tr( "Combine groups by target language to \"->%1\"" ) )
|
QAction *combineTargetAction = new QAction( QString( tr( "Combine groups by target language to \"->%1\"" ) )
|
||||||
.arg( name.right( 2 ) ), &menu );
|
.arg( name.right( 2 ) ), &menu );
|
||||||
combineTargetAction->setEnabled( false );
|
combineTargetAction->setEnabled( false );
|
||||||
|
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
QString str = tabText( i );
|
QString str = tabText( i );
|
||||||
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " && str.endsWith( name.right( 2 ) ) )
|
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " && str.endsWith( grRight ) )
|
||||||
{
|
{
|
||||||
combineTargetAction->setEnabled( true );
|
combineTargetAction->setEnabled( true );
|
||||||
break;
|
break;
|
||||||
|
@ -818,20 +837,18 @@ void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
menu.addAction( combineTargetAction );
|
menu.addAction( combineTargetAction );
|
||||||
|
|
||||||
QAction *combineTwoSidedAction = NULL;
|
QAction *combineTwoSidedAction = NULL;
|
||||||
int secondGroup = -1;
|
if( grLeft != grRight )
|
||||||
if( name.left( 2 ) != name.right( 2 ) )
|
|
||||||
{
|
{
|
||||||
combineTwoSidedAction = new QAction( QString( tr( "Make two-side translate group \"%1-%2-%1\"" ) )
|
combineTwoSidedAction = new QAction( QString( tr( "Make two-side translate group \"%1-%2-%1\"" ) )
|
||||||
.arg( name.left( 2 ) ).arg( name.right( 2 ) ), &menu );
|
.arg( grLeft ).arg( grRight ), &menu );
|
||||||
|
|
||||||
combineTwoSidedAction->setEnabled( false );
|
combineTwoSidedAction->setEnabled( false );
|
||||||
|
|
||||||
QString str = name.right( 2 ) + " - " + name.left( 2 );
|
QString str = grRight + " - " + grLeft;
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
if( str == tabText( i ) )
|
if( str == tabText( i ) )
|
||||||
{
|
{
|
||||||
secondGroup = i;
|
|
||||||
combineTwoSidedAction->setEnabled( true );
|
combineTwoSidedAction->setEnabled( true );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -840,6 +857,42 @@ void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
menu.addAction( combineTwoSidedAction );
|
menu.addAction( combineTwoSidedAction );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAction *combineFirstAction = new QAction( QString( tr( "Combine groups with \"%1\"" ) )
|
||||||
|
.arg( grLeft ), &menu );
|
||||||
|
combineFirstAction->setEnabled( false );
|
||||||
|
for( int i = 0; i < count(); i++ )
|
||||||
|
{
|
||||||
|
QString str = tabText( i );
|
||||||
|
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " &&
|
||||||
|
( str.startsWith( grLeft ) || str.endsWith( grLeft ) ) )
|
||||||
|
{
|
||||||
|
combineFirstAction->setEnabled( true );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu.addAction( combineFirstAction );
|
||||||
|
|
||||||
|
QAction *combineSecondAction = NULL;
|
||||||
|
|
||||||
|
if( grLeft != grRight )
|
||||||
|
{
|
||||||
|
combineSecondAction = new QAction( QString( tr( "Combine groups with \"%1\"" ) )
|
||||||
|
.arg( grRight ), &menu );
|
||||||
|
combineSecondAction->setEnabled( false );
|
||||||
|
|
||||||
|
for( int i = 0; i < count(); i++ )
|
||||||
|
{
|
||||||
|
QString str = tabText( i );
|
||||||
|
if( i != clickedGroup && str.length() == 7 && str.mid( 2, 3 ) == " - " &&
|
||||||
|
( str.startsWith( grRight ) || str.endsWith( grRight ) ) )
|
||||||
|
{
|
||||||
|
combineSecondAction->setEnabled( true );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu.addAction( combineSecondAction );
|
||||||
|
}
|
||||||
|
|
||||||
QAction *result = menu.exec( mapToGlobal( pos ) );
|
QAction *result = menu.exec( mapToGlobal( pos ) );
|
||||||
|
|
||||||
setUpdatesEnabled( false );
|
setUpdatesEnabled( false );
|
||||||
|
@ -847,73 +900,61 @@ void DictGroupsWidget::contextMenu( QPoint const & pos )
|
||||||
|
|
||||||
if( result && result == combineSourceAction )
|
if( result && result == combineSourceAction )
|
||||||
{
|
{
|
||||||
QString grBase = name.left( 2 );
|
|
||||||
setCurrentIndex( clickedGroup );
|
setCurrentIndex( clickedGroup );
|
||||||
targetGroup = addUniqueGroup( grBase + "->" );
|
targetGroup = addUniqueGroup( grLeft + "->" );
|
||||||
|
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
QString str = tabText( i );
|
QString str = tabText( i );
|
||||||
if( str.length() == 7 && str.mid( 2, 3 ) == " - " && str.startsWith( grBase ) )
|
if( str.length() == 7 && str.mid( 2, 3 ) == " - " && str.startsWith( grLeft ) )
|
||||||
{
|
combineGroups( i, targetGroup );
|
||||||
setCurrentIndex( i );
|
|
||||||
vector< sptr< Dictionary::Class > > const & dicts = getCurrentModel()->getCurrentDictionaries();
|
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
|
||||||
DictListModel *model = getCurrentModel();
|
|
||||||
|
|
||||||
for( unsigned j = 0; j < dicts.size(); j++ )
|
|
||||||
model->addRow( QModelIndex(), dicts[ j ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
setCurrentIndex( targetGroup );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( result && result == combineTargetAction )
|
if( result && result == combineTargetAction )
|
||||||
{
|
{
|
||||||
QString grBase = name.right( 2 );
|
|
||||||
|
|
||||||
setCurrentIndex( clickedGroup );
|
setCurrentIndex( clickedGroup );
|
||||||
targetGroup = addUniqueGroup( "->" + grBase );
|
targetGroup = addUniqueGroup( "->" + grRight );
|
||||||
|
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
QString str = tabText( i );
|
QString str = tabText( i );
|
||||||
if( str.length() == 7 && str.mid( 2, 3 ) == " - " && str.endsWith( grBase ) )
|
if( str.length() == 7 && str.mid( 2, 3 ) == " - " && str.endsWith( grRight ) )
|
||||||
{
|
combineGroups( i, targetGroup );
|
||||||
setCurrentIndex( i );
|
|
||||||
vector< sptr< Dictionary::Class > > const & dicts = getCurrentModel()->getCurrentDictionaries();
|
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
|
||||||
DictListModel *model = getCurrentModel();
|
|
||||||
|
|
||||||
for( unsigned j = 0; j < dicts.size(); j++ )
|
|
||||||
model->addRow( QModelIndex(), dicts[ j ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
setCurrentIndex( targetGroup );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( result && result == combineTwoSidedAction )
|
if( result && result == combineTwoSidedAction )
|
||||||
{
|
{
|
||||||
setCurrentIndex( clickedGroup );
|
setCurrentIndex( clickedGroup );
|
||||||
targetGroup = addUniqueGroup( name + " - " + name.left( 2 ) );
|
targetGroup = addUniqueGroup( name + " - " + grLeft );
|
||||||
QString str = name.right( 2 ) + " - " + name.left( 2 );
|
QString str = grRight + " - " + grLeft;
|
||||||
|
|
||||||
|
for( int i = 0; i < count(); i++ )
|
||||||
|
if( tabText( i ) == name || tabText( i ) == str )
|
||||||
|
combineGroups( i, targetGroup );
|
||||||
|
|
||||||
|
setCurrentIndex( targetGroup );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( result && ( result == combineFirstAction || result == combineSecondAction ) )
|
||||||
|
{
|
||||||
|
QString const & grBase = result == combineFirstAction ? grLeft : grRight;
|
||||||
|
setCurrentIndex( clickedGroup );
|
||||||
|
targetGroup = addUniqueGroup( grBase );
|
||||||
|
|
||||||
for( int i = 0; i < count(); i++ )
|
for( int i = 0; i < count(); i++ )
|
||||||
{
|
{
|
||||||
if( tabText( i ) == name || tabText( i ) == str )
|
QString str = tabText( i );
|
||||||
{
|
if( str.length() == 7 && str.mid( 2, 3 ) == " - " &&
|
||||||
setCurrentIndex( i );
|
( str.startsWith( grBase ) || str.endsWith( grBase ) ) )
|
||||||
vector< sptr< Dictionary::Class > > const & dicts = getCurrentModel()->getCurrentDictionaries();
|
combineGroups( i, targetGroup );
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
|
||||||
DictListModel *model = getCurrentModel();
|
|
||||||
|
|
||||||
for( unsigned j = 0; j < dicts.size(); j++ )
|
|
||||||
model->addRow( QModelIndex(), dicts[ j ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentIndex( targetGroup );
|
setCurrentIndex( targetGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/// Add source group to target group
|
||||||
|
void combineGroups( int source, int target );
|
||||||
|
|
||||||
unsigned nextId;
|
unsigned nextId;
|
||||||
std::vector< sptr< Dictionary::Class > > const * allDicts;
|
std::vector< sptr< Dictionary::Class > > const * allDicts;
|
||||||
std::vector< sptr< Dictionary::Class > > const * activeDicts;
|
std::vector< sptr< Dictionary::Class > > const * activeDicts;
|
||||||
|
|
Loading…
Reference in a new issue