mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-22 04:11:16 -05:00
Use Qt signals to process configuration name changes
This change maintains the encapsulation of the MultiSettings class by using a signal to notify clients of changes to the current configuration name. Modifications to the MainWindow class to display the current configuration name in the status bar, if it is not "Default", based on MultiSettings events rather than polling for changes. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7257 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
5fb0b05198
commit
cfb1a3cbe2
@ -144,7 +144,7 @@ class MultiSettings::impl final
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit impl ();
|
||||
explicit impl (MultiSettings const * parent);
|
||||
bool reposition ();
|
||||
void create_menu_actions (QMainWindow * main_window, QMenu * menu);
|
||||
bool exit ();
|
||||
@ -183,6 +183,9 @@ private:
|
||||
// remove a configuration
|
||||
void delete_configuration (QMainWindow *);
|
||||
|
||||
MultiSettings const * parent_; // required for emitting signals
|
||||
bool name_change_emit_pending_; // delayed until menu built
|
||||
|
||||
QFont original_font_;
|
||||
QString current_;
|
||||
|
||||
@ -203,8 +206,10 @@ private:
|
||||
};
|
||||
|
||||
#include "MultiSettings.moc"
|
||||
#include "moc_MultiSettings.cpp"
|
||||
|
||||
MultiSettings::MultiSettings ()
|
||||
: m_ {this}
|
||||
{
|
||||
}
|
||||
|
||||
@ -265,8 +270,10 @@ bool MultiSettings::exit ()
|
||||
return m_->exit ();
|
||||
}
|
||||
|
||||
MultiSettings::impl::impl ()
|
||||
MultiSettings::impl::impl (MultiSettings const * parent)
|
||||
: settings_ {settings_path (), QSettings::IniFormat}
|
||||
, parent_ {parent}
|
||||
, name_change_emit_pending_ {true}
|
||||
, reposition_type_ {RepositionType::unchanged}
|
||||
, exit_flag_ {true}
|
||||
, configurations_group_ {new QActionGroup {this}}
|
||||
@ -382,6 +389,7 @@ bool MultiSettings::impl::reposition ()
|
||||
reposition_type_ = RepositionType::unchanged; // reset
|
||||
bool exit {exit_flag_};
|
||||
exit_flag_ = true; // reset exit flag so normal exit works
|
||||
|
||||
return exit;
|
||||
}
|
||||
|
||||
@ -430,6 +438,12 @@ void MultiSettings::impl::create_menu_actions (QMainWindow * main_window, QMenu
|
||||
delete_configuration (main_window);
|
||||
});
|
||||
if (current_group.size ()) settings_.beginGroup (current_group);
|
||||
|
||||
if (name_change_emit_pending_)
|
||||
{
|
||||
Q_EMIT parent_->configurationNameChanged (current_);
|
||||
name_change_emit_pending_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
// call this at the end of the main program loop to determine if the
|
||||
@ -442,6 +456,9 @@ bool MultiSettings::impl::exit ()
|
||||
}
|
||||
action_connections_.clear ();
|
||||
|
||||
// ensure that configuration name changed signal gets fired on restart
|
||||
name_change_emit_pending_ = true;
|
||||
|
||||
// do any configuration swap required and return exit flag
|
||||
return reposition ();
|
||||
}
|
||||
@ -532,6 +549,7 @@ void MultiSettings::impl::select_configuration (QMainWindow * main_window)
|
||||
}
|
||||
// and set up the restart
|
||||
current_ = target_name;
|
||||
Q_EMIT parent_->configurationNameChanged (current_);
|
||||
reposition_type_ = RepositionType::save_and_replace;
|
||||
exit_flag_ = false;
|
||||
main_window->close ();
|
||||
@ -708,6 +726,7 @@ void MultiSettings::impl::rename_configuration (QMainWindow * main_window)
|
||||
settings_.setValue (multi_settings_current_name_key, dialog.new_name ());
|
||||
settings_.sync ();
|
||||
current_ = dialog.new_name ();
|
||||
Q_EMIT parent_->configurationNameChanged (current_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef MULTISETTINGS_HPP__
|
||||
#define MULTISETTINGS_HPP__
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
#include "pimpl_h.hpp"
|
||||
@ -59,7 +60,10 @@ class QString;
|
||||
//
|
||||
|
||||
class MultiSettings
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MultiSettings ();
|
||||
MultiSettings (MultiSettings const&) = delete;
|
||||
@ -86,6 +90,9 @@ public:
|
||||
// again.
|
||||
bool exit ();
|
||||
|
||||
// emitted when the name of the current configuration changes
|
||||
Q_SIGNAL void configurationNameChanged (QString const& name) const;
|
||||
|
||||
private:
|
||||
class impl;
|
||||
pimpl<impl> m_;
|
||||
|
@ -340,6 +340,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
m_manual {network_manager}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
createStatusBar();
|
||||
add_child_to_event_filter (this);
|
||||
ui->dxGridEntry->setValidator (new MaidenheadLocatorValidator {this});
|
||||
ui->dxCallEntry->setValidator (new CallsignValidator {this});
|
||||
@ -580,6 +581,15 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
connect (&m_config, &Configuration::udp_server_port_changed, m_messageClient, &MessageClient::set_server_port);
|
||||
|
||||
// set up configurations menu
|
||||
connect (m_multi_settings, &MultiSettings::configurationNameChanged, [this] (QString const& name) {
|
||||
if ("Default" != name) {
|
||||
config_label.setText (name);
|
||||
config_label.show ();
|
||||
}
|
||||
else {
|
||||
config_label.hide ();
|
||||
}
|
||||
});
|
||||
m_multi_settings->create_menu_actions (this, ui->menuConfig);
|
||||
m_configurations_button = m_rigErrorMessageBox.addButton (tr ("Configurations...")
|
||||
, QMessageBox::ActionRole);
|
||||
@ -666,8 +676,6 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
ui->decodedTextLabel2->setText(t);
|
||||
|
||||
readSettings(); //Restore user's setup params
|
||||
m_configName = m_multi_settings->common_value("CurrentName").toString();
|
||||
createStatusBar();
|
||||
|
||||
m_audioThread.start (m_audioThreadPriority);
|
||||
|
||||
@ -1701,13 +1709,11 @@ void MainWindow::createStatusBar() //createStatusBar
|
||||
tx_status_label.setFrameStyle (QFrame::Panel | QFrame::Sunken);
|
||||
statusBar()->addWidget (&tx_status_label);
|
||||
|
||||
if(m_configName!="Default") {
|
||||
config_label.setAlignment (Qt::AlignHCenter);
|
||||
config_label.setMinimumSize (QSize {80, 18});
|
||||
config_label.setFrameStyle (QFrame::Panel | QFrame::Sunken);
|
||||
config_label.setText(m_configName);
|
||||
statusBar()->addWidget (&config_label);
|
||||
}
|
||||
config_label.setAlignment (Qt::AlignHCenter);
|
||||
config_label.setMinimumSize (QSize {80, 18});
|
||||
config_label.setFrameStyle (QFrame::Panel | QFrame::Sunken);
|
||||
statusBar()->addWidget (&config_label);
|
||||
config_label.hide (); // only shown for non-default configuration
|
||||
|
||||
mode_label.setAlignment (Qt::AlignHCenter);
|
||||
mode_label.setMinimumSize (QSize {80, 18});
|
||||
@ -2952,11 +2958,6 @@ void MainWindow::guiUpdate()
|
||||
|
||||
//Once per second:
|
||||
if(nsec != m_sec0) {
|
||||
if(m_multi_settings->common_value("CurrentName").toString() != m_configName &&
|
||||
m_configName!="Default") {
|
||||
m_configName=m_multi_settings->common_value("CurrentName").toString();
|
||||
config_label.setText(m_configName);
|
||||
}
|
||||
if(m_auto and m_mode=="Echo" and m_bEchoTxOK) {
|
||||
progressBar.setMaximum(6);
|
||||
progressBar.setValue(int(m_s6));
|
||||
|
@ -489,7 +489,6 @@ private:
|
||||
QString m_msgSent0;
|
||||
QString m_fileToSave;
|
||||
QString m_calls;
|
||||
QString m_configName;
|
||||
|
||||
QSet<QString> m_pfx;
|
||||
QSet<QString> m_sfx;
|
||||
|
Loading…
Reference in New Issue
Block a user