Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI] Transaction Date Range: persistence added and format modified #884

Merged
merged 1 commit into from
Jun 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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