| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | #include "CabrilloLogWindow.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | #include <QIdentityProxyModel>
 | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | #include <QSqlTableModel>
 | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | #include "Configuration.hpp"
 | 
					
						
							|  |  |  | #include "models/Bands.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/ForeignKeyDelegate.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/DateTimeAsSecsSinceEpochDelegate.hpp"
 | 
					
						
							|  |  |  | #include "item_delegates/CallsignDelegate.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | #include "pimpl_impl.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "ui_CabrilloLogWindow.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | namespace | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   class FormatProxyModel final | 
					
						
							|  |  |  |     : public QIdentityProxyModel | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     explicit FormatProxyModel (QObject * parent = nullptr) | 
					
						
							|  |  |  |       : QIdentityProxyModel {parent} | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |     QVariant data (QModelIndex const& index, int role) const override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (Qt::TextAlignmentRole == role && index.isValid ()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           switch (index.column ()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |             case 1: | 
					
						
							|  |  |  |             case 6: | 
					
						
							|  |  |  |               return Qt::AlignRight + Qt::AlignVCenter; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       return QIdentityProxyModel::data (index, role); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | class CabrilloLogWindow::impl final | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | 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
										 |  |  |   FormatProxyModel format_model_; | 
					
						
							|  |  |  |   Ui::CabrilloLogWindow ui_; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const * configuration | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |                             , QSqlTableModel * cabrillo_log_model, QWidget * parent) | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   : AbstractLogWindow {"Cabrillo Log Window", settings, configuration, parent} | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   , m_{cabrillo_log_model} | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   setWindowTitle (QApplication::applicationName () + " - Cabrillo Log"); | 
					
						
							|  |  |  |   m_->ui_.setupUi (this); | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  |   m_->format_model_.setSourceModel (m_->log_model_); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setModel (&m_->format_model_); | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  |   set_log_view (m_->ui_.log_table_view); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (2, new DateTimeAsSecsSinceEpochDelegate {this}); | 
					
						
							|  |  |  |   m_->ui_.log_table_view->setItemDelegateForColumn (3, new CallsignDelegate {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); // band to first column
 | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 01:18:39 +00:00
										 |  |  | CabrilloLogWindow::~CabrilloLogWindow () | 
					
						
							| 
									
										
										
										
											2018-11-12 04:13:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-25 22:19:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void CabrilloLogWindow::log_model_changed (int row) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (row >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_->log_model_->selectRow (row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_->log_model_->select (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |