mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #474, role class so I can start with access rights in mapping GUI
Remark: Added upfront, as I need that for the screenshots when writing the BLOG article
This commit is contained in:
committed by
Mathew Sutcliffe
parent
eaa8339f2b
commit
e534a64d9a
45
src/blackgui/roles.cpp
Normal file
45
src/blackgui/roles.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "roles.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
CRoles::CRoles() { }
|
||||
|
||||
bool CRoles::hasRole(const QString &role) const
|
||||
{
|
||||
return m_roles.contains(role);
|
||||
}
|
||||
|
||||
bool CRoles::isAdmin() const
|
||||
{
|
||||
return m_roles.contains("ADMIN");
|
||||
}
|
||||
|
||||
void CRoles::setAdmin(bool admin)
|
||||
{
|
||||
if (admin)
|
||||
{
|
||||
if (isAdmin()) { return; }
|
||||
m_roles.append("ADMIN");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_roles.removeAll("ADMIN");
|
||||
}
|
||||
}
|
||||
|
||||
CRoles &CRoles::roles()
|
||||
{
|
||||
static CRoles roles;
|
||||
return roles;
|
||||
}
|
||||
|
||||
} // roles
|
||||
47
src/blackgui/roles.h
Normal file
47
src/blackgui/roles.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_ROLES_H
|
||||
#define BLACKGUI_ROLES_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
/*!
|
||||
* Roles
|
||||
*/
|
||||
class BLACKGUI_EXPORT CRoles
|
||||
{
|
||||
public:
|
||||
//! Has role?
|
||||
bool hasRole(const QString &role) const;
|
||||
|
||||
//! Admin?
|
||||
bool isAdmin() const;
|
||||
|
||||
//! Set admin
|
||||
void setAdmin(bool admin);
|
||||
|
||||
//! Roles
|
||||
static CRoles &roles();
|
||||
|
||||
private:
|
||||
//! Constructor
|
||||
CRoles();
|
||||
|
||||
QStringList m_roles;
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
|
||||
QScopedPointer<Ui::CSwiftData> ui;
|
||||
BlackGui::CManagedStatusBar m_statusBar;
|
||||
BlackCore::CWebDataServices *m_webDataReader = nullptr;
|
||||
BlackCore::CWebDataServices *m_webDataReader = nullptr;
|
||||
};
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "blackgui/components/datainfoareacomponent.h"
|
||||
#include "blackgui/components/logcomponent.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackgui/roles.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/project.h"
|
||||
@@ -38,8 +39,8 @@ void CSwiftData::ps_onMenuClicked()
|
||||
}
|
||||
else if (sender == this->ui->menu_WindowFont)
|
||||
{
|
||||
// this->ps_setMainPageToInfoArea();
|
||||
// this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui);
|
||||
// this->ps_setMainPageToInfoArea();
|
||||
// this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui);
|
||||
}
|
||||
else if (sender == this->ui->menu_WindowMinimize)
|
||||
{
|
||||
@@ -76,6 +77,17 @@ void CSwiftData::ps_onMenuClicked()
|
||||
CDbMappingComponent *mappingComponent = this->ui->comp_MainInfoArea->getMappingComponent();
|
||||
mappingComponent->resizeForMapping();
|
||||
}
|
||||
else
|
||||
{
|
||||
QAction *a = qobject_cast<QAction *>(sender);
|
||||
if (a)
|
||||
{
|
||||
if (a->data() == "admin")
|
||||
{
|
||||
CRoles::roles().setAdmin(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSwiftData::initDynamicMenus()
|
||||
@@ -95,4 +107,10 @@ void CSwiftData::initDynamicMenus()
|
||||
this->ui->menu_Mapping->addAction(CIcons::save16(), "Save DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(writeDbDataToResourceDir()));
|
||||
}
|
||||
}
|
||||
|
||||
if (CProject::isRunningInDeveloperEnvironment() && !CRoles::roles().isAdmin())
|
||||
{
|
||||
QAction *a = this->ui->menu_Internals->addAction(CIcons::user16(), "Set administrator");
|
||||
a->setData("admin");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user