Commit be120daf authored by Frédéric Brière's avatar Frédéric Brière
Browse files

radselect: Display radicals in the same order as listed in radkfile

parent 27512846
......@@ -58,14 +58,14 @@ void ButtonGrid::buildRadicalButtons()
//Get a list of radicals (organized by strokes)
QMultiMap<int, Radical> *radicalMap = m_radicalInfo->mapRadicalsByStrokes();
QMultiMap<int, Radical>::const_iterator it = radicalMap->constBegin();
QList<int> radicalStrokeCounts = radicalMap->uniqueKeys();
//Now create all the buttons
unsigned int last_column = 0;
int row_index = 1;
while( it != radicalMap->constEnd() )
foreach( int strokeCount, radicalStrokeCounts )
{
//For each radical, figure out which slot it goes in (0-based column index)
unsigned int column_index = it.key() - 1;
//(0-based column index)
unsigned int column_index = strokeCount - 1;
if( column_index >= number_of_radical_columns )
{
column_index = number_of_radical_columns - 1;
......@@ -77,20 +77,24 @@ void ButtonGrid::buildRadicalButtons()
row_index = 1;
}
//Make the button
RadicalButton *button = new RadicalButton( *it, this );
grid->addWidget( button, row_index++, column_index );
//Bind slots/signals for this button
connect( button, &RadicalButton::userClicked,
this, &ButtonGrid::radicalClicked );
connect( this, &ButtonGrid::clearButtonSelections,
button, &RadicalButton::resetButton );
//Add this button to our list
m_buttons.insert( *it, button );
QList<Radical> radicals = radicalMap->values( strokeCount );
std::sort( radicals.begin(), radicals.end() );
foreach( const Radical &radical, radicals )
{
//Make the button
RadicalButton *button = new RadicalButton( radical, this );
grid->addWidget( button, row_index++, column_index );
//Bind slots/signals for this button
connect( button, &RadicalButton::userClicked,
this, &ButtonGrid::radicalClicked );
connect( this, &ButtonGrid::clearButtonSelections,
button, &RadicalButton::resetButton );
//Add this button to our list
m_buttons.insert( radical, button );
}
last_column = column_index;
++it;
}
delete radicalMap;
setLayout( grid );
......
......@@ -12,9 +12,10 @@ Radical::Radical()
{
}
Radical::Radical( const QString &irad, unsigned int strokes )
Radical::Radical( const QString &irad, unsigned int strokes, unsigned int index )
: QString( irad.at( 0 ) )
, strokeCount( strokes )
, idx( index )
{
}
......@@ -35,5 +36,5 @@ unsigned int Radical::strokes() const
bool Radical::operator<( const Radical &other ) const
{
return this->strokeCount < other.strokeCount;
return this->idx < other.idx;
}
......@@ -16,7 +16,8 @@ class Radical : public QString
public:
Radical();
explicit Radical( const QString &irad
, unsigned int strokes = 0 );
, unsigned int strokes = 0
, unsigned int index = 0 );
const QSet<QString>& getKanji() const;
void addKanji( const QSet<QString> &newKanji );
......@@ -26,6 +27,7 @@ class Radical : public QString
protected:
unsigned int strokeCount;
unsigned int idx;
QSet<QString> kanji;
QSet<QString> components;
};
......
......@@ -82,7 +82,8 @@ bool RadicalFile::loadRadicalFile( QString &radkfile )
delete newestRadical;
QStringList lineElements = line.split( QRegExp( QStringLiteral( "\\s+" ) ) );
newestRadical = new Radical( lineElements.at( 1 )
, lineElements.at( 2 ).toUInt() );
, lineElements.at( 2 ).toUInt()
, m_radicals.size() );
}
else if( newestRadical != nullptr )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment