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
00028
00029 #ifndef PG_PROPERTYFIELD_INTEGER_H
00030 #define PG_PROPERTYFIELD_INTEGER_H
00031
00032 #include <sstream>
00033 #include <limits>
00034
00035 #include "pgpropertyeditor_linefield.h"
00036
00037
00043 template <class IntegerType=int>
00044 class PG_PropertyField_Integer : public PG_PropertyEditor_LineField {
00045 IntegerType* myProperty;
00046 IntegerType minValue;
00047 IntegerType maxValue;
00048 protected:
00049 bool convert( IntegerType& i ) {
00050 std::istringstream s( lineEdit->GetText() );
00051 if ( !( s >> i ))
00052 return false;
00053
00054 return s.eof();
00055 };
00056
00057 void set
00058 ( IntegerType i ) {
00059 std::ostringstream s;
00060 s << i;
00061 lineEdit->SetText( s.str() );
00062 }
00063
00064 bool EditEnd() {
00065 IntegerType i ;
00066 if ( convert(i)) {
00067 sigValueChanged(this,i);
00068 return true;
00069 } else
00070 return false;
00071 }
00072
00073 public:
00074
00075 typedef PG_Signal2<PG_PropertyField_Integer*, IntegerType> IntegerPropertySignal;
00076 IntegerPropertySignal sigValueChanged;
00077 IntegerPropertySignal sigValueApplied;
00078
00084 PG_PropertyField_Integer( PG_PropertyEditor* propertyEditor, const std::string& name, IntegerType* myInteger ) : PG_PropertyEditor_LineField( propertyEditor, name ), myProperty( myInteger ) {
00085 minValue = std::numeric_limits<IntegerType>::min();
00086 maxValue = std::numeric_limits<IntegerType>::max();
00087 Reload();
00088 };
00089
00095 PG_PropertyField_Integer( PG_PropertyEditor* propertyEditor, const std::string& name, IntegerType myInteger ) : PG_PropertyEditor_LineField( propertyEditor, name ), myProperty( NULL ) {
00096 minValue = std::numeric_limits<IntegerType>::min();
00097 maxValue = std::numeric_limits<IntegerType>::max();
00098 set
00099 ( myInteger );
00100 };
00101
00102 void SetRange( IntegerType min, IntegerType max ) {
00103 if ( min <= max ) {
00104 minValue = min;
00105 maxValue = max;
00106 }
00107 }
00108
00109 virtual bool CheckValue( IntegerType value ) {
00110 return value >= minValue && value <= maxValue;
00111 }
00112
00113 bool Valid() {
00114 IntegerType i;
00115 if ( !convert(i) )
00116 return false;
00117
00118 if ( !CheckValue( i ))
00119 return false;
00120
00121 return true;
00122 };
00123
00124 bool Apply() {
00125 IntegerType i;
00126 if ( !convert(i) )
00127 return false;
00128
00129 if ( !CheckValue( i ))
00130 return false;
00131
00132 sigValueApplied( this, i );
00133
00134 if ( myProperty )
00135 *myProperty = i;
00136
00137 return true;
00138 };
00139
00140 void Reload() {
00141 if ( myProperty )
00142 set
00143 ( *myProperty );
00144 };
00145
00146 };
00147
00148 #endif