Skip to content

Commit

Permalink
[UI] Transaction Date Range: persistence added and format modified
Browse files Browse the repository at this point in the history
  • Loading branch information
crowning- committed Jun 13, 2016
1 parent 5945b70 commit b7546d2
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <QUrl>
#include <QVBoxLayout>

/** Date format for persistence */
static const char* PERSISTENCE_DATE_FORMAT = "yyyy-MM-dd";

TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent), model(0), transactionProxyModel(0),
transactionView(0)
Expand Down Expand Up @@ -258,6 +261,8 @@ void TransactionView::chooseDate(int idx)
{
if(!transactionProxyModel)
return;

QSettings settings;
QDate current = QDate::currentDate();
dateRangeWidget->setVisible(false);
switch(dateWidget->itemData(idx).toInt())
Expand Down Expand Up @@ -300,10 +305,11 @@ void TransactionView::chooseDate(int idx)
dateRangeChanged();
break;
}
// Persist settings
if (dateWidget->itemData(idx).toInt() != Range){
QSettings settings;
settings.setValue("transactionDate", idx);
// Persist new date settings
settings.setValue("transactionDate", idx);
if (dateWidget->itemData(idx).toInt() == Range){
settings.setValue("transactionDateFrom", dateFrom->date().toString(PERSISTENCE_DATE_FORMAT));
settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT));
}
}

Expand Down Expand Up @@ -507,6 +513,11 @@ void TransactionView::openThirdPartyTxUrl(QString url)

QWidget *TransactionView::createDateRangeWidget()
{
// Create default dates in case nothing is persisted
QString defaultDateFrom = QDate::currentDate().toString(PERSISTENCE_DATE_FORMAT);
QString defaultDateTo = QDate::currentDate().addDays(1).toString(PERSISTENCE_DATE_FORMAT);
QSettings settings;

dateRangeWidget = new QFrame();
dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
dateRangeWidget->setContentsMargins(1,1,1,1);
Expand All @@ -516,18 +527,20 @@ QWidget *TransactionView::createDateRangeWidget()
layout->addWidget(new QLabel(tr("Range:")));

dateFrom = new QDateTimeEdit(this);
dateFrom->setDisplayFormat("dd/MM/yy");
dateFrom->setCalendarPopup(true);
dateFrom->setMinimumWidth(100);
dateFrom->setDate(QDate::currentDate().addDays(-7));
// Load persisted FROM date
dateFrom->setDate(QDate::fromString(settings.value("transactionDateFrom", defaultDateFrom).toString(), PERSISTENCE_DATE_FORMAT));

layout->addWidget(dateFrom);
layout->addWidget(new QLabel(tr("to")));

dateTo = new QDateTimeEdit(this);
dateTo->setDisplayFormat("dd/MM/yy");
dateTo->setCalendarPopup(true);
dateTo->setMinimumWidth(100);
dateTo->setDate(QDate::currentDate());
// Load persisted TO date
dateTo->setDate(QDate::fromString(settings.value("transactionDateTo", defaultDateTo).toString(), PERSISTENCE_DATE_FORMAT));

layout->addWidget(dateTo);
layout->addStretch();

Expand All @@ -545,9 +558,15 @@ void TransactionView::dateRangeChanged()
{
if(!transactionProxyModel)
return;

// Persist new date range
QSettings settings;
settings.setValue("transactionDateFrom", dateFrom->date().toString(PERSISTENCE_DATE_FORMAT));
settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT));

transactionProxyModel->setDateRange(
QDateTime(dateFrom->date()),
QDateTime(dateTo->date()).addDays(1));
QDateTime(dateTo->date()));
}

void TransactionView::focusTransaction(const QModelIndex &idx)
Expand Down

0 comments on commit b7546d2

Please sign in to comment.