mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-24 21:28:41 -05:00
show contacts by ID, scroll to insertion when sorted by tha column up or down
This commit is contained in:
parent
d81a3d799c
commit
c85ed8cc7d
@ -88,6 +88,7 @@ CabrilloLog::impl::impl (CabrilloLog * self, Configuration const * configuration
|
||||
|
||||
setEditStrategy (QSqlTableModel::OnFieldChange);
|
||||
setTable ("cabrillo_log_v2");
|
||||
setHeaderData (fieldIndex ("id"), Qt::Horizontal, tr ("Qso #"));
|
||||
setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(MHz)"));
|
||||
setHeaderData (fieldIndex ("mode"), Qt::Horizontal, tr ("Mode"));
|
||||
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
|
||||
@ -234,8 +235,10 @@ bool CabrilloLog::add_QSO (Frequency frequency, QString const& mode, QDateTime c
|
||||
m_->adding_row_ = true;
|
||||
auto ok = m_->insertRecord (-1, record);
|
||||
transaction.submit ();
|
||||
|
||||
m_->adding_row_ = false;
|
||||
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QSqlTableModel>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QItemSelection>
|
||||
#include <QTimer>
|
||||
#include "Configuration.hpp"
|
||||
#include "SettingsGroup.hpp"
|
||||
#include "MessageBox.hpp"
|
||||
@ -88,29 +89,37 @@ void AbstractLogWindow::impl::delete_QSOs ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AbstractLogWindow::AbstractLogWindow (QString const& settings_key, QSettings * settings
|
||||
, Configuration const * configuration
|
||||
, QWidget * parent)
|
||||
: QWidget {parent}
|
||||
, m_ {this, settings_key, settings, configuration}
|
||||
{
|
||||
// this attempt to scroll to the last new record doesn't work, some
|
||||
// sort of issue with model indexes and optimized DB fetches. For
|
||||
// now sorting by the same column and direction as the underlying DB
|
||||
// select and that DB select being in descending order so new rows
|
||||
// at the end appear at view row 0 gets the job done
|
||||
, m_ {this, settings_key, settings, configuration} {
|
||||
// when we're viewing the log by contact ID (visually, up/down chevron in the column heading),
|
||||
// when we add a contact, scroll the list to the top or bottom, depending on the sort order.
|
||||
// If the table is sorted by some other criteria, don't change anything.
|
||||
|
||||
// // ensure view scrolls to latest new row
|
||||
// connect (&m_->model_, &QAbstractItemModel::rowsInserted, this, [this] (QModelIndex const& parent, int first, int last) {
|
||||
// // note col 0 is hidden so use col 1
|
||||
// // queued connection required otherwise row may not be available
|
||||
// // in time
|
||||
// auto index = m_->model_.index (last, 1, parent);
|
||||
// if (m_->log_view_)
|
||||
// {
|
||||
// m_->log_view_->scrollTo (index);
|
||||
// }
|
||||
// }, Qt::QueuedConnection);
|
||||
connect(&m_->model_, &QAbstractItemModel::rowsInserted, this,
|
||||
[this](QModelIndex const &parent, int first, int last) {
|
||||
(void) (parent); // UNUSED
|
||||
(void) (first); // UNUSED
|
||||
(void) (last); // UNUSED
|
||||
QTimer::singleShot(0, [=] {
|
||||
// if we're sorting by the contact #, then show the most-recently logged contact.
|
||||
// Otherwise, leave the scroll alone
|
||||
auto horizontal_header = m_->log_view_->horizontalHeader ();
|
||||
if (horizontal_header->sortIndicatorSection() == 0) {
|
||||
if (horizontal_header->sortIndicatorOrder() == Qt::AscendingOrder) {
|
||||
// we're sorting 1->N, so go to bottom
|
||||
m_->log_view_->scrollToBottom();
|
||||
} else {
|
||||
m_->log_view_->scrollToTop();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
AbstractLogWindow::~AbstractLogWindow ()
|
||||
@ -134,11 +143,14 @@ void AbstractLogWindow::set_log_view (QTableView * log_view)
|
||||
log_view->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
|
||||
m_->model_.setSourceModel (log_view->model ());
|
||||
log_view->setModel (&m_->model_);
|
||||
log_view->setColumnHidden (0, true);
|
||||
log_view->setColumnHidden (0, false); // show the ID column, which is also QSO #
|
||||
auto horizontal_header = log_view->horizontalHeader ();
|
||||
|
||||
horizontal_header->setResizeContentsPrecision (0); // visible region only
|
||||
horizontal_header->setSectionResizeMode (QHeaderView::ResizeToContents);
|
||||
horizontal_header->setSectionsMovable (true);
|
||||
horizontal_header->setSortIndicator(0,Qt::AscendingOrder); // sort by the contact id. show 1->N
|
||||
|
||||
auto vertical_header = log_view->horizontalHeader ();
|
||||
vertical_header->setResizeContentsPrecision (0); // visible region only
|
||||
vertical_header->setSectionResizeMode (QHeaderView::ResizeToContents);
|
||||
@ -149,6 +161,9 @@ void AbstractLogWindow::set_log_view (QTableView * log_view)
|
||||
connect (delete_action, &QAction::triggered, [this] (bool /*checked*/) {
|
||||
m_->delete_QSOs ();
|
||||
});
|
||||
|
||||
// scroll to bottom, since we're showing 1-N
|
||||
log_view->scrollToBottom();
|
||||
}
|
||||
|
||||
void AbstractLogWindow::set_log_view_font (QFont const& font)
|
||||
|
@ -70,7 +70,8 @@ CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (3, new SQLiteDateTimeDelegate {this});
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (4, new CallsignDelegate {this});
|
||||
auto h_header = m_->ui_.log_table_view->horizontalHeader ();
|
||||
h_header->moveSection (7, 1); // band to first column
|
||||
m_->ui_.log_table_view->verticalHeader()->setVisible(false); // turn off line numbers for the table, use index
|
||||
h_header->moveSection (7, 2); // band to 2nd column
|
||||
}
|
||||
|
||||
CabrilloLogWindow::~CabrilloLogWindow ()
|
||||
|
Loading…
Reference in New Issue
Block a user