X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FQDS%2FQDS_LineEdit.cxx;h=ad62c3746cd08befa075d812b93e1a7aa0b8fa51;hb=39b71280d566791e1af60ea44244bf4ea8ca6020;hp=15cc3f0570e5aa74494c18a4373e670bc53f03a2;hpb=758c66ca44d214e40e828e41790408af0540231f;p=modules%2Fgui.git diff --git a/src/QDS/QDS_LineEdit.cxx b/src/QDS/QDS_LineEdit.cxx index 15cc3f057..ad62c3746 100644 --- a/src/QDS/QDS_LineEdit.cxx +++ b/src/QDS/QDS_LineEdit.cxx @@ -1,11 +1,34 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "QDS_LineEdit.h" -#include -#include +#include +#include -/* - Class: QDS_LineEdit::Editor - Descr: Internal class inherited from line edit +/*! + \class QDS_LineEdit::Editor + \internal + \brief Improved version of QLineEdit. */ class QDS_LineEdit::Editor : public QLineEdit @@ -32,12 +55,32 @@ private: }; /* - Class: QDS_LineEdit - Descr: Data control corresponding to line edit + \class QDS_LineEdit + + \brief Datum with control corresponding to the line edit. + + User can enter parameter value in single line editor. + The value entered by the user is checked by the validator according to item type + according to the item properties (minimum, maximum, filter, precision, etc). + + If user input is not valid, the value is displayed in red color. */ /*! - Constructor. + \brief Constructor. + + Create line edit datum object with datum identifier \a id and parent widget \a parent. + + Parameter \a flags defines behaviour of datum and set of created + subwidgets. Default value of this parameter is QDS::All. + + Parameter \a comp specifies the component name which will be used + when searching the dictionary item. + + \param id datum identifier + \param parent parent widget + \param flags datum flags + \param comp component */ QDS_LineEdit::QDS_LineEdit( const QString& id, QWidget* parent, const int flags, const QString& comp ) : QDS_Datum( id, parent, flags, comp ) @@ -45,12 +88,19 @@ QDS_LineEdit::QDS_LineEdit( const QString& id, QWidget* parent, const int flags, } /*! - Destructor. + \brief Destructor. */ QDS_LineEdit::~QDS_LineEdit() { } +/*! + \brief Process notification about active units system changing. + + Update validator settings for line edit. + + \param system new active units system +*/ void QDS_LineEdit::unitSystemChanged( const QString& system ) { QDS_Datum::unitSystemChanged( system ); @@ -60,14 +110,14 @@ void QDS_LineEdit::unitSystemChanged( const QString& system ) return; delete le->validator(); - le->clearValidator(); + le->setValidator(0); QValidator* valid = validator(); if ( valid ) le->setValidator( valid ); QString aFormat = format(); int num = 0; - int pos = aFormat.find( '%' ); + int pos = aFormat.indexOf( '%' ); if ( pos != -1 ) { pos++; @@ -84,23 +134,65 @@ void QDS_LineEdit::unitSystemChanged( const QString& system ) int minLen = format( format(), type(), minValue() ).length(); int maxLen = format( format(), type(), maxValue() ).length(); - num = QMAX( QMAX( num, zeroLen ), QMAX( minLen, maxLen ) ); + num = qMax( qMax( num, zeroLen ), qMax( minLen, maxLen ) ); ((Editor*)le)->setNumber( num ); } /*! - Set the aligment of line edit. + \brief Select all text in the editor. +*/ +void QDS_LineEdit::selectAll() +{ + if ( lineEdit() ) + lineEdit()->selectAll(); +} + +/*! + \brief Deselect all text in the editor. +*/ +void QDS_LineEdit::deselect() +{ + if ( lineEdit() ) + lineEdit()->deselect(); +} + +/*! + \brief Select/deselect all text in the editor. + \param on select text if \c true and deselect if \c false +*/ +void QDS_LineEdit::setSelection( const bool on ) +{ + if ( on ) + selectAll(); + else + deselect(); +} + +/*! + \brief Check if there is selection in the editor. + \return \c true if the editor has selected text +*/ +bool QDS_LineEdit::hasSelection() const +{ + return lineEdit() ? lineEdit()->hasSelectedText() : false; +} + +/*! + \brief Set the aligment for the line edit. + \param align alignment type (Qt::Alignment) + \param type ORed subwidget flags */ void QDS_LineEdit::setAlignment( const int align, const int type ) { if ( ( type & Control ) && lineEdit() ) - lineEdit()->setAlignment( align ); + lineEdit()->setAlignment( Qt::Alignment(align) ); QDS_Datum::setAlignment( align, type ); } /*! - Returns string from QLineEdit widget. + \brief Get string value from datum. + \return datum string value */ QString QDS_LineEdit::getString() const { @@ -111,7 +203,8 @@ QString QDS_LineEdit::getString() const } /*! - Sets the string into QLineEdit widget. + \brief Set string value to datum. + \param txt new datum string value */ void QDS_LineEdit::setString( const QString& txt ) { @@ -120,15 +213,18 @@ void QDS_LineEdit::setString( const QString& txt ) } /*! - Returns pointer to QLineEdit widget. + \brief Get line edit widget. + \return pointer to the QLineEdit widget */ QLineEdit* QDS_LineEdit::lineEdit() const { - return ::qt_cast( controlWidget() ); + return ::qobject_cast( controlWidget() ); } /*! - Create QLineEdit widget as control subwidget. + \brief Create line edit widget as control subwidget. + \param parent parent widget + \return created line edit widget */ QWidget* QDS_LineEdit::createControl( QWidget* parent ) { @@ -139,9 +235,13 @@ QWidget* QDS_LineEdit::createControl( QWidget* parent ) } /*! - Notify about text changing in line edit. + \brief Called when text in the edit box is modified by the user. + + Notify about text changing in the line edit. + + \param txt current text in the line edit widget (not used) */ -void QDS_LineEdit::onTextChanged( const QString& ) +void QDS_LineEdit::onTextChanged( const QString& /*txt*/ ) { invalidateCache(); @@ -152,7 +252,11 @@ void QDS_LineEdit::onTextChanged( const QString& ) } /*! - Checks the current parameter value on validity. + \brief Called when text is changed. + + Validate the current parameter value. If value is not valid then set text color as red. + + Emits signal paramChanged() to notify about changing of the control state. */ void QDS_LineEdit::onParamChanged() { @@ -164,9 +268,14 @@ void QDS_LineEdit::onParamChanged() QPalette aPal = anEdit->palette(); if ( !aValid ) - aPal.setColor( QPalette::Active, QColorGroup::Text, QColor( 255, 0, 0 ) ); + aPal.setColor( QPalette::Active, QPalette::Text, QColor( 255, 0, 0 ) ); else - aPal.setColor( QPalette::Active, QColorGroup::Text, QColor( 0, 0, 0 ) ); + aPal.setColor( QPalette::Active, QPalette::Text, QColor( 0, 0, 0 ) ); anEdit->setPalette( aPal ); } + +/*! + \brief void QDS_LineEdit::returnPressed(); + \brief The signal is emitted when user presses \c Enter key in the line edit. +*/