| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | #include "FrequencyList.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 22:36:13 +00:00
										 |  |  | #include <cstdlib>
 | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2016-10-30 22:36:13 +00:00
										 |  |  | #include <limits>
 | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 10:08:35 +00:00
										 |  |  | #include <QMetaType>
 | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | #include <QAbstractTableModel>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QList>
 | 
					
						
							|  |  |  | #include <QListIterator>
 | 
					
						
							|  |  |  | #include <QVector>
 | 
					
						
							|  |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | #include <QMimeData>
 | 
					
						
							|  |  |  | #include <QDataStream>
 | 
					
						
							|  |  |  | #include <QByteArray>
 | 
					
						
							| 
									
										
										
										
											2016-04-06 17:11:02 +00:00
										 |  |  | #include <QDebugStateSaver>
 | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:00 +00:00
										 |  |  | #include "Radio.hpp"
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | #include "Bands.hpp"
 | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | #include "pimpl_impl.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 14:30:23 +00:00
										 |  |  | #include "moc_FrequencyList.cpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | namespace | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  |   FrequencyList_v2::FrequencyItems const default_frequency_list = | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       {198000, Modes::FreqCal, IARURegions::R1}, // BBC Radio 4 Droitwich
 | 
					
						
							|  |  |  |       {4996000, Modes::FreqCal, IARURegions::R1},  // RWM time signal
 | 
					
						
							|  |  |  |       {9996000, Modes::FreqCal, IARURegions::R1},  // RWM time signal
 | 
					
						
							|  |  |  |       {14996000, Modes::FreqCal, IARURegions::R1}, // RWM time signal
 | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {660000, Modes::FreqCal, IARURegions::R2}, | 
					
						
							|  |  |  |       {880000, Modes::FreqCal, IARURegions::R2}, | 
					
						
							|  |  |  |       {1210000, Modes::FreqCal, IARURegions::R2}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {2500000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {3330000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {5000000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {7850000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {10000000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {14670000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {15000000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |       {20000000, Modes::FreqCal, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {136000, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {136130, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {136130, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {474200, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {474200, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {474200, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {1836600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {1838000, Modes::JT65, IARURegions::ALL}, // squeezed allocations
 | 
					
						
							|  |  |  |       {1839000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {1840000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {3570000, Modes::JT65, IARURegions::ALL}, // JA compatible
 | 
					
						
							|  |  |  |       {3572000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {3573000, Modes::FT8, IARURegions::ALL}, // above as below JT65
 | 
					
						
							|  |  |  |                                                // is out of DM allocation
 | 
					
						
							| 
									
										
										
										
											2017-07-14 09:25:46 +00:00
										 |  |  |       {3568600, Modes::WSPR, IARURegions::ALL}, // needs guard marker
 | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |                                                 // and lock out
 | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {7038600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {7074000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {7076000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {7078000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {10136000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {10138000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {10138700, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {10140000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {14095600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {14074000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {14076000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {14078000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {18100000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {18102000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {18104000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {18104600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {21074000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {21076000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {21078000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {21094600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {24915000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {24917000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {24919000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {24924600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {28074000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {28076000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {28078000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {28124600, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |        | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {50200000, Modes::Echo, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       {50276000, Modes::JT65, IARURegions::R2}, | 
					
						
							|  |  |  |       {50276000, Modes::JT65, IARURegions::R3}, | 
					
						
							|  |  |  |       {50260000, Modes::MSK144, IARURegions::R2}, | 
					
						
							|  |  |  |       {50260000, Modes::MSK144, IARURegions::R3}, | 
					
						
							|  |  |  |       {50293000, Modes::WSPR, IARURegions::R2}, | 
					
						
							|  |  |  |       {50293000, Modes::WSPR, IARURegions::R3}, | 
					
						
							|  |  |  |       {50310000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {50312000, Modes::JT9, IARURegions::ALL}, | 
					
						
							|  |  |  |       {50313000, Modes::FT8, IARURegions::ALL}, | 
					
						
							|  |  |  |       {50360000, Modes::MSK144, IARURegions::R1}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {70100000, Modes::FT8, IARURegions::R1}, | 
					
						
							|  |  |  |       {70102000, Modes::JT65, IARURegions::R1}, | 
					
						
							|  |  |  |       {70104000, Modes::JT9, IARURegions::R1}, | 
					
						
							|  |  |  |       {70091000, Modes::WSPR, IARURegions::R1}, | 
					
						
							|  |  |  |       {70230000, Modes::MSK144, IARURegions::R1}, | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       {144120000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {144120000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {144360000, Modes::MSK144, IARURegions::R1}, | 
					
						
							|  |  |  |       {144150000, Modes::MSK144, IARURegions::R2}, | 
					
						
							|  |  |  |       {144489000, Modes::WSPR, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {144120000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {222065000, Modes::Echo, IARURegions::R2}, | 
					
						
							|  |  |  |       {222065000, Modes::JT65, IARURegions::R2}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {222065000, Modes::QRA64, IARURegions::R2}, | 
					
						
							|  |  |  | 	   | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       {432065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {432065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {432300000, Modes::WSPR, IARURegions::ALL}, | 
					
						
							|  |  |  |       {432360000, Modes::MSK144, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {432065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {902065000, Modes::JT65, IARURegions::R2}, | 
					
						
							|  |  |  |       {902065000, Modes::QRA64, IARURegions::R2}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {1296065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {1296065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							|  |  |  |       {1296500000, Modes::WSPR, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {1296065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {2301000000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2301065000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2301065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {2301065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       {2304065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2304065000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2304065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {2304065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {2320065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2320065000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {2320065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {2320065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {3400065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {3400065000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {3400065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {3400065000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {5760065000, Modes::Echo, IARURegions::ALL}, | 
					
						
							|  |  |  |       {5760065000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {5760065000, Modes::JT65, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {5760200000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |        | 
					
						
							|  |  |  |       {10368100000, Modes::Echo, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {10368200000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {10368200000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							|  |  |  | 	   | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       {24048100000, Modes::Echo, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2017-07-12 12:41:36 +00:00
										 |  |  |       {24048200000, Modes::JT4, IARURegions::ALL}, | 
					
						
							|  |  |  |       {24048200000, Modes::QRA64, IARURegions::ALL}, | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined (QT_NO_DEBUG_STREAM)
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QDebug operator << (QDebug debug, FrequencyList_v2::Item const& item) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-04-06 17:11:02 +00:00
										 |  |  |   QDebugStateSaver saver {debug}; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   debug.nospace () << "FrequencyItem(" | 
					
						
							|  |  |  |                    << item.frequency_ << ", " | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |                    << item.region_ << ", " | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |                    << item.mode_ << ')'; | 
					
						
							| 
									
										
										
										
											2016-04-06 17:11:02 +00:00
										 |  |  |   return debug; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QDataStream& operator << (QDataStream& os, FrequencyList_v2::Item const& item) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return os << item.frequency_ | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |             << item.mode_ | 
					
						
							|  |  |  |             << item.region_; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QDataStream& operator >> (QDataStream& is, FrequencyList_v2::Item& item) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return is >> item.frequency_ | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |             >> item.mode_ | 
					
						
							|  |  |  |             >> item.region_; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | class FrequencyList_v2::impl final | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   : public QAbstractTableModel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   impl (Bands const * bands, QObject * parent) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |     : QAbstractTableModel {parent} | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     , bands_ {bands} | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |     , region_filter_ {IARURegions::ALL} | 
					
						
							|  |  |  |     , mode_filter_ {Modes::ALL} | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   FrequencyItems frequency_list (FrequencyItems); | 
					
						
							|  |  |  |   QModelIndex add (Item); | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |   void add (FrequencyItems); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Implement the QAbstractTableModel interface
 | 
					
						
							|  |  |  |   int rowCount (QModelIndex const& parent = QModelIndex {}) const override; | 
					
						
							|  |  |  |   int columnCount (QModelIndex const& parent = QModelIndex {}) const override; | 
					
						
							|  |  |  |   Qt::ItemFlags flags (QModelIndex const& = QModelIndex {}) const override; | 
					
						
							|  |  |  |   QVariant data (QModelIndex const&, int role = Qt::DisplayRole) const override; | 
					
						
							|  |  |  |   bool setData (QModelIndex const&, QVariant const& value, int role = Qt::EditRole) override; | 
					
						
							|  |  |  |   QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override; | 
					
						
							|  |  |  |   bool removeRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override; | 
					
						
							|  |  |  |   bool insertRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override; | 
					
						
							|  |  |  |   QStringList mimeTypes () const override; | 
					
						
							|  |  |  |   QMimeData * mimeData (QModelIndexList const&) const override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |   static int constexpr num_cols {SENTINAL}; | 
					
						
							| 
									
										
										
										
											2016-05-01 00:40:51 +00:00
										 |  |  |   static auto constexpr mime_type = "application/wsjt.Frequencies"; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   Bands const * bands_; | 
					
						
							|  |  |  |   FrequencyItems frequency_list_; | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |   Region region_filter_; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   Mode mode_filter_; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | FrequencyList_v2::FrequencyList_v2 (Bands const * bands, QObject * parent) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   : QSortFilterProxyModel {parent} | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   , m_ {bands, parent} | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   setSourceModel (&*m_); | 
					
						
							|  |  |  |   setSortRole (SortRole); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | FrequencyList_v2::~FrequencyList_v2 () | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::frequency_list (FrequencyItems frequency_list) -> FrequencyItems | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return m_->frequency_list (frequency_list); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::frequency_list () const -> FrequencyItems const& | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return m_->frequency_list_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::frequency_list (QModelIndexList const& model_index_list) const -> FrequencyItems | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   FrequencyItems list; | 
					
						
							|  |  |  |   Q_FOREACH (auto const& index, model_index_list) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       list << m_->frequency_list_[mapToSource (index).row ()]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return list; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | void FrequencyList_v2::frequency_list_merge (FrequencyItems const& items) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   m_->add (items); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | int FrequencyList_v2::best_working_frequency (Frequency f) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |   int result {-1}; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   auto const& target_band = m_->bands_->find (f); | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |   if (!target_band.isEmpty ()) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-30 22:36:13 +00:00
										 |  |  |       Radio::FrequencyDelta delta {std::numeric_limits<Radio::FrequencyDelta>::max ()}; | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |       // find a frequency in the same band that is allowed
 | 
					
						
							|  |  |  |       for (int row = 0; row < rowCount (); ++row) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           auto const& source_row = mapToSource (index (row, 0)).row (); | 
					
						
							| 
									
										
										
										
											2016-10-30 22:36:13 +00:00
										 |  |  |           auto const& candidate_frequency = m_->frequency_list_[source_row].frequency_; | 
					
						
							|  |  |  |           auto const& band = m_->bands_->find (candidate_frequency); | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |           if (band == target_band) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2016-10-30 22:36:13 +00:00
										 |  |  |               // take closest band match
 | 
					
						
							|  |  |  |               Radio::FrequencyDelta new_delta = f - candidate_frequency; | 
					
						
							|  |  |  |               if (std::abs (new_delta) < std::abs (delta)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   delta = new_delta; | 
					
						
							|  |  |  |                   result = row; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | int FrequencyList_v2::best_working_frequency (QString const& target_band) const | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int result {-1}; | 
					
						
							|  |  |  |   if (!target_band.isEmpty ()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       // find a frequency in the same band that is allowed
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       for (int row = 0; row < rowCount (); ++row) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           auto const& source_row = mapToSource (index (row, 0)).row (); | 
					
						
							|  |  |  |           auto const& band = m_->bands_->find (m_->frequency_list_[source_row].frequency_); | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |           if (band == target_band) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |               return row; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |   return result; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | void FrequencyList_v2::reset_to_defaults () | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   m_->frequency_list (default_frequency_list); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QModelIndex FrequencyList_v2::add (Item f) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return mapFromSource (m_->add (f)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::remove (Item f) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   auto row = m_->frequency_list_.indexOf (f); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (0 > row) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return m_->removeRow (row); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bool row_is_higher (QModelIndex const& lhs, QModelIndex const& rhs) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return lhs.row () > rhs.row (); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::removeDisjointRows (QModelIndexList rows) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bool result {true}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // We must work with source model indexes because we don't want row
 | 
					
						
							|  |  |  |   // removes to invalidate model indexes we haven't yet processed. We
 | 
					
						
							|  |  |  |   // achieve that by processing them in decending row order.
 | 
					
						
							|  |  |  |   for (int r = 0; r < rows.size (); ++r) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       rows[r] = mapToSource (rows[r]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // reverse sort by row
 | 
					
						
							|  |  |  |   qSort (rows.begin (), rows.end (), row_is_higher); | 
					
						
							|  |  |  |   Q_FOREACH (auto index, rows) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (result && !m_->removeRow (index.row ())) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           result = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | void FrequencyList_v2::filter (Region region, Mode mode) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |   m_->region_filter_ = region; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   m_->mode_filter_ = mode; | 
					
						
							|  |  |  |   invalidateFilter (); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::filterAcceptsRow (int source_row, QModelIndex const& /* parent */) const | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bool result {true}; | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |   auto const& item = m_->frequency_list_[source_row]; | 
					
						
							|  |  |  |   if (m_->region_filter_ != IARURegions::ALL) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       result = IARURegions::ALL == item.region_ || m_->region_filter_ == item.region_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   if (result && m_->mode_filter_ != Modes::ALL) | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       // we pass ALL mode rows unless filtering for FreqCal mode
 | 
					
						
							|  |  |  |       result = (Modes::ALL == item.mode_ && m_->mode_filter_ != Modes::FreqCal) | 
					
						
							| 
									
										
										
										
											2017-01-12 21:03:30 +00:00
										 |  |  |         || m_->mode_filter_ == item.mode_; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::impl::frequency_list (FrequencyItems frequency_list) -> FrequencyItems | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   beginResetModel (); | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   std::swap (frequency_list_, frequency_list); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   endResetModel (); | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   return frequency_list; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QModelIndex FrequencyList_v2::impl::add (Item f) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   // Any Frequency that isn't in the list may be added
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   if (!frequency_list_.contains (f)) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       auto row = frequency_list_.size (); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       beginInsertRows (QModelIndex {}, row, row); | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       frequency_list_.append (f); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |       endInsertRows (); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return index (row, 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return QModelIndex {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | void FrequencyList_v2::impl::add (FrequencyItems items) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   // Any Frequency that isn't in the list may be added
 | 
					
						
							|  |  |  |   for (auto p = items.begin (); p != items.end ();) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (frequency_list_.contains (*p)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           p = items.erase (p); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (items.size ()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       auto row = frequency_list_.size (); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beginInsertRows (QModelIndex {}, row, row + items.size () - 1); | 
					
						
							|  |  |  |       frequency_list_.append (items); | 
					
						
							|  |  |  |       endInsertRows (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | int FrequencyList_v2::impl::rowCount (QModelIndex const& parent) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   return parent.isValid () ? 0 : frequency_list_.size (); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | int FrequencyList_v2::impl::columnCount (QModelIndex const& parent) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return parent.isValid () ? 0 : num_cols; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | Qt::ItemFlags FrequencyList_v2::impl::flags (QModelIndex const& index) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   auto result = QAbstractTableModel::flags (index) | Qt::ItemIsDropEnabled; | 
					
						
							|  |  |  |   auto row = index.row (); | 
					
						
							|  |  |  |   auto column = index.column (); | 
					
						
							|  |  |  |   if (index.isValid () | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       && row < frequency_list_.size () | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |       && column < num_cols) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       if (frequency_mhz_column != column) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |           result |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QVariant FrequencyList_v2::impl::data (QModelIndex const& index, int role) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   QVariant item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   auto const& row = index.row (); | 
					
						
							|  |  |  |   auto const& column = index.column (); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (index.isValid () | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       && row < frequency_list_.size () | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |       && column < num_cols) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       auto const& frequency_item = frequency_list_.at (row); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |       switch (column) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |         case region_column: | 
					
						
							|  |  |  |           switch (role) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case SortRole: | 
					
						
							|  |  |  |             case Qt::DisplayRole: | 
					
						
							|  |  |  |             case Qt::EditRole: | 
					
						
							|  |  |  |             case Qt::AccessibleTextRole: | 
					
						
							|  |  |  |               item = IARURegions::name (frequency_item.region_); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::ToolTipRole: | 
					
						
							|  |  |  |             case Qt::AccessibleDescriptionRole: | 
					
						
							|  |  |  |               item = tr ("IARU Region"); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::TextAlignmentRole: | 
					
						
							|  |  |  |               item = Qt::AlignHCenter + Qt::AlignVCenter; | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |         case mode_column: | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |           switch (role) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case SortRole: | 
					
						
							|  |  |  |             case Qt::DisplayRole: | 
					
						
							|  |  |  |             case Qt::EditRole: | 
					
						
							|  |  |  |             case Qt::AccessibleTextRole: | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |               item = Modes::name (frequency_item.mode_); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::ToolTipRole: | 
					
						
							|  |  |  |             case Qt::AccessibleDescriptionRole: | 
					
						
							|  |  |  |               item = tr ("Mode"); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::TextAlignmentRole: | 
					
						
							|  |  |  |               item = Qt::AlignHCenter + Qt::AlignVCenter; | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case frequency_column: | 
					
						
							|  |  |  |           switch (role) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case SortRole: | 
					
						
							|  |  |  |             case Qt::EditRole: | 
					
						
							|  |  |  |             case Qt::AccessibleTextRole: | 
					
						
							|  |  |  |               item = frequency_item.frequency_; | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::DisplayRole: | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 auto const& band = bands_->find (frequency_item.frequency_); | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |                 item = Radio::pretty_frequency_MHz_string (frequency_item.frequency_) | 
					
						
							|  |  |  |                   + " MHz (" + (band.isEmpty () ? "OOB" : band) + ')'; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::ToolTipRole: | 
					
						
							|  |  |  |             case Qt::AccessibleDescriptionRole: | 
					
						
							|  |  |  |               item = tr ("Frequency"); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::TextAlignmentRole: | 
					
						
							|  |  |  |               item = Qt::AlignRight + Qt::AlignVCenter; | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |         case frequency_mhz_column: | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |           switch (role) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case Qt::EditRole: | 
					
						
							|  |  |  |             case Qt::AccessibleTextRole: | 
					
						
							| 
									
										
										
										
											2015-09-10 21:03:42 +00:00
										 |  |  |               item = Radio::frequency_MHz_string (frequency_item.frequency_); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |             case Qt::DisplayRole: | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 auto const& band = bands_->find (frequency_item.frequency_); | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  |                 item = Radio::pretty_frequency_MHz_string (frequency_item.frequency_) | 
					
						
							|  |  |  |                   + " MHz (" + (band.isEmpty () ? "OOB" : band) + ')'; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::ToolTipRole: | 
					
						
							|  |  |  |             case Qt::AccessibleDescriptionRole: | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |               item = tr ("Frequency (MHz)"); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |               break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case Qt::TextAlignmentRole: | 
					
						
							|  |  |  |               item = Qt::AlignRight + Qt::AlignVCenter; | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return item; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::impl::setData (QModelIndex const& model_index, QVariant const& value, int role) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   bool changed {false}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |   auto const& row = model_index.row (); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |   if (model_index.isValid () | 
					
						
							|  |  |  |       && Qt::EditRole == role | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       && row < frequency_list_.size ()) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       QVector<int> roles; | 
					
						
							|  |  |  |       roles << role; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       auto& item = frequency_list_[row]; | 
					
						
							|  |  |  |       switch (model_index.column ()) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |         case region_column: | 
					
						
							|  |  |  |           if (value.canConvert<Region> ()) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-07-11 01:59:19 +00:00
										 |  |  |               auto region = static_cast<Region> (value.toUInt ()); | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |               if (region != item.region_) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   item.region_ = region; | 
					
						
							|  |  |  |                   Q_EMIT dataChanged (model_index, model_index, roles); | 
					
						
							|  |  |  |                   changed = true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |         case mode_column: | 
					
						
							|  |  |  |           if (value.canConvert<Mode> ()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               auto mode = Modes::value (value.toString ()); | 
					
						
							|  |  |  |               if (mode != item.mode_) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   item.mode_ = mode; | 
					
						
							|  |  |  |                   Q_EMIT dataChanged (model_index, model_index, roles); | 
					
						
							|  |  |  |                   changed = true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         case frequency_column: | 
					
						
							|  |  |  |           if (value.canConvert<Frequency> ()) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:00 +00:00
										 |  |  |               Radio::Frequency frequency {qvariant_cast <Radio::Frequency> (value)}; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |               if (frequency != item.frequency_) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   item.frequency_ = frequency; | 
					
						
							|  |  |  |                   // mark derived column (1) changed as well
 | 
					
						
							|  |  |  |                   Q_EMIT dataChanged (index (model_index.row (), 1), model_index, roles); | 
					
						
							|  |  |  |                   changed = true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return changed; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QVariant FrequencyList_v2::impl::headerData (int section, Qt::Orientation orientation, int role) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   QVariant header; | 
					
						
							|  |  |  |   if (Qt::DisplayRole == role | 
					
						
							|  |  |  |       && Qt::Horizontal == orientation | 
					
						
							|  |  |  |       && section < num_cols) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       switch (section) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |         case region_column: header = tr ("IARU Region"); break; | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |         case mode_column: header = tr ("Mode"); break; | 
					
						
							|  |  |  |         case frequency_column: header = tr ("Frequency"); break; | 
					
						
							|  |  |  |         case frequency_mhz_column: header = tr ("Frequency (MHz)"); break; | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       header = QAbstractTableModel::headerData (section, orientation, role); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return header; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::impl::removeRows (int row, int count, QModelIndex const& parent) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (0 < count && (row + count) <= rowCount (parent)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       beginRemoveRows (parent, row, row + count - 1); | 
					
						
							|  |  |  |       for (auto r = 0; r < count; ++r) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |           frequency_list_.removeAt (row); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       endRemoveRows (); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::impl::insertRows (int row, int count, QModelIndex const& parent) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (0 < count) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       beginInsertRows (parent, row, row + count - 1); | 
					
						
							|  |  |  |       for (auto r = 0; r < count; ++r) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |           frequency_list_.insert (row, Item {0, Mode::ALL, IARURegions::ALL}); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       endInsertRows (); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QStringList FrequencyList_v2::impl::mimeTypes () const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   QStringList types; | 
					
						
							|  |  |  |   types << mime_type; | 
					
						
							|  |  |  |   return types; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | QMimeData * FrequencyList_v2::impl::mimeData (QModelIndexList const& items) const | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   QMimeData * mime_data = new QMimeData {}; | 
					
						
							|  |  |  |   QByteArray encoded_data; | 
					
						
							|  |  |  |   QDataStream stream {&encoded_data, QIODevice::WriteOnly}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Q_FOREACH (auto const& item, items) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-28 23:22:17 +00:00
										 |  |  |       if (item.isValid () && frequency_column == item.column ()) | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2015-11-13 23:44:48 +00:00
										 |  |  |           stream << frequency_list_.at (item.row ()); | 
					
						
							| 
									
										
										
										
											2015-04-06 01:57:47 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mime_data->setData (mime_type, encoded_data); | 
					
						
							|  |  |  |   return mime_data; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::const_iterator::operator * () const -> Item const& | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return parent_->frequency_list ().at(parent_->mapToSource (parent_->index (row_, 0)).row ()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::const_iterator::operator -> () const -> Item const * | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return &parent_->frequency_list ().at(parent_->mapToSource (parent_->index (row_, 0)).row ()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::const_iterator::operator != (const_iterator const& rhs) const | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return parent_ != rhs.parent_ || row_ != rhs.row_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | bool FrequencyList_v2::const_iterator::operator == (const_iterator const& rhs) const | 
					
						
							| 
									
										
										
										
											2017-01-08 23:58:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return parent_ == rhs.parent_ && row_ == rhs.row_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::const_iterator::operator ++ () -> const_iterator& | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   ++row_; | 
					
						
							|  |  |  |   return *this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::begin () const -> const_iterator | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return const_iterator (this, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::end () const -> const_iterator | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return const_iterator (this, rowCount ()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::find (Frequency f) const -> const_iterator | 
					
						
							| 
									
										
										
										
											2017-01-12 21:03:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int row {0}; | 
					
						
							|  |  |  |   for (; row < rowCount (); ++row) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (m_->frequency_list_[mapToSource (index (row, 0)).row ()].frequency_ == f) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return const_iterator (this, row); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::filtered_bands () const -> BandSet | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BandSet result; | 
					
						
							| 
									
										
										
										
											2015-06-06 00:06:46 +00:00
										 |  |  |   for (auto const& item : *this) | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       result << m_->bands_->find (item.frequency_); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | auto FrequencyList_v2::all_bands (Region region, Mode mode) const -> BandSet | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   BandSet result; | 
					
						
							| 
									
										
										
										
											2015-06-06 00:06:46 +00:00
										 |  |  |   for (auto const& item : m_->frequency_list_) | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:11:41 +00:00
										 |  |  |       if (region == IARURegions::ALL || item.region_ == region | 
					
						
							|  |  |  |           || mode == Modes::ALL || item.mode_ == mode) | 
					
						
							| 
									
										
										
										
											2015-06-06 00:06:46 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |           result << m_->bands_->find (item.frequency_); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-31 11:51:40 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-09 16:06:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Obsolete version of FrequencyList no longer used but needed to
 | 
					
						
							|  |  |  | // allow loading and saving of old settings contents without damage
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | QDataStream& operator << (QDataStream& os, FrequencyList::Item const& item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return os << item.frequency_ | 
					
						
							|  |  |  |             << item.mode_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QDataStream& operator >> (QDataStream& is, FrequencyList::Item& item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return is >> item.frequency_ | 
					
						
							|  |  |  |             >> item.mode_; | 
					
						
							|  |  |  | } |