Skip to content

Commit 566b6fc

Browse files
Mrs-XFuzzbawls
authored andcommitted
[GUI] Load persisted transaction filter/sort during start (V3)
Github-Pull: #1287 Rebased-From: 96a4232
1 parent 5d22583 commit 566b6fc

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

src/qt/pivx/dashboardwidget.cpp

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,18 @@ void DashboardWidget::loadWalletModel()
182182
filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
183183
filter->setSortRole(Qt::EditRole);
184184
filter->setSourceModel(txModel);
185-
filter->sort(TransactionTableModel::Date, Qt::DescendingOrder);
185+
186+
// Read filter settings
187+
QSettings settings;
188+
int filterByType = settings.value("transactionType", TransactionFilterProxy::ALL_TYPES).toInt();
189+
190+
filter->setTypeFilter(filterByType); // Set filter
191+
int filterIndex = ui->comboBoxSortType->findData(filterByType); // Find index
192+
ui->comboBoxSortType->setCurrentIndex(filterIndex); // Set item in ComboBox
193+
194+
// Read sort settings
195+
changeSort(settings.value("transactionSort", SortTx::DATE_DESC).toInt());
196+
186197
txHolder->setFilter(filter);
187198
ui->listTransactions->setModel(filter);
188199
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
@@ -256,39 +267,59 @@ void DashboardWidget::updateDisplayUnit()
256267
void DashboardWidget::onSortChanged(const QString& value)
257268
{
258269
if (!filter) return;
259-
int columnIndex = 0;
260-
Qt::SortOrder order = Qt::DescendingOrder;
270+
261271
if (!value.isNull()) {
262-
switch (ui->comboBoxSort->itemData(ui->comboBoxSort->currentIndex()).toInt()) {
263-
case SortTx::DATE_ASC:{
264-
columnIndex = TransactionTableModel::Date;
265-
order = Qt::AscendingOrder;
266-
break;
267-
}
268-
case SortTx::DATE_DESC:{
269-
columnIndex = TransactionTableModel::Date;
270-
break;
271-
}
272-
case SortTx::AMOUNT_ASC:{
273-
columnIndex = TransactionTableModel::Amount;
274-
order = Qt::AscendingOrder;
275-
break;
276-
}
277-
case SortTx::AMOUNT_DESC:{
278-
columnIndex = TransactionTableModel::Amount;
279-
break;
280-
}
272+
changeSort(ui->comboBoxSort->currentIndex());
273+
} else {
274+
changeSort(SortTx::DATE_DESC);
275+
}
276+
}
277+
278+
void DashboardWidget::changeSort(int nSortIndex)
279+
{
280+
int nColumnIndex = TransactionTableModel::Date;
281+
Qt::SortOrder order = Qt::DescendingOrder;
281282

283+
switch (nSortIndex) {
284+
case SortTx::DATE_DESC:
285+
{
286+
nColumnIndex = TransactionTableModel::Date;
287+
break;
288+
}
289+
case SortTx::DATE_ASC:
290+
{
291+
nColumnIndex = TransactionTableModel::Date;
292+
order = Qt::AscendingOrder;
293+
break;
294+
}
295+
case SortTx::AMOUNT_DESC:
296+
{
297+
nColumnIndex = TransactionTableModel::Amount;
298+
break;
299+
}
300+
case SortTx::AMOUNT_ASC:
301+
{
302+
nColumnIndex = TransactionTableModel::Amount;
303+
order = Qt::AscendingOrder;
304+
break;
282305
}
283306
}
284-
filter->sort(columnIndex, order);
307+
308+
ui->comboBoxSort->setCurrentIndex(nSortIndex);
309+
filter->sort(nColumnIndex, order);
285310
ui->listTransactions->update();
311+
312+
// Store settings
313+
QSettings settings;
314+
settings.setValue("transactionSort", nSortIndex);
286315
}
287316

288317
void DashboardWidget::onSortTypeChanged(const QString& value)
289318
{
290319
if (!filter) return;
291-
int filterByType = ui->comboBoxSortType->itemData(ui->comboBoxSortType->currentIndex()).toInt();
320+
int filterIndex = ui->comboBoxSortType->currentIndex();
321+
int filterByType = ui->comboBoxSortType->itemData(filterIndex).toInt();
322+
292323
filter->setTypeFilter(filterByType);
293324
ui->listTransactions->update();
294325

src/qt/pivx/dashboardwidget.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class SortEdit : public QLineEdit{
6161
};
6262

6363
enum SortTx {
64-
DATE_ASC = 0,
65-
DATE_DESC = 1,
66-
AMOUNT_ASC = 2,
67-
AMOUNT_DESC = 3
64+
DATE_DESC = 0,
65+
DATE_ASC = 1,
66+
AMOUNT_DESC = 2,
67+
AMOUNT_ASC = 3
6868
};
6969

7070
enum ChartShowType {
@@ -140,6 +140,7 @@ private Q_SLOTS:
140140
TransactionTableModel* txModel;
141141
int nDisplayUnit = -1;
142142
bool isSync = false;
143+
void changeSort(int nSortIndex);
143144

144145
#ifdef USE_QTCHARTS
145146

0 commit comments

Comments
 (0)