mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Move CInputManager from singleton to CApplication member
The main reason why CInputManager was singleton is the easy access across the code. That had the negative side effect that time of destruction was at a very late stage of the shutdown and could not be controlled by us. My moving it to CApplication, the access is equally easy (using sApp) and allows to be cleaned up properly during graceful shutdown. ref T391
This commit is contained in:
committed by
Klaus Basan
parent
705a56b1cb
commit
f6ea2a9107
@@ -70,7 +70,6 @@ namespace BlackGui
|
||||
m_actionModel(this)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
m_inputManager = BlackCore::CInputManager::instance();
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->qf_Advanced->hide();
|
||||
@@ -105,8 +104,8 @@ namespace BlackGui
|
||||
connect(ui->pb_SelectedHotkey, &QPushButton::clicked, this, &CHotkeyDialog::selectHotkey);
|
||||
connect(ui->pb_Accept, &QPushButton::clicked, this, &CHotkeyDialog::accept);
|
||||
connect(ui->pb_Cancel, &QPushButton::clicked, this, &CHotkeyDialog::reject);
|
||||
connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged);
|
||||
connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::combinationSelectionFinished);
|
||||
connect(sApp->getInputManager(), &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged);
|
||||
connect(sApp->getInputManager(), &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::combinationSelectionFinished);
|
||||
connect(ui->tv_Actions->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CHotkeyDialog::changeSelectedAction);
|
||||
connect(ui->cb_Identifier, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &CHotkeyDialog::changeApplicableMachine);
|
||||
|
||||
@@ -155,7 +154,7 @@ namespace BlackGui
|
||||
void CHotkeyDialog::selectHotkey()
|
||||
{
|
||||
ui->pb_SelectedHotkey->setText("Press any key/button...");
|
||||
m_inputManager->startCapture();
|
||||
sApp->getInputManager()->startCapture();
|
||||
}
|
||||
|
||||
void CHotkeyDialog::combinationSelectionChanged(const CHotkeyCombination &combination)
|
||||
|
||||
@@ -107,7 +107,6 @@ namespace BlackGui
|
||||
QScopedPointer<Ui::CHotkeyDialog> ui;
|
||||
BlackMisc::Input::CActionHotkey m_actionHotkey;
|
||||
BlackGui::Models::CActionModel m_actionModel;
|
||||
BlackCore::CInputManager *m_inputManager = nullptr;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -67,7 +67,8 @@ namespace BlackGui
|
||||
|
||||
void CSettingsHotkeyComponent::registerDummyPttEntry()
|
||||
{
|
||||
CInputManager::instance()->registerAction(IContextAudio::pttHotkeyAction(), IContextAudio::pttHotkeyIcon());
|
||||
Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager");
|
||||
sApp->getInputManager()->registerAction(IContextAudio::pttHotkeyAction(), IContextAudio::pttHotkeyIcon());
|
||||
}
|
||||
|
||||
void CSettingsHotkeyComponent::addEntry()
|
||||
|
||||
@@ -19,16 +19,17 @@ namespace BlackGui
|
||||
CGuiActionBindHandler::CGuiActionBindHandler(QAction *action) : QObject(action), m_action(action)
|
||||
{
|
||||
this->connectDestroy(action);
|
||||
connect(sApp, &CApplication::aboutToShutdown, this, &CGuiActionBindHandler::unbind);
|
||||
}
|
||||
|
||||
CGuiActionBindHandler::CGuiActionBindHandler(QAbstractButton *button) : QObject(button), m_button(button)
|
||||
{
|
||||
this->connectDestroy(button);
|
||||
connect(sApp, &CApplication::aboutToShutdown, this, &CGuiActionBindHandler::unbind);
|
||||
}
|
||||
|
||||
CGuiActionBindHandler::~CGuiActionBindHandler()
|
||||
{
|
||||
this->unbind();
|
||||
}
|
||||
|
||||
CActionBindings CGuiActionBindHandler::bindMenu(QMenu *menu, const QString &path)
|
||||
@@ -87,10 +88,10 @@ namespace BlackGui
|
||||
|
||||
void CGuiActionBindHandler::unbind()
|
||||
{
|
||||
Q_ASSERT_X(CInputManager::instance(), Q_FUNC_INFO, "Missing input manager");
|
||||
if (this->hasTarget())
|
||||
{
|
||||
CInputManager::instance()->unbind(m_index);
|
||||
Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager");
|
||||
sApp->getInputManager()->unbind(m_index);
|
||||
}
|
||||
this->reset();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackcore/inputmanager.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackgui/models/actionitem.h"
|
||||
#include "blackgui/models/actionmodel.h"
|
||||
#include "blackmisc/icons.h"
|
||||
@@ -57,7 +57,7 @@ namespace BlackGui
|
||||
|
||||
Qt::ItemFlags CActionModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return 0; }
|
||||
if (!index.isValid()) { return Qt::NoItemFlags; }
|
||||
const CActionItem *item = static_cast<CActionItem *>(index.internalPointer());
|
||||
const Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
const bool selectable = item && !item->hasChildren(); // only leafs are selectable
|
||||
@@ -103,7 +103,8 @@ namespace BlackGui
|
||||
{
|
||||
m_rootItem.reset(new CActionItem(QString(), QString()));
|
||||
|
||||
const QMap<QString, QPixmap> availableActionsAndIcons = CInputManager::instance()->allAvailableActionsAndIcons();
|
||||
Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager");
|
||||
const QMap<QString, QPixmap> availableActionsAndIcons = sApp->getInputManager()->allAvailableActionsAndIcons();
|
||||
QStringList keys = availableActionsAndIcons.keys();
|
||||
keys.sort();
|
||||
for (const QString &actionPath : as_const(keys))
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace BlackGui
|
||||
|
||||
/*!
|
||||
* Action tree model, used with hotkey actions
|
||||
* \remark data from CInputManager::instance()
|
||||
* \remark data from CInputManager
|
||||
*/
|
||||
class BLACKGUI_EXPORT CActionModel : public QAbstractItemModel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user