| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | #include "FoxLogWindow.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | #include <QSqlTableModel>
 | 
					
						
							|  |  |  | #include <QAction>
 | 
					
						
							|  |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "SettingsGroup.hpp"
 | 
					
						
							|  |  |  | #include "Configuration.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | #include "MessageBox.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | #include "models/Bands.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/ForeignKeyDelegate.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-12 04:06:26 +00:00
										 |  |  | #include "item_delegates/DateTimeAsSecsSinceEpochDelegate.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/CallsignDelegate.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/MaidenheadLocatorDelegate.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | #include "pimpl_impl.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "ui_FoxLogWindow.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-26 01:42:57 +00:00
										 |  |  | #include "moc_FoxLogWindow.cpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | class FoxLogWindow::impl final | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   explicit impl (QSqlTableModel * log_model) | 
					
						
							|  |  |  |     : log_model_ {log_model} | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   QSqlTableModel * log_model_; | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   Ui::FoxLogWindow ui_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | FoxLogWindow::FoxLogWindow (QSettings * settings, Configuration const * configuration | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |                             , QSqlTableModel * fox_log_model, QWidget * parent) | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   : AbstractLogWindow {"Fox Log Window", settings, configuration, parent} | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   , m_ {fox_log_model} | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   setWindowTitle (QApplication::applicationName () + " - Fox Log"); | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   m_->ui_.setupUi (this); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   m_->ui_.log_table_view->setModel (m_->log_model_); | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   set_log_view (m_->ui_.log_table_view); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (1, new DateTimeAsSecsSinceEpochDelegate {this}); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (2, new CallsignDelegate {this}); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (3, new MaidenheadLocatorDelegate {this}); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), m_->log_model_, 0, 6, this}); | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   m_->ui_.log_table_view->horizontalHeader ()->moveSection (6, 1); // move band to first column
 | 
					
						
							|  |  |  |   m_->ui_.rate_label->setNum (0); | 
					
						
							|  |  |  |   m_->ui_.queued_label->setNum (0); | 
					
						
							|  |  |  |   m_->ui_.callers_label->setNum (0); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // actions
 | 
					
						
							|  |  |  |   auto reset_action = new QAction {tr ("&Reset ..."), m_->ui_.log_table_view}; | 
					
						
							|  |  |  |   m_->ui_.log_table_view->insertAction (nullptr, reset_action); | 
					
						
							|  |  |  |   connect (reset_action, &QAction::triggered, [this, configuration] (bool /*checked*/) { | 
					
						
							|  |  |  |       if (MessageBox::Yes == MessageBox::query_message( this | 
					
						
							|  |  |  |                                                         , tr ("Confirm Reset") | 
					
						
							|  |  |  |                                                         , tr ("Are you sure you want to erase file FoxQSO.txt " | 
					
						
							|  |  |  |                                                               "and start a new Fox log?"))) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           QFile f{configuration->writeable_data_dir ().absoluteFilePath ("FoxQSO.txt")}; | 
					
						
							|  |  |  |           f.remove (); | 
					
						
							|  |  |  |           Q_EMIT reset_log_model (); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FoxLogWindow::~FoxLogWindow () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FoxLogWindow::callers (int n) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   m_->ui_.callers_label->setNum (n); | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FoxLogWindow::queued (int n) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   m_->ui_.queued_label->setNum (n); | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FoxLogWindow::rate (int n) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   m_->ui_.rate_label->setNum (n); | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void FoxLogWindow::log_model_changed (int row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (row >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_->log_model_->selectRow (row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_->log_model_->select (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |