Skip to content

Commit

Permalink
[Qt] don't allow amount changes when AmountSpinBox is read-only
Browse files Browse the repository at this point in the history
- before it was possible to use the steps to change e.g. amouns of
  authenticated or unauthenticated payment requests (AmountSpinBox is
  already set to read-only here) - this is now fixed
- also move the reimplemented stepEnabled() function to the
  protected section of our class, where it belongs (see Qt doc)
  • Loading branch information
Philip Kaufmann committed Jan 10, 2015
1 parent 4f73a8f commit 0fd9e2b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/qt/bitcoinamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class AmountSpinBox: public QAbstractSpinBox
{
Q_OBJECT

public:
explicit AmountSpinBox(QWidget *parent):
QAbstractSpinBox(parent),
Expand Down Expand Up @@ -72,23 +73,6 @@ class AmountSpinBox: public QAbstractSpinBox
setValue(val);
}

StepEnabled stepEnabled() const
{
StepEnabled rv = 0;
if(text().isEmpty()) // Allow step-up with empty field
return StepUpEnabled;
bool valid = false;
CAmount val = value(&valid);
if(valid)
{
if(val > 0)
rv |= StepDownEnabled;
if(val < BitcoinUnits::maxMoney())
rv |= StepUpEnabled;
}
return rv;
}

void setDisplayUnit(int unit)
{
bool valid = false;
Expand Down Expand Up @@ -139,6 +123,7 @@ class AmountSpinBox: public QAbstractSpinBox
}
return cachedMinimumSizeHint;
}

private:
int currentUnit;
CAmount singleStep;
Expand Down Expand Up @@ -179,6 +164,25 @@ class AmountSpinBox: public QAbstractSpinBox
return QAbstractSpinBox::event(event);
}

StepEnabled stepEnabled() const
{
StepEnabled rv = 0;
if (isReadOnly()) // Disable steps when AmountSpinBox is read-only
return StepNone;
if(text().isEmpty()) // Allow step-up with empty field
return StepUpEnabled;
bool valid = false;
CAmount val = value(&valid);
if(valid)
{
if(val > 0)
rv |= StepDownEnabled;
if(val < BitcoinUnits::maxMoney())
rv |= StepUpEnabled;
}
return rv;
}

signals:
void valueChanged();
};
Expand Down

0 comments on commit 0fd9e2b

Please sign in to comment.