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

radselect: Add option to display radicals in decreasing frequency order

BUG: 431866
parent 66a2be94
......@@ -27,6 +27,7 @@ ButtonGrid::ButtonGrid( QWidget *parent, RadicalFile *radicalInfo )
: QWidget( parent )
, CurrentMode( Selection )
, m_radicalInfo( radicalInfo )
, m_sortByFrequency( false )
{
if ( m_radicalInfo )
{
......@@ -76,7 +77,8 @@ void ButtonGrid::buildRadicalButtons()
int row_index = 1;
QList<Radical> radicals = radicalMap->values( strokeCount );
std::sort( radicals.begin(), radicals.end(), Radical::compareIndices );
std::sort( radicals.begin(), radicals.end(),
m_sortByFrequency ? Radical::compareFrequencies : Radical::compareIndices );
foreach( const Radical &radical, radicals )
{
//Make the button
......@@ -98,6 +100,15 @@ void ButtonGrid::buildRadicalButtons()
updateButtons();
}
void ButtonGrid::setSortByFrequency( bool enable )
{
if( m_sortByFrequency != enable )
{
m_sortByFrequency = enable;
buildRadicalButtons();
}
}
void ButtonGrid::clearSelections()
{
m_selectedRadicals.clear();
......
......@@ -48,6 +48,8 @@ class ButtonGrid : public QWidget
*/
void clearSelections();
void setSortByFrequency( bool enable );
private:
void buildRadicalButtons();
void updateButtons();
......@@ -64,6 +66,7 @@ class ButtonGrid : public QWidget
QString m_relationalRadical;
QSet<QString> m_selectedRadicals;
RadicalFile *m_radicalInfo;
bool m_sortByFrequency;
//Radical -> Button Mapping
QHash<QString, RadicalButton*> m_buttons;
......
......@@ -5,6 +5,8 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <tuple>
#include "radical.h"
Radical::Radical()
......@@ -43,3 +45,10 @@ bool Radical::compareIndices( const Radical &a, const Radical &b )
{
return a.idx < b.idx;
}
bool Radical::compareFrequencies( const Radical &a, const Radical &b )
{
// Negative frequency results in a descending order
return std::make_tuple( - a.getKanji().size(), a.idx ) <
std::make_tuple( - b.getKanji().size(), b.idx );
}
......@@ -26,6 +26,7 @@ class Radical
unsigned int strokes() const;
static bool compareIndices( const Radical &a, const Radical &b );
static bool compareFrequencies( const Radical &a, const Radical &b );
protected:
QString string;
......
......@@ -16,6 +16,10 @@
<default>resultListFnt</default>
</entry>
<entry key="font" type="Font"></entry>
<entry key="sortByFrequency" type="Bool">
<label>Display radicals in descending frequency order</label>
<default>true</default>
</entry>
<entry key="closeOnSearch" type="Bool">
<label>Do we close this program when searching?</label>
<default>false</default>
......
......@@ -25,6 +25,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_sortByFrequency" >
<property name="text">
<string>Display radicals in descending frequency order</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" >
<property name="margin" >
......
......@@ -207,6 +207,8 @@ void RadSelectView::loadSettings()
//Suggested options: Lookup in Kiten, Add to Search Bar, Copy to Clipboard
selected_radicals->setFont( RadSelectConfigSkeleton::self()->resultListFont() );
m_buttongrid->setFont( RadSelectConfigSkeleton::self()->font() );
m_buttongrid->setSortByFrequency( RadSelectConfigSkeleton::self()->sortByFrequency() );
}
void RadSelectView::strokeLimitChanged( int newvalue )
......
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