Ensure that pending log table edits do not lock out adding new QSOs

Pending edits are  now discarded when adding a new  log contest or Fox
log record.  Also switch to commit  on fields change edit  strategy so
there should be no pending edits now anyway.
This commit is contained in:
Bill Somerville 2018-12-02 02:30:32 +00:00
parent dac6a2cc26
commit d5c59e51c1
2 changed files with 12 additions and 4 deletions

View File

@ -51,7 +51,7 @@ CabrilloLog::impl::impl (Configuration const * configuration)
SQL_error_check (export_query_, &QSqlQuery::prepare,
"SELECT frequency, \"when\", exchange_sent, call, exchange_rcvd FROM cabrillo_log ORDER BY \"when\"");
setEditStrategy (QSqlTableModel::OnRowChange);
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("cabrillo_log");
setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(kHz)"));
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
@ -109,6 +109,10 @@ bool CabrilloLog::add_QSO (Frequency frequency, QDateTime const& when, QString c
set_value_maybe_null (record, "exchange_sent", exchange_sent);
set_value_maybe_null (record, "exchange_rcvd", exchange_received);
set_value_maybe_null (record, "band", m_->configuration_->bands ()->find (frequency));
if (m_->isDirty ())
{
m_->revert (); // discard any uncommitted changes
}
auto ok = m_->insertRecord (-1, record);
if (ok)
{
@ -135,7 +139,7 @@ void CabrilloLog::reset ()
SQL_error_check (*m_, &QSqlTableModel::removeRows, 0, m_->rowCount (), QModelIndex {});
transaction.submit ();
m_->select (); // to refresh views
m_->setEditStrategy (QSqlTableModel::OnRowChange);
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
}
}

View File

@ -43,7 +43,7 @@ FoxLog::impl::impl ()
SQL_error_check (dupe_query_, &QSqlQuery::prepare,
"SELECT COUNT(*) FROM fox_log WHERE call = :call AND band = :band");
setEditStrategy (QSqlTableModel::OnRowChange);
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("fox_log");
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
setHeaderData (fieldIndex ("call"), Qt::Horizontal, tr ("Call"));
@ -100,6 +100,10 @@ bool FoxLog::add_QSO (QDateTime const& when, QString const& call, QString const&
set_value_maybe_null (record, "report_sent", report_sent);
set_value_maybe_null (record, "report_rcvd", report_received);
set_value_maybe_null (record, "band", band);
if (m_->isDirty ())
{
m_->revert (); // discard any uncommitted changes
}
auto ok = m_->insertRecord (-1, record);
if (ok)
{
@ -126,6 +130,6 @@ void FoxLog::reset ()
SQL_error_check (*m_, &QSqlTableModel::removeRows, 0, m_->rowCount (), QModelIndex {});
transaction.submit ();
m_->select (); // to refresh views
m_->setEditStrategy (QSqlTableModel::OnRowChange);
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
}
}