Updated editing experience for frequency schedule. Fixed some bugs with the data storage

This commit is contained in:
Jordan Sherer 2018-08-09 09:44:22 -04:00
parent d2ad5ee893
commit 2989c20175
6 changed files with 74 additions and 42 deletions

View File

@ -87,13 +87,14 @@ int Bands::find (QString const& band) const
return result;
}
bool Bands::findFreq(QString const& band, Radio::Frequency *pFreq) const {
bool Bands::findFreq(QString const& band, Radio::Frequency *pFreqLower, Radio::Frequency *pFreqHigher) const {
int row = find(band);
if(row == -1){
return false;
}
if(pFreq) *pFreq = ADIF_bands[row].lower_bound_;
if(pFreqLower) *pFreqLower = ADIF_bands[row].lower_bound_;
if(pFreqHigher) *pFreqHigher = ADIF_bands[row].upper_bound_;
return true;
}

View File

@ -56,7 +56,7 @@ public:
//
QString find (Frequency) const; // find band Frequency is in
int find (QString const&) const; // find row of band (-1 if not valid)
bool findFreq(QString const& band, Radio::Frequency *pFreq) const;
bool findFreq(QString const& band, Radio::Frequency *pFreqLower, Radio::Frequency *pFreqHigher) const;
static QString const& oob ();

View File

@ -259,6 +259,7 @@ class StationDialog final
public:
explicit StationDialog (StationList const * stations, Bands * bands, QWidget * parent = nullptr)
: QDialog {parent}
, all_bands_ {bands}
, filtered_bands_ {new CandidateKeyFilter {bands, stations, 0, 0}}
{
setWindowTitle (QApplication::applicationName () + " - " + tr ("Add Schedule"));
@ -272,11 +273,11 @@ public:
switch_until_.setDisplayFormat("hh:mm");
auto form_layout = new QFormLayout ();
form_layout->addRow (tr ("&Band:"), &band_);
//form_layout->addRow (tr ("&Band:"), &band_);
form_layout->addRow (tr ("&Frequency (MHz):"), &freq_);
form_layout->addRow (tr ("&Switch at (UTC):"), &switch_at_);
form_layout->addRow (tr ("&Until (UTC):"), &switch_until_);
//form_layout->addRow (tr ("&Antenna:"), &description_);
form_layout->addRow (tr ("&Description:"), &description_);
auto main_layout = new QVBoxLayout (this);
main_layout->addLayout (form_layout);
@ -290,12 +291,16 @@ public:
StationList::Station station () const
{
auto band = all_bands_->find(freq_.frequency());
int offset = 0;
if(switch_until_.time() <= switch_at_.time()){
offset += 1;
}
return {
band_.currentText (),
//band_.currentText (),
band,
freq_.frequency(),
QDateTime(QDate(2000, 1, 1), switch_at_.time(), Qt::UTC),
QDateTime(QDate(2000, 1, 1 + offset), switch_until_.time(), Qt::UTC),
@ -310,6 +315,7 @@ public:
private:
QScopedPointer<CandidateKeyFilter> filtered_bands_;
Bands * all_bands_;
QComboBox band_;
FrequencyLineEdit freq_;
@ -1121,17 +1127,23 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
//
// setup stations table model & view
//
stations_.sort (StationList::band_column);
stations_.sort (StationList::switch_at_column);
ui_->stations_table_view->setModel (&next_stations_);
ui_->stations_table_view->sortByColumn (StationList::band_column, Qt::AscendingOrder);
ui_->stations_table_view->sortByColumn (StationList::switch_at_column, Qt::AscendingOrder);
connect(ui_->auto_switch_bands_check_box, &QCheckBox::clicked, ui_->stations_table_view, &QTableView::setEnabled);
// delegates
auto stations_item_delegate = new QStyledItemDelegate {this};
stations_item_delegate->setItemEditorFactory (item_editor_factory ());
ui_->stations_table_view->setItemDelegate (stations_item_delegate);
ui_->stations_table_view->setItemDelegateForColumn (StationList::band_column, new ForeignKeyDelegate {&bands_, &next_stations_, 0, StationList::band_column, this});
//ui_->stations_table_view->setItemDelegateForColumn (StationList::band_column, new ForeignKeyDelegate {&bands_, &next_stations_, 0, StationList::band_column, this});
ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_at_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_until_column);
ui_->stations_table_view->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// actions
station_delete_action_ = new QAction {tr ("&Delete"), ui_->stations_table_view};
@ -2489,6 +2501,7 @@ void Configuration::impl::delete_stations ()
ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_at_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_until_column);
}
void Configuration::impl::insert_station ()
@ -2497,9 +2510,10 @@ void Configuration::impl::insert_station ()
{
auto station = station_dialog_->station ();
if(station.frequency_ == 0){
Frequency f;
if(bands_.findFreq(station.band_name_, &f)){
station.frequency_ = f;
Frequency l;
Frequency h;
if(bands_.findFreq(station.band_name_, &l, &h)){
station.frequency_ = l;
}
}
@ -2507,6 +2521,7 @@ void Configuration::impl::insert_station ()
ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_at_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_until_column);
}
}

View File

@ -31,7 +31,7 @@ QDebug operator << (QDebug debug, StationList::Station const& station)
<< station.frequency_ << ", "
<< station.switch_at_ << ", "
<< station.switch_until_ << ", "
<< station.antenna_description_ << ')';
<< station.description_ << ')';
return debug;
}
#endif
@ -42,7 +42,7 @@ QDataStream& operator << (QDataStream& os, StationList::Station const& station)
<< station.frequency_
<< station.switch_at_
<< station.switch_until_
<< station.antenna_description_;
<< station.description_;
}
QDataStream& operator >> (QDataStream& is, StationList::Station& station)
@ -51,7 +51,7 @@ QDataStream& operator >> (QDataStream& is, StationList::Station& station)
>> station.frequency_
>> station.switch_at_
>> station.switch_until_
>> station.antenna_description_;
>> station.description_;
}
@ -96,7 +96,7 @@ public:
return matches.isEmpty () ? QModelIndex {} : matches.first ();
}
static int constexpr num_columns {4};
static int constexpr num_columns {5};
static auto constexpr mime_type = "application/wsjt.antenna-descriptions";
Bands const * bands_;
@ -244,7 +244,10 @@ Qt::ItemFlags StationList::impl::flags (QModelIndex const& index) const
&& row < stations_.size ()
&& column < num_columns)
{
if (description_column == column)
if (band_column == column){
result |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
} else if (description_column == column)
{
result |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
@ -336,7 +339,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
case Qt::EditRole:
case Qt::DisplayRole:
case Qt::AccessibleTextRole:
item = stations_.at (row).switch_at_.time().toString();
item = stations_.at (row).switch_at_.time().toString("hh:mm");
break;
case Qt::ToolTipRole:
@ -357,7 +360,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
case Qt::EditRole:
case Qt::DisplayRole:
case Qt::AccessibleTextRole:
item = stations_.at (row).switch_until_.time().toString();
item = stations_.at (row).switch_until_.time().toString("hh:mm");
break;
case Qt::ToolTipRole:
@ -378,7 +381,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
case Qt::EditRole:
case Qt::DisplayRole:
case Qt::AccessibleTextRole:
item = stations_.at (row).antenna_description_;
item = stations_.at (row).description_;
break;
case Qt::ToolTipRole:
@ -409,7 +412,7 @@ QVariant StationList::impl::headerData (int section, Qt::Orientation orientation
case frequency_column: header = tr ("Freq. (MHz)"); break;
case switch_at_column: header = tr ("Switch at (UTC)"); break;
case switch_until_column: header = tr ("Until (UTC)"); break;
case description_column: header = tr ("Antenna Description"); break;
case description_column: header = tr ("Description"); break;
}
}
else
@ -455,14 +458,20 @@ bool StationList::impl::setData (QModelIndex const& model_index, QVariant const&
Frequency offset {qvariant_cast<Radio::Frequency> (value)};
if(offset == 0){
Frequency f;
if(bands_->findFreq(stations_[row].band_name_, &f)){
offset = f;
Frequency l;
Frequency h;
if(bands_->findFreq(stations_[row].band_name_, &l, &h)){
offset = l;
}
}
if (offset != stations_[row].frequency_)
{
auto band = bands_->find(offset);
if(band != stations_[row].band_name_){
stations_[row].band_name_ = band;
}
stations_[row].frequency_ = offset;
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
@ -471,17 +480,37 @@ bool StationList::impl::setData (QModelIndex const& model_index, QVariant const&
}
break;
case switch_at_column:
stations_[row].switch_at_ = value.toDateTime();
{
QString s = value.toString();
if(s.length() < 5){
s = QString("0").repeated(5-s.length()) + s;
}
auto t = QTime::fromString(s);
auto dt = QDateTime(QDate(2000,1,1), t);
stations_[row].switch_at_ = dt;
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
break;
}
case switch_until_column:
stations_[row].switch_until_ = value.toDateTime();
{
int o = 0;
QString s = value.toString();
if(s.length() < 5){
s = QString("0").repeated(5-s.length()) + s;
}
auto t = QTime::fromString(s);
if(t < stations_[row].switch_at_.time()){
o += 1;
}
auto dt = QDateTime(QDate(2000,1,1+o), t);
stations_[row].switch_until_ = dt;
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
break;
}
case description_column:
stations_[row].antenna_description_ = value.toString ();
stations_[row].description_ = value.toString ();
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
break;

View File

@ -56,7 +56,7 @@ public:
Frequency frequency_;
QDateTime switch_at_;
QDateTime switch_until_;
QString antenna_description_;
QString description_;
};
using Stations = QList<Station>;

View File

@ -7837,21 +7837,8 @@ bool MainWindow::shortList(QString callsign)
void MainWindow::pskSetLocal ()
{
// find the station row, if any, that matches the band we are on
auto stations = m_config.stations ();
auto matches = stations->match (stations->index (0, StationList::band_column)
, Qt::DisplayRole
, ui->bandComboBox->currentText ()
, 1
, Qt::MatchExactly);
QString antenna_description;
if (!matches.isEmpty ()) {
antenna_description = stations->index (matches.first ().row ()
, StationList::description_column).data ().toString ();
}
// qDebug() << "To PSKreporter: local station details";
psk_Reporter->setLocalStation(m_config.my_callsign (), m_config.my_grid (),
antenna_description, QString {"FT8Call v" + version() }.simplified ());
m_config.my_station(), QString {"FT8Call v" + version() }.simplified ());
}
void MainWindow::transmitDisplay (bool transmitting)