From af3e06144ce9e0ae54b6420bf29a28e85fc6a665 Mon Sep 17 00:00:00 2001 From: Brian Moran Date: Fri, 15 Jul 2022 11:24:57 -0700 Subject: [PATCH 1/3] refresh QSO # when the underlying data changes --- widgets/AbstractLogWindow.cpp | 9 +++++---- widgets/CabrilloLogWindow.cpp | 1 + widgets/CabrilloLogWindow.ui | 9 ++++++++- widgets/mainwindow.cpp | 8 +++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/widgets/AbstractLogWindow.cpp b/widgets/AbstractLogWindow.cpp index 656eff7f1..667573ce0 100644 --- a/widgets/AbstractLogWindow.cpp +++ b/widgets/AbstractLogWindow.cpp @@ -72,7 +72,7 @@ void AbstractLogWindow::impl::delete_QSOs () { // We must work with source model indexes because we don't want row // removes to invalidate model indexes we haven't yet processed. We - // achieve that by processing them in decending row order. + // achieve that by processing them in descending row order. for (auto& row_index : row_indexes) { row_index = model_.mapToSource (row_index); @@ -80,11 +80,12 @@ void AbstractLogWindow::impl::delete_QSOs () // reverse sort by row std::sort (row_indexes.begin (), row_indexes.end (), row_is_higher); + for (auto index : row_indexes) { - auto row = model_.mapFromSource (index).row (); - model_.removeRow (row); - self_->log_model_changed (); + auto row = model_.mapFromSource(index).row(); + model_.removeRow(row); + self_->log_model_changed(); } } } diff --git a/widgets/CabrilloLogWindow.cpp b/widgets/CabrilloLogWindow.cpp index 3315181a0..4a7611193 100644 --- a/widgets/CabrilloLogWindow.cpp +++ b/widgets/CabrilloLogWindow.cpp @@ -88,6 +88,7 @@ void CabrilloLogWindow::log_model_changed (int row) { m_->log_model_->select (); } + this->set_nQSO(m_->log_model_->rowCount()); } void CabrilloLogWindow::set_nQSO(int n) diff --git a/widgets/CabrilloLogWindow.ui b/widgets/CabrilloLogWindow.ui index 1b44d0652..1457d9564 100644 --- a/widgets/CabrilloLogWindow.ui +++ b/widgets/CabrilloLogWindow.ui @@ -28,13 +28,20 @@ - + 100 16777215 + + * { + font-family: Courier; + font-size: 10pt; + font-weight: bold; + } + 0 QSOs diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 8d0aecf42..3c87a92bd 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -2779,7 +2779,7 @@ void MainWindow::on_contest_log_action_triggered() m_contestLogWindow->showNormal (); m_contestLogWindow->raise (); m_contestLogWindow->activateWindow (); - m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); + //m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); } void MainWindow::on_actionColors_triggered() @@ -4678,7 +4678,7 @@ void MainWindow::guiUpdate() //Once per second (onesec) if(nsec != m_sec0) { // qDebug() << "AAA" << nsec; - if(m_contestLogWindow) m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); + //if(m_contestLogWindow) m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); if(m_mode=="FST4") chk_FST4_freq_range(); m_currentBand=m_config.bands()->find(m_freqNominal); @@ -6377,9 +6377,7 @@ void MainWindow::acceptQSO (QDateTime const& QSO_date_off, QString const& call, m_xSent.clear (); m_xRcvd.clear (); - if(m_contestLogWindow) { - m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); - } + } void MainWindow::updateRate() From 8bd3dd65bb05835beb58015944991c5e06e0a6ae Mon Sep 17 00:00:00 2001 From: Brian Moran Date: Fri, 15 Jul 2022 20:42:57 -0700 Subject: [PATCH 2/3] use correct method for getting row count from the DB; use signals/slots to inform the CabrilloLogWindow the qso_count has changed --- models/CabrilloLog.cpp | 13 +++++++++++-- models/CabrilloLog.hpp | 1 + widgets/CabrilloLogWindow.cpp | 2 +- widgets/CabrilloLogWindow.hpp | 2 +- widgets/CabrilloLogWindow.ui | 10 +++------- widgets/mainwindow.cpp | 4 +++- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/models/CabrilloLog.cpp b/models/CabrilloLog.cpp index b0f467f33..77166859e 100644 --- a/models/CabrilloLog.cpp +++ b/models/CabrilloLog.cpp @@ -73,7 +73,9 @@ public: Configuration const * configuration_; QSqlQuery mutable dupe_query_; QSqlQuery mutable export_query_; + QSqlQuery mutable qso_count_query_; bool adding_row_; + int n_qso(); }; CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration) @@ -109,6 +111,7 @@ CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration { Q_EMIT self_->data_changed (); } + Q_EMIT self_->qso_count_changed(self_->n_qso()); }); SQL_error_check (*this, &QSqlTableModel::select); @@ -132,6 +135,10 @@ CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration " cabrillo_log_v2 " " ORDER BY " " \"when\""); + + SQL_error_check (qso_count_query_, &QSqlQuery::prepare, + "SELECT COUNT(*) FROM cabrillo_log_v2"); + } void CabrilloLog::impl::create_table () @@ -237,7 +244,7 @@ bool CabrilloLog::add_QSO (Frequency frequency, QString const& mode, QDateTime c m_->adding_row_ = false; m_->setEditStrategy (QSqlTableModel::OnFieldChange); - + Q_EMIT this->qso_count_changed(this->n_qso()); return ok; } @@ -260,7 +267,9 @@ bool CabrilloLog::dupe (Frequency frequency, QString const& call) const int CabrilloLog::n_qso() { - return m_->rowCount(); + SQL_error_check (m_->qso_count_query_, static_cast (&QSqlQuery::exec)); + m_->qso_count_query_.first(); + return m_->qso_count_query_.value(0).toInt(); } void CabrilloLog::reset () diff --git a/models/CabrilloLog.hpp b/models/CabrilloLog.hpp index 40c27380d..68b76fc2a 100644 --- a/models/CabrilloLog.hpp +++ b/models/CabrilloLog.hpp @@ -39,6 +39,7 @@ public: worked_set unique_DXCC_entities (AD1CCty const *) const; Q_SIGNAL void data_changed () const; + Q_SIGNAL void qso_count_changed (int) const; private: class impl; diff --git a/widgets/CabrilloLogWindow.cpp b/widgets/CabrilloLogWindow.cpp index 4a7611193..89aba0cb3 100644 --- a/widgets/CabrilloLogWindow.cpp +++ b/widgets/CabrilloLogWindow.cpp @@ -72,6 +72,7 @@ CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const auto h_header = m_->ui_.log_table_view->horizontalHeader (); m_->ui_.log_table_view->verticalHeader()->setVisible(false); // turn off line numbers for the table view h_header->moveSection (7, 1); // band to first column + } CabrilloLogWindow::~CabrilloLogWindow () @@ -88,7 +89,6 @@ void CabrilloLogWindow::log_model_changed (int row) { m_->log_model_->select (); } - this->set_nQSO(m_->log_model_->rowCount()); } void CabrilloLogWindow::set_nQSO(int n) diff --git a/widgets/CabrilloLogWindow.hpp b/widgets/CabrilloLogWindow.hpp index 044986620..25780bc50 100644 --- a/widgets/CabrilloLogWindow.hpp +++ b/widgets/CabrilloLogWindow.hpp @@ -16,7 +16,7 @@ public: explicit CabrilloLogWindow (QSettings *, Configuration const *, QSqlTableModel * cabrillo_log_model , QWidget * parent = nullptr); ~CabrilloLogWindow (); - void set_nQSO(int n); + Q_SLOT void set_nQSO(int n); private: void log_model_changed (int row) override; diff --git a/widgets/CabrilloLogWindow.ui b/widgets/CabrilloLogWindow.ui index 1457d9564..5f31b0687 100644 --- a/widgets/CabrilloLogWindow.ui +++ b/widgets/CabrilloLogWindow.ui @@ -28,19 +28,15 @@ - + 100 16777215 - - * { - font-family: Courier; - font-size: 10pt; - font-weight: bold; - } + + true 0 QSOs diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 3c87a92bd..9b0dd9da1 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -2779,7 +2779,9 @@ void MainWindow::on_contest_log_action_triggered() m_contestLogWindow->showNormal (); m_contestLogWindow->raise (); m_contestLogWindow->activateWindow (); - //m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); + // connect signal from m_logBook.contest_log to m_contestLogWindow + connect(m_logBook.contest_log(), &CabrilloLog::qso_count_changed, m_contestLogWindow.data (), &CabrilloLogWindow::set_nQSO); + m_contestLogWindow->set_nQSO(m_logBook.contest_log()->n_qso()); } void MainWindow::on_actionColors_triggered() From c60aa83aa500904c24eca8915fe0e5aa717f2601 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Sat, 16 Jul 2022 09:43:55 -0400 Subject: [PATCH 3/3] ActiveStations lineEdits for Rate, Score, and Band changes should be ReadOnly. --- widgets/activeStations.ui | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/widgets/activeStations.ui b/widgets/activeStations.ui index 16f077687..02b1f618a 100644 --- a/widgets/activeStations.ui +++ b/widgets/activeStations.ui @@ -63,6 +63,9 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true + @@ -127,6 +130,9 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true + @@ -160,6 +166,9 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true +