AdminSettingForm show and hide for different user role
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
#include "loginwindow.h"
|
#include "loginwindow.h"
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include "models/User.h"
|
||||||
|
#include "AdminSettingForm.h"
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::QMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
void MainWindow::QMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||||
@@ -101,10 +103,13 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
"QDialog#formDialog{border:3px solid silver; border-radius:8px}"
|
"QDialog#formDialog{border:3px solid silver; border-radius:8px}"
|
||||||
"QWidget#formWidget QLabel#endline{border-bottom:1px solid silver}"
|
"QWidget#formWidget QLabel#endline{border-bottom:1px solid silver}"
|
||||||
"QWidget#formWidget QLabel#title{font-size:30px; }"
|
"QWidget#formWidget QLabel#title{font-size:30px; }"
|
||||||
|
"QListView{border:none;margin:5px; font-weight:bold}"
|
||||||
|
"QListView::item{background:#4c5052;min-height:30px; border:1px solid silver; border-radius:5px}"
|
||||||
|
"QListView::item:selected{background:#365880; font-weight:bold;color:white}"
|
||||||
;
|
;
|
||||||
this->setStyleSheet(style);
|
this->setStyleSheet(style);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
QTabWidget* tab = new QTabWidget(this);
|
tab = new QTabWidget(this);
|
||||||
tab->setTabPosition(QTabWidget::South);
|
tab->setTabPosition(QTabWidget::South);
|
||||||
tab->setContentsMargins(0, 0, 0, 0);
|
tab->setContentsMargins(0, 0, 0, 0);
|
||||||
connect(EventCenter::Default(), &EventCenter::PatientSelected, [=](QObject* sender, QObject* data) {
|
connect(EventCenter::Default(), &EventCenter::PatientSelected, [=](QObject* sender, QObject* data) {
|
||||||
@@ -183,7 +188,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) {
|
connect(EventCenter::Default(), &EventCenter::RequestLogin, [=](QObject*, QObject* msg) {
|
||||||
this->requestLogin();
|
this->requestLogin();
|
||||||
});
|
});
|
||||||
DeviceManager::Default()->initDevice();
|
DeviceManager::Default()->initDevice();
|
||||||
centerWidgetHide();
|
centerWidgetHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +203,19 @@ void MainWindow::centerWidgetHide() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::centerWidgetShow() {
|
void MainWindow::centerWidgetShow() {
|
||||||
|
if (User::Current()->isAdmin() )
|
||||||
|
{
|
||||||
|
if (admin_tab_index == -1)
|
||||||
|
{
|
||||||
|
AdminSettingForm * form = new AdminSettingForm(this);
|
||||||
|
admin_tab_index = tab->addTab(form,"Admin");
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if (admin_tab_index != -1){
|
||||||
|
tab->removeTab(admin_tab_index);
|
||||||
|
admin_tab_index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
ui->centralWidget->setVisible(true);
|
ui->centralWidget->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace Ui {
|
|||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
class GUIMessageDialog;
|
class GUIMessageDialog;
|
||||||
|
class QTabWidget;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -25,6 +26,8 @@ private:
|
|||||||
GUIMessageDialog* msgDialog = nullptr;
|
GUIMessageDialog* msgDialog = nullptr;
|
||||||
StdOutRedirector* redir = nullptr;
|
StdOutRedirector* redir = nullptr;
|
||||||
QTextEdit* console = nullptr;
|
QTextEdit* console = nullptr;
|
||||||
|
QTabWidget* tab= nullptr;
|
||||||
|
int admin_tab_index = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ bool User::submitChange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool User::QueryUser(QString userID, QString Pwd) {
|
bool User::QueryUser(QString userID, QString Pwd) {
|
||||||
|
|
||||||
QString sql = QString("select * from Account where UserCode=:userID and Password=:pwd");
|
QString sql = QString("select * from Account where UserCode=:userID and Password=:pwd");
|
||||||
QMap<QString,QVariant> map;
|
QMap<QString,QVariant> map;
|
||||||
QMap<QString,QVariant> params;
|
QMap<QString,QVariant> params;
|
||||||
@@ -54,12 +55,26 @@ bool User::QueryUser(QString userID, QString Pwd) {
|
|||||||
{
|
{
|
||||||
if (!currentUser) currentUser = new User;
|
if (!currentUser) currentUser = new User;
|
||||||
#define USER_READONLY_PROPERTY(name) currentUser->m_##name = map[#name].toString();
|
#define USER_READONLY_PROPERTY(name) currentUser->m_##name = map[#name].toString();
|
||||||
#define USER_PROPERTY(name)\
|
#define USER_PROPERTY(name) currentUser->mf_##name = false;\
|
||||||
USER_READONLY_PROPERTY(name)
|
USER_READONLY_PROPERTY(name)
|
||||||
USER_PROPERTIES_MACRO()
|
USER_PROPERTIES_MACRO()
|
||||||
#undef USER_PROPERTY
|
#undef USER_PROPERTY
|
||||||
#undef USER_READONLY_PROPERTY
|
#undef USER_READONLY_PROPERTY
|
||||||
|
currentUser->isAdminFlag = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool User::isAdmin() {
|
||||||
|
if (isAdminFlag<0)
|
||||||
|
{
|
||||||
|
QString sql = QString("select RoleName from Role where RoleID=:RoleID");
|
||||||
|
QMap<QString,QVariant> map;
|
||||||
|
QMap<QString,QVariant> params;
|
||||||
|
params[":RoleID"] = this->m_RoleID;
|
||||||
|
SQLHelper::QueryFirst(sql, map, ¶ms);
|
||||||
|
isAdminFlag = map["RoleName"].toString() == "admin"?1:0 ;
|
||||||
|
}
|
||||||
|
return isAdminFlag;
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public:
|
|||||||
mf_Password = false;
|
mf_Password = false;
|
||||||
}
|
}
|
||||||
bool submitChange();
|
bool submitChange();
|
||||||
|
bool isAdmin();
|
||||||
private:
|
private:
|
||||||
static User* currentUser;
|
static User* currentUser;
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ private:
|
|||||||
USER_PROPERTIES_MACRO()
|
USER_PROPERTIES_MACRO()
|
||||||
#undef USER_PROPERTY
|
#undef USER_PROPERTY
|
||||||
#undef USER_READONLY_PROPERTY
|
#undef USER_READONLY_PROPERTY
|
||||||
|
int isAdminFlag = -1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user