Display date in locale format

Add GetLocale(), GetDateFormat() and FormatDate()
This commit is contained in:
Grégory Soutadé 2012-03-27 21:12:55 +02:00
parent 57792fba92
commit a3dc4deff1
9 changed files with 49 additions and 13 deletions

View File

@ -1,4 +1,4 @@
v0.3 (20/03/2012)
v0.3 (27/03/2012)
** User **
New interface in Qt
Use BDD file from .local/share/kisscount
@ -6,6 +6,7 @@ v0.3 (20/03/2012)
New account attribute : hidden
Description is now auto-completed
Snapshot feature
Display date in locale format
** Dev **
Version 3 of database (account hidden item added)

View File

@ -649,3 +649,18 @@ bool KissCount::ChangeDatabase(QString filename)
{
return _db->ChangeDatabase(filename);
}
QLocale* KissCount::GetLocale()
{
return _wxUI->GetLocale();
}
QString KissCount::GetDateFormat()
{
return _wxUI->GetDateFormat();
}
QString KissCount::FormatDate(int day, int month, int year)
{
return QDate(year, month, day).toString(_wxUI->GetDateFormat());
}

View File

@ -139,6 +139,10 @@ public:
bool ChangeDatabase(QString filename);
QLocale* GetLocale();
QString GetDateFormat();
QString FormatDate(int day, int month, int year);
private:
wxUI* _wxUI;
Database* _db;

View File

@ -30,11 +30,12 @@ namespace SupportedLanguages {
QString icon;
QLocale::Language language;
QString filename;
QString dateFormat;
} language ;
static const language languages[NB_SUPPORTED_LANGUAGES] = {
{ "English", ICONS_PATH "/United Kingdom.png", QLocale::English, "english"},
{ "Français",ICONS_PATH "/France.png", QLocale::French, "french"}
{ "English", ICONS_PATH "/United Kingdom.png", QLocale::English, "english", "yyyy/MM/dd"},
{ "Français",ICONS_PATH "/France.png", QLocale::French, "french", "dd/MM/yyyy"}
};
}

View File

@ -38,7 +38,7 @@ void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QComboBox *combo = qobject_cast<QComboBox *>(editor);
QString s ;
s = s.sprintf("%02d/%02d/%04d", combo->currentIndex()+1, _month, _year);
s = QDate(_year, _month, combo->currentIndex()+1).toString(_dateFormat);
model->setData(index, qVariantFromValue(s));
}
@ -46,6 +46,9 @@ void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
void DateDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
int day;
QComboBox* combo = qobject_cast<QComboBox *>(editor);
combo->setCurrentIndex(qVariantValue<QString>(index.data()).left(2).toInt()-1);
day = QDate::fromString(qVariantValue<QString>(index.data()), _dateFormat).day()-1;
combo->setCurrentIndex(day);
}

View File

@ -28,7 +28,7 @@ class DateDelegate : public TableViewDelegate
Q_OBJECT;
public:
DateDelegate(QWidget *parent = 0, int month=0, int year=0) : TableViewDelegate(parent), _day(1), _month(month), _year(year) {}
DateDelegate(QWidget *parent = 0, int month=0, int year=0, QString dateFormat="") : TableViewDelegate(parent), _day(1), _month(month), _year(year), _dateFormat(dateFormat) {}
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
@ -37,6 +37,7 @@ public:
private:
int _day, _month, _year;
QString _dateFormat;
};
#endif

View File

@ -236,7 +236,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts);
setItemDelegateForColumn(ACCOUNT, accountEditor);
DateDelegate* dateEditor = new DateDelegate(this, month+1, year);
DateDelegate* dateEditor = new DateDelegate(this, month+1, year, _kiss->GetDateFormat());
setItemDelegateForColumn(OP_DATE, dateEditor);
FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations);
@ -328,7 +328,7 @@ void GridAccount::InsertOperationWithWeek(User* user, Operation& op, int line, b
if (op.id && !fix)
ComputeWeeks();
}
#include <QtDebug>
void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year)
{
std::vector<Operation>::iterator it;
@ -373,7 +373,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
else
setItem(line, DESCRIPTION, new QTableWidgetItem(description));
item = new QTableWidgetItem();
setItem(line, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", op.day+1, month+1, year)));
setItem(line, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(op.day+1, month+1, year)));
if (op.amount < 0)
{
setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", -op.amount)));
@ -440,7 +440,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
}
else
{
setItem(line, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", curDate.day(), month+1, year)));
setItem(line, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(curDate.day(), month+1, year)));
SET_ROW_COLOR(line, view::OWN_GREEN, Qt::black);
}
@ -914,7 +914,7 @@ void GridAccount::OnOperationModified(int row, int col)
value = item(row, OP_DATE)->text();
if (value.length())
{
date = QDate::fromString(value, "dd/MM/yyyy");
date = QDate::fromString(value, _kiss->GetDateFormat());
new_op.day = date.day()-1;
new_op.month = date.month()-1;
new_op.year = date.year();
@ -1050,7 +1050,7 @@ void GridAccount::OnOperationModified(int row, int col)
{
if (_curMonth+1 == curDate.month() &&
_curYear == curDate.year())
setItem(row, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", curDate.day(), _curMonth+1, _curYear)));
setItem(row, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(curDate.day(), _curMonth+1, _curYear)));
}
DEFAULT_FONT(font);
@ -1119,7 +1119,7 @@ void GridAccount::OnOperationModified(int row, int col)
else
checkBox->setCheckState(Qt::Unchecked);
setItem(row, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", new_op.day+1, _curMonth+1, _curYear)));
setItem(row, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(new_op.day+1, _curMonth+1, _curYear)));
if (!_displayedOperations[row].amount)
{

View File

@ -147,6 +147,7 @@ bool wxUI::SetLanguage(QString language)
}
_language = SupportedLanguages::languages[i].language;
_curLanguage = SupportedLanguages::languages[i];
_locale = new QLocale(SupportedLanguages::languages[i].language);
QLocale::setDefault(*_locale);
@ -331,3 +332,8 @@ void wxUI::NeedReload()
{
_needReload = true;
}
QString wxUI::GetDateFormat()
{
return _curLanguage.dateFormat;
}

View File

@ -33,6 +33,7 @@ class ImportEngine;
#include <controller/KissCount.hpp>
#include "view.hpp"
#include "SupportedLanguages.hpp"
#include <qtranslator.h>
#include <qtextcodec.h>
@ -73,7 +74,11 @@ public:
void ShowPanel(KissPanel* panel);
void NeedReload();
QLocale* GetLocale() {return _locale;}
QString GetDateFormat();
QString _language;
SupportedLanguages::language _curLanguage;
private slots:
void OnButtonClicked(int id);