mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-23 20:58:55 -05:00
Use DB date time field item delegate to imbue editing in log windows
This commit is contained in:
parent
b6b8271a6d
commit
32c36f566d
@ -50,20 +50,17 @@ public:
|
||||
else
|
||||
{
|
||||
value = QSqlTableModel::data (model_index, role);
|
||||
if (model_index.column () == fieldIndex ("frequency") && Qt::DisplayRole == role)
|
||||
if (Qt::DisplayRole == role)
|
||||
{
|
||||
value = Radio::frequency_MHz_string (value.value<Radio::Frequency> (), 3); // kHz precision
|
||||
}
|
||||
else if (model_index.column () == fieldIndex ("when")
|
||||
&& (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
{ // adjust date/time to Qt format
|
||||
auto t = QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC);
|
||||
if (Qt::DisplayRole == role)
|
||||
if (model_index.column () == fieldIndex ("frequency"))
|
||||
{
|
||||
QLocale locale;
|
||||
return locale.toString (t, locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
|
||||
value = Radio::frequency_MHz_string (value.value<Radio::Frequency> (), 3); // kHz precision
|
||||
}
|
||||
else if (model_index.column () == fieldIndex ("when"))
|
||||
{ // adjust date/time to Qt format
|
||||
QLocale locale;
|
||||
value = locale.toString (QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC), locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
|
||||
}
|
||||
value = t;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
@ -26,16 +26,10 @@ public:
|
||||
QVariant data (QModelIndex const& index, int role) const
|
||||
{
|
||||
auto value = QSqlTableModel::data (index, role);
|
||||
if (index.column () == fieldIndex ("when")
|
||||
&& (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
if (index.column () == fieldIndex ("when") && Qt::DisplayRole == role)
|
||||
{
|
||||
auto t = QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC);
|
||||
if (Qt::DisplayRole == role)
|
||||
{
|
||||
QLocale locale;
|
||||
return locale.toString (t, locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
|
||||
}
|
||||
value = t;
|
||||
QLocale locale;
|
||||
value = locale.toString (QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC), locale.dateFormat (QLocale::ShortFormat) + " hh:mm:ss");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "item_delegates/FrequencyDelegate.hpp"
|
||||
#include "item_delegates/ForeignKeyDelegate.hpp"
|
||||
#include "item_delegates/CallsignDelegate.hpp"
|
||||
#include "item_delegates/SQLiteDateTimeDelegate.hpp"
|
||||
#include "pimpl_impl.hpp"
|
||||
|
||||
#include "ui_CabrilloLogWindow.h"
|
||||
@ -66,6 +67,7 @@ CabrilloLogWindow::CabrilloLogWindow (QSettings * settings, Configuration const
|
||||
m_->ui_.log_table_view->setModel (&m_->format_model_);
|
||||
set_log_view (m_->ui_.log_table_view);
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (1, new FrequencyDelegate {this});
|
||||
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
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "item_delegates/ForeignKeyDelegate.hpp"
|
||||
#include "item_delegates/CallsignDelegate.hpp"
|
||||
#include "item_delegates/MaidenheadLocatorDelegate.hpp"
|
||||
#include "item_delegates/SQLiteDateTimeDelegate.hpp"
|
||||
#include "pimpl_impl.hpp"
|
||||
|
||||
#include "ui_FoxLogWindow.h"
|
||||
@ -41,6 +42,7 @@ FoxLogWindow::FoxLogWindow (QSettings * settings, Configuration const * configur
|
||||
m_->ui_.setupUi (this);
|
||||
m_->ui_.log_table_view->setModel (m_->log_->model ());
|
||||
set_log_view (m_->ui_.log_table_view);
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (1, new SQLiteDateTimeDelegate {this});
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (2, new CallsignDelegate {this});
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (3, new MaidenheadLocatorDelegate {this});
|
||||
m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), 0, this});
|
||||
|
Loading…
Reference in New Issue
Block a user