diff --git a/models/CabrilloLog.cpp b/models/CabrilloLog.cpp index 95aba4378..d558e66e0 100644 --- a/models/CabrilloLog.cpp +++ b/models/CabrilloLog.cpp @@ -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); } } diff --git a/models/FoxLog.cpp b/models/FoxLog.cpp index 1503e5662..691647fdc 100644 --- a/models/FoxLog.cpp +++ b/models/FoxLog.cpp @@ -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); } }