mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-21 19:55:20 -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);
|
setEditStrategy (QSqlTableModel::OnFieldChange);
|
||||||
setTable ("cabrillo_log_v2");
|
setTable ("cabrillo_log_v2");
|
||||||
|
setHeaderData (fieldIndex ("id"), Qt::Horizontal, tr ("Qso #"));
|
||||||
setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(MHz)"));
|
setHeaderData (fieldIndex ("frequency"), Qt::Horizontal, tr ("Freq(MHz)"));
|
||||||
setHeaderData (fieldIndex ("mode"), Qt::Horizontal, tr ("Mode"));
|
setHeaderData (fieldIndex ("mode"), Qt::Horizontal, tr ("Mode"));
|
||||||
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
|
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;
|
m_->adding_row_ = true;
|
||||||
auto ok = m_->insertRecord (-1, record);
|
auto ok = m_->insertRecord (-1, record);
|
||||||
transaction.submit ();
|
transaction.submit ();
|
||||||
|
|
||||||
m_->adding_row_ = false;
|
m_->adding_row_ = false;
|
||||||
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
|
m_->setEditStrategy (QSqlTableModel::OnFieldChange);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <QSqlTableModel>
|
#include <QSqlTableModel>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
#include <QItemSelection>
|
#include <QItemSelection>
|
||||||
|
#include <QTimer>
|
||||||
#include "Configuration.hpp"
|
#include "Configuration.hpp"
|
||||||
#include "SettingsGroup.hpp"
|
#include "SettingsGroup.hpp"
|
||||||
#include "MessageBox.hpp"
|
#include "MessageBox.hpp"
|
||||||
@ -88,29 +89,37 @@ void AbstractLogWindow::impl::delete_QSOs ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AbstractLogWindow::AbstractLogWindow (QString const& settings_key, QSettings * settings
|
AbstractLogWindow::AbstractLogWindow (QString const& settings_key, QSettings * settings
|
||||||
, Configuration const * configuration
|
, Configuration const * configuration
|
||||||
, QWidget * parent)
|
, QWidget * parent)
|
||||||
: QWidget {parent}
|
: QWidget {parent}
|
||||||
, m_ {this, settings_key, settings, configuration}
|
, m_ {this, settings_key, settings, configuration} {
|
||||||
{
|
// when we're viewing the log by contact ID (visually, up/down chevron in the column heading),
|
||||||
// this attempt to scroll to the last new record doesn't work, some
|
// when we add a contact, scroll the list to the top or bottom, depending on the sort order.
|
||||||
// sort of issue with model indexes and optimized DB fetches. For
|
// If the table is sorted by some other criteria, don't change anything.
|
||||||
// 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
|
|
||||||
|
|
||||||
// // ensure view scrolls to latest new row
|
connect(&m_->model_, &QAbstractItemModel::rowsInserted, this,
|
||||||
// connect (&m_->model_, &QAbstractItemModel::rowsInserted, this, [this] (QModelIndex const& parent, int first, int last) {
|
[this](QModelIndex const &parent, int first, int last) {
|
||||||
// // note col 0 is hidden so use col 1
|
(void) (parent); // UNUSED
|
||||||
// // queued connection required otherwise row may not be available
|
(void) (first); // UNUSED
|
||||||
// // in time
|
(void) (last); // UNUSED
|
||||||
// auto index = m_->model_.index (last, 1, parent);
|
QTimer::singleShot(0, [=] {
|
||||||
// if (m_->log_view_)
|
// if we're sorting by the contact #, then show the most-recently logged contact.
|
||||||
// {
|
// Otherwise, leave the scroll alone
|
||||||
// m_->log_view_->scrollTo (index);
|
auto horizontal_header = m_->log_view_->horizontalHeader ();
|
||||||
// }
|
if (horizontal_header->sortIndicatorSection() == 0) {
|
||||||
// }, Qt::QueuedConnection);
|
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 ()
|
AbstractLogWindow::~AbstractLogWindow ()
|
||||||
@ -134,11 +143,14 @@ void AbstractLogWindow::set_log_view (QTableView * log_view)
|
|||||||
log_view->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
|
log_view->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
|
||||||
m_->model_.setSourceModel (log_view->model ());
|
m_->model_.setSourceModel (log_view->model ());
|
||||||
log_view->setModel (&m_->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 ();
|
auto horizontal_header = log_view->horizontalHeader ();
|
||||||
|
|
||||||
horizontal_header->setResizeContentsPrecision (0); // visible region only
|
horizontal_header->setResizeContentsPrecision (0); // visible region only
|
||||||
horizontal_header->setSectionResizeMode (QHeaderView::ResizeToContents);
|
horizontal_header->setSectionResizeMode (QHeaderView::ResizeToContents);
|
||||||
horizontal_header->setSectionsMovable (true);
|
horizontal_header->setSectionsMovable (true);
|
||||||
|
horizontal_header->setSortIndicator(0,Qt::AscendingOrder); // sort by the contact id. show 1->N
|
||||||
|
|
||||||
auto vertical_header = log_view->horizontalHeader ();
|
auto vertical_header = log_view->horizontalHeader ();
|
||||||
vertical_header->setResizeContentsPrecision (0); // visible region only
|
vertical_header->setResizeContentsPrecision (0); // visible region only
|
||||||
vertical_header->setSectionResizeMode (QHeaderView::ResizeToContents);
|
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*/) {
|
connect (delete_action, &QAction::triggered, [this] (bool /*checked*/) {
|
||||||
m_->delete_QSOs ();
|
m_->delete_QSOs ();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// scroll to bottom, since we're showing 1-N
|
||||||
|
log_view->scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractLogWindow::set_log_view_font (QFont const& font)
|
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 (3, new SQLiteDateTimeDelegate {this});
|
||||||
m_->ui_.log_table_view->setItemDelegateForColumn (4, new CallsignDelegate {this});
|
m_->ui_.log_table_view->setItemDelegateForColumn (4, new CallsignDelegate {this});
|
||||||
auto h_header = m_->ui_.log_table_view->horizontalHeader ();
|
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 ()
|
CabrilloLogWindow::~CabrilloLogWindow ()
|
||||||
|
Loading…
Reference in New Issue
Block a user