|  | @@ -20,6 +20,50 @@ TotalsWidget::~TotalsWidget()
 | 
	
		
			
				|  |  |      delete ui;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/*!
 | 
	
		
			
				|  |  | + * \brief TotalsWidget::setup Sets the line edits as editable or read-only and connects signals if required
 | 
	
		
			
				|  |  | + * \details This widget can be used to either display the totals (in the home widget) or
 | 
	
		
			
				|  |  | + * to edit the total previous experience, from previous logbooks (in the settings widget).
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +void TotalsWidget::setup(const WidgetType widgetType)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    const QList<QLineEdit *> lineEdits = this->findChildren<QLineEdit *>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    switch (widgetType) {
 | 
	
		
			
				|  |  | +    case TotalTimeWidget:
 | 
	
		
			
				|  |  | +        LOG << "Setting up totals widget";
 | 
	
		
			
				|  |  | +        // disable editing
 | 
	
		
			
				|  |  | +        for (const auto &lineEdit : lineEdits) {
 | 
	
		
			
				|  |  | +            lineEdit->setFocusPolicy(Qt::FocusPolicy::NoFocus);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // populate the UI
 | 
	
		
			
				|  |  | +        fillTotals(widgetType);
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +    case PreviousExperienceWidget:
 | 
	
		
			
				|  |  | +        LOG << "Setting up previous XP widget";
 | 
	
		
			
				|  |  | +        for (const auto &lineEdit : lineEdits) {
 | 
	
		
			
				|  |  | +            lineEdit->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
 | 
	
		
			
				|  |  | +            // set a validator for the TO/LDG line edits, the other ones get validated seperately
 | 
	
		
			
				|  |  | +            if(lineEdit->objectName().contains(QLatin1String("to")) || lineEdit->objectName().contains(QLatin1String("ldg"))) {
 | 
	
		
			
				|  |  | +                lineEdit->setValidator( new QIntValidator(0,  std::numeric_limits<int>::max(), this) );
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // initialise m_rowData
 | 
	
		
			
				|  |  | +        m_rowData = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
 | 
	
		
			
				|  |  | +        // DB returns empty object if no entry exists. Crate a stub to prepare for user data
 | 
	
		
			
				|  |  | +        if(m_rowData == OPL::RowData_T()) {
 | 
	
		
			
				|  |  | +            fillStubData();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // populate the UI
 | 
	
		
			
				|  |  | +        fillTotals(widgetType);
 | 
	
		
			
				|  |  | +        connectSignalsAndSlots();
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +    default:
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /*!
 | 
	
		
			
				|  |  |   * \brief HomeWidget::fillTotals Retreives a Database Summary of Total Flight Time via the OPL::Statistics::totals
 | 
	
		
			
				|  |  |   * function and parses the return to fill out the QLineEdits.
 | 
	
	
		
			
				|  | @@ -35,7 +79,6 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |      case PreviousExperienceWidget:
 | 
	
		
			
				|  |  |          time_data = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
 | 
	
		
			
				|  |  | -        DEB << time_data;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // fill the line edits with the data obtained
 | 
	
	
		
			
				|  | @@ -51,7 +94,7 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
 | 
	
		
			
				|  |  |                  // line edits for take offs and landings
 | 
	
		
			
				|  |  |                  line_edit->setText(field.toString());
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  | -                // line edits for total times
 | 
	
		
			
				|  |  | +                // line edits for total time
 | 
	
		
			
				|  |  |                  const QString time_string = OPL::Time::toString(field.toInt());
 | 
	
		
			
				|  |  |                  line_edit->setText(time_string);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -60,44 +103,25 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -/*!
 | 
	
		
			
				|  |  | - * \brief TotalsWidget::setup Sets the line edits as editable or read-only and connects signals if required
 | 
	
		
			
				|  |  | - * \details This widget can be used to either display the totals (in the home widget) or
 | 
	
		
			
				|  |  | - * to edit the total previous experience, from previous logbooks (in the settings widget).
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * @brief TotalsWidget::fillStubData Fills the row entry object with stub data if it is empty.
 | 
	
		
			
				|  |  | + * \details The Widget retreives previous experience from the database. If the user has not entered
 | 
	
		
			
				|  |  | + * any previous experience this database entry does not exist. The database returns an empty
 | 
	
		
			
				|  |  | + * row object in this case. In order for the user to be able to fill in the previous experience,
 | 
	
		
			
				|  |  | + * a stub entry has to be created to fulfill the databases NOT NULL constrains.
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -void TotalsWidget::setup(const WidgetType widgetType)
 | 
	
		
			
				|  |  | +void TotalsWidget::fillStubData()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    const QList<QLineEdit *> lineEdits = this->findChildren<QLineEdit *>();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    switch (widgetType) {
 | 
	
		
			
				|  |  | -    case TotalTimeWidget:
 | 
	
		
			
				|  |  | -        LOG << "Setting up totals widget";
 | 
	
		
			
				|  |  | -        // disable editing
 | 
	
		
			
				|  |  | -        for (const auto &lineEdit : lineEdits) {
 | 
	
		
			
				|  |  | -            lineEdit->setFocusPolicy(Qt::FocusPolicy::NoFocus);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        // populate the UI
 | 
	
		
			
				|  |  | -        fillTotals(widgetType);
 | 
	
		
			
				|  |  | -        break;
 | 
	
		
			
				|  |  | -    case PreviousExperienceWidget:
 | 
	
		
			
				|  |  | -        LOG << "Setting up previous XP widget";
 | 
	
		
			
				|  |  | -        for (const auto &lineEdit : lineEdits) {
 | 
	
		
			
				|  |  | -            lineEdit->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
 | 
	
		
			
				|  |  | -            // set a validator for the TO/LDG line edits, the other ones get validated seperately
 | 
	
		
			
				|  |  | -            if(lineEdit->objectName().contains(QLatin1String("to")) || lineEdit->objectName().contains(QLatin1String("ldg"))) {
 | 
	
		
			
				|  |  | -                lineEdit->setValidator( new QIntValidator(0,  std::numeric_limits<int>::max(), this) );
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        // initialise m_rowData
 | 
	
		
			
				|  |  | -        m_rowData = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // populate the UI
 | 
	
		
			
				|  |  | -        fillTotals(widgetType);
 | 
	
		
			
				|  |  | -        connectSignalsAndSlots();
 | 
	
		
			
				|  |  | -        break;
 | 
	
		
			
				|  |  | -    default:
 | 
	
		
			
				|  |  | -        break;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_ROWID, OPL::STUB_ROW_ID);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_DOFT, OPL::STUB_ISO_DATE);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_TOFB, 0);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_TONB, 0);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_TBLK, 0);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_DEPT, OPL::STUB_AIRPORT_CODE);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_DEST, OPL::STUB_AIRPORT_CODE);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_PIC, OPL::STUB_ROW_ID);
 | 
	
		
			
				|  |  | +    m_rowData.insert(OPL::Db::FLIGHTS_ACFT, OPL::STUB_ROW_ID);
 | 
	
		
			
				|  |  | +    DEB << m_rowData;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /*!
 |