refactor: Remove separate login mode buttons

This commit is contained in:
Lars Toenning
2025-03-24 10:21:34 +01:00
parent d959c13682
commit 509d34ed37
8 changed files with 12 additions and 251 deletions

View File

@@ -629,9 +629,6 @@ add_library(gui SHARED
lineedithistory.h
loadindicator.cpp
loadindicator.h
loginmodebuttons.cpp
loginmodebuttons.h
loginmodebuttons.ui
mainwindowaccess.cpp
mainwindowaccess.h
managedstatusbar.cpp

View File

@@ -31,7 +31,6 @@
#include "gui/editors/pilotform.h"
#include "gui/editors/serverform.h"
#include "gui/guiapplication.h"
#include "gui/loginmodebuttons.h"
#include "gui/ticklabel.h"
#include "gui/uppercasevalidator.h"
#include "misc/aviation/aircrafticaocode.h"

View File

@@ -392,12 +392,6 @@
<header>gui/components/ownaircraftcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>swift::gui::CLoginModeButtons</class>
<extends>QFrame</extends>
<header>gui/loginmodebuttons.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>swift::gui::CTickLabel</class>
<extends>QLabel</extends>

View File

@@ -66,9 +66,16 @@ namespace swift::gui::components
CNetworkDetailsComponent::~CNetworkDetailsComponent() {}
CLoginMode CNetworkDetailsComponent::getLoginMode() const { return ui->frp_LoginMode->getLoginMode(); }
CLoginMode CNetworkDetailsComponent::getLoginMode() const
{
return ui->cb_observer->isChecked() ? CLoginMode::Observer : CLoginMode::Pilot;
}
void CNetworkDetailsComponent::setLoginMode(CLoginMode mode) { ui->frp_LoginMode->setLoginMode(mode); }
void CNetworkDetailsComponent::setLoginMode(CLoginMode mode)
{
if (mode == CLoginMode::Observer) { ui->cb_observer->setChecked(true); }
else { ui->cb_observer->setChecked(false); }
}
bool CNetworkDetailsComponent::isVatsimServerSelected() const
{

View File

@@ -223,12 +223,9 @@
</widget>
</item>
<item row="0" column="1">
<widget class="swift::gui::CLoginModeButtons" name="frp_LoginMode">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
<widget class="QCheckBox" name="cb_observer">
<property name="text">
<string>Observer (co-pilot)</string>
</property>
</widget>
</item>
@@ -259,12 +256,6 @@
<extends>QComboBox</extends>
<header>gui/components/serverlistselector.h</header>
</customwidget>
<customwidget>
<class>swift::gui::CLoginModeButtons</class>
<extends>QFrame</extends>
<header>gui/loginmodebuttons.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tw_Network</tabstop>

View File

@@ -1,91 +0,0 @@
// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
#include "gui/loginmodebuttons.h"
#include <QRadioButton>
#include "ui_loginmodebuttons.h"
#include "config/buildconfig.h"
#include "core/context/contextsimulator.h"
#include "gui/guiapplication.h"
#include "misc/verify.h"
using namespace swift::config;
using namespace swift::core;
using namespace swift::core::context;
using namespace swift::misc::network;
namespace swift::gui
{
CLoginModeButtons::CLoginModeButtons(QWidget *parent) : QFrame(parent), ui(new Ui::CLoginModeButtons)
{
ui->setupUi(this);
ui->lbl_NoSimulator->setVisible(false);
this->configureLoginModes();
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this,
&CLoginModeButtons::configureLoginModes, Qt::QueuedConnection);
}
CLoginModeButtons::~CLoginModeButtons() {}
CLoginMode swift::gui::CLoginModeButtons::getLoginMode() const
{
CLoginMode mode = CLoginMode::Pilot;
if (ui->rb_LoginObserver->isChecked()) { mode.setLoginMode(CLoginMode::Observer); }
return mode;
}
void CLoginModeButtons::setLoginMode(CLoginMode mode)
{
switch (mode.getLoginMode())
{
case CLoginMode::Observer: ui->rb_LoginObserver->setChecked(true); break;
default:
case CLoginMode::Pilot: ui->rb_LoginNormal->setChecked(true); break;
}
}
void CLoginModeButtons::setReadOnly(bool readonly)
{
ui->rb_LoginNormal->setEnabled(!readonly);
ui->rb_LoginObserver->setEnabled(!readonly);
ui->rb_LoginStealth->setEnabled(!readonly);
}
void CLoginModeButtons::configureLoginModes()
{
if (!sGui || sGui->isShuttingDown()) { return; }
// we have no idea how we can get here without the context existing Ref T389
if (CBuildConfig::isLocalDeveloperDebugBuild() && !sGui->getIContextSimulator())
{
// how is this possible? In debug builds I do crosscheck
Q_ASSERT_X(false, Q_FUNC_INFO, "No context or sGUI");
}
if (!sGui->getIContextSimulator() ||
(!sGui->isDeveloperFlagSet() && !sGui->getIContextSimulator()->isSimulatorSimulating()))
{
// Disable pilot login modes, only observer
ui->rb_LoginNormal->setEnabled(false);
ui->rb_LoginStealth->setEnabled(false);
ui->rb_LoginNormal->setToolTip("No simulator available");
ui->rb_LoginStealth->setToolTip("No simulator available");
ui->rb_LoginObserver->setChecked(true);
ui->lbl_NoSimulator->setVisible(true);
}
else
{
ui->rb_LoginNormal->setEnabled(true);
ui->rb_LoginStealth->setEnabled(true);
ui->rb_LoginNormal->setToolTip({});
ui->rb_LoginStealth->setToolTip({});
ui->rb_LoginNormal->setChecked(true);
ui->lbl_NoSimulator->setVisible(false);
}
ui->rb_LoginStealth->setVisible(false); // 2019-01 hide as based on discussion with RR
}
} // namespace swift::gui

View File

@@ -1,50 +0,0 @@
// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
//! \file
#ifndef SWIFT_GUI_LOGINMODEBUTTONS_H
#define SWIFT_GUI_LOGINMODEBUTTONS_H
#include <QFrame>
#include <QObject>
#include <QScopedPointer>
#include "gui/swiftguiexport.h"
#include "misc/network/loginmode.h"
namespace Ui
{
class CLoginModeButtons;
}
namespace swift::gui
{
//! Display login modes (normal, stealth, ...)
class SWIFT_GUI_EXPORT CLoginModeButtons : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CLoginModeButtons(QWidget *parent = nullptr);
//! Destructor
virtual ~CLoginModeButtons() override;
//! Get login mode, \sa swift::core::INetwork::LoginMode
swift::misc::network::CLoginMode getLoginMode() const;
//! Set login mode
void setLoginMode(swift::misc::network::CLoginMode mode);
//! Set to read only
void setReadOnly(bool readonly);
private:
void configureLoginModes();
QScopedPointer<Ui::CLoginModeButtons> ui;
};
} // namespace swift::gui
#endif // SWIFT_GUI_LOGINMODEBUTTONS_H

View File

@@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CLoginModeButtons</class>
<widget class="QFrame" name="CLoginModeButtons">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>363</width>
<height>22</height>
</rect>
</property>
<property name="windowTitle">
<string>Login mode</string>
</property>
<property name="title" stdset="0">
<string/>
</property>
<property name="flat" stdset="0">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="hl_LoginMode">
<property name="spacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item alignment="Qt::AlignRight">
<widget class="QRadioButton" name="rb_LoginNormal">
<property name="text">
<string>Normal</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QRadioButton" name="rb_LoginStealth">
<property name="text">
<string>Stealth</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QRadioButton" name="rb_LoginObserver">
<property name="text">
<string>Observer (co-pilot)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_NoSimulator">
<property name="text">
<string>No simulator!</string>
</property>
</widget>
</item>
<item>
<spacer name="hs_LoginModeButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>