Skip to content

Commit

Permalink
Add Coin Control Filter Combo Box
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Aug 29, 2014
1 parent 8119728 commit 60b53e5
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 31 deletions.
122 changes: 93 additions & 29 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "addresstablemodel.h"
#include "optionsmodel.h"
#include "coincontrol.h"
#include "qcomboboxfiltercoins.h"

#include <QApplication>
#include <QCheckBox>
Expand Down Expand Up @@ -123,6 +124,14 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) :

// default view is sorted by amount desc
sortView(COLUMN_CONFIRMATIONS, Qt::DescendingOrder);

// combo box to select coin filter
ui->QComboBoxFilterCoins->addItem("< Amount");
ui->QComboBoxFilterCoins->addItem("> Amount");
ui->QComboBoxFilterCoins->addItem("< Weight");
ui->QComboBoxFilterCoins->addItem("> Weight");
ui->QComboBoxFilterCoins->addItem("> Age");
ui->QComboBoxFilterCoins->addItem("< Age");
}

CoinControlDialog::~CoinControlDialog()
Expand Down Expand Up @@ -181,43 +190,98 @@ void CoinControlDialog::buttonSelectAllClicked()
void CoinControlDialog::customSelectCoins()
{
QString strUserAmount = ui->lineEditCustomCC->text();
double dUserAmount = QString(strUserAmount).toDouble();
QString strComboText = ui->QComboBoxFilterCoins->currentText();

double dUserAmount = QString(strUserAmount).toDouble();
bool treeMode = ui->radioTreeMode->isChecked();

QFlags<Qt::ItemFlag> flgCheckbox=Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;

QFlags<Qt::ItemFlag> flgCheckbox=Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;

map<QString, vector<COutput> > mapCoins;
model->listCoins(mapCoins);
map<QString, vector<COutput> > mapCoins;
model->listCoins(mapCoins);

BOOST_FOREACH(PAIRTYPE(QString, vector<COutput>) coins, mapCoins)
{
QTreeWidgetItem *itemWalletAddress = new QTreeWidgetItem();
BOOST_FOREACH(PAIRTYPE(QString, vector<COutput>) coins, mapCoins)
{
QTreeWidgetItem *itemWalletAddress = new QTreeWidgetItem();

QTreeWidgetItem *itemOutput;
if (treeMode) itemOutput = new QTreeWidgetItem(itemWalletAddress);
else itemOutput = new QTreeWidgetItem(ui->treeWidget);
itemOutput->setFlags(flgCheckbox);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);

BOOST_FOREACH(const COutput& out, coins.second)
{
// transaction hash
uint256 txhash = out.tx->GetHash();
QTreeWidgetItem *itemOutput;
if (treeMode) itemOutput = new QTreeWidgetItem(itemWalletAddress);
else itemOutput = new QTreeWidgetItem(ui->treeWidget);
itemOutput->setFlags(flgCheckbox);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);
BOOST_FOREACH(const COutput& out, coins.second)
{
// transaction hash
uint256 txhash = out.tx->GetHash();

//Getting the coin amount
double nCoinAmount = out.tx->vout[out.i].nValue;
//Getting the coin amount
double dCoinAmount = out.tx->vout[out.i].nValue;

//Coin Weight
uint64 nTxWeight = 0;
model->getStakeWeightFromValue(out.tx->GetTxTime(), out.tx->vout[out.i].nValue, nTxWeight);

//Age
double dAge = (GetTime() - out.tx->GetTxTime()) / (double)(1440 * 60);

//selecting the coins
if ((nCoinAmount) < dUserAmount * COIN)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
}
CoinControlDialog::updateLabels(model, this);
//selecting the coins
if (strComboText == "< Amount")
{
if (dCoinAmount < dUserAmount * COIN)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
else if (strComboText == "> Amount")
{
if (dCoinAmount > dUserAmount * COIN)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
else if (strComboText == "< Weight")
{
if (nTxWeight < dUserAmount)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
else if (strComboText == "> Weight")
{
if (nTxWeight > dUserAmount)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
else if (strComboText == "< Age")
{
if (dAge < dUserAmount)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
else if (strComboText == "> Age")
{
if (dAge > dUserAmount)
{
COutPoint outpt(txhash, out.i);
coinControl->Select(outpt);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked);
}
}
}
}
updateView();
}

Expand Down
7 changes: 5 additions & 2 deletions src/qt/forms/coincontroldialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayoutPanel" stretch="0,0,0,0,0,0">
<layout class="QHBoxLayout" name="horizontalLayoutPanel" stretch="0,0,0,0,0,0,0">
<property name="spacing">
<number>14</number>
</property>
Expand Down Expand Up @@ -431,10 +431,13 @@
<item>
<widget class="QPushButton" name="pushButtonCustomCC">
<property name="text">
<string>Select Coins Less Than</string>
<string>Select Coins</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="QComboBoxFilterCoins"/>
</item>
<item>
<widget class="QLineEdit" name="lineEditCustomCC">
<property name="enabled">
Expand Down
33 changes: 33 additions & 0 deletions src/qt/qcomboboxfiltercoins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "qcomboboxfiltercoins.h"
#include <QtGui>

QComboBoxFilterCoins::QComboBoxFilterCoins(QWidget *parent) :
QComboBox(parent), role(Qt::UserRole)
{
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
}

QVariant QComboBoxFilterCoins::value() const
{
return itemData(currentIndex(), role);
}

void QComboBoxFilterCoins::setValue(const QVariant &value)
{
setCurrentIndex(findData(value, role));
}

void QComboBoxFilterCoins::setRole(int role)
{
this->role = role;
}

void QComboBoxFilterCoins::handleSelectionChanged(int idx)
{

QMessageBox* msg = new QMessageBox();
msg->setWindowTitle("Hello !");
msg->setText("Selected Index is :"+QString::number(index));
msg->show();
//emit valueChanged();
}
29 changes: 29 additions & 0 deletions src/qt/qcomboboxfiltercoins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef QCOMBOBOCFILTERCOINS_H
#define QCOMBOBOCFILTERCOINS_H

#include <QtGui>

//Derived Class from QComboBox
class QComboBoxFilterCoins: public QComboBox
{
Q_OBJECT
public:
QComboBoxFilterCoins(QWidget* parent):QComboBox(parent)
{
this->setParent(parent);
connect(this , SIGNAL(currentIndexChanged(int)),this,SLOT(handleSelectionChanged(int)));
};
~ QComboBoxFilterCoins(){};

public slots:
//Slot that is called when QComboBox selection is changed
void handleSelectionChanged(int index)
{
QMessageBox* msg = new QMessageBox();
msg->setWindowTitle("Hello !");
msg->setText("Selected Index is :"+QString::number(index));
msg->show();
};

};
#endif

0 comments on commit 60b53e5

Please sign in to comment.