Sort categories with translated names

This commit is contained in:
Grégory Soutadé 2012-12-16 09:49:51 +01:00
parent d206d5b051
commit 3e89eb7279
5 changed files with 27 additions and 6 deletions

View File

@ -150,7 +150,7 @@ QDebug operator<<(QDebug dbg, const KDChart::BackgroundAttributes& ba)
<< "visible="<<ba.isVisible()
<< "brush="<<ba.brush()
<< "pixmapmode="<<ba.pixmapMode()
<< "pixmap="<<ba.pixmap()
// << "pixmap="<<ba.pixmap()
<< ")";
return dbg;
}

View File

@ -76,6 +76,7 @@ void KissCount::LoadUser(const QString& user)
{
if (_user) delete _user;
_user = _db->LoadUser(user) ;
if (_user)
_wxUI->LoadUser();
}
@ -504,6 +505,9 @@ QFont KissCount::ExtractFont(QString strFont)
weight = list[3].toInt();
faceName = list[4];
(void) family;
(void) style;
return QFont(faceName, pointSize, weight);
}

View File

@ -23,6 +23,8 @@
#include <string>
#include <QColor>
#include <QApplication>
struct Category
{
int id;
@ -38,7 +40,7 @@ struct Category
if (cat1.fix_cost) return true;
if (cat2.fix_cost) return false;
return cat1.name < cat2.name;
return QApplication::translate("", cat1.name.toStdString().c_str()) < QApplication::translate("", cat2.name.toStdString().c_str());
}
bool operator == (int catId)

View File

@ -35,6 +35,8 @@ User::~User()
void User::InvalidateOperations()
{
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
std::vector<Category>::iterator it2;
int i;
for (it = _operations.begin(); it != _operations.end(); it++)
{
@ -48,6 +50,11 @@ void User::InvalidateOperations()
std::sort(_accounts.begin(), _accounts.end(), Account());
std::sort(_categories.begin(), _categories.end(), Category());
for (i=0, it2=_categories.begin(); it2 !=_categories.end(); it2++, i++)
{
_categoriesFonts[i] = KissCount::ExtractFont(it2->font);
}
}
Category User::GetCategory(int catId)

View File

@ -238,12 +238,20 @@ void wxUI::LoadPanels()
void wxUI::LoadUser()
{
User* user = _kiss->GetUser();
int i;
if (user->_preferences["language"].size())
SetLanguage(user->GetLanguage());
else
SetLanguage(SupportedLanguages::languages[0].name);
// Sort with translated names
std::sort(user->_categories.begin(), user->_categories.end(), Category());
for (i=0; i < (int)user->_categories.size(); i++)
{
user->_categoriesFonts[i] = KissCount::ExtractFont(user->_categories[i].font);
}
LoadPanels();
if (_panels.size())