From 2989c20175a6839a44ef50b0663bf1e95552a078 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Thu, 9 Aug 2018 09:44:22 -0400 Subject: [PATCH] Updated editing experience for frequency schedule. Fixed some bugs with the data storage --- Bands.cpp | 5 ++-- Bands.hpp | 2 +- Configuration.cpp | 33 ++++++++++++++++++-------- StationList.cpp | 59 +++++++++++++++++++++++++++++++++++------------ StationList.hpp | 2 +- mainwindow.cpp | 15 +----------- 6 files changed, 74 insertions(+), 42 deletions(-) diff --git a/Bands.cpp b/Bands.cpp index 59d7ed3..4ded525 100644 --- a/Bands.cpp +++ b/Bands.cpp @@ -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; } diff --git a/Bands.hpp b/Bands.hpp index b66422d..b72d621 100644 --- a/Bands.hpp +++ b/Bands.hpp @@ -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 (); diff --git a/Configuration.cpp b/Configuration.cpp index 1e87f4e..9408f21 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -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 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); } } diff --git a/StationList.cpp b/StationList.cpp index 04bc43a..c7568c9 100644 --- a/StationList.cpp +++ b/StationList.cpp @@ -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 (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; diff --git a/StationList.hpp b/StationList.hpp index db19d7c..7e191aa 100644 --- a/StationList.hpp +++ b/StationList.hpp @@ -56,7 +56,7 @@ public: Frequency frequency_; QDateTime switch_at_; QDateTime switch_until_; - QString antenna_description_; + QString description_; }; using Stations = QList; diff --git a/mainwindow.cpp b/mainwindow.cpp index 5863571..fa7cf78 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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)