Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
balancesview.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "balancesview.h"
6 
7 #include "addresstablemodel.h"
8 #include "bitcoinunits.h"
9 #include "csvmodelwriter.h"
10 #include "editaddressdialog.h"
11 #include "guiutil.h"
12 #include "optionsmodel.h"
13 #include "transactiondescdialog.h"
14 #include "transactionfilterproxy.h"
15 #include "transactionrecord.h"
16 #include "transactiontablemodel.h"
17 #include "walletmodel.h"
18 #include "wallet.h"
19 
20 #include "ui_interface.h"
21 
22 #include <boost/filesystem.hpp>
23 
24 #include "leveldb/db.h"
25 #include "leveldb/write_batch.h"
26 
27 // potentially overzealous includes here
28 #include "base58.h"
29 #include "rpcserver.h"
30 #include "init.h"
31 #include "util.h"
32 #include <fstream>
33 #include <algorithm>
34 #include <vector>
35 #include <utility>
36 #include <string>
37 #include <boost/assign/list_of.hpp>
38 #include <boost/algorithm/string.hpp>
39 #include <boost/algorithm/string/find.hpp>
40 #include <boost/algorithm/string/join.hpp>
41 #include <boost/lexical_cast.hpp>
42 #include <boost/format.hpp>
43 #include <boost/filesystem.hpp>
44 #include "json/json_spirit_utils.h"
45 #include "json/json_spirit_value.h"
46 #include "leveldb/db.h"
47 #include "leveldb/write_batch.h"
48 // end potentially overzealous includes
49 using namespace json_spirit; // since now using Array in mastercore.h this needs to come first
50 
51 #include "mastercore.h"
52 using namespace mastercore;
53 
54 // potentially overzealous using here
55 using namespace std;
56 using namespace boost;
57 using namespace boost::assign;
58 using namespace leveldb;
59 // end potentially overzealous using
60 
61 #include "mastercore_dex.h"
62 #include "mastercore_tx.h"
63 #include "mastercore_sp.h"
64 
65 #include <QComboBox>
66 #include <QDateTimeEdit>
67 #include <QDesktopServices>
68 #include <QDoubleValidator>
69 #include <QHBoxLayout>
70 #include <QHeaderView>
71 #include <QLabel>
72 #include <QLineEdit>
73 #include <QMenu>
74 #include <QPoint>
75 #include <QScrollBar>
76 #include <QSignalMapper>
77 #include <QTableView>
78 #include <QUrl>
79 #include <QVBoxLayout>
80 
82  QWidget(parent), model(0), balancesView(0)
83 {
84  // Build filter row
85  setContentsMargins(0,0,0,0);
86 
87  QHBoxLayout *hlayout = new QHBoxLayout();
88  hlayout->setContentsMargins(0,0,0,0);
89 #ifdef Q_OS_MAC
90  hlayout->setSpacing(5);
91  hlayout->addSpacing(26);
92 #else
93  hlayout->setSpacing(0);
94  hlayout->addSpacing(23);
95 #endif
96  hlayout->addStretch();
97  // property ID selector
98  propSelLabel = new QLabel("Show Balances For: ");
99  hlayout->addWidget(propSelLabel);
100 
101  propSelectorWidget = new QComboBox(this);
102 #ifdef Q_OS_MAC
103  propSelectorWidget->setFixedWidth(301);
104 #else
105  propSelectorWidget->setFixedWidth(300);
106 #endif
107  propSelectorWidget->addItem("Wallet Totals (Summary)","2147483646"); //use last possible ID for summary for now
108  // trigger update of global balances
110  // populate property selector
111  for (unsigned int propertyId = 1; propertyId<100000; propertyId++)
112  {
113  if ((global_balance_money_maineco[propertyId] > 0) || (global_balance_reserved_maineco[propertyId] > 0))
114  {
115  string spName;
116  spName = getPropertyName(propertyId).c_str();
117  if(spName.size()>20) spName=spName.substr(0,20)+"...";
118  string spId = static_cast<ostringstream*>( &(ostringstream() << propertyId) )->str();
119  spName += " (#" + spId + ")";
120  propSelectorWidget->addItem(spName.c_str(),spId.c_str());
121 //propSelectorWidget->addItem(tr(spName.c_str()));
122  }
123  }
124  for (unsigned int propertyId = 1; propertyId<100000; propertyId++)
125  {
126  if ((global_balance_money_testeco[propertyId] > 0) || (global_balance_reserved_testeco[propertyId] > 0))
127  {
128  string spName;
129  spName = getPropertyName(propertyId+2147483647).c_str();
130  if(spName.size()>20) spName=spName.substr(0,20)+"...";
131  string spId = static_cast<ostringstream*>( &(ostringstream() << propertyId+2147483647) )->str();
132  spName += " (#" + spId + ")";
133  propSelectorWidget->addItem(spName.c_str(),spId.c_str());
134 
135  // spName += " (#" + static_cast<ostringstream*>( &(ostringstream() << propertyId+2147483647) )->str() + ")";
136  // propSelectorWidget->addItem(tr(spName.c_str()));
137  }
138  }
139  //add the selector to the layout
140  hlayout->addWidget(propSelectorWidget);
141 
142  QVBoxLayout *vlayout = new QVBoxLayout(this);
143  vlayout->setContentsMargins(0,0,0,0);
144  vlayout->setSpacing(0);
145 
146  //populate
147  //prep matrix
148  const int numRows = 3000;
149  const int numColumns = 3;
150  uint matrix[numRows][numColumns];
151  MatrixModel *mmp = NULL;
152  QTableView *view = NULL;
153  //create matrix
154  for (int i = 0; i < numRows; ++i)
155  for (int j = 0; j < numColumns; ++j)
156  matrix[i][j] = (i+1) * (j+1);
157  //create a model which adapts the data (the matrix) to the view.
158  mmp = new MatrixModel(numRows, numColumns, (uint*)matrix, 2147483646); //id for all (summary)
159  view = new QTableView(this);
160  view->setModel(mmp);
161  //adjust sizing
162  view->horizontalHeader()->resizeSection(0, 160);
163  #if QT_VERSION < 0x050000
164  view->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
165  #else
166  view->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
167  #endif
168  view->horizontalHeader()->resizeSection(2, 140);
169  view->horizontalHeader()->resizeSection(3, 140);
170  view->verticalHeader()->setVisible(false);
171  view->setSelectionBehavior(QAbstractItemView::SelectRows);
172  view->setSelectionMode(QAbstractItemView::SingleSelection);
173  vlayout->addLayout(hlayout);
174  vlayout->addWidget(view);
175  vlayout->setSpacing(0);
176  int width = view->verticalScrollBar()->sizeHint().width();
177  // Cover scroll bar width with spacing
178 #ifdef Q_OS_MAC
179  hlayout->addSpacing(width+2);
180 #else
181  hlayout->addSpacing(width);
182 #endif
183  // Always show scroll bar
184  view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
185  view->setTabKeyNavigation(false);
186  view->setContextMenuPolicy(Qt::CustomContextMenu);
187 
188  balancesView = view;
189 
190  // Actions
191  QAction *balancesCopyAddressAction = new QAction(tr("Copy address"), this);
192  QAction *balancesCopyLabelAction = new QAction(tr("Copy label"), this);
193  QAction *balancesCopyAmountAction = new QAction(tr("Copy amount"), this);
194 
195  contextMenu = new QMenu();
196  contextMenu->addAction(balancesCopyAddressAction);
197  contextMenu->addAction(balancesCopyLabelAction);
198  contextMenu->addAction(balancesCopyAmountAction);
199 
200  mapperThirdPartyTxUrls = new QSignalMapper(this);
201 
202  // Connect actions
203  connect(propSelectorWidget, SIGNAL(activated(int)), this, SLOT(propSelectorChanged(int)));
204 
205  connect(balancesCopyAddressAction, SIGNAL(triggered()), this, SLOT(balancesCopyAddress()));
206  connect(balancesCopyLabelAction, SIGNAL(triggered()), this, SLOT(balancesCopyLabel()));
207  connect(balancesCopyAmountAction, SIGNAL(triggered()), this, SLOT(balancesCopyAmount()));
208 }
209 
211 {
212  QString spId = propSelectorWidget->itemData(idx).toString();
213  unsigned int propertyId = spId.toUInt();
214  //repopulate with new selected balances
215  //prep matrix
216  const int numRows = 3000;
217  const int numColumns = 3;
218  uint matrix[numRows][numColumns];
219  MatrixModel *mmp = NULL;
220  //create matrix
221  for (int i = 0; i < numRows; ++i)
222  for (int j = 0; j < numColumns; ++j)
223  matrix[i][j] = (i+1) * (j+1);
224  //create a model which adapts the data (the matrix) to the view.
225  mmp = new MatrixModel(numRows, numColumns, (uint*)matrix, propertyId);
226  balancesView->setModel(mmp);
227 }
228 
229 void BalancesView::contextualMenu(const QPoint &point)
230 {
231  QModelIndex index = balancesView->indexAt(point);
232  if(index.isValid())
233  {
234 // contextMenu->exec(QCursor::pos());
235  }
236 }
237 
239 {
240 // GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole);
241 }
242 
244 {
245 // GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole);
246 }
247 
249 {
250 // GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole);
251 }
252 
253 // We override the virtual resizeEvent of the QWidget to adjust tables column
254 // sizes as the tables width is proportional to the dialogs width.
255 void BalancesView::resizeEvent(QResizeEvent* event)
256 {
257 // QWidget::resizeEvent(event);
258 // columnResizingFixer->stretchColumnWidth(TransactionTableModel::ToAddress);
259 }
QTableView * balancesView
Definition: balancesview.h:61
Definition: init.h:13
virtual void resizeEvent(QResizeEvent *event)
QTableView * view
Definition: balancesview.h:62
void propSelectorChanged(int idx)
void balancesCopyLabel()
STL namespace.
uint64_t global_balance_reserved_testeco[100000]
Definition: mastercore.cpp:93
QMenu * contextMenu
Definition: balancesview.h:70
void balancesCopyAddress()
uint64_t global_balance_money_testeco[100000]
Definition: mastercore.cpp:92
QSignalMapper * mapperThirdPartyTxUrls
Definition: balancesview.h:71
void balancesCopyAmount()
uint64_t global_balance_reserved_maineco[100000]
Definition: mastercore.cpp:91
string getPropertyName(unsigned int propertyId)
QLabel * propSelLabel
Definition: balancesview.h:64
BalancesView(QWidget *parent=0)
int set_wallet_totals()
Definition: mastercore.cpp:943
QComboBox * propSelectorWidget
Definition: balancesview.h:65
void contextualMenu(const QPoint &)
uint64_t global_balance_money_maineco[100000]
Definition: mastercore.cpp:90