1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : Plot2d_FitDataDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "Plot2d_FitDataDlg.h"
30 #include <QPushButton>
31 #include <QRadioButton>
35 #define SPACING_SIZE 6
36 #define MARGIN_SIZE 11
37 #define MIN_EDIT_SIZE 100
42 Plot2d_FitDataDlg::Plot2d_FitDataDlg( QWidget* parent, bool secondAxisY )
43 : QDialog( parent ? parent : 0,
44 Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
45 myY2MinEdit( 0 ), myY2MaxEdit( 0 ), mySecondAxisY( secondAxisY )
48 setObjectName( "Plot2d_FitDataDlg" );
50 setWindowTitle( tr( "FIT_DATA_TLT" ) );
51 setSizeGripEnabled( TRUE );
52 QGridLayout* topLayout = new QGridLayout( this );
53 topLayout->setSpacing( SPACING_SIZE );
54 topLayout->setMargin( MARGIN_SIZE );
57 myRangeGrp = new QGroupBox( this );
58 QGridLayout* aGridLayout = new QGridLayout( myRangeGrp );
59 myRangeGrp->setLayout( aGridLayout );
60 aGridLayout->setAlignment( Qt::AlignTop );
61 aGridLayout->setMargin( MARGIN_SIZE );
62 aGridLayout->setSpacing( SPACING_SIZE );
64 myModeAllRB = new QRadioButton( tr( "FIT_ALL" ), myRangeGrp );
65 myModeHorRB = new QRadioButton( tr( "FIT_HORIZONTAL" ), myRangeGrp );
66 myModeVerRB = new QRadioButton( tr( "FIT_VERTICAL" ), myRangeGrp );
68 QDoubleValidator* aValidator = new QDoubleValidator( this );
69 myXMinEdit = new QLineEdit( myRangeGrp );
70 myXMinEdit->setValidator( aValidator );
71 myXMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
72 myXMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
73 myXMinEdit->setText( "0.0" );
75 myYMinEdit = new QLineEdit( myRangeGrp );
76 myYMinEdit->setValidator( aValidator );
77 myYMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
78 myYMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
79 myYMinEdit->setText( "0.0" );
81 myXMaxEdit = new QLineEdit( myRangeGrp );
82 myXMaxEdit->setValidator( aValidator );
83 myXMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
84 myXMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
85 myXMaxEdit->setText( "0.0" );
87 myYMaxEdit = new QLineEdit( myRangeGrp );
88 myYMaxEdit->setValidator( aValidator );
89 myYMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 myYMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
91 myYMaxEdit->setText( "0.0" );
94 myY2MinEdit = new QLineEdit( myRangeGrp );
95 myY2MinEdit->setValidator( aValidator );
96 myY2MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
97 myY2MinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
98 myY2MinEdit->setText( "0.0" );
100 myY2MaxEdit = new QLineEdit( myRangeGrp );
101 myY2MaxEdit->setValidator( aValidator );
102 myY2MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
103 myY2MaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
104 myY2MaxEdit->setText( "0.0" );
107 QFrame* aHLine = new QFrame( myRangeGrp );
108 aHLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
110 QHBoxLayout* aModeLayout = new QHBoxLayout;
111 aModeLayout->setMargin( 0 );
112 aModeLayout->setSpacing( SPACING_SIZE );
113 aModeLayout->addWidget( myModeAllRB );
114 aModeLayout->addWidget( myModeHorRB );
115 aModeLayout->addWidget( myModeVerRB );
117 QLabel* horLab = new QLabel( tr( "HORIZONTAL_AXIS" ), myRangeGrp );
118 QLabel* verLab = new QLabel( tr( "VERTICAL_AXIS" ), myRangeGrp );
120 verLab->setText( tr( "VERTICAL_LEFT_AXIS" ) );
122 QFont font = horLab->font(); font.setBold( true );
123 horLab->setFont( font ); verLab->setFont( font );
125 aGridLayout->addLayout( aModeLayout, 0, 0, 1, 5 );
126 aGridLayout->addWidget( aHLine, 1, 0, 1, 5 );
127 aGridLayout->addWidget( horLab, 2, 0 );
128 aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ),
130 aGridLayout->addWidget( myXMinEdit, 2, 2 );
131 aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ),
133 aGridLayout->addWidget( myXMaxEdit, 2, 4 );
134 aGridLayout->addWidget( verLab, 3, 0 );
135 aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ),
137 aGridLayout->addWidget( myYMinEdit, 3, 2 );
138 aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ),
140 aGridLayout->addWidget( myYMaxEdit, 3, 4 );
143 QLabel* ver2Lab = new QLabel(tr( "VERTICAL_RIGHT_AXIS" ), myRangeGrp );
144 ver2Lab->setFont( font );
145 aGridLayout->addWidget( ver2Lab, 4, 0 );
146 aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ),
148 aGridLayout->addWidget( myY2MinEdit, 4, 2 );
149 aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ),
151 aGridLayout->addWidget( myY2MaxEdit, 4, 4 );
155 myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
156 myOkBtn->setObjectName( "buttonOk" );
157 myOkBtn->setAutoDefault( TRUE );
158 myOkBtn->setDefault( TRUE );
159 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
160 myCancelBtn->setObjectName( "buttonCancel" );
161 myCancelBtn->setAutoDefault( TRUE );
163 topLayout->addWidget( myRangeGrp, 0, 0, 1, 3 );
164 topLayout->addWidget( myOkBtn, 1, 0 );
165 topLayout->setColumnStretch( 1, 5 );
166 topLayout->addWidget( myCancelBtn, 1, 2 );
169 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
170 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
171 connect( myRangeGrp, SIGNAL( clicked( int ) ), this, SLOT( onModeChanged( int ) ) );
174 myModeAllRB->setChecked( true );
181 void Plot2d_FitDataDlg::setRange( const double xMin,
188 myXMinEdit->setText( QString::number( xMin ) );
189 myXMaxEdit->setText( QString::number( xMax ) );
190 myYMinEdit->setText( QString::number( yMin ) );
191 myYMaxEdit->setText( QString::number( yMax ) );
193 myY2MinEdit->setText( QString::number( y2Min ) );
194 myY2MaxEdit->setText( QString::number( y2Max ) );
199 Gets range, returns mode (see getMode())
201 int Plot2d_FitDataDlg::getRange( double& xMin,
208 xMin = myXMinEdit->text().toDouble();
209 xMax = myXMaxEdit->text().toDouble();
210 yMin = myYMinEdit->text().toDouble();
211 yMax = myYMaxEdit->text().toDouble();
213 y2Min = myY2MinEdit->text().toDouble();
214 y2Max = myY2MaxEdit->text().toDouble();
221 if ( myModeAllRB->isChecked() )
223 if ( myModeHorRB->isChecked() )
225 if ( myModeVerRB->isChecked() )
231 Gets mode : 0 - Fit all; 1 - Fit horizontal, 2 - Fit vertical
233 int Plot2d_FitDataDlg::getMode()
236 if ( myModeAllRB->isChecked() )
238 if ( myModeHorRB->isChecked() )
240 if ( myModeVerRB->isChecked() )
246 Called when range mode changed
248 void Plot2d_FitDataDlg::onModeChanged(int mode)
252 case 0: // fit all mode
253 myXMinEdit->setEnabled(true);
254 myXMaxEdit->setEnabled(true);
255 myYMinEdit->setEnabled(true);
256 myYMaxEdit->setEnabled(true);
258 myY2MinEdit->setEnabled(true);
259 myY2MaxEdit->setEnabled(true);
262 case 1: // fit horizontal mode
263 badFocus = myYMinEdit->hasFocus() || myYMaxEdit->hasFocus();
264 myXMinEdit->setEnabled(true);
265 myXMaxEdit->setEnabled(true);
266 myYMinEdit->setEnabled(false);
267 myYMaxEdit->setEnabled(false);
269 myY2MinEdit->setEnabled(false);
270 myY2MaxEdit->setEnabled(false);
273 myXMinEdit->setFocus();
275 case 2: // fit vertical mode
276 badFocus = myXMinEdit->hasFocus() || myXMaxEdit->hasFocus();
277 myXMinEdit->setEnabled(false);
278 myXMaxEdit->setEnabled(false);
279 myYMinEdit->setEnabled(true);
280 myYMaxEdit->setEnabled(true);
282 myY2MinEdit->setEnabled(true);
283 myY2MaxEdit->setEnabled(true);
286 myYMinEdit->setFocus();