Switched to time range instead of a fixed point for easier comparisons

This commit is contained in:
Jordan Sherer 2018-08-09 00:06:02 -04:00
parent 330eb3a57e
commit d2ad5ee893
5 changed files with 81 additions and 31 deletions

View File

@ -268,10 +268,14 @@ public:
switch_at_.setTimeSpec(Qt::UTC); switch_at_.setTimeSpec(Qt::UTC);
switch_at_.setDisplayFormat("hh:mm"); switch_at_.setDisplayFormat("hh:mm");
switch_until_.setTimeSpec(Qt::UTC);
switch_until_.setDisplayFormat("hh:mm");
auto form_layout = new QFormLayout (); 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 ("&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_); //form_layout->addRow (tr ("&Antenna:"), &description_);
auto main_layout = new QVBoxLayout (this); auto main_layout = new QVBoxLayout (this);
@ -286,7 +290,16 @@ public:
StationList::Station station () const 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 int exec () override
@ -301,6 +314,7 @@ private:
QComboBox band_; QComboBox band_;
FrequencyLineEdit freq_; FrequencyLineEdit freq_;
QTimeEdit switch_at_; QTimeEdit switch_at_;
QTimeEdit switch_until_;
QLineEdit description_; QLineEdit description_;
}; };
@ -2474,6 +2488,7 @@ void Configuration::impl::delete_stations ()
next_stations_.removeDisjointRows (selection_model->selectedRows ()); next_stations_.removeDisjointRows (selection_model->selectedRows ());
ui_->stations_table_view->resizeColumnToContents (StationList::band_column); ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column); ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_at_column);
} }
void Configuration::impl::insert_station () 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->setCurrentIndex (next_stations_.add (station));
ui_->stations_table_view->resizeColumnToContents (StationList::band_column); ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column); ui_->stations_table_view->resizeColumnToContents (StationList::frequency_column);
ui_->stations_table_view->resizeColumnToContents (StationList::switch_at_column);
} }
} }

View File

@ -2394,12 +2394,24 @@ Right click for insert and delete options.</string>
<attribute name="horizontalHeaderCascadingSectionResizes"> <attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool> <bool>true</bool>
</attribute> </attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>120</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>100</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection"> <attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool> <bool>true</bool>
</attribute> </attribute>
<attribute name="verticalHeaderVisible"> <attribute name="verticalHeaderVisible">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>30</number>
</attribute>
<attribute name="verticalHeaderMinimumSectionSize">
<number>24</number>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -30,6 +30,7 @@ QDebug operator << (QDebug debug, StationList::Station const& station)
<< station.band_name_ << ", " << station.band_name_ << ", "
<< station.frequency_ << ", " << station.frequency_ << ", "
<< station.switch_at_ << ", " << station.switch_at_ << ", "
<< station.switch_until_ << ", "
<< station.antenna_description_ << ')'; << station.antenna_description_ << ')';
return debug; return debug;
} }
@ -40,6 +41,7 @@ QDataStream& operator << (QDataStream& os, StationList::Station const& station)
return os << station.band_name_ return os << station.band_name_
<< station.frequency_ << station.frequency_
<< station.switch_at_ << station.switch_at_
<< station.switch_until_
<< station.antenna_description_; << station.antenna_description_;
} }
@ -48,6 +50,7 @@ QDataStream& operator >> (QDataStream& is, StationList::Station& station)
return is >> station.band_name_ return is >> station.band_name_
>> station.frequency_ >> station.frequency_
>> station.switch_at_ >> station.switch_at_
>> station.switch_until_
>> station.antenna_description_; >> station.antenna_description_;
} }
@ -93,7 +96,7 @@ public:
return matches.isEmpty () ? QModelIndex {} : matches.first (); 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"; static auto constexpr mime_type = "application/wsjt.antenna-descriptions";
Bands const * bands_; Bands const * bands_;
@ -294,7 +297,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
break; break;
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
item = Qt::AlignHCenter + Qt::AlignVCenter; item = (int)Qt::AlignHCenter | Qt::AlignVCenter;
break; break;
} }
break; break;
@ -320,20 +323,20 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
break; break;
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
item = Qt::AlignRight + Qt::AlignVCenter; item = (int)Qt::AlignRight | Qt::AlignVCenter;
break; break;
} }
} }
break; break;
case switch_column: case switch_at_column:
switch (role) switch (role)
{ {
case SortRole: case SortRole:
case Qt::EditRole: case Qt::EditRole:
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::AccessibleTextRole: case Qt::AccessibleTextRole:
item = stations_.at (row).switch_at_.toUTC().time().toString("hh:mm"); item = stations_.at (row).switch_at_.time().toString();
break; break;
case Qt::ToolTipRole: case Qt::ToolTipRole:
@ -342,7 +345,28 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
break; break;
case Qt::TextAlignmentRole: 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;
} }
break; break;
@ -363,7 +387,7 @@ QVariant StationList::impl::data (QModelIndex const& index, int role) const
break; break;
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
item = Qt::AlignLeft + Qt::AlignVCenter; item = (int)Qt::AlignLeft | Qt::AlignVCenter;
break; break;
} }
break; break;
@ -383,7 +407,8 @@ QVariant StationList::impl::headerData (int section, Qt::Orientation orientation
{ {
case band_column: header = tr ("Band"); break; case band_column: header = tr ("Band"); break;
case frequency_column: header = tr ("Freq. (MHz)"); 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; case description_column: header = tr ("Antenna Description"); break;
} }
} }
@ -445,11 +470,16 @@ bool StationList::impl::setData (QModelIndex const& model_index, QVariant const&
} }
} }
break; break;
case switch_column: case switch_at_column:
stations_[row].switch_at_ = value.toDateTime(); stations_[row].switch_at_ = value.toDateTime();
Q_EMIT dataChanged (model_index, model_index, roles); Q_EMIT dataChanged (model_index, model_index, roles);
changed = true; changed = true;
break; 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: case description_column:
stations_[row].antenna_description_ = value.toString (); stations_[row].antenna_description_ = value.toString ();
Q_EMIT dataChanged (model_index, model_index, roles); 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;})) , [&band] (Station const& s) {return s.band_name_ == band;}))
{ {
// not found so add it // not found so add it
add (Station {band, 0, QDateTime::currentDateTimeUtc(), QString {}}); add (Station {band, 0, QDateTime::currentDateTimeUtc(), QDateTime::currentDateTimeUtc(), QString {}});
} }
} }
return true; return true;

View File

@ -55,12 +55,13 @@ public:
QString band_name_; QString band_name_;
Frequency frequency_; Frequency frequency_;
QDateTime switch_at_; QDateTime switch_at_;
QDateTime switch_until_;
QString antenna_description_; QString antenna_description_;
}; };
using Stations = QList<Station>; using Stations = QList<Station>;
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, QObject * parent = nullptr);
explicit StationList (Bands const * bands, Stations, QObject * parent = nullptr); explicit StationList (Bands const * bands, Stations, QObject * parent = nullptr);

View File

@ -1350,30 +1350,21 @@ void MainWindow::on_the_minute ()
} }
// see if we need to hop bands... // see if we need to hop bands...
auto now = QDateTime::currentDateTimeUtc().time(); auto const& band_name = ui->bandComboBox->currentText();
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 stations = m_config.stations()->station_list(); auto stations = m_config.stations()->station_list();
qSort(stations.begin(), stations.end(), [](StationList::Station const &a, StationList::Station const &b){ 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){ foreach(auto station, stations){
if(station == stations.first()){ // we just set it to a known date to make the comparisons easier ;)
prev = station; QDateTime d = QDateTime::currentDateTimeUtc();
continue; d.setDate(QDate(2000, 1, 1));
}
if(prev.switch_at_.time() <= now && now < station.switch_at_.time()){ bool canSwitch = station.switch_at_ <= d && d < station.switch_until_;
qDebug() << "switch to" << station.band_name_ << station.frequency_; 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_;
} }
} }