Commit e1dbf1b0 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Small changes in Radical

Remove the operator< and add an explicit compareIndices function that
makes it clear what we're sorting by

Make Radical have a QString instead be a QString so that operator < from
QString doesn't break the explicitless of compareIndices we just
introduced
parent 25f14794
......@@ -67,11 +67,11 @@ void ButtonGrid::buildRadicalButtons()
int row_index = 1;
QList<Radical> radicals = radicalMap->values( strokeCount );
std::sort( radicals.begin(), radicals.end() );
std::sort( radicals.begin(), radicals.end(), Radical::compareIndices );
foreach( const Radical &radical, radicals )
{
//Make the button
RadicalButton *button = new RadicalButton( radical, this );
RadicalButton *button = new RadicalButton( radical.toString(), this );
grid->addWidget( button, row_index++, column_index );
//Bind slots/signals for this button
connect( button, &RadicalButton::userClicked,
......@@ -80,7 +80,7 @@ void ButtonGrid::buildRadicalButtons()
button, &RadicalButton::resetButton );
//Add this button to our list
m_buttons.insert( radical, button );
m_buttons.insert( radical.toString(), button );
}
}
delete radicalMap;
......
......@@ -13,12 +13,17 @@ Radical::Radical()
}
Radical::Radical( const QString &irad, unsigned int strokes, unsigned int index )
: QString( irad.at( 0 ) )
: string( irad.at( 0 ) )
, strokeCount( strokes )
, idx( index )
{
}
QString Radical::toString() const
{
return string;
}
void Radical::addKanji( const QSet<QString> &newKanji )
{
kanji += newKanji;
......@@ -34,7 +39,7 @@ unsigned int Radical::strokes() const
return strokeCount;
}
bool Radical::operator<( const Radical &other ) const
bool Radical::compareIndices( const Radical &a, const Radical &b )
{
return this->idx < other.idx;
return a.idx < b.idx;
}
......@@ -11,7 +11,7 @@
#include <QSet>
#include <QString>
class Radical : public QString
class Radical
{
public:
Radical();
......@@ -19,13 +19,16 @@ class Radical : public QString
, unsigned int strokes = 0
, unsigned int index = 0 );
QString toString() const;
const QSet<QString>& getKanji() const;
void addKanji( const QSet<QString> &newKanji );
unsigned int strokes() const;
bool operator<( const Radical &other ) const;
static bool compareIndices( const Radical &a, const Radical &b );
protected:
QString string;
unsigned int strokeCount;
unsigned int idx;
QSet<QString> kanji;
......
......@@ -77,7 +77,7 @@ bool RadicalFile::loadRadicalFile( QString &radkfile )
//Start of a new radical
if( newestRadical != nullptr )
{
m_radicals.insert( *newestRadical, *newestRadical );
m_radicals.insert( newestRadical->toString(), *newestRadical );
}
delete newestRadical;
QStringList lineElements = line.split( QRegExp( QStringLiteral( "\\s+" ) ) );
......@@ -101,13 +101,13 @@ bool RadicalFile::loadRadicalFile( QString &radkfile )
#endif
foreach( const QString &kanji, m_kanjiList )
{
krad[ kanji ] += *newestRadical;
krad[ kanji ] += newestRadical->toString();
}
}
}
if( newestRadical != nullptr )
{
m_radicals[ *newestRadical ] = *newestRadical;
m_radicals[ newestRadical->toString() ] = *newestRadical;
delete newestRadical;
}
......
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