axis_limits_dialog.cpp
Go to the documentation of this file.
1 #include "axis_limits_dialog.h"
2 #include "ui_axis_limits_dialog.h"
3 
4 #include <QLineEdit>
5 #include <QDoubleValidator>
6 
7 using std::numeric_limits;
8 
10  QDialog(parent),
11  ui(new Ui::AxisLimitsDialog)
12 {
13  ui->setupUi(this);
14 
15  _limits.min = ( -numeric_limits<double>::max() / 2 );
16  _limits.max = ( numeric_limits<double>::max() / 2 );
17 
18  ui->lineEditMinY->setValidator( new QDoubleValidator( this) );
19  ui->lineEditMaxY->setValidator( new QDoubleValidator( this) );
20 
21 }
22 
24 {
25  delete ui;
26 }
27 
28 void AxisLimitsDialog::setDefaultRange(PlotData::RangeValue range)
29 {
30  _parent_limits = range;
31 
32  if( !ui->checkBoxMinY->isChecked() )
33  {
34  ui->lineEditMinY->setText( QString::number( _parent_limits.min ));
35  }
36  if( !ui->checkBoxMaxY->isChecked() )
37  {
38  ui->lineEditMaxY->setText( QString::number( _parent_limits.max ));
39  }
40 }
41 
42 void AxisLimitsDialog::enableMin(bool enabled, double value)
43 {
44  _parent_limits.min = value;
45  ui->lineEditMinY->setText( QString::number( _parent_limits.min ));
46  ui->checkBoxMinY->setChecked(enabled);
47 }
48 
49 void AxisLimitsDialog::enableMax(bool enabled, double value)
50 {
51  _parent_limits.max = value;
52  ui->lineEditMaxY->setText( QString::number( _parent_limits.max ));
53  ui->checkBoxMaxY->setChecked(enabled);
54 }
55 
57 {
58  return ui->checkBoxMinY->isChecked() || ui->checkBoxMaxY->isChecked();
59 }
60 
62 {
63  ui->lineEditMinY->setEnabled(checked);
64  ui->pushButtonMinY->setEnabled(checked);
65 }
66 
68 {
69  ui->lineEditMaxY->setEnabled(checked);
70  ui->pushButtonMaxY->setEnabled(checked);
71 }
72 
74 {
75  double ymin = -numeric_limits<double>::max();
76  double ymax = numeric_limits<double>::max();
77 
78  if ( !ui->lineEditMinY->text().isEmpty() )
79  {
80  ymin = ui->lineEditMinY->text().toDouble();
81  }
82 
83  if ( !ui->lineEditMaxY->text().isEmpty() )
84  {
85  ymax = ui->lineEditMaxY->text().toDouble();
86  }
87 
88  if( ymin > ymax)
89  {
90  //swap
91  ui->lineEditMinY->setText( QString::number( ymax ));
92  ui->lineEditMaxY->setText( QString::number( ymin ));
93  }
94  else{
95  _limits.min = ( ui->checkBoxMinY->isChecked() ? ymin : -numeric_limits<double>::max()/2 );
96  _limits.max = ( ui->checkBoxMaxY->isChecked() ? ymax : numeric_limits<double>::max()/2 );
97  this->accept();
98  }
99 }
100 
102 {
103  ui->lineEditMinY->setText( QString::number( _parent_limits.min) );
104 }
105 
107 {
108  ui->lineEditMaxY->setText( QString::number( _parent_limits.max) );
109 }
110 
111 void AxisLimitsDialog::closeEvent(QCloseEvent *event)
112 {
114 }
PlotData::RangeValue _limits
void enableMin(bool enabled, double value)
AxisLimitsDialog(QWidget *parent=0)
virtual void closeEvent(QCloseEvent *event) override
void on_checkBoxMinY_toggled(bool checked)
void enableMax(bool enabled, double value)
bool limitsEnabled() const
void on_checkBoxMaxY_toggled(bool checked)
Ui::AxisLimitsDialog * ui
PlotData::RangeValue _parent_limits
void setDefaultRange(PlotData::RangeValue range)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:16