Display date in locale format

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

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)
{