mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +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
|
||||
Reference in New Issue
Block a user