| 
									
										
										
										
											2015-09-10 21:03:42 +00:00
										 |  |  | #include "FrequencyLineEdit.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:00 +00:00
										 |  |  | #include <limits>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDoubleValidator>
 | 
					
						
							| 
									
										
										
										
											2015-09-10 21:03:42 +00:00
										 |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QLocale>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "moc_FrequencyLineEdit.cpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:00 +00:00
										 |  |  | namespace | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   class MHzValidator | 
					
						
							|  |  |  |     : public QDoubleValidator | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     MHzValidator (double bottom, double top, QObject * parent = nullptr) | 
					
						
							|  |  |  |       : QDoubleValidator {bottom, top, 6, parent} | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     State validate (QString& input, int& pos) const override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       State result = QDoubleValidator::validate (input, pos); | 
					
						
							|  |  |  |       if (Acceptable == result) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           bool ok; | 
					
						
							|  |  |  |           (void)QLocale {}.toDouble (input, &ok); | 
					
						
							|  |  |  |           if (!ok) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               result = Intermediate; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       return result; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 21:03:42 +00:00
										 |  |  | FrequencyLineEdit::FrequencyLineEdit (QWidget * parent) | 
					
						
							|  |  |  |   : QLineEdit (parent) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:00 +00:00
										 |  |  |   setValidator (new MHzValidator {0., std::numeric_limits<Radio::Frequency>::max () / 10.e6, this}); | 
					
						
							| 
									
										
										
										
											2015-09-10 21:03:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | auto FrequencyLineEdit::frequency () const -> Frequency | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return Radio::frequency (text (), 6); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FrequencyLineEdit::frequency (Frequency f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   setText (Radio::frequency_MHz_string (f)); | 
					
						
							|  |  |  | } |