Skip to content
Permalink
Browse files

fix bug with negative values in spin box (issue 140)

  • Loading branch information...
SimonSegert committed Nov 14, 2018
1 parent 2ec6831 commit 95e243549a51523e576667e88a3f14faaf6cc055
Showing with 38 additions and 1 deletion.
  1. +10 −1 customspinbox.h
  2. +28 −0 visualizationwindow.cpp
@@ -10,6 +10,15 @@ class CustomSpinBox : public QDoubleSpinBox

}

bool from_button=false; //whether the value change came from the up/down buttons (as opposed to typing the value)

//called whenever the up or down button is pushed
void stepBy(int steps){
from_button=true;
QDoubleSpinBox::stepBy(steps); //this will change the value and thereby call CustomSpinBox::textFromValue
from_button=false;
}

//this function controls the appearance of the text
QString textFromValue(double val) const {

@@ -24,7 +33,7 @@ class CustomSpinBox : public QDoubleSpinBox

//add in the minus sign if the value is negative, or if the user was in the middle of typing
//a negative value >-1 (e.g. -0.5)
if(val<0 ||(lineEdit()->text().size()>0&& lineEdit()->text().at(0)=='-')){
if(val<0 ||(!from_button && (lineEdit()->text().size()>0&& lineEdit()->text().at(0)=='-'))){
str="-"+str;
}

@@ -846,12 +846,27 @@ void VisualizationWindow::on_actionRestore_default_window_triggered()

double yrev_sign=y_reverse? -1 :1;


//this is necessary to correctly deal with the case where the current value is negative
//but the reset value is not
ui->BottomCornerXSpinBox->from_button=true;
ui->BottomCornerYSpinBox->from_button=true;
ui->TopCornerXSpinBox->from_button=true;
ui->TopCornerYSpinBox->from_button=true;

//set the values displayed in the controls
ui->BottomCornerXSpinBox->setValue(orig_xmin*xrev_sign);
ui->BottomCornerYSpinBox->setValue(orig_ymin*yrev_sign);
ui->TopCornerXSpinBox->setValue(orig_xmax*xrev_sign);
ui->TopCornerYSpinBox->setValue(orig_ymax*yrev_sign);


ui->BottomCornerXSpinBox->from_button=false;
ui->BottomCornerYSpinBox->from_button=false;
ui->TopCornerXSpinBox->from_button=false;
ui->TopCornerYSpinBox->from_button=false;


xmin_precise=orig_xmin; //overwrite the value set by the call to setValue to avoid rounding errors in reset_line()
xmax_precise=orig_xmax;
ymin_precise=orig_ymin;
@@ -886,11 +901,24 @@ void VisualizationWindow::on_actionBetti_number_window_triggered()

double yrev_sign=y_reverse? -1 :1;

//this is necessary to correctly deal with the case where the current value is negative
//but the reset value is not
ui->BottomCornerXSpinBox->from_button=true;
ui->BottomCornerYSpinBox->from_button=true;
ui->TopCornerXSpinBox->from_button=true;
ui->TopCornerYSpinBox->from_button=true;


ui->BottomCornerXSpinBox->setValue(xmin*xrev_sign);
ui->BottomCornerYSpinBox->setValue(ymin*yrev_sign);
ui->TopCornerXSpinBox->setValue(xmax*xrev_sign);
ui->TopCornerYSpinBox->setValue(ymax*yrev_sign);

ui->BottomCornerXSpinBox->from_button=false;
ui->BottomCornerYSpinBox->from_button=false;
ui->TopCornerXSpinBox->from_button=false;
ui->TopCornerYSpinBox->from_button=false;

xmin_precise=xmin; //overwrite the value set by the call to setValue to avoid rounding errors in reset_line()
xmax_precise=xmax;
ymin_precise=ymin;

0 comments on commit 95e2435

Please sign in to comment.
You can’t perform that action at this time.