Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SMESHGUI_IDVALIDATOR_H
00028 #define SMESHGUI_IDVALIDATOR_H
00029
00030
00031 #include "SMESH_SMESHGUI.hxx"
00032
00033
00034 #include <QValidator>
00035
00036
00037
00038 class SMESHGUI_EXPORT SMESHGUI_IdValidator : public QValidator
00039 {
00040 public:
00041 SMESHGUI_IdValidator( QWidget* parent, const int maxNbId = 0 ) :
00042 QValidator( parent ), myMaxNbId( maxNbId ) {}
00043
00044 State validate( QString& input, int& pos ) const
00045 {
00046 input.replace( QRegExp(" *[^0-9]+ *"), " " );
00047 if ( myMaxNbId && input.length() > myMaxNbId ) {
00048
00049 int ind = 0, nbId = 0;
00050 while ( ind < input.length() ) {
00051 if ( input.at( ind ) != ' ' ) {
00052 if ( ++nbId > myMaxNbId ) {
00053 input.truncate( ind );
00054 break;
00055 }
00056 ind = input.indexOf( ' ', ind );
00057 if ( ind < 0 ) break;
00058 }
00059 ind++;
00060 }
00061 }
00062 if ( pos > input.length() )
00063 pos = input.length();
00064 return Acceptable;
00065 }
00066
00067 private:
00068 int myMaxNbId;
00069 };
00070
00071 #endif // SMESHGUI_IDVALIDATOR_H