| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | #include "FoxLogWindow.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | #include <QAction>
 | 
					
						
							|  |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  | #include <QSqlTableModel>
 | 
					
						
							|  |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  | #include "models/FoxLog.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:45 +00:00
										 |  |  | #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-12-30 12:35:41 +00:00
										 |  |  |   explicit impl (FoxLog * log) | 
					
						
							|  |  |  |     : log_ {log} | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  |   FoxLog * log_; | 
					
						
							| 
									
										
										
										
											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-12-30 12:35:41 +00:00
										 |  |  |                             , FoxLog * fox_log, QWidget * parent) | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   : AbstractLogWindow {"Fox Log Window", settings, configuration, parent} | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  |   , m_ {fox_log} | 
					
						
							| 
									
										
										
										
											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-12-30 12:35: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-12-02 03:37:56 +00:00
										 |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), 0, 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
 | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  |   auto export_action = new QAction {tr ("&Export ADIF ..."), m_->ui_.log_table_view}; | 
					
						
							|  |  |  |   m_->ui_.log_table_view->insertAction (nullptr, export_action); | 
					
						
							|  |  |  |   connect (export_action, &QAction::triggered, [this, configuration] (bool /*checked*/) { | 
					
						
							|  |  |  |       auto file_name = QFileDialog::getSaveFileName (this | 
					
						
							|  |  |  |                                                      , tr ("Export ADIF Log File") | 
					
						
							|  |  |  |                                                      , configuration->writeable_data_dir ().absolutePath () | 
					
						
							|  |  |  |                                                      , tr ("ADIF Log (*.adi)")); | 
					
						
							|  |  |  |       if (file_name.size () && m_->log_) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           QFile ADIF_file {file_name}; | 
					
						
							|  |  |  |           if (ADIF_file.open (QIODevice::WriteOnly | QIODevice::Text)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               QTextStream output_stream {&ADIF_file}; | 
					
						
							|  |  |  |               m_->log_->export_qsos (output_stream); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               MessageBox::warning_message (this | 
					
						
							|  |  |  |                                            , tr ("Export ADIF File Error") | 
					
						
							|  |  |  |                                            , tr ("Cannot open \"%1\" for writing: %2") | 
					
						
							|  |  |  |                                            .arg (ADIF_file.fileName ()).arg (ADIF_file.errorString ())); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   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) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  |       m_->log_->model ()->selectRow (row); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-30 12:35:41 +00:00
										 |  |  |       m_->log_->model ()->select (); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |