Bitcoin Forum
May 11, 2024, 06:38:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Where can I find a code for BC 0.8 GUI?  (Read 221 times)
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
May 08, 2018, 11:21:31 AM
 #1

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!
Make sure you back up your wallet regularly! Unlike a bank account, nobody can help you if you lose access to your BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715452686
Hero Member
*
Offline Offline

Posts: 1715452686

View Profile Personal Message (Offline)

Ignore
1715452686
Reply with quote  #2

1715452686
Report to moderator
Xynerise
Sr. Member
****
Offline Offline

Activity: 322
Merit: 363

39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD


View Profile
May 08, 2018, 12:16:16 PM
 #2

Bitcoin Core uses the Qt GUI, and everything pertaining to it can be found in
Code:
master/src/qt
starmyc
Full Member
***
Offline Offline

Activity: 198
Merit: 130

Some random software engineer


View Profile
May 08, 2018, 12:34:50 PM
 #3

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);
}

Hi, I'm just some random software engineer.
You can check my projects: Bitcoin & altcoin balances/addresses listing dumps: https://balances.crypto-nerdz.org/
shahzadafzal
Copper Member
Legendary
*
Offline Offline

Activity: 1540
Merit: 2912



View Profile
May 08, 2018, 12:35:43 PM
Merited by ABCbits (2), mocacinno (1)
 #4


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;
}

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
May 08, 2018, 03:33:23 PM
 #5

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?
starmyc
Full Member
***
Offline Offline

Activity: 198
Merit: 130

Some random software engineer


View Profile
May 08, 2018, 04:39:29 PM
 #6

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)

Hi, I'm just some random software engineer.
You can check my projects: Bitcoin & altcoin balances/addresses listing dumps: https://balances.crypto-nerdz.org/
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
May 08, 2018, 04:52:46 PM
 #7

or put 5 instead of modifying the function


Yes, its working Smiley Thank you.

I'll try to change the function.
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
May 08, 2018, 04:56:47 PM
 #8

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!
shahzadafzal
Copper Member
Legendary
*
Offline Offline

Activity: 1540
Merit: 2912



View Profile
May 09, 2018, 07:02:23 AM
 #9

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?

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
May 09, 2018, 09: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?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!