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

radselect: Merge last button column directly in mapRadicalsByStrokes()

parent be120daf
......@@ -57,25 +57,14 @@ void ButtonGrid::buildRadicalButtons()
}
//Get a list of radicals (organized by strokes)
QMultiMap<int, Radical> *radicalMap = m_radicalInfo->mapRadicalsByStrokes();
QMultiMap<int, Radical> *radicalMap = m_radicalInfo->mapRadicalsByStrokes( number_of_radical_columns );
QList<int> radicalStrokeCounts = radicalMap->uniqueKeys();
//Now create all the buttons
unsigned int last_column = 0;
int row_index = 1;
foreach( int strokeCount, radicalStrokeCounts )
{
//(0-based column index)
unsigned int column_index = strokeCount - 1;
if( column_index >= number_of_radical_columns )
{
column_index = number_of_radical_columns - 1;
}
//If we're starting a new column, reset the row
if( last_column != column_index )
{
row_index = 1;
}
int row_index = 1;
QList<Radical> radicals = radicalMap->values( strokeCount );
std::sort( radicals.begin(), radicals.end() );
......@@ -93,8 +82,6 @@ void ButtonGrid::buildRadicalButtons()
//Add this button to our list
m_buttons.insert( radical, button );
}
last_column = column_index;
}
delete radicalMap;
setLayout( grid );
......
......@@ -152,12 +152,17 @@ bool RadicalFile::loadKanjidic( const QString &kanjidic )
return true;
}
QMultiMap<int,Radical>* RadicalFile::mapRadicalsByStrokes() const
QMultiMap<int,Radical>* RadicalFile::mapRadicalsByStrokes( int max_strokes ) const
{
QMultiMap<int, Radical> *result = new QMultiMap<int, Radical>();
foreach( const Radical &rad, m_radicals )
{
result->insert( m_radicals[ rad ].strokes(), m_radicals[ rad ] );
int strokes = rad.strokes();
if( ( max_strokes > 0 ) && ( strokes > max_strokes ) )
{
strokes = max_strokes;
}
result->insert( strokes, rad );
}
return result;
}
......
......@@ -25,7 +25,7 @@ class RadicalFile
QSet<Kanji> kanjiContainingRadicals( QSet<QString> &radicalList ) const;
bool loadRadicalFile( QString &radkfile );
bool loadKanjidic( const QString &kanjidic );
QMultiMap<int,Radical> *mapRadicalsByStrokes() const;
QMultiMap<int,Radical> *mapRadicalsByStrokes( int max_strokes = 0 ) const;
QSet<QString> radicalsInKanji( QSet<Kanji> &kanjiList ) const;
private:
......
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