mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
added auto creation of language pair based groups
This commit is contained in:
parent
00476b0776
commit
d8b76db518
|
@ -40,6 +40,8 @@ Groups::Groups( QWidget * parent,
|
|||
this, SLOT( addToGroup() ) );
|
||||
connect( ui.removeDictsFromGroup, SIGNAL( clicked() ),
|
||||
this, SLOT( removeFromGroup() ) );
|
||||
connect( ui.autoGroups, SIGNAL( clicked() ),
|
||||
this, SLOT( addAutoGroups() ) );
|
||||
|
||||
countChanged();
|
||||
}
|
||||
|
@ -100,6 +102,12 @@ void Groups::addNew()
|
|||
}
|
||||
}
|
||||
|
||||
void Groups::addAutoGroups()
|
||||
{
|
||||
ui.groups->addAutoGroups();
|
||||
countChanged();
|
||||
}
|
||||
|
||||
void Groups::renameCurrent()
|
||||
{
|
||||
int current = ui.groups->currentIndex();
|
||||
|
|
|
@ -45,6 +45,7 @@ private slots:
|
|||
void removeAll();
|
||||
void addToGroup();
|
||||
void removeFromGroup();
|
||||
void addAutoGroups();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
21
groups.ui
21
groups.ui
|
@ -144,6 +144,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="autoGroups">
|
||||
<property name="toolTip">
|
||||
<string>Create language-based groups</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto groups</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="renameGroup">
|
||||
<property name="toolTip">
|
||||
|
@ -203,6 +213,17 @@
|
|||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>dictionaries</tabstop>
|
||||
<tabstop>addDictsToGroup</tabstop>
|
||||
<tabstop>removeDictsFromGroup</tabstop>
|
||||
<tabstop>groups</tabstop>
|
||||
<tabstop>addGroup</tabstop>
|
||||
<tabstop>autoGroups</tabstop>
|
||||
<tabstop>renameGroup</tabstop>
|
||||
<tabstop>removeGroup</tabstop>
|
||||
<tabstop>removeAllGroups</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "langcoder.hh"
|
||||
#include "language.hh"
|
||||
|
||||
//#include "initializing.hh"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
|
@ -224,6 +226,19 @@ bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
|
|||
return true;
|
||||
}
|
||||
|
||||
void DictListModel::addRow(const QModelIndex & parent, sptr< Dictionary::Class > dict)
|
||||
{
|
||||
for (int i = 0; i < dictionaries.size(); i++)
|
||||
{
|
||||
if (dictionaries[i]->getId() == dict->getId())
|
||||
return;
|
||||
}
|
||||
|
||||
beginInsertRows( parent, dictionaries.size(), dictionaries.size()+1 );
|
||||
dictionaries.push_back(dict);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
bool DictListModel::removeRows( int row, int count,
|
||||
const QModelIndex & parent )
|
||||
{
|
||||
|
@ -547,6 +562,65 @@ void DictGroupsWidget::addNewGroup( QString const & name )
|
|||
setCurrentIndex( idx );
|
||||
}
|
||||
|
||||
void DictGroupsWidget::addAutoGroups()
|
||||
{
|
||||
if ( !allDicts )
|
||||
return;
|
||||
|
||||
QMap< QPair<quint32,quint32>, int > tabMap;
|
||||
|
||||
// ::Initializing init( this, true );
|
||||
// QApplication::processEvents();
|
||||
|
||||
for ( int i = 0; i < allDicts->size(); i++ )
|
||||
{
|
||||
sptr<Dictionary::Class> dict = allDicts->at( i );
|
||||
|
||||
quint32 idfrom = dict->getLangFrom();
|
||||
quint32 idto = dict->getLangTo();
|
||||
QPair<quint32,quint32> key(idfrom, idto);
|
||||
|
||||
if (tabMap.contains(key))
|
||||
{
|
||||
setCurrentIndex(tabMap[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString lfrom = LangCoder::intToCode2( idfrom );
|
||||
QString lto = LangCoder::intToCode2( idto );
|
||||
QString name("Unassigned");
|
||||
if (lfrom.isEmpty() == false && lto.isEmpty() == false)
|
||||
name = lfrom + " - " + lto;
|
||||
|
||||
// search for the language group
|
||||
bool found = false;
|
||||
for (int j = 0; j < count(); j++)
|
||||
{
|
||||
if (tabText(j) == name)
|
||||
{
|
||||
found = true;
|
||||
setCurrentIndex(j);
|
||||
tabMap[key] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// group not found - add it
|
||||
if (!found)
|
||||
{
|
||||
addNewGroup(name);
|
||||
int j = currentIndex();
|
||||
tabMap[key] = j;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// add dictionary into the current group
|
||||
DictListModel *model = getCurrentModel();
|
||||
model->addRow(QModelIndex(), dict);
|
||||
}
|
||||
}
|
||||
|
||||
QString DictGroupsWidget::getCurrentGroupName() const
|
||||
{
|
||||
int current = currentIndex();
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
bool removeRows( int row, int count, const QModelIndex & parent );
|
||||
bool setData( QModelIndex const & index, const QVariant & value, int role );
|
||||
|
||||
void addRow(const QModelIndex & parent, sptr< Dictionary::Class > dict);
|
||||
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
|
||||
void filterDuplicates();
|
||||
|
@ -136,6 +138,8 @@ public:
|
|||
/// Creates new empty group with the given name
|
||||
void addNewGroup( QString const & );
|
||||
|
||||
void addAutoGroups();
|
||||
|
||||
/// Returns currently chosen group's name
|
||||
QString getCurrentGroupName() const;
|
||||
|
||||
|
|
|
@ -31,13 +31,6 @@ QIcon LangCoder::icon(quint32 code)
|
|||
if (langCoder.codeMap.contains(code))
|
||||
{
|
||||
const LangCode &lc = LangCodes[ langCoder.codeMap[ code ] ];
|
||||
// QString flag_id( lc.code );
|
||||
// if (flag_id == "en")
|
||||
// flag_id = "gb";
|
||||
// else
|
||||
// if (flag_id == "uk")
|
||||
// flag_id = "ua";
|
||||
|
||||
return QIcon( ":/flags/" + QString(lc.code) + ".png" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue