Added support for dashboard.

master
Josef Rokos 7 years ago
parent 5794510bd2
commit 22936f2a3f

@ -19,6 +19,8 @@ MainWindow::MainWindow(QWidget *parent) :
m_loginDialog = new LoginDialog(this);
ui->tabWidget->setVisible(false);
QFile styleFile(":/style.css");
if (styleFile.open(QIODevice::ReadOnly | QIODevice::Text))
@ -29,9 +31,10 @@ MainWindow::MainWindow(QWidget *parent) :
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);
openDashboard();
m_loginDialog->reset();
});
connect(m_loginDialog, &LoginDialog::rejected, [this]{
@ -86,11 +89,8 @@ void MainWindow::openPlugin()
void MainWindow::on_actionOpen_database_triggered()
{
int tabCount = ui->tabWidget->count();
for (int i = 0; i < tabCount; i++)
{
ui->tabWidget->removeTab(0);
}
closaAllTabs();
closeDashboard();
QString dbFile = QFileDialog::getOpenFileName(this, "Open Database", "", "Database Files (*.db)");
if (!dbFile.isEmpty())
@ -104,15 +104,20 @@ void MainWindow::on_actionOpen_database_triggered()
void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
ui->tabWidget->removeTab(index);
if (ui->tabWidget->count() == 0)
{
ui->dashboard->setVisible(true);
ui->tabWidget->setVisible(false);
refreshDashboard();
}
}
void MainWindow::on_actionLogin_triggered()
{
int tabCount = ui->tabWidget->count();
for (int i = 0; i < tabCount; i++)
{
ui->tabWidget->removeTab(0);
}
closaAllTabs();
closeDashboard();
QSharedPointer<User> u;
Context::instance().setCurrentUser(u);
@ -153,6 +158,9 @@ void MainWindow::on_actionPost_register_triggered()
void MainWindow::openPlugin(IPlugin *plugin)
{
ui->tabWidget->setVisible(true);
ui->dashboard->setVisible(false);
for (int i = 0; i < ui->tabWidget->count(); i++) {
if (ui->tabWidget->widget(i)->objectName() == plugin->pluginId()) {
ui->tabWidget->setCurrentIndex(i);
@ -179,6 +187,68 @@ void MainWindow::on_actionCountry_register_triggered()
}
void MainWindow::closeDashboard()
{
foreach (QFrame *dbFrame, m_dbWidgets) {
dbFrame->setVisible(false);
}
}
void MainWindow::openDashboard()
{
PermissionEvaluator permEv;
foreach (IPlugin *plugin, Context::instance().plugins()) {
if (!plugin->dasboardWidgets().isEmpty()
&& permEv.hasPermission(plugin->pluginId(), PERM_READ)) {
foreach (QFrame *frame, plugin->dasboardWidgets()) {
if (m_dbWidgets.contains(frame))
{
frame->setVisible(true);
}
else
{
ui->dbWidget->layout()->addWidget(frame);
m_dbWidgets.append(frame);
}
}
}
}
if (!Context::instance().currentUser().isNull())
{
m_lblUser->setText(Context::instance().currentUser()->name());
ui->labelUser->setText(Context::instance().currentUser()->name());
}
refreshDashboard();
}
void MainWindow::refreshDashboard()
{
foreach (QFrame *frame, m_dbWidgets) {
IDashboardWidget *dbWidget = dynamic_cast<IDashboardWidget*>(frame);
if (dbWidget != nullptr)
{
dbWidget->refresh();
}
}
}
void MainWindow::closaAllTabs()
{
ui->tabWidget->setVisible(false);
ui->dashboard->setVisible(true);
int tabCount = ui->tabWidget->count();
for (int i = 0; i < tabCount; i++)
{
ui->tabWidget->removeTab(0);
}
}
void MainWindow::on_actionAbout_Qt_triggered()
{
QMessageBox::aboutQt(this);

@ -47,7 +47,13 @@ private:
Ui::MainWindow *ui;
LoginDialog *m_loginDialog;
QLabel *m_lblUser;
QList<QFrame*> m_dbWidgets;
void openPlugin(IPlugin *plugin);
void closeDashboard();
void openDashboard();
void refreshDashboard();
void closaAllTabs();
// QWidget interface
protected:

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>Prodejna</string>
</property>
<property name="windowIcon">
<iconset resource="appRc.qrc">
@ -52,6 +52,83 @@
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="dashboard" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="dbWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="appRc.qrc">:/icons/login_32.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelUser">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<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 row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Prodejna 2.0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
@ -60,7 +137,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>25</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -144,12 +221,12 @@
</action>
<action name="actionAbout">
<property name="text">
<string>About</string>
<string>&amp;About</string>
</property>
</action>
<action name="actionAbout_Qt">
<property name="text">
<string>About Qt</string>
<string>About &amp;Qt</string>
</property>
</action>
</widget>

@ -21,3 +21,7 @@
min-width: 90px;
font: 10pt;
}
#dashboard {
background-color: qlineargradient(spread:pad, x1:0.507, y1:1, x2:0.518, y2:0.291, stop:0 rgba(83, 145, 169, 255), stop:1 rgba(255, 255, 255, 255));
}

@ -14,5 +14,6 @@
#include "enums.h"
#include "objectbinder.h"
#include "helper.h"
#include "idashboardwidget.h"
#endif // CORE_H

@ -134,7 +134,8 @@ HEADERS += core.h\
importdialog.h \
importprogress.h \
reporting/variablefiller.h \
helper.h
helper.h \
idashboardwidget.h
unix {
target.path = /usr/lib

@ -0,0 +1,10 @@
#ifndef IDASHBOARDWIDGET_H
#define IDASHBOARDWIDGET_H
class IDashboardWidget
{
public:
virtual void refresh() = 0;
};
#endif // IDASHBOARDWIDGET_H

@ -70,6 +70,10 @@ public:
return filled ? m_ui : NULL;
}
QList<QFrame*> dasboardWidgets() {
return m_dashboardWidgets;
}
virtual QWidget *settingsUi() {
return m_settingsUi;
}
@ -103,6 +107,7 @@ protected:
QWidget *m_settingsUi;
IService *m_service;
QMap<QString, QString> m_translations;
QList<QFrame*> m_dashboardWidgets;
};
#define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"

Loading…
Cancel
Save