mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-06-10 17:59:04 -04:00
Add mode dependent working frequencies
Working frequencies are mode dependent and a reset to defaults button has been added. Also re-factored much of the model and item delegate code to simplify several of the model implementations. Introduced a single routine called from main to register the custom types with Qt. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5453 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
+54
-50
@@ -171,6 +171,7 @@
|
||||
#include "TransceiverFactory.hpp"
|
||||
#include "Transceiver.hpp"
|
||||
#include "Bands.hpp"
|
||||
#include "Modes.hpp"
|
||||
#include "FrequencyList.hpp"
|
||||
#include "StationList.hpp"
|
||||
#include "NetworkServerLookup.hpp"
|
||||
@@ -182,17 +183,6 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
struct init
|
||||
{
|
||||
init ()
|
||||
{
|
||||
qRegisterMetaType<Configuration::DataMode> ("Configuration::DataMode");
|
||||
qRegisterMetaTypeStreamOperators<Configuration::DataMode> ("Configuration::DataMode");
|
||||
qRegisterMetaType<Configuration::Type2MsgGen> ("Configuration::Type2MsgGen");
|
||||
qRegisterMetaTypeStreamOperators<Configuration::Type2MsgGen> ("Configuration::Type2MsgGen");
|
||||
}
|
||||
} static_initializer;
|
||||
|
||||
// these undocumented flag values when stored in (Qt::UserRole - 1)
|
||||
// of a ComboBox item model index allow the item to be enabled or
|
||||
// disabled
|
||||
@@ -210,14 +200,17 @@ class FrequencyDialog final
|
||||
: public QDialog
|
||||
{
|
||||
public:
|
||||
using Frequency = Radio::Frequency;
|
||||
using Item = FrequencyList::Item;
|
||||
|
||||
explicit FrequencyDialog (QWidget * parent = nullptr)
|
||||
explicit FrequencyDialog (Modes * modes_model, QWidget * parent = nullptr)
|
||||
: QDialog {parent}
|
||||
{
|
||||
setWindowTitle (QApplication::applicationName () + " - " + tr ("Add Frequency"));
|
||||
|
||||
mode_combo_box_.setModel (modes_model);
|
||||
|
||||
auto form_layout = new QFormLayout ();
|
||||
form_layout->addRow (tr ("&Mode:"), &mode_combo_box_);
|
||||
form_layout->addRow (tr ("&Frequency (MHz):"), &frequency_line_edit_);
|
||||
|
||||
auto main_layout = new QVBoxLayout (this);
|
||||
@@ -230,12 +223,13 @@ public:
|
||||
connect (button_box, &QDialogButtonBox::rejected, this, &FrequencyDialog::reject);
|
||||
}
|
||||
|
||||
Frequency frequency () const
|
||||
Item item () const
|
||||
{
|
||||
return frequency_line_edit_.frequency ();
|
||||
return {frequency_line_edit_.frequency (), Modes::value (mode_combo_box_.currentText ())};
|
||||
}
|
||||
|
||||
private:
|
||||
QComboBox mode_combo_box_;
|
||||
FrequencyLineEdit frequency_line_edit_;
|
||||
};
|
||||
|
||||
@@ -249,7 +243,7 @@ class StationDialog final
|
||||
public:
|
||||
explicit StationDialog (StationList const * stations, Bands * bands, QWidget * parent = nullptr)
|
||||
: QDialog {parent}
|
||||
, filtered_bands_ {new CandidateKeyFilter {stations, bands}}
|
||||
, filtered_bands_ {new CandidateKeyFilter {bands, stations, 0, 0}}
|
||||
{
|
||||
setWindowTitle (QApplication::applicationName () + " - " + tr ("Add Station"));
|
||||
|
||||
@@ -311,6 +305,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Class MessageItemDelegate
|
||||
//
|
||||
// Item delegate for message entry such as free text message macros.
|
||||
@@ -336,7 +331,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Internal implementation of the Configuration class.
|
||||
class Configuration::impl final
|
||||
: public QDialog
|
||||
@@ -416,6 +410,7 @@ private:
|
||||
void delete_selected_macros (QModelIndexList);
|
||||
Q_SLOT void on_save_path_select_push_button_clicked (bool);
|
||||
Q_SLOT void delete_frequencies ();
|
||||
Q_SLOT void on_reset_frequencies_push_button_clicked (bool);
|
||||
Q_SLOT void insert_frequency ();
|
||||
Q_SLOT void delete_stations ();
|
||||
Q_SLOT void insert_station ();
|
||||
@@ -469,8 +464,9 @@ private:
|
||||
QStringListModel macros_;
|
||||
RearrangableMacrosModel next_macros_;
|
||||
QAction * macro_delete_action_;
|
||||
|
||||
|
||||
Bands bands_;
|
||||
Modes modes_;
|
||||
FrequencyList frequencies_;
|
||||
FrequencyList next_frequencies_;
|
||||
StationList stations_;
|
||||
@@ -697,24 +693,17 @@ void Configuration::sync_transceiver (bool force_signal, bool enforce_mode_and_s
|
||||
m_->sync_transceiver (force_signal);
|
||||
}
|
||||
|
||||
|
||||
Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget * parent)
|
||||
: QDialog {parent}
|
||||
, self_ {self}
|
||||
, ui_ {new Ui::configuration_dialog}
|
||||
, settings_ {settings}
|
||||
, doc_dir_ {QApplication::applicationDirPath ()}
|
||||
, frequencies_ {
|
||||
{ 136000, 136130, 474200, 1836600, 1838000, 3576000, 3592600, 5287200, 5357000,
|
||||
7038600, 7076000, 10138000, 10138700, 14076000, 14095600, 18102000, 18104600,
|
||||
21076000, 21094600, 24917000, 24924600, 28076000, 28124600, 50276000, 50293000,
|
||||
70091000, 144000000, 144489000, 222000000, 432000000, 432300000,
|
||||
902000000, 1296000000, 1296500000, 2301000000, 2304000000, 2320000000, 3400000000,
|
||||
3456000000, 5760000000,10368000000, 24048000000 }
|
||||
}
|
||||
, frequencies_ {&bands_}
|
||||
, next_frequencies_ {&bands_}
|
||||
, stations_ {&bands_}
|
||||
, next_stations_ {&bands_}
|
||||
, frequency_dialog_ {new FrequencyDialog {this}}
|
||||
, frequency_dialog_ {new FrequencyDialog {&modes_, this}}
|
||||
, station_dialog_ {new StationDialog {&next_stations_, &bands_, this}}
|
||||
, rig_active_ {false}
|
||||
, have_rig_ {false}
|
||||
@@ -891,12 +880,12 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget *
|
||||
//
|
||||
// setup working frequencies table model & view
|
||||
//
|
||||
frequencies_.sort (0);
|
||||
frequencies_.sort (FrequencyList::frequency_column);
|
||||
|
||||
ui_->frequencies_table_view->setModel (&next_frequencies_);
|
||||
ui_->frequencies_table_view->sortByColumn (0, Qt::AscendingOrder);
|
||||
ui_->frequencies_table_view->setItemDelegateForColumn (0, new FrequencyItemDelegate {&bands_, this});
|
||||
ui_->frequencies_table_view->setColumnHidden (1, true);
|
||||
ui_->frequencies_table_view->sortByColumn (FrequencyList::frequency_column, Qt::AscendingOrder);
|
||||
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList::mode_column, new ForeignKeyDelegate {&modes_, 0, this});
|
||||
ui_->frequencies_table_view->setColumnHidden (FrequencyList::frequency_mhz_column, true);
|
||||
|
||||
frequency_delete_action_ = new QAction {tr ("&Delete"), ui_->frequencies_table_view};
|
||||
ui_->frequencies_table_view->insertAction (nullptr, frequency_delete_action_);
|
||||
@@ -910,13 +899,11 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget *
|
||||
//
|
||||
// setup stations table model & view
|
||||
//
|
||||
stations_.sort (0);
|
||||
stations_.sort (StationList::band_column);
|
||||
|
||||
ui_->stations_table_view->setModel (&next_stations_);
|
||||
ui_->stations_table_view->sortByColumn (0, Qt::AscendingOrder);
|
||||
ui_->stations_table_view->setColumnWidth (1, 150);
|
||||
ui_->stations_table_view->setItemDelegateForColumn (0, new ForeignKeyDelegate {&next_stations_, &bands_, 0, 0, this});
|
||||
ui_->stations_table_view->setItemDelegateForColumn (1, new FrequencyDeltaItemDelegate {this});
|
||||
ui_->stations_table_view->sortByColumn (StationList::band_column, Qt::AscendingOrder);
|
||||
ui_->stations_table_view->setItemDelegateForColumn (StationList::band_column, new ForeignKeyDelegate {&bands_, &next_stations_, 0, StationList::band_column, this});
|
||||
|
||||
station_delete_action_ = new QAction {tr ("&Delete"), ui_->stations_table_view};
|
||||
ui_->stations_table_view->insertAction (nullptr, station_delete_action_);
|
||||
@@ -1041,8 +1028,8 @@ void Configuration::impl::initialize_models ()
|
||||
}
|
||||
|
||||
next_macros_.setStringList (macros_.stringList ());
|
||||
next_frequencies_ = frequencies_.frequencies ();
|
||||
next_stations_ = stations_.stations ();
|
||||
next_frequencies_.frequency_list (frequencies_.frequency_list ());
|
||||
next_stations_.station_list (stations_.station_list ());
|
||||
|
||||
set_rig_invariants ();
|
||||
}
|
||||
@@ -1170,10 +1157,10 @@ void Configuration::impl::read_settings ()
|
||||
|
||||
if (settings_->contains ("frequencies"))
|
||||
{
|
||||
frequencies_ = settings_->value ("frequencies").value<Radio::Frequencies> ();
|
||||
frequencies_.frequency_list (settings_->value ("frequencies").value<FrequencyList::FrequencyItems> ());
|
||||
}
|
||||
|
||||
stations_ = settings_->value ("stations").value<StationList::Stations> ();
|
||||
stations_.station_list (settings_->value ("stations").value<StationList::Stations> ());
|
||||
|
||||
log_as_RTTY_ = settings_->value ("toRTTY", false).toBool ();
|
||||
report_in_comments_ = settings_->value("dBtoComments", false).toBool ();
|
||||
@@ -1262,8 +1249,8 @@ void Configuration::impl::write_settings ()
|
||||
settings_->setValue ("After73", id_after_73_);
|
||||
settings_->setValue ("TxQSYAllowed", tx_QSY_allowed_);
|
||||
settings_->setValue ("Macros", macros_.stringList ());
|
||||
settings_->setValue ("frequencies", QVariant::fromValue (frequencies_.frequencies ()));
|
||||
settings_->setValue ("stations", QVariant::fromValue (stations_.stations ()));
|
||||
settings_->setValue ("frequencies", QVariant::fromValue (frequencies_.frequency_list ()));
|
||||
settings_->setValue ("stations", QVariant::fromValue (stations_.station_list ()));
|
||||
settings_->setValue ("toRTTY", log_as_RTTY_);
|
||||
settings_->setValue ("dBtoComments", report_in_comments_);
|
||||
settings_->setValue ("Rig", rig_params_.rig_name);
|
||||
@@ -1674,16 +1661,16 @@ void Configuration::impl::accept ()
|
||||
macros_.setStringList (next_macros_.stringList ());
|
||||
}
|
||||
|
||||
if (frequencies_.frequencies () != next_frequencies_.frequencies ())
|
||||
if (frequencies_.frequency_list () != next_frequencies_.frequency_list ())
|
||||
{
|
||||
frequencies_ = next_frequencies_.frequencies ();
|
||||
frequencies_.sort (0);
|
||||
frequencies_.frequency_list (next_frequencies_.frequency_list ());
|
||||
frequencies_.sort (FrequencyList::frequency_column);
|
||||
}
|
||||
|
||||
if (stations_.stations () != next_stations_.stations ())
|
||||
if (stations_.station_list () != next_stations_.station_list ())
|
||||
{
|
||||
stations_ = next_stations_.stations ();
|
||||
stations_.sort (0);
|
||||
stations_.station_list(next_stations_.station_list ());
|
||||
stations_.sort (StationList::band_column);
|
||||
}
|
||||
|
||||
write_settings (); // make visible to all
|
||||
@@ -1975,13 +1962,26 @@ void Configuration::impl::delete_frequencies ()
|
||||
auto selection_model = ui_->frequencies_table_view->selectionModel ();
|
||||
selection_model->select (selection_model->selection (), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
next_frequencies_.removeDisjointRows (selection_model->selectedRows ());
|
||||
ui_->frequencies_table_view->resizeColumnToContents (FrequencyList::mode_column);
|
||||
}
|
||||
|
||||
void Configuration::impl::on_reset_frequencies_push_button_clicked (bool /* checked */)
|
||||
{
|
||||
if (QMessageBox::Yes == QMessageBox::question (this, tr ("Reset Working Frequencies")
|
||||
, tr ("Are you sure you want to discard your current "
|
||||
"working frequencies and replace them with default "
|
||||
"ones?")))
|
||||
{
|
||||
next_frequencies_.reset_to_defaults ();
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::impl::insert_frequency ()
|
||||
{
|
||||
if (QDialog::Accepted == frequency_dialog_->exec ())
|
||||
{
|
||||
ui_->frequencies_table_view->setCurrentIndex (next_frequencies_.add (frequency_dialog_->frequency ()));
|
||||
ui_->frequencies_table_view->setCurrentIndex (next_frequencies_.add (frequency_dialog_->item ()));
|
||||
ui_->frequencies_table_view->resizeColumnToContents (FrequencyList::mode_column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1990,6 +1990,8 @@ void Configuration::impl::delete_stations ()
|
||||
auto selection_model = ui_->stations_table_view->selectionModel ();
|
||||
selection_model->select (selection_model->selection (), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
next_stations_.removeDisjointRows (selection_model->selectedRows ());
|
||||
ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
|
||||
ui_->stations_table_view->resizeColumnToContents (StationList::offset_column);
|
||||
}
|
||||
|
||||
void Configuration::impl::insert_station ()
|
||||
@@ -1997,6 +1999,8 @@ void Configuration::impl::insert_station ()
|
||||
if (QDialog::Accepted == station_dialog_->exec ())
|
||||
{
|
||||
ui_->stations_table_view->setCurrentIndex (next_stations_.add (station_dialog_->station ()));
|
||||
ui_->stations_table_view->resizeColumnToContents (StationList::band_column);
|
||||
ui_->stations_table_view->resizeColumnToContents (StationList::offset_column);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user