00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef QMITK_NUMBERPROPERTYEDITOR_H_INCLUDED 00018 #define QMITK_NUMBERPROPERTYEDITOR_H_INCLUDED 00019 00020 #include <mitkPropertyObserver.h> 00021 #include "QmitkExtExports.h" 00022 #include <mitkProperties.h> 00023 #include <QSpinBox> 00024 00026 class QmitkExt_EXPORT QmitkNumberPropertyEditor : public QSpinBox, public mitk::PropertyEditor 00027 { 00028 Q_OBJECT 00029 Q_PROPERTY( short decimalPlaces READ getDecimalPlaces WRITE setDecimalPlaces ) 00030 Q_PROPERTY( bool showPercent READ getShowPercent WRITE setShowPercent ) 00031 Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) 00032 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) 00033 00034 public: 00035 00036 //QmitkNumberPropertyEditor( mitk::GenericProperty<short>*, QWidget* parent, const char* name = 0 ); 00037 QmitkNumberPropertyEditor( mitk::IntProperty*, QWidget* parent ); 00038 QmitkNumberPropertyEditor( mitk::FloatProperty*, QWidget* parent ); 00039 QmitkNumberPropertyEditor( mitk::DoubleProperty*, QWidget* parent ); 00040 00041 virtual ~QmitkNumberPropertyEditor(); 00042 00043 short getDecimalPlaces() const; 00044 void setDecimalPlaces(short); 00045 00046 bool getShowPercent() const; 00047 void setShowPercent(bool); 00048 00049 int minValue() const; 00050 void setMinValue(int); 00051 int maxValue() const; 00052 void setMaxValue(int); 00053 double doubleValue() const; 00054 void setDoubleValue(double); 00055 00056 protected: 00057 00058 void initialize(); 00059 00060 virtual QString textFromValue(int) const; 00061 virtual int valueFromText(const QString&) const; 00062 00063 virtual void PropertyChanged(); 00064 virtual void PropertyRemoved(); 00065 00066 void DisplayNumber(); 00067 00068 union { 00069 //mitk::GenericProperty<short>* m_ShortProperty; 00070 mitk::GenericProperty<int>* m_IntProperty; 00071 mitk::GenericProperty<float>* m_FloatProperty; 00072 mitk::GenericProperty<double>* m_DoubleProperty; 00073 }; 00074 00075 const int m_DataType; 00076 00077 short m_DecimalPlaces; // how many decimal places are shown 00078 double m_FactorPropertyToSpinbox; // internal conversion factor. neccessary because spinbox ranges work only with ints 00079 double m_FactorSpinboxToDisplay; // internal conversion factor. neccessary because spinbox ranges work only with ints 00080 bool m_ShowPercents; // whether values are given in percent (0.5 -> 50%) 00081 00082 protected slots: 00083 00084 void onValueChanged(int); 00085 00086 private: 00087 00088 void adjustFactors(short, bool); 00089 00090 bool m_SelfChangeLock; 00091 }; 00092 00093 #endif 00094