Author

Topic: Where can I find a code for BC 0.8 GUI? (Read 251 times)

member
Activity: 294
Merit: 11
Lord Shiva
May 09, 2018, 04:07:34 AM
#10


Well I thought you want to change on that particular screen.

Here bitcoinunits.cpp you will change the bitcoin decimals for the whole system? Btw why want to do this?

I'll show you later Smiley

By the way, do you happen to know why these values are necessary:

Code:
amount->setDecimals(8); in src/qt/bitcoinamountfield.cpp

Code:
amountValidator->setDecimals(8); in src/qt/guiutil.cpp

Code:
case real_type:  os_ << std::showpoint << std::fixed << std::setprecision(8) in src/json/json_spirit_writer_template.h


Huh

What do they influence?
copper member
Activity: 1526
Merit: 2890
Wow! So simply! ))

in src/qt/bitcoinunits.cpp

Well I thought you want to change on that particular screen.

Here bitcoinunits.cpp you will change the bitcoin decimals for the whole system? Btw why want to do this?
member
Activity: 294
Merit: 11
Lord Shiva
Wow! So simply! ))

in src/qt/bitcoinunits.cpp

Code:
int BitcoinUnits::decimals(int unit)
{
    switch(unit)
    {
    case BTC: return 8;
    case mBTC: return 5;
    case uBTC: return 2;
    default: return 0;
    }
}

 Smiley

Thank you!
member
Activity: 294
Merit: 11
Lord Shiva
or put 5 instead of modifying the function


Yes, its working Smiley Thank you.

I'll try to change the function.
full member
Activity: 198
Merit: 130
Some random software engineer
shahzadafzal, starmyc, Xynerise

Thank you!

but I try change

Code:
amount->setDecimals(8);

to "5" in src\qt\bitcoinamountfield.cpp and

Code:
amountValidator->setDecimals(8);

No way. The number of zeros after the comma is still 8 and not 5.

How to change it in src\qt\bitcoingui.cpp - I do not understand.

Can you tell me please?

Okay, I was wrong.

Your widget is created in bitcoinamountfield.cpp like this:

Code:
BitcoinAmountField::BitcoinAmountField(QWidget *parent):
        QWidget(parent), amount(0), currentUnit(-1)
{
    amount = new QDoubleSpinBox(this);
    amount->setLocale(QLocale::c());
    amount->setDecimals(8);
    amount->installEventFilter(this);
    amount->setMaximumWidth(500);
    amount->setSingleStep(0.001);

    ...

    // Set default based on configuration
    unitChanged(unit->currentIndex());
}

But, the function (also a qt "slot") will also change it:

Code:
void BitcoinAmountField::unitChanged(int idx)
{
    // Use description tooltip for current unit for the combobox
    unit->setToolTip(unit->itemData(idx, Qt::ToolTipRole).toString());

    // Determine new unit ID
    int newUnit = unit->itemData(idx, BitcoinUnits::UnitRole).toInt();

    // Parse current value and convert to new unit
    bool valid = false;
    qint64 currentValue = value(&valid);

    currentUnit = newUnit;

    // Set max length after retrieving the value, to prevent truncation
    amount->setDecimals(BitcoinUnits::decimals(currentUnit));

    ...

If you want to change the number of decimals to 5, you need to change it in the UI constructor and in the BitcoinUnits::decimals function as well (or put 5 instead of modifying the function - at least, it worked for me on your coin source tree)
member
Activity: 294
Merit: 11
Lord Shiva
shahzadafzal, starmyc, Xynerise

Thank you!

but I try change

Code:
amount->setDecimals(8);

to "5" in src\qt\bitcoinamountfield.cpp and

Code:
amountValidator->setDecimals(8);

in guiutil.cpp and

Code:
case real_type:  os_ << std::showpoint << std::fixed << std::setprecision(8)

in src\json\json_spirit_writer_template.h

No way. The number of zeros after the comma is still 8 and not 5.

How to change it in src\qt\bitcoingui.cpp - I do not understand.

Can you tell me please?
copper member
Activity: 1526
Merit: 2890

Check below source code at location
Code:
\bitcoin-master\src\qt\bitcoingui.cpp

This is the code responsible for formatting the amounts:

Code:
QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators)
{
    // Note: not using straight sprintf here because we do NOT want
    // localized number formatting.
    if(!valid(unit))
        return QString(); // Refuse to format invalid unit
    qint64 n = (qint64)nIn;
    qint64 coin = factor(unit);
    int num_decimals = decimals(unit);
    qint64 n_abs = (n > 0 ? n : -n);
    qint64 quotient = n_abs / coin;
    qint64 remainder = n_abs % coin;
    QString quotient_str = QString::number(quotient);
    QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');

    // Use SI-style thin space separators as these are locale independent and can't be
    // confused with the decimal marker.
    QChar thin_sp(THIN_SP_CP);
    int q_size = quotient_str.size();
    if (separators == separatorAlways || (separators == separatorStandard && q_size > 4))
        for (int i = 3; i < q_size; i += 3)
            quotient_str.insert(q_size - i, thin_sp);

    if (n < 0)
        quotient_str.insert(0, '-');
    else if (fPlus && n > 0)
        quotient_str.insert(0, '+');
    return quotient_str + QString(".") + remainder_str;
}
full member
Activity: 198
Merit: 130
Some random software engineer
Hello!

Where is the code responsible for the autocomplete form fields in Bitcoin Core 0.8?

Not 100% sure, but it is most likely filed by validator in the widget there:

Code:
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
{
    QDoubleValidator *amountValidator = new QDoubleValidator(parent);
    amountValidator->setDecimals(8);
    amountValidator->setBottom(0.0);
    widget->setValidator(amountValidator);
    widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
sr. member
Activity: 322
Merit: 363
39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD
Bitcoin Core uses the Qt GUI, and everything pertaining to it can be found in
Code:
master/src/qt
member
Activity: 294
Merit: 11
Lord Shiva
Hello!

Where is the code responsible for the autocomplete form fields in Bitcoin Core 0.8?

For example:



Here, the "Amount" field is auto-completed with zeros after the number is entered. I want to find the code that does this. Where do I need to look?

Thank you!
Jump to: