1 #include "mintingview.h"
2 #include "mintingfilterproxy.h"
3 #include "transactionrecord.h"
4 #include "mintingtablemodel.h"
5 #include "walletmodel.h"
6 #include "guiconstants.h"
8 #include "csvmodelwriter.h"
11 #include <QHBoxLayout>
12 #include <QHeaderView>
13 #include <QVBoxLayout>
19 #include <QMessageBox>
21 MintingView::MintingView(QWidget *parent) :
22 QWidget(parent), model(0), mintingView(0)
24 QHBoxLayout *hlayout = new QHBoxLayout();
25 hlayout->setContentsMargins(0,0,0,0);
27 QString legendBoxStyle = "background-color: rgb(%1,%2,%3); border: 1px solid black;";
29 QLabel *youngColor = new QLabel(" ");
30 youngColor->setMaximumHeight(15);
31 youngColor->setMaximumWidth(10);
32 youngColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_YOUNG.red()).arg(COLOR_MINT_YOUNG.green()).arg(COLOR_MINT_YOUNG.blue()));
33 QLabel *youngLegend = new QLabel(tr("transaction is too young"));
34 youngLegend->setContentsMargins(5,0,15,0);
36 QLabel *matureColor = new QLabel(" ");
37 matureColor->setMaximumHeight(15);
38 matureColor->setMaximumWidth(10);
39 matureColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_MATURE.red()).arg(COLOR_MINT_MATURE.green()).arg(COLOR_MINT_MATURE.blue()));
40 QLabel *matureLegend = new QLabel(tr("transaction is mature"));
41 matureLegend->setContentsMargins(5,0,15,0);
43 QLabel *oldColor = new QLabel(" ");
44 oldColor->setMaximumHeight(15);
45 oldColor->setMaximumWidth(10);
46 oldColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_OLD.red()).arg(COLOR_MINT_OLD.green()).arg(COLOR_MINT_OLD.blue()));
47 QLabel *oldLegend = new QLabel(tr("transaction has reached maximum probability"));
48 oldLegend->setContentsMargins(5,0,15,0);
50 QHBoxLayout *legendLayout = new QHBoxLayout();
51 legendLayout->setContentsMargins(10,10,0,0);
52 legendLayout->addWidget(youngColor);
53 legendLayout->addWidget(youngLegend);
54 legendLayout->addWidget(matureColor);
55 legendLayout->addWidget(matureLegend);
56 legendLayout->addWidget(oldColor);
57 legendLayout->addWidget(oldLegend);
58 legendLayout->insertStretch(-1);
60 QLabel *mintingLabel = new QLabel(tr("Display minting probability within : "));
61 mintingCombo = new QComboBox();
62 mintingCombo->addItem(tr("10 min"), Minting10min);
63 mintingCombo->addItem(tr("24 hours"), Minting1day);
64 mintingCombo->addItem(tr("30 days"), Minting30days);
65 mintingCombo->addItem(tr("90 days"), Minting90days);
66 mintingCombo->setFixedWidth(120);
69 hlayout->insertStretch(0);
70 hlayout->addWidget(mintingLabel);
71 hlayout->addWidget(mintingCombo);
73 QVBoxLayout *vlayout = new QVBoxLayout(this);
74 vlayout->setContentsMargins(0,0,0,0);
75 vlayout->setSpacing(0);
77 QTableView *view = new QTableView(this);
78 vlayout->addLayout(hlayout);
79 vlayout->addWidget(view);
80 vlayout->addLayout(legendLayout);
82 vlayout->setSpacing(0);
83 int width = view->verticalScrollBar()->sizeHint().width();
84 // Cover scroll bar width with spacing
86 hlayout->addSpacing(width+2);
88 hlayout->addSpacing(width);
90 // Always show scroll bar
91 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
92 view->setTabKeyNavigation(false);
93 view->setContextMenuPolicy(Qt::CustomContextMenu);
97 connect(mintingCombo, SIGNAL(activated(int)), this, SLOT(chooseMintingInterval(int)));
102 void MintingView::setModel(WalletModel *model)
107 mintingProxyModel = new MintingFilterProxy(this);
108 mintingProxyModel->setSourceModel(model->getMintingTableModel());
109 mintingProxyModel->setDynamicSortFilter(true);
110 mintingProxyModel->setSortRole(Qt::EditRole);
112 mintingView->setModel(mintingProxyModel);
113 mintingView->setAlternatingRowColors(true);
114 mintingView->setSelectionBehavior(QAbstractItemView::SelectRows);
115 mintingView->setSelectionMode(QAbstractItemView::ExtendedSelection);
116 mintingView->setSortingEnabled(true);
117 mintingView->sortByColumn(MintingTableModel::CoinDay, Qt::DescendingOrder);
118 mintingView->verticalHeader()->hide();
120 mintingView->horizontalHeader()->resizeSection(
121 MintingTableModel::Address, 300);
122 #if QT_VERSION < 0x050000
123 mintingView->horizontalHeader()->setResizeMode(
124 MintingTableModel::TxHash, QHeaderView::Stretch);
126 mintingView->horizontalHeader()->setSectionResizeMode(
127 MintingTableModel::TxHash, QHeaderView::Stretch);
129 mintingView->horizontalHeader()->resizeSection(
130 MintingTableModel::Age, 120);
131 mintingView->horizontalHeader()->resizeSection(
132 MintingTableModel::Balance, 120);
133 mintingView->horizontalHeader()->resizeSection(
134 MintingTableModel::CoinDay,120);
135 mintingView->horizontalHeader()->resizeSection(
136 MintingTableModel::MintProbability, 120);
137 mintingView->horizontalHeader()->resizeSection(
138 MintingTableModel::MintReward, 300);
142 void MintingView::chooseMintingInterval(int idx)
145 switch(mintingCombo->itemData(idx).toInt())
160 model->getMintingTableModel()->setMintingInterval(interval);
161 mintingProxyModel->invalidate();
164 void MintingView::exportClicked()
166 // CSV is currently the only supported format
167 QString filename = GUIUtil::getSaveFileName(
169 tr("Export Minting Data"), QString(),
170 tr("Comma separated file (*.csv)"));
172 if (filename.isNull()) return;
174 CSVModelWriter writer(filename);
176 // name, column, role
177 writer.setModel(mintingProxyModel);
178 writer.addColumn(tr("Address"),0, MintingTableModel::Address);
179 writer.addColumn(tr("Transaction"), 0, MintingTableModel::TxHash);
180 writer.addColumn(tr("Age"), 0, MintingTableModel::Age);
181 writer.addColumn(tr("CoinDay"), 0, MintingTableModel::CoinDay);
182 writer.addColumn(tr("Balance"), 0, MintingTableModel::Balance);
183 writer.addColumn(tr("MintingProbability"), 0, MintingTableModel::MintProbability);
184 writer.addColumn(tr("MintingReward"), 0, MintingTableModel::MintReward);
188 QMessageBox::critical(this, tr("Error exporting"), tr("Could not write to file %1.").arg(filename),
189 QMessageBox::Abort, QMessageBox::Abort);