Fix bug, about application collapse by
db can't connect
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include "components/ULineEdit.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "db/SQLHelper.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -158,6 +161,18 @@ void LoginDialog::clearInputData()
|
||||
|
||||
void LoginDialog::doLogin()
|
||||
{
|
||||
if (!(AppGlobalValues::DBconnected().toBool())){
|
||||
bool sqlConnected= SQLHelper::Open();
|
||||
if (sqlConnected)
|
||||
{
|
||||
AppGlobalValues::setDBconnected(true);
|
||||
}
|
||||
else{
|
||||
mErrorMessage->setText(QString(tr("Can't connect db. Please reboot the device and retry, or call for the service help.")).arg(LOGIN_LOCK_MINUTIES));
|
||||
mErrorMessage->setVisible(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(mLoginFailedCount >= LOGIN_LOCK_COUNT)
|
||||
{
|
||||
mErrorMessage->setText(QString(tr("Login locked. Please retry after %1 minutes.")).arg(LOGIN_LOCK_MINUTIES));
|
||||
@@ -176,6 +191,7 @@ void LoginDialog::doLogin()
|
||||
{
|
||||
resetLoginFailedCount();
|
||||
mErrorMessage->setVisible(false);
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::LoginSuccess,nullptr,nullptr);
|
||||
accept();
|
||||
LOG_USER_OPERATION("Login Sucessful");
|
||||
JsonObject::Instance()->setDefaultUser(strUserCode);
|
||||
|
||||
@@ -31,18 +31,17 @@ MainWindow::MainWindow(QWidget* aParent)
|
||||
: QMainWindow(aParent)
|
||||
, mUI(new Ui::MainWindow)
|
||||
, mDebugConsoleWidget(nullptr)
|
||||
, mDebugMessageConsole(nullptr)
|
||||
, mTabWidget(new QTabWidget(this))
|
||||
, mInitializWidget(new InitializeWidget(this))
|
||||
, mShutdownWidget(new ShutdownWidget(nullptr))
|
||||
, mAdminTabIndex(-1)
|
||||
, mThread(nullptr)
|
||||
, mIsDebugMode(false)
|
||||
, mTabInited(false)
|
||||
{
|
||||
mUI->setupUi(this);
|
||||
this->setWindowFlags(Qt::Window);
|
||||
|
||||
initializeTabWidget();
|
||||
|
||||
initializeLayout();
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
||||
@@ -59,8 +58,18 @@ MainWindow::MainWindow(QWidget* aParent)
|
||||
connect(DialogManager::Default(), &DialogManager::loginDialogShown, this, [this]()
|
||||
{
|
||||
mInitializWidget->setVisible(false);
|
||||
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::LoginSuccess, this, [this]()
|
||||
{
|
||||
if(!mTabInited){
|
||||
mTabInited = true;
|
||||
initializeTabWidget();
|
||||
mTabWidget->setCurrentIndex(0);
|
||||
}
|
||||
mTabWidget->setVisible(true);
|
||||
});
|
||||
|
||||
GUIErrorHandle::Default()->init();
|
||||
QApplication::setActiveWindow(centralWidget());
|
||||
}
|
||||
@@ -105,13 +114,14 @@ void MainWindow::initializeTabWidget()
|
||||
{
|
||||
mTabWidget->setTabPosition(QTabWidget::South);
|
||||
mTabWidget->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
auto selectForm = new SelectFormWidget(this);
|
||||
mTabWidget->addTab(selectForm, tr("Select"));
|
||||
auto scanForm = new ScanFormWidget(this);
|
||||
mTabWidget->addTab(scanForm, tr("Scan"));
|
||||
auto verifyForm = new ReconFormWidget(this);
|
||||
mTabWidget->addTab(verifyForm, tr("Recon"));
|
||||
mTabWidget->insertTab(0,verifyForm, tr("Recon"));
|
||||
auto scanForm = new ScanFormWidget(this);
|
||||
mTabWidget->insertTab(0,scanForm, tr("Scan"));
|
||||
auto selectForm = new SelectFormWidget(this);
|
||||
mTabWidget->insertTab(0,selectForm, tr("Select"));
|
||||
|
||||
|
||||
mTabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
@@ -251,36 +261,6 @@ void MainWindow::swipeTriggered(QSwipeGesture* aSwipeGesture)
|
||||
{
|
||||
if (aSwipeGesture->state() == Qt::GestureFinished)
|
||||
{
|
||||
//if (gesture->horizontalDirection() == QSwipeGesture::Right) {
|
||||
// int index = tab->currentIndex();
|
||||
// index--;
|
||||
// if (index >= 0) {
|
||||
// tab->setCurrentIndex(index);
|
||||
// }
|
||||
|
||||
//}
|
||||
//if (gesture->horizontalDirection() == QSwipeGesture::Left) {
|
||||
// int index = tab->currentIndex();
|
||||
// index++;
|
||||
// if (index < tab->count()) {
|
||||
// tab->setCurrentIndex(index);
|
||||
// }
|
||||
//}
|
||||
if (aSwipeGesture->verticalDirection() == QSwipeGesture::Down)
|
||||
{
|
||||
if (mIsDebugMode)
|
||||
{
|
||||
mDebugConsoleWidget->show();
|
||||
}
|
||||
}
|
||||
if (aSwipeGesture->verticalDirection() == QSwipeGesture::Up)
|
||||
{
|
||||
if (mIsDebugMode)
|
||||
{
|
||||
mDebugConsoleWidget->hide();
|
||||
}
|
||||
}
|
||||
//update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,55 +296,3 @@ void MainWindow::resetRoleLayout() {
|
||||
}
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
//------log out about----------------------------------------------------------
|
||||
|
||||
QTextEdit* MainWindow::getEdit()
|
||||
{
|
||||
return mDebugMessageConsole;
|
||||
}
|
||||
|
||||
void MainWindow::debugConsoleOn()
|
||||
{
|
||||
mIsDebugMode = true;
|
||||
mDebugConsoleWidget = new QDockWidget(this);
|
||||
mDebugConsoleWidget->setObjectName(QString::fromUtf8("dockWidget"));
|
||||
mDebugConsoleWidget->setAllowedAreas(Qt::RightDockWidgetArea);
|
||||
this->addDockWidget(static_cast<Qt::DockWidgetArea>(2), mDebugConsoleWidget);
|
||||
|
||||
mDebugMessageConsole = new UTextEdit(this);
|
||||
mDebugMessageConsole->setFocusPolicy(Qt::NoFocus);
|
||||
mDebugConsoleWidget->setWidget(mDebugMessageConsole);
|
||||
|
||||
const QString edit_style =
|
||||
"QScrollBar:vertical{border: 0px solid grey; background:#2d2d2d; width: 15px; margin: 0px 0 0px 0; }"
|
||||
"QScrollBar::handle:vertical{background:#5a5a5a;min-height: 25px;}"
|
||||
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical{background:#2d2d2d;}";
|
||||
mDebugMessageConsole->verticalScrollBar()->setStyleSheet(edit_style);
|
||||
//clear buffer before redirect;
|
||||
}
|
||||
|
||||
void MainWindow::QMessageOutput(QtMsgType aType, const QMessageLogContext& aContext, const QString& msg)
|
||||
{
|
||||
|
||||
std::cout << msg.toStdString().c_str() << std::endl;
|
||||
|
||||
//QByteArray localMsg = msg.toLocal8Bit();
|
||||
//switch (type) {
|
||||
//case QtDebugMsg:
|
||||
// fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
// break;
|
||||
//case QtInfoMsg:
|
||||
// fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
// break;
|
||||
//case QtWarningMsg:
|
||||
// fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
// break;
|
||||
//case QtCriticalMsg:
|
||||
// fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
// break;
|
||||
//case QtFatalMsg:
|
||||
// fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
// abort();
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,9 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
explicit MainWindow(QWidget* aParent = nullptr);
|
||||
~MainWindow() override;
|
||||
static void QMessageOutput(QtMsgType aType, const QMessageLogContext& aContext, const QString& aMessage);
|
||||
void centerWidgetHide();
|
||||
void centerWidgetShow();
|
||||
void requestScreenSaver();
|
||||
QTextEdit* getEdit();
|
||||
void debugConsoleOn();
|
||||
void grabGestures(const QList<Qt::GestureType>& aGestures);
|
||||
|
||||
public slots:
|
||||
@@ -60,14 +57,14 @@ private:
|
||||
private:
|
||||
Ui::MainWindow* mUI;
|
||||
QDockWidget* mDebugConsoleWidget;
|
||||
QTextEdit* mDebugMessageConsole;
|
||||
QTabWidget* mTabWidget;
|
||||
InitializeWidget* mInitializWidget;
|
||||
ShutdownWidget* mShutdownWidget;
|
||||
|
||||
int mAdminTabIndex;
|
||||
QThread* mThread;
|
||||
bool mIsDebugMode;
|
||||
bool mTabInited;
|
||||
|
||||
|
||||
void switchToScanTab(QObject* sender, QObject* data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user