refs #502, use user object / roles in GUI components

This commit is contained in:
Klaus Basan
2015-11-04 03:05:21 +01:00
committed by Mathew Sutcliffe
parent 87a55edc04
commit e11e8e5716
3 changed files with 158 additions and 47 deletions

View File

@@ -2,39 +2,58 @@
<ui version="4.0">
<class>CDbLoginComponent</class>
<widget class="QFrame" name="CDbLoginComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>333</width>
<height>299</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>DB login</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="vl_LoginComponent">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QFrame" name="fr_Header">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="hl_Header">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lbl_SwiftDBIcon">
<property name="maximumSize">
@@ -75,7 +94,22 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gl_Login">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>4</number>
</property>
<item row="0" column="1">
<widget class="QLineEdit" name="le_Username">
<property name="maxLength">
@@ -123,18 +157,55 @@
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="hs_Login">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="fr_Logoff">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>125</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gl_Logoff">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
@@ -174,12 +245,6 @@
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="documentTitle">
<string>User roles</string>
</property>
@@ -188,9 +253,38 @@
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="hs_Logoff">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>

View File

@@ -32,8 +32,6 @@ namespace BlackGui
COverlayMessagesFrame(parent),
ui(new Ui::CDbMappingComponent)
{
m_authenticationService = new CDatabaseAuthenticationService(this);
ui->setupUi(this);
this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
connect(ui->editor_Model, &CModelMappingForm::requestSave, this, &CDbMappingComponent::save);
@@ -47,7 +45,7 @@ namespace BlackGui
ui->editor_Distributor->setMappingMode();
ui->editor_Livery->setMappingMode();
initVPilotLoading();
this->initVPilotLoading();
}
CDbMappingComponent::~CDbMappingComponent()
@@ -57,24 +55,31 @@ namespace BlackGui
void CDbMappingComponent::initVPilotLoading()
{
if (m_authenticationService->getUser().isAdmin() &&
CProject::isRunningOnWindowsNtPlatform() &&
CProject::isCompiledWithMsFlightSimulatorSupport())
bool canUseVPilot = CProject::isRunningOnWindowsNtPlatform() && CProject::isCompiledWithMsFlightSimulatorSupport();
bool withVPilotRights = canUseVPilot && this->m_user.get().isMappingAdmin();
this->m_withVPilot = withVPilotRights;
static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(1));
if (this->m_vPilot1stInit && canUseVPilot)
{
this->m_withVPilot = true;
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged);
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
}
this->m_vPilot1stInit = false;
this->ui->tab_VPilot->setEnabled(withVPilotRights);
this->ui->tab_VPilot->setVisible(withVPilotRights);
if (withVPilotRights)
{
this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName);
}
else
{
this->m_withVPilot = false;
this->ui->tw_ModelsToBeMapped->removeTab(1);
}
this->ui->tab_VPilot->setEnabled(m_withVPilot);
this->ui->tab_VPilot->setVisible(m_withVPilot);
this->ui->tw_ModelsToBeMapped->removeTab(1);
}
bool CDbMappingComponent::initModelLoader(const CSimulatorInfo &simInfo)
@@ -114,7 +119,6 @@ namespace BlackGui
this->disconnect();
CWebDataServicesAware::gracefulShutdown();
this->m_vPilotReader.gracefulShutdown();
this->m_authenticationService->gracefulShutdown();
if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); }
}
@@ -250,6 +254,11 @@ namespace BlackGui
this->ps_loadInstalledModels(sim);
}
void CDbMappingComponent::ps_userChanged()
{
this->initVPilotLoading();
}
void CDbMappingComponent::ps_onModelRowSelected(const QModelIndex &index)
{
QObject *sender = QObject::sender();
@@ -371,7 +380,8 @@ namespace BlackGui
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access parent");
if (this->mappingComponent()->m_authenticationService->getUser().isAdmin())
bool canUseVPilot = mappingComponent()->withVPilot();
if (canUseVPilot)
{
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
menu.addSeparator();

View File

@@ -12,7 +12,7 @@
#ifndef BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H
#define BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H
#include "blackcore/databaseauthentication.h"
#include "blackcore/data/authenticateduser.h"
#include "blackgui/blackguiexport.h"
#include "blackgui/overlaymessagesframe.h"
#include "blackgui/menudelegate.h"
@@ -55,6 +55,9 @@ namespace BlackGui
//! Graceful shutdown
void gracefulShutdown();
//! With vPilot rules
bool withVPilot() const { return m_withVPilot; }
signals:
//! Request to filter by livery
void filterByLivery(const BlackMisc::Aviation::CLivery &livery);
@@ -103,17 +106,21 @@ namespace BlackGui
//! Request simulator models
void ps_requestSimulatorModels();
//! User object changed
void ps_userChanged();
private:
QScopedPointer<Ui::CDbMappingComponent> ui;
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader;
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader;
BlackCore::CDatabaseAuthenticationService *m_authenticationService = nullptr;
bool m_withVPilot = false;
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader;
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader;
BlackCore::CData<BlackCore::Data::AuthenticatedUser> m_user {this, &CDbMappingComponent::ps_userChanged};
bool m_vPilot1stInit = true;
bool m_withVPilot = false;
//! Consolidated aircraft model
BlackMisc::Simulation::CAircraftModel getAircraftModel() const;
//! Init vPilot loading is suitable
//! Init vPilot if rights and suitable
void initVPilotLoading();
//! Init model loader