smesh/src/SMESHGUI/SMESHGUI_SpinBox.cxx

126 lines
4.6 KiB
C++
Raw Normal View History

2012-08-09 16:03:55 +06:00
// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
2003-07-10 19:18:22 +06:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2003-07-10 19:18:22 +06:00
//
2012-08-09 16:03:55 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2003-07-10 19:18:22 +06:00
//
2012-08-09 16:03:55 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_SpinBox.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
// SMESH includes
2003-07-10 19:18:22 +06:00
//
2003-05-19 20:07:00 +06:00
#include "SMESHGUI_SpinBox.h"
2012-08-09 16:03:55 +06:00
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
2009-02-17 10:27:49 +05:00
// Qt includes
#include <QLineEdit>
2012-08-09 16:03:55 +06:00
#include <QVariant>
2004-12-01 15:48:31 +05:00
2003-05-19 20:07:00 +06:00
//=================================================================================
// class : SMESHGUI_SpinBox()
// purpose : constructor of specific widget accepting floats in double precision.
//=================================================================================
2009-02-17 10:27:49 +05:00
SMESHGUI_SpinBox::SMESHGUI_SpinBox( QWidget* parent )
: SalomeApp_DoubleSpinBox( parent )
2003-05-19 20:07:00 +06:00
{
}
//=================================================================================
2009-02-17 10:27:49 +05:00
// function : ~SMESHGUI_SpinBox()
// purpose : destructor
2003-05-19 20:07:00 +06:00
//=================================================================================
2009-02-17 10:27:49 +05:00
SMESHGUI_SpinBox::~SMESHGUI_SpinBox()
2003-05-19 20:07:00 +06:00
{
}
//=================================================================================
2009-02-17 10:27:49 +05:00
// function : SetStep() [SLOT]
// purpose :
2003-05-19 20:07:00 +06:00
//=================================================================================
2009-02-17 10:27:49 +05:00
void SMESHGUI_SpinBox::SetStep( double newStep )
2003-05-19 20:07:00 +06:00
{
2009-02-17 10:27:49 +05:00
setSingleStep( newStep );
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : SetValue()
// purpose :
//=================================================================================
2009-02-17 10:27:49 +05:00
void SMESHGUI_SpinBox::SetValue( double v )
2003-05-19 20:07:00 +06:00
{
2012-08-09 16:03:55 +06:00
setValue(valueFromText(textFromValue(v)));
editor()->setCursorPosition( 0 );
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : GetValue()
// purpose : returns a double
//=================================================================================
2009-02-17 10:27:49 +05:00
double SMESHGUI_SpinBox::GetValue() const
2003-05-19 20:07:00 +06:00
{
return value();
}
//=================================================================================
// function : GetString()
// purpose : returns a QString
//=================================================================================
2009-02-17 10:27:49 +05:00
QString SMESHGUI_SpinBox::GetString() const
2003-05-19 20:07:00 +06:00
{
return cleanText();
}
2009-02-17 10:27:49 +05:00
//=================================================================================
// function : editor()
// purpose : returns editor
//=================================================================================
QLineEdit* SMESHGUI_SpinBox::editor() const
{
return SalomeApp_DoubleSpinBox::lineEdit();
}
2003-05-19 20:07:00 +06:00
//=================================================================================
// function : RangeStepAndValidator()
// purpose :
//=================================================================================
2009-02-17 10:27:49 +05:00
void SMESHGUI_SpinBox::RangeStepAndValidator( double min,
2012-08-09 16:03:55 +06:00
double max,
double step,
const char* quantity )
2003-05-19 20:07:00 +06:00
{
2012-08-09 16:03:55 +06:00
// Obtain precision from preferences
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int precision = resMgr->integerValue( "SMESH", quantity, -3 );
setPrecision(precision); // PAL8769. Minus is for using 'g' double->string conversion specifier,
// see QtxDoubleSpinBox::mapValueToText( double v )
// san: this can be achieved using preferences
setDecimals( 20 ); // qAbs(precision)
setRange(min, max);
2009-02-17 10:27:49 +05:00
setSingleStep( step );
setDefaultValue( min );
2012-08-09 16:03:55 +06:00
// Add a hint for the user saying how to tune precision
QString userPropName = QObject::tr( QString( "SMESH_PREF_%1" ).arg( quantity ).toLatin1().constData() );
setProperty( "validity_tune_hint",
QVariant( QObject::tr( "SMESH_PRECISION_HINT" ).arg( userPropName ) ) );
2003-05-19 20:07:00 +06:00
}