Implemented application login.
Minor UI improvement. Fixed memory leaks.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>icons/login_32.png</file>
|
||||
<file>icons/login_64.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -22,10 +22,13 @@ win32 {
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
logindialog.cpp
|
||||
|
||||
HEADERS += mainwindow.h
|
||||
HEADERS += mainwindow.h \
|
||||
logindialog.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
FORMS += mainwindow.ui \
|
||||
logindialog.ui
|
||||
|
||||
|
||||
unix {
|
||||
@@ -43,3 +46,6 @@ else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore
|
||||
|
||||
INCLUDEPATH += $$PWD/../core
|
||||
DEPENDPATH += $$PWD/../core
|
||||
|
||||
RESOURCES += \
|
||||
appRc.qrc
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.8 KiB |
@@ -0,0 +1,45 @@
|
||||
#include "logindialog.h"
|
||||
#include "ui_logindialog.h"
|
||||
#include "../core/core.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
LoginDialog::LoginDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LoginDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
LoginDialog::~LoginDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString LoginDialog::login() const
|
||||
{
|
||||
return ui->editLogin->text();
|
||||
}
|
||||
|
||||
QString LoginDialog::password() const
|
||||
{
|
||||
return ui->editPassword->text();
|
||||
}
|
||||
|
||||
void LoginDialog::reset()
|
||||
{
|
||||
ui->editLogin->setText("");
|
||||
ui->editPassword->setText("");
|
||||
}
|
||||
|
||||
void LoginDialog::accept()
|
||||
{
|
||||
PermissionService srv;
|
||||
if (srv.checkLogin(ui->editLogin->text(), ui->editPassword->text()))
|
||||
{
|
||||
QDialog::accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, "Bad login", "Bad login or password");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef LOGINDIALOG_H
|
||||
#define LOGINDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class LoginDialog;
|
||||
}
|
||||
|
||||
class LoginDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LoginDialog(QWidget *parent = 0);
|
||||
~LoginDialog();
|
||||
QString login() const;
|
||||
QString password() const;
|
||||
void reset();
|
||||
|
||||
private:
|
||||
Ui::LoginDialog *ui;
|
||||
|
||||
// QDialog interface
|
||||
public slots:
|
||||
void accept() override;
|
||||
};
|
||||
|
||||
#endif // LOGINDIALOG_H
|
||||
@@ -0,0 +1,146 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LoginDialog</class>
|
||||
<widget class="QDialog" name="LoginDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>408</width>
|
||||
<height>220</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="appRc.qrc">:/icons/login_64.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="editLogin"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="editPassword">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="appRc.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LoginDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LoginDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
@@ -7,6 +8,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.move(QApplication::desktop()->screen()->rect().center() - w.rect().center());
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
|
||||
@@ -13,6 +13,22 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_lblUser = new QLabel(this);
|
||||
ui->statusBar->addWidget(m_lblUser);
|
||||
|
||||
m_loginDialog = new LoginDialog(this);
|
||||
|
||||
connect(m_loginDialog, &LoginDialog::accepted, [this]{
|
||||
PermissionService service;
|
||||
QSharedPointer<User> u = service.loadUser(m_loginDialog->login());
|
||||
m_lblUser->setText(u->name());
|
||||
m_loginDialog->reset();
|
||||
Context::instance().setCurrentUser(u);
|
||||
});
|
||||
|
||||
connect(m_loginDialog, &LoginDialog::rejected, [this]{
|
||||
close();
|
||||
});
|
||||
|
||||
Context::instance().loadPlugins();
|
||||
int i = 0;
|
||||
@@ -27,6 +43,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
}
|
||||
|
||||
((QVBoxLayout*)ui->navigation->layout())->addStretch(1);
|
||||
|
||||
if (Context::instance().db() != NULL)
|
||||
{
|
||||
ui->navigation->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -59,13 +80,37 @@ void MainWindow::openPlugin()
|
||||
|
||||
void MainWindow::on_actionOpen_database_triggered()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
/*QFileDialog dialog(this);
|
||||
dialog.setNameFilter(tr("Database Files (*.db)"));
|
||||
dialog.setWindowTitle(tr("Open Database"));
|
||||
Context::instance().openDb(dialog.getOpenFileName());
|
||||
dialog.setWindowTitle(tr("Open Database"));*/
|
||||
|
||||
QString dbFile = QFileDialog::getOpenFileName(this, "Open Database", "", "Database Files (*.db)");
|
||||
if (!dbFile.isEmpty())
|
||||
{
|
||||
Context::instance().openDb(dbFile);
|
||||
ui->navigation->setEnabled(true);
|
||||
on_actionLogin_triggered();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_tabWidget_tabCloseRequested(int index)
|
||||
{
|
||||
ui->tabWidget->removeTab(index);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLogin_triggered()
|
||||
{
|
||||
QSharedPointer<User> u;
|
||||
Context::instance().setCurrentUser(u);
|
||||
m_lblUser->setText("");
|
||||
m_loginDialog->show();
|
||||
}
|
||||
|
||||
void MainWindow::showEvent(QShowEvent *evt)
|
||||
{
|
||||
QWidget::showEvent(evt);
|
||||
if (Context::instance().db() != NULL && Context::instance().currentUser().data() == NULL)
|
||||
{
|
||||
m_loginDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLabel>
|
||||
|
||||
#include "logindialog.h"
|
||||
|
||||
#define PLUGIN_INDEX "plug_index"
|
||||
|
||||
@@ -25,8 +28,16 @@ private slots:
|
||||
|
||||
void on_tabWidget_tabCloseRequested(int index);
|
||||
|
||||
void on_actionLogin_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
LoginDialog *m_loginDialog;
|
||||
QLabel *m_lblUser;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void showEvent(QShowEvent *evt);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -15,8 +15,17 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="navigation" native="true">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -52,6 +61,8 @@
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionOpen_database"/>
|
||||
<addaction name="actionLogin"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
@@ -63,6 +74,7 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionLogin"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionExit">
|
||||
@@ -75,8 +87,19 @@
|
||||
<string>Open database...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLogin">
|
||||
<property name="icon">
|
||||
<iconset resource="appRc.qrc">
|
||||
<normaloff>:/icons/login_32.png</normaloff>:/icons/login_32.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Login...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="appRc.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user