155 lines
3.5 KiB
C++
155 lines
3.5 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QVBoxLayout>
|
|
#include "base/HGBase.h"
|
|
#include "HGUIGlobal.h"
|
|
#include "dialog_login.h"
|
|
#include "dialog_changepwd.h"
|
|
#include "dialog_accountmanage.h"
|
|
|
|
MainWindow::MainWindow(HGPdtToolDbUserMgr userMgr, QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, m_pdtToolDbuserMgr(userMgr)
|
|
, m_form_mainInterface(nullptr)
|
|
, m_top_splitter(nullptr)
|
|
, m_bot_splitter(nullptr)
|
|
, m_splitterCount(1)
|
|
, m_isLogOut(false)
|
|
{
|
|
ui->setupUi(this);
|
|
setWindowIcon(QIcon(":image/image_rsc/logo/logo.ico"));
|
|
|
|
HGUInt userType = 0;
|
|
HGPdtToolDb_GetUserType(m_pdtToolDbuserMgr, &userType);
|
|
if (userType == HGPDTTOOLDB_USERTYPE_NORMAL)
|
|
ui->act_manage->setVisible(false);
|
|
|
|
HGChar userName[128];
|
|
HGPdtToolDb_GetUserName(m_pdtToolDbuserMgr, userName, 128);
|
|
setWindowTitle(userName);
|
|
|
|
m_top_splitter = new QSplitter(Qt::Horizontal);
|
|
m_bot_splitter = new QSplitter(Qt::Horizontal);
|
|
m_form_mainInterface = new Form_mainInterface();
|
|
m_top_splitter->addWidget(m_form_mainInterface);
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
|
vLayout->addWidget(m_top_splitter);
|
|
vLayout->addWidget(m_bot_splitter);
|
|
vLayout->setStretch(0, 1);
|
|
vLayout->setStretch(1, 0);
|
|
this->centralWidget()->setLayout(vLayout);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
|
|
m_pdtToolDbuserMgr = NULL;
|
|
|
|
delete ui;
|
|
}
|
|
|
|
bool MainWindow::isExitApp()
|
|
{
|
|
return !m_isLogOut;
|
|
}
|
|
|
|
void MainWindow::on_act_newDevice_triggered()
|
|
{
|
|
m_splitterCount++;
|
|
switch (m_splitterCount)
|
|
{
|
|
case 2:
|
|
{
|
|
Form_mainInterface *form_mainInterface = new Form_mainInterface();
|
|
m_top_splitter->addWidget(form_mainInterface);
|
|
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
{
|
|
Form_mainInterface *form_mainInterface = new Form_mainInterface();
|
|
m_bot_splitter->addWidget(form_mainInterface);
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
{
|
|
Form_mainInterface *form_mainInterface = new Form_mainInterface();
|
|
m_bot_splitter->addWidget(form_mainInterface);
|
|
break;
|
|
}
|
|
|
|
case 5:
|
|
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
return;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_manage_triggered()
|
|
{
|
|
Dialog_accountManage dlg(m_pdtToolDbuserMgr, this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_changePwd_triggered()
|
|
{
|
|
Dialog_changePwd dlg(m_pdtToolDbuserMgr, this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_export_triggered()
|
|
{
|
|
HGChar cfgPath[256]= {0};
|
|
HGBase_GetConfigPath(cfgPath, 256);
|
|
strcat(cfgPath, "1.xls");
|
|
HGPdtToolDb_Export(m_pdtToolDbuserMgr, getStdString(cfgPath).c_str());
|
|
}
|
|
|
|
void MainWindow::on_act_logOut_triggered()
|
|
{
|
|
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
|
|
m_isLogOut = true;
|
|
close();
|
|
}
|
|
|
|
|
|
void MainWindow::on_act_close_triggered()
|
|
{
|
|
close();
|
|
}
|
|
|
|
QString MainWindow::getLogInfo(HGResult ret)
|
|
{
|
|
QString str;
|
|
if (HGPDTTOOLDB_ERR_INVALID_USER == ret)
|
|
{
|
|
str = tr("Illegal user");
|
|
}
|
|
else if (HGPDTTOOLDB_ERR_WRONG_PASSWORD == ret)
|
|
{
|
|
str = tr("Wrong password");
|
|
}
|
|
else if (HGPDTTOOLDB_ERR_DATABASE == ret)
|
|
{
|
|
str = tr("Database error");
|
|
}
|
|
else if (HGPDTTOOLDB_ERR_CONNECT == ret)
|
|
{
|
|
str = tr("connect error");
|
|
}
|
|
else
|
|
{
|
|
str = tr("Failed");
|
|
}
|
|
|
|
return str;
|
|
}
|