use correct method for getting row count from the DB; use signals/slots to inform the CabrilloLogWindow the qso_count has changed

This commit is contained in:
Brian Moran 2022-07-15 20:42:57 -07:00
parent aa16455320
commit 8bd3dd65bb
6 changed files with 20 additions and 12 deletions

View File

@ -73,7 +73,9 @@ public:
Configuration const * configuration_; Configuration const * configuration_;
QSqlQuery mutable dupe_query_; QSqlQuery mutable dupe_query_;
QSqlQuery mutable export_query_; QSqlQuery mutable export_query_;
QSqlQuery mutable qso_count_query_;
bool adding_row_; bool adding_row_;
int n_qso();
}; };
CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration) 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_->data_changed ();
} }
Q_EMIT self_->qso_count_changed(self_->n_qso());
}); });
SQL_error_check (*this, &QSqlTableModel::select); SQL_error_check (*this, &QSqlTableModel::select);
@ -132,6 +135,10 @@ CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration
" cabrillo_log_v2 " " cabrillo_log_v2 "
" ORDER BY " " ORDER BY "
" \"when\""); " \"when\"");
SQL_error_check (qso_count_query_, &QSqlQuery::prepare,
"SELECT COUNT(*) FROM cabrillo_log_v2");
} }
void CabrilloLog::impl::create_table () 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_->adding_row_ = false;
m_->setEditStrategy (QSqlTableModel::OnFieldChange); m_->setEditStrategy (QSqlTableModel::OnFieldChange);
Q_EMIT this->qso_count_changed(this->n_qso());
return ok; return ok;
} }
@ -260,7 +267,9 @@ bool CabrilloLog::dupe (Frequency frequency, QString const& call) const
int CabrilloLog::n_qso() int CabrilloLog::n_qso()
{ {
return m_->rowCount(); SQL_error_check (m_->qso_count_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec));
m_->qso_count_query_.first();
return m_->qso_count_query_.value(0).toInt();
} }
void CabrilloLog::reset () void CabrilloLog::reset ()

View File

@ -39,6 +39,7 @@ public:
worked_set unique_DXCC_entities (AD1CCty const *) const; worked_set unique_DXCC_entities (AD1CCty const *) const;
Q_SIGNAL void data_changed () const; Q_SIGNAL void data_changed () const;
Q_SIGNAL void qso_count_changed (int) const;
private: private:
class impl; class impl;

View File

@ -72,6 +72,7 @@ CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const
auto h_header = m_->ui_.log_table_view->horizontalHeader (); 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 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 h_header->moveSection (7, 1); // band to first column
} }
CabrilloLogWindow::~CabrilloLogWindow () CabrilloLogWindow::~CabrilloLogWindow ()
@ -88,7 +89,6 @@ void CabrilloLogWindow::log_model_changed (int row)
{ {
m_->log_model_->select (); m_->log_model_->select ();
} }
this->set_nQSO(m_->log_model_->rowCount());
} }
void CabrilloLogWindow::set_nQSO(int n) void CabrilloLogWindow::set_nQSO(int n)

View File

@ -16,7 +16,7 @@ public:
explicit CabrilloLogWindow (QSettings *, Configuration const *, QSqlTableModel * cabrillo_log_model explicit CabrilloLogWindow (QSettings *, Configuration const *, QSqlTableModel * cabrillo_log_model
, QWidget * parent = nullptr); , QWidget * parent = nullptr);
~CabrilloLogWindow (); ~CabrilloLogWindow ();
void set_nQSO(int n); Q_SLOT void set_nQSO(int n);
private: private:
void log_model_changed (int row) override; void log_model_changed (int row) override;

View File

@ -28,19 +28,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="nQSO_lineEdit"> <widget class="QLineEdit" name="nQSO_lineEdit">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>100</width> <width>100</width>
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="styleSheet"> <property name="readOnly">
<string notr="true">* { <bool>true</bool>
font-family: Courier;
font-size: 10pt;
font-weight: bold;
}</string>
</property> </property>
<property name="text"> <property name="text">
<string>0 QSOs</string> <string>0 QSOs</string>

View File

@ -2779,7 +2779,9 @@ void MainWindow::on_contest_log_action_triggered()
m_contestLogWindow->showNormal (); m_contestLogWindow->showNormal ();
m_contestLogWindow->raise (); m_contestLogWindow->raise ();
m_contestLogWindow->activateWindow (); 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() void MainWindow::on_actionColors_triggered()