src/crypter.h \
src/qt/sendcoinsentry.h \
src/qt/qvalidatedlineedit.h \
- src/qt/bitcoinunits.h
+ src/qt/bitcoinunits.h \
+ src/qt/qvaluecombobox.h
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/transactiontablemodel.cpp \
src/qt/addresstablemodel.cpp \
src/crypter.cpp \
src/qt/sendcoinsentry.cpp \
src/qt/qvalidatedlineedit.cpp \
- src/qt/bitcoinunits.cpp
+ src/qt/bitcoinunits.cpp \
+ src/qt/qvaluecombobox.cpp
RESOURCES += \
src/qt/bitcoin.qrc
#include "bitcoingui.h"
#include "clientmodel.h"
#include "walletmodel.h"
+#include "optionsmodel.h"
#include "qtwin.h"
#include "headers.h"
// Put this in a block, so that BitcoinGUI is cleaned up properly before
// calling shutdown.
BitcoinGUI window;
- ClientModel clientModel(pwalletMain);
- WalletModel walletModel(pwalletMain);
+ OptionsModel optionsModel(pwalletMain);
+ ClientModel clientModel(&optionsModel);
+ WalletModel walletModel(pwalletMain, &optionsModel);
guiref = &window;
window.setClientModel(&clientModel);
#include "bitcoinamountfield.h"
#include "qvalidatedlineedit.h"
+#include "qvaluecombobox.h"
#include "bitcoinunits.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QComboBox>
+#include <QDebug>
BitcoinAmountField::BitcoinAmountField(QWidget *parent):
QWidget(parent), amount(0), decimals(0), currentUnit(-1)
layout->addWidget(amount);
layout->addWidget(new QLabel(QString(".")));
layout->addWidget(decimals);
- unit = new QComboBox(this);
+ unit = new QValueComboBox(this);
unit->setModel(new BitcoinUnits(this));
layout->addWidget(unit);
layout->addStretch(1);
decimals->setValid(false);
valid = false;
}
- if(!BitcoinUnits::parse(BitcoinUnits::BTC, text(), 0))
+ if(!BitcoinUnits::parse(currentUnit, text(), 0))
{
setValid(false);
valid = false;
setText("");
}
setValid(true);
+}
-
+void BitcoinAmountField::setDisplayUnit(int newUnit)
+{
+ unit->setValue(newUnit);
}
QT_BEGIN_NAMESPACE
class QValidatedLineEdit;
-class QComboBox;
+class QValueComboBox;
QT_END_NAMESPACE
// Coin amount entry widget with separate parts for whole
class BitcoinAmountField: public QWidget
{
Q_OBJECT
- //Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true);
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY textChanged USER true);
public:
explicit BitcoinAmountField(QWidget *parent = 0);
void setValid(bool valid);
bool validate();
+ // Change current unit
+ void setDisplayUnit(int unit);
+
// Make field empty and ready for new input
void clear();
private:
QValidatedLineEdit *amount;
QValidatedLineEdit *decimals;
- QComboBox *unit;
+ QValueComboBox *unit;
int currentUnit;
void setText(const QString &text);
trayIcon->showMessage((amount)<0 ? tr("Sent transaction") :
tr("Incoming transaction"),
tr("Date: ") + date + "\n" +
- tr("Amount: ") + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, amount, true) + "\n" +
+ tr("Amount: ") + BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), amount, true) + "\n" +
tr("Type: ") + type + "\n" +
tr("Address: ") + address + "\n",
QSystemTrayIcon::Information);
#include <QTimer>
#include <QDateTime>
-ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
- QObject(parent), wallet(wallet), optionsModel(0),
+ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
+ QObject(parent), optionsModel(optionsModel),
cachedNumConnections(0), cachedNumBlocks(0)
{
// Until signal notifications is built into the bitcoin core,
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(MODEL_UPDATE_DELAY);
-
- optionsModel = new OptionsModel(wallet, this);
}
int ClientModel::getNumConnections() const
public:
// The only reason that this constructor takes a wallet is because
// the global client settings are stored in the main wallet.
- explicit ClientModel(CWallet *wallet, QObject *parent = 0);
+ explicit ClientModel(OptionsModel *optionsModel, QObject *parent = 0);
OptionsModel *getOptionsModel();
QString formatFullVersion() const;
private:
- CWallet *wallet;
-
OptionsModel *optionsModel;
int cachedNumConnections;
#include "bitcoinamountfield.h"
#include "monitoreddatamapper.h"
#include "guiutil.h"
+#include "bitcoinunits.h"
+#include "qvaluecombobox.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
void setMapper(MonitoredDataMapper *mapper);
private:
- QLineEdit *unit;
+ QValueComboBox *unit;
signals:
public slots:
pages_widget->addWidget(main_page);
QListWidgetItem *item_display = new QListWidgetItem(tr("Display"));
- //contents_widget->addItem(item_display);
+ contents_widget->addItem(item_display);
display_page = new DisplayOptionsPage(this);
pages_widget->addWidget(display_page);
void OptionsDialog::changePage(int index)
{
- qDebug() << "page" << index;
pages_widget->setCurrentIndex(index);
}
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *unit_hbox = new QHBoxLayout();
unit_hbox->addSpacing(18);
- QLabel *unit_label = new QLabel(tr("&Unit: "));
+ QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: "));
unit_hbox->addWidget(unit_label);
- unit = new QLineEdit();
+ unit = new QValueComboBox(this);
+ unit->setModel(new BitcoinUnits(this));
+ unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
unit_label->setBuddy(unit);
unit_hbox->addWidget(unit);
void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
{
+ mapper->addMapping(unit, OptionsModel::DisplayUnit);
}
#include "optionsmodel.h"
+#include "bitcoinunits.h"
#include "headers.h"
OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
QAbstractListModel(parent),
- wallet(wallet)
+ wallet(wallet),
+ nDisplayUnit(BitcoinUnits::BTC)
{
+ // Read our specific settings from the wallet db
+ CWalletDB walletdb(wallet->strWalletFile);
+ walletdb.ReadSetting("nDisplayUnit", nDisplayUnit);
}
int OptionsModel::rowCount(const QModelIndex & parent) const
return QVariant(QString::fromStdString(addrProxy.ToStringPort()));
case Fee:
return QVariant(nTransactionFee);
+ case DisplayUnit:
+ return QVariant(nDisplayUnit);
default:
return QVariant();
}
walletdb.WriteSetting("nTransactionFee", nTransactionFee);
}
break;
+ case DisplayUnit: {
+ int unit = value.toInt();
+ nDisplayUnit = unit;
+ walletdb.WriteSetting("nDisplayUnit", nDisplayUnit);
+ emit displayUnitChanged(unit);
+ }
default:
break;
}
{
return fMinimizeOnClose;
}
+
+int OptionsModel::getDisplayUnit()
+{
+ return nDisplayUnit;
+}
ProxyIP, // QString
ProxyPort, // QString
Fee, // qint64
+ DisplayUnit, // BitcoinUnits::Unit
OptionIDRowCount
};
qint64 getTransactionFee();
bool getMinimizeToTray();
bool getMinimizeOnClose();
+ int getDisplayUnit();
private:
// Wallet stores persistent options
CWallet *wallet;
+ int nDisplayUnit;
signals:
+ void displayUnitChanged(int unit);
public slots:
#include "walletmodel.h"
#include "bitcoinunits.h"
+#include "optionsmodel.h"
+
+#include <QDebug>
OverviewPage::OverviewPage(QWidget *parent) :
QWidget(parent),
- ui(new Ui::OverviewPage)
+ ui(new Ui::OverviewPage),
+ currentBalance(-1),
+ currentUnconfirmedBalance(-1)
{
ui->setupUi(this);
void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance)
{
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, balance));
- ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, unconfirmedBalance));
+ int unit = model->getOptionsModel()->getDisplayUnit();
+ currentBalance = balance;
+ currentUnconfirmedBalance = unconfirmedBalance;
+ ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
+ ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance));
}
void OverviewPage::setNumTransactions(int count)
setNumTransactions(model->getNumTransactions());
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));
+ connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(displayUnitChanged()));
+}
+
+void OverviewPage::displayUnitChanged()
+{
+ if(currentBalance != -1)
+ setBalance(currentBalance, currentUnconfirmedBalance);
}
private:
Ui::OverviewPage *ui;
WalletModel *model;
+ qint64 currentBalance;
+ qint64 currentUnconfirmedBalance;
+private slots:
+ void displayUnitChanged();
};
#endif // OVERVIEWPAGE_H
--- /dev/null
+#include "qvaluecombobox.h"
+
+QValueComboBox::QValueComboBox(QWidget *parent) :
+ QComboBox(parent), role(Qt::UserRole)
+{
+ connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
+}
+
+int QValueComboBox::value() const
+{
+ return itemData(currentIndex(), role).toInt();
+}
+
+void QValueComboBox::setValue(int value)
+{
+ setCurrentIndex(findData(value, role));
+}
+
+void QValueComboBox::setRole(int role)
+{
+ this->role = role;
+}
+
+void QValueComboBox::handleSelectionChanged(int idx)
+{
+ emit valueChanged();
+}
--- /dev/null
+#ifndef QVALUECOMBOBOX_H
+#define QVALUECOMBOBOX_H
+
+#include <QComboBox>
+
+// QComboBox that can be used with QDataWidgetMapper to select
+// ordinal values from a model.
+class QValueComboBox : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true);
+public:
+ explicit QValueComboBox(QWidget *parent = 0);
+
+ int value() const;
+ void setValue(int value);
+
+ // Model role to use as value
+ void setRole(int role);
+
+signals:
+ void valueChanged();
+
+public slots:
+
+private:
+ int role;
+
+private slots:
+ void handleSelectionChanged(int idx);
+};
+
+#endif // QVALUECOMBOBOX_H
#include "bitcoinunits.h"
#include "addressbookpage.h"
#include "walletmodel.h"
+#include "optionsmodel.h"
#include "addresstablemodel.h"
#include "qapplication.h"
ui->addAsLabel->clear();
ui->payAmount->clear();
ui->payTo->setFocus();
+ if(model)
+ {
+ ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
+ }
}
void SendCoinsEntry::on_deleteButton_clicked()
#include "guiconstants.h"
#include "transactiondesc.h"
#include "walletmodel.h"
+#include "optionsmodel.h"
#include "addresstablemodel.h"
#include "bitcoinunits.h"
QVariant TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed) const
{
- QString str = BitcoinUnits::format(BitcoinUnits::BTC, wtx->credit + wtx->debit);
+ QString str = BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->credit + wtx->debit);
if(showUnconfirmed)
{
if(!wtx->status.confirmed || wtx->status.maturity != TransactionStatus::Mature)
#include "csvmodelwriter.h"
#include "transactiondescdialog.h"
#include "editaddressdialog.h"
+#include "optionsmodel.h"
#include <QScrollBar>
#include <QComboBox>
void TransactionView::changedAmount(const QString &amount)
{
qint64 amount_parsed = 0;
- if(BitcoinUnits::parse(BitcoinUnits::BTC, amount, &amount_parsed))
+ if(BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, &amount_parsed))
{
transactionProxyModel->setMinAmount(amount_parsed);
}
#include <QTimer>
#include <QSet>
-WalletModel::WalletModel(CWallet *wallet, QObject *parent) :
- QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0),
+WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
+ QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
transactionTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0)
{
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(MODEL_UPDATE_DELAY);
- optionsModel = new OptionsModel(wallet, this);
addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(wallet, this);
}
{
Q_OBJECT
public:
- explicit WalletModel(CWallet *wallet, QObject *parent = 0);
+ explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
enum StatusCode
{