From d2ad5ee8930c91408b3aa67af5b65569248059b9 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Thu, 9 Aug 2018 00:06:02 -0400 Subject: [PATCH] Switched to time range instead of a fixed point for easier comparisons --- Configuration.cpp | 22 ++++++++++++++++++--- Configuration.ui | 12 ++++++++++++ StationList.cpp | 50 +++++++++++++++++++++++++++++++++++++---------- StationList.hpp | 3 ++- mainwindow.cpp | 25 ++++++++---------------- 5 files changed, 81 insertions(+), 31 deletions(-) diff --git a/Configuration.cpp b/Configuration.cpp index bb55b8e..1e87f4e 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -267,11 +267,15 @@ public: switch_at_.setTimeSpec(Qt::UTC); switch_at_.setDisplayFormat("hh:mm"); - + + switch_until_.setTimeSpec(Qt::UTC); + switch_until_.setDisplayFormat("hh:mm"); + auto form_layout = new QFormLayout (); 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 ("&Switch at (UTC):"), &switch_at_); + form_layout->addRow (tr ("&Until (UTC):"), &switch_until_); //form_layout->addRow (tr ("&Antenna:"), &description_); auto main_layout = new QVBoxLayout (this); @@ -286,7 +290,16 @@ public: StationList::Station station () const { - return {band_.currentText (), freq_.frequency(), QDateTime(QDate(2000, 1, 1), switch_at_.time(), Qt::UTC), description_.text ()}; + int offset = 0; + if(switch_until_.time() <= switch_at_.time()){ + offset += 1; + } + return { + band_.currentText (), + freq_.frequency(), + QDateTime(QDate(2000, 1, 1), switch_at_.time(), Qt::UTC), + QDateTime(QDate(2000, 1, 1 + offset), switch_until_.time(), Qt::UTC), + description_.text ()}; } int exec () override @@ -301,6 +314,7 @@ private: QComboBox band_; FrequencyLineEdit freq_; QTimeEdit switch_at_; + QTimeEdit switch_until_; QLineEdit description_; }; @@ -2474,6 +2488,7 @@ void Configuration::impl::delete_stations () next_stations_.removeDisjointRows (selection_model->selectedRows ()); 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); } void Configuration::impl::insert_station () @@ -2491,6 +2506,7 @@ void Configuration::impl::insert_station () ui_->stations_table_view->setCurrentIndex (next_stations_.add (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); } } diff --git a/Configuration.ui b/Configuration.ui index 10000ac..bcb18c0 100644 --- a/Configuration.ui +++ b/Configuration.ui @@ -2394,12 +2394,24 @@ Right click for insert and delete options. true + + 120 + + + 100 + true false + + 30 + + + 24 + diff --git a/StationList.cpp b/StationList.cpp index bcd7cc9..04bc43a 100644 --- a/StationList.cpp +++ b/StationList.cpp @@ -30,6 +30,7 @@ QDebug operator << (QDebug debug, StationList::Station const& station) << station.band_name_ << ", " << station.frequency_ << ", " << station.switch_at_ << ", " + << station.switch_until_ << ", " << station.antenna_description_ << ')'; return debug; } @@ -40,6 +41,7 @@ QDataStream& operator << (QDataStream& os, StationList::Station const& station) return os << station.band_name_ << station.frequency_ << station.switch_at_ + << station.switch_until_ << station.antenna_description_; } @@ -48,6 +50,7 @@ QDataStream& operator >> (QDataStream& is, StationList::Station& station) return is >> station.band_name_ >> station.frequency_ >> station.switch_at_ + >> station.switch_until_ >> station.antenna_description_; } @@ -93,7 +96,7 @@ public: return matches.isEmpty () ? QModelIndex {} : matches.first (); } - static int constexpr num_columns {3}; + static int constexpr num_columns {4}; static auto constexpr mime_type = "application/wsjt.antenna-descriptions"; Bands const * bands_; @@ -294,7 +297,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const break; case Qt::TextAlignmentRole: - item = Qt::AlignHCenter + Qt::AlignVCenter; + item = (int)Qt::AlignHCenter | Qt::AlignVCenter; break; } break; @@ -320,20 +323,20 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const break; case Qt::TextAlignmentRole: - item = Qt::AlignRight + Qt::AlignVCenter; + item = (int)Qt::AlignRight | Qt::AlignVCenter; break; } } break; - case switch_column: + case switch_at_column: switch (role) { case SortRole: case Qt::EditRole: case Qt::DisplayRole: case Qt::AccessibleTextRole: - item = stations_.at (row).switch_at_.toUTC().time().toString("hh:mm"); + item = stations_.at (row).switch_at_.time().toString(); break; case Qt::ToolTipRole: @@ -342,7 +345,28 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const break; case Qt::TextAlignmentRole: - item = Qt::AlignCenter + Qt::AlignVCenter; + item = (int)Qt::AlignHCenter | Qt::AlignVCenter; + break; + } + break; + + case switch_until_column: + switch (role) + { + case SortRole: + case Qt::EditRole: + case Qt::DisplayRole: + case Qt::AccessibleTextRole: + item = stations_.at (row).switch_until_.time().toString(); + break; + + case Qt::ToolTipRole: + case Qt::AccessibleDescriptionRole: + item = tr ("Switch until this time"); + break; + + case Qt::TextAlignmentRole: + item = (int)Qt::AlignHCenter | Qt::AlignVCenter; break; } break; @@ -363,7 +387,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const break; case Qt::TextAlignmentRole: - item = Qt::AlignLeft + Qt::AlignVCenter; + item = (int)Qt::AlignLeft | Qt::AlignVCenter; break; } break; @@ -383,7 +407,8 @@ QVariant StationList::impl::headerData (int section, Qt::Orientation orientation { case band_column: header = tr ("Band"); break; case frequency_column: header = tr ("Freq. (MHz)"); break; - case switch_column: header = tr ("Switch at (UTC)"); 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; } } @@ -445,11 +470,16 @@ bool StationList::impl::setData (QModelIndex const& model_index, QVariant const& } } break; - case switch_column: + case switch_at_column: stations_[row].switch_at_ = value.toDateTime(); Q_EMIT dataChanged (model_index, model_index, roles); changed = true; break; + case switch_until_column: + stations_[row].switch_until_ = value.toDateTime(); + Q_EMIT dataChanged (model_index, model_index, roles); + changed = true; + break; case description_column: stations_[row].antenna_description_ = value.toString (); Q_EMIT dataChanged (model_index, model_index, roles); @@ -560,7 +590,7 @@ bool StationList::impl::dropMimeData (QMimeData const * data, Qt::DropAction act , [&band] (Station const& s) {return s.band_name_ == band;})) { // not found so add it - add (Station {band, 0, QDateTime::currentDateTimeUtc(), QString {}}); + add (Station {band, 0, QDateTime::currentDateTimeUtc(), QDateTime::currentDateTimeUtc(), QString {}}); } } return true; diff --git a/StationList.hpp b/StationList.hpp index 343f32f..db19d7c 100644 --- a/StationList.hpp +++ b/StationList.hpp @@ -55,12 +55,13 @@ public: QString band_name_; Frequency frequency_; QDateTime switch_at_; + QDateTime switch_until_; QString antenna_description_; }; using Stations = QList; - enum Column {band_column, frequency_column, switch_column, description_column}; + enum Column {band_column, frequency_column, switch_at_column, switch_until_column, description_column}; explicit StationList (Bands const * bands, QObject * parent = nullptr); explicit StationList (Bands const * bands, Stations, QObject * parent = nullptr); diff --git a/mainwindow.cpp b/mainwindow.cpp index f036ef9..5863571 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1350,30 +1350,21 @@ void MainWindow::on_the_minute () } // see if we need to hop bands... - auto now = QDateTime::currentDateTimeUtc().time(); - Frequency dial_frequency {m_rigState.ptt () && m_rigState.split () ? - m_rigState.tx_frequency () : m_rigState.frequency ()}; - auto const& band_name = m_config.bands ()->find (dial_frequency); + auto const& band_name = ui->bandComboBox->currentText(); auto stations = m_config.stations()->station_list(); qSort(stations.begin(), stations.end(), [](StationList::Station const &a, StationList::Station const &b){ - return a.switch_at_ < b.switch_at_; + return (a.switch_at_ < b.switch_at_) || (a.switch_at_ == b.switch_at_ && a.switch_until_ < b.switch_until_); }); - StationList::Station prev; foreach(auto station, stations){ - if(station == stations.first()){ - prev = station; - continue; - } + // we just set it to a known date to make the comparisons easier ;) + QDateTime d = QDateTime::currentDateTimeUtc(); + d.setDate(QDate(2000, 1, 1)); - if(prev.switch_at_.time() <= now && now < station.switch_at_.time()){ - qDebug() << "switch to" << station.band_name_ << station.frequency_; + bool canSwitch = station.switch_at_ <= d && d < station.switch_until_; + if(canSwitch && station.band_name_ != band_name){ + qDebug() << "should switch to" << station.band_name_ << station.frequency_; } - - prev = station; - } - if(prev.switch_at_.time() <= now && now < QTime(11, 59)){ - qDebug() << "switch to" << prev.band_name_ << prev.frequency_; } }