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>
22 MintingView::MintingView(QWidget *parent) :
23 QWidget(parent), model(0), mintingView(0)
25 QHBoxLayout *hlayout = new QHBoxLayout();
26 hlayout->setContentsMargins(0,0,0,0);
28 QString legendBoxStyle = "background-color: rgb(%1,%2,%3); border: 1px solid black;";
30 QLabel *youngColor = new QLabel(" ");
31 youngColor->setMaximumHeight(15);
32 youngColor->setMaximumWidth(10);
33 youngColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_YOUNG.red()).arg(COLOR_MINT_YOUNG.green()).arg(COLOR_MINT_YOUNG.blue()));
34 QLabel *youngLegend = new QLabel(tr("transaction is too young"));
35 youngLegend->setContentsMargins(5,0,15,0);
37 QLabel *matureColor = new QLabel(" ");
38 matureColor->setMaximumHeight(15);
39 matureColor->setMaximumWidth(10);
40 matureColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_MATURE.red()).arg(COLOR_MINT_MATURE.green()).arg(COLOR_MINT_MATURE.blue()));
41 QLabel *matureLegend = new QLabel(tr("transaction is mature"));
42 matureLegend->setContentsMargins(5,0,15,0);
44 QLabel *oldColor = new QLabel(" ");
45 oldColor->setMaximumHeight(15);
46 oldColor->setMaximumWidth(10);
47 oldColor->setStyleSheet(legendBoxStyle.arg(COLOR_MINT_OLD.red()).arg(COLOR_MINT_OLD.green()).arg(COLOR_MINT_OLD.blue()));
48 QLabel *oldLegend = new QLabel(tr("transaction has reached maximum probability"));
49 oldLegend->setContentsMargins(5,0,15,0);
51 QHBoxLayout *legendLayout = new QHBoxLayout();
52 legendLayout->setContentsMargins(10,10,0,0);
53 legendLayout->addWidget(youngColor);
54 legendLayout->addWidget(youngLegend);
55 legendLayout->addWidget(matureColor);
56 legendLayout->addWidget(matureLegend);
57 legendLayout->addWidget(oldColor);
58 legendLayout->addWidget(oldLegend);
59 legendLayout->insertStretch(-1);
61 QLabel *mintingLabel = new QLabel(tr("Display minting probability within : "));
62 mintingCombo = new QComboBox();
63 mintingCombo->addItem(tr("10 min"), Minting10min);
64 mintingCombo->addItem(tr("24 hours"), Minting1day);
65 mintingCombo->addItem(tr("7 days"), Minting7days);
66 mintingCombo->addItem(tr("30 days"), Minting30days);
67 mintingCombo->addItem(tr("60 days"), Minting60days);
68 mintingCombo->addItem(tr("90 days"), Minting90days);
69 mintingCombo->setFixedWidth(120);
72 hlayout->insertStretch(0);
73 hlayout->addWidget(mintingLabel);
74 hlayout->addWidget(mintingCombo);
76 QVBoxLayout *vlayout = new QVBoxLayout(this);
77 vlayout->setContentsMargins(0,0,0,0);
78 vlayout->setSpacing(0);
80 QTableView *view = new QTableView(this);
81 vlayout->addLayout(hlayout);
82 vlayout->addWidget(view);
83 vlayout->addLayout(legendLayout);
85 vlayout->setSpacing(0);
86 int width = view->verticalScrollBar()->sizeHint().width();
87 // Cover scroll bar width with spacing
89 hlayout->addSpacing(width+2);
91 hlayout->addSpacing(width);
93 // Always show scroll bar
94 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
95 view->setTabKeyNavigation(false);
96 view->setContextMenuPolicy(Qt::CustomContextMenu);
100 connect(mintingCombo, SIGNAL(activated(int)), this, SLOT(chooseMintingInterval(int)));
103 QAction *copyTxIDAction = new QAction(tr("Copy transaction ID of input"), this);
104 QAction *copyAddressAction = new QAction(tr("Copy address of input"), this);
106 contextMenu = new QMenu();
107 contextMenu->addAction(copyAddressAction);
108 contextMenu->addAction(copyTxIDAction);
110 connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
111 connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID()));
113 connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
117 void MintingView::setModel(WalletModel *model)
122 mintingProxyModel = new MintingFilterProxy(this);
123 mintingProxyModel->setSourceModel(model->getMintingTableModel());
124 mintingProxyModel->setDynamicSortFilter(true);
125 mintingProxyModel->setSortRole(Qt::EditRole);
127 mintingView->setModel(mintingProxyModel);
128 mintingView->setAlternatingRowColors(true);
129 mintingView->setSelectionBehavior(QAbstractItemView::SelectRows);
130 mintingView->setSelectionMode(QAbstractItemView::ExtendedSelection);
131 mintingView->setSortingEnabled(true);
132 mintingView->sortByColumn(MintingTableModel::CoinDay, Qt::DescendingOrder);
133 mintingView->verticalHeader()->hide();
135 mintingView->horizontalHeader()->resizeSection(
136 MintingTableModel::Age, 120);
137 mintingView->horizontalHeader()->resizeSection(
138 MintingTableModel::Balance, 120);
139 mintingView->horizontalHeader()->resizeSection(
140 MintingTableModel::CoinDay,120);
141 mintingView->horizontalHeader()->resizeSection(
142 MintingTableModel::MintProbability, 120);
143 #if QT_VERSION < 0x050000
144 mintingView->horizontalHeader()->setResizeMode(
145 MintingTableModel::MintReward, QHeaderView::Stretch);
147 mintingView->horizontalHeader()->setSectionResizeMode(
148 MintingTableModel::MintReward, QHeaderView::Stretch);
150 mintingView->horizontalHeader()->resizeSection(
151 MintingTableModel::Address, 0);
152 mintingView->horizontalHeader()->resizeSection(
153 MintingTableModel::TxHash, 0);
155 mintingView->horizontalHeader()->setSectionHidden(
156 MintingTableModel::Address, true);
157 mintingView->horizontalHeader()->setSectionHidden(
158 MintingTableModel::TxHash, true);
163 void MintingView::chooseMintingInterval(int idx)
166 switch(mintingCombo->itemData(idx).toInt())
187 model->getMintingTableModel()->setMintingInterval(interval);
188 mintingProxyModel->invalidate();
191 void MintingView::exportClicked()
193 // CSV is currently the only supported format
194 QString filename = GUIUtil::getSaveFileName(
196 tr("Export Minting Data"), QString(),
197 tr("Comma separated file (*.csv)"));
199 if (filename.isNull()) return;
201 CSVModelWriter writer(filename);
203 // name, column, role
204 writer.setModel(mintingProxyModel);
205 writer.addColumn(tr("Address"),0, MintingTableModel::Address);
206 writer.addColumn(tr("Transaction"), 0, MintingTableModel::TxHash);
207 writer.addColumn(tr("Age"), 0, MintingTableModel::Age);
208 writer.addColumn(tr("CoinDay"), 0, MintingTableModel::CoinDay);
209 writer.addColumn(tr("Balance"), 0, MintingTableModel::Balance);
210 writer.addColumn(tr("MintingProbability"), 0, MintingTableModel::MintProbability);
211 writer.addColumn(tr("MintingReward"), 0, MintingTableModel::MintReward);
215 QMessageBox::critical(this, tr("Error exporting"), tr("Could not write to file %1.").arg(filename),
216 QMessageBox::Abort, QMessageBox::Abort);
220 void MintingView::copyTxID()
222 GUIUtil::copyEntryData(mintingView, MintingTableModel::TxHash, 0);
225 void MintingView::copyAddress()
227 GUIUtil::copyEntryData(mintingView, MintingTableModel::Address, 0 );
230 void MintingView::contextualMenu(const QPoint &point)
232 QModelIndex index = mintingView->indexAt(point);
235 contextMenu->exec(QCursor::pos());