diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 77e7e89..546ac36 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -85,9 +85,12 @@ void MainWindow::openPlugin() } } - ui->tabWidget->addTab(plugin->ui(), plugin->pluginIcon(), plugin->pluginName()); - ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); - ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + if (plugin->ui() != NULL) + { + ui->tabWidget->addTab(plugin->ui(), plugin->pluginIcon(), plugin->pluginName()); + ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + } } void MainWindow::on_actionOpen_database_triggered() diff --git a/core/autoform.h b/core/autoform.h index 34d063a..af84ddf 100644 --- a/core/autoform.h +++ b/core/autoform.h @@ -38,12 +38,14 @@ public slots: if (!m_serviceConnected) { this->connect(service(), &IService::dbError, [this](QString msg) { - QMessageBox::critical(this, "Database error", msg.toStdString().c_str()); + QMessageBox::critical(this, this->tr("Database error"), msg.toStdString().c_str()); m_saved = false; }); this->connect(service(), &IService::permissionDenied, [this](QString permission) { - QMessageBox::critical(this, "Permission denied", permission.toStdString().c_str()); - m_saved = false; + if (permission != PERM_DELETE) { + QMessageBox::critical(this, this->tr("Permission denied"), permission.toStdString().c_str()); + m_saved = false; + } }); this->connect(service(), &IService::dataChanged, [this]() { m_saved = true; diff --git a/core/gridform.h b/core/gridform.h index 2e18917..c057c95 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -22,6 +22,7 @@ public: IGridForm(parent) { m_serviceConnected = false; + m_permissionDenied = false; m_tableModel = NULL; m_formHandler = new DefaultFormHandler(); @@ -80,12 +81,13 @@ public: } public slots: - void fillData() { + bool fillData() { if (m_tableModel == NULL) { Q_ASSERT(false); - return; + return false; } + m_permissionDenied = false; connectService(); m_tableModel->setData(service()->all()); @@ -105,6 +107,8 @@ public slots: connect(tableView()->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(widthChanged(int,int,int))); hideColumns(hide); + + return !m_permissionDenied; } private: @@ -140,12 +144,19 @@ private: connect(service(), &IService::dbErrorDelete, [this](QString msg) { QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str())); }); + this->connect(service(), &IService::permissionDenied, [this](QString permission) { + if (permission == PERM_READ || permission == PERM_DELETE) { + QMessageBox::critical(this, "Permission denied", permission .toStdString().c_str()); + m_permissionDenied = true; + } + }); m_serviceConnected = true; } } bool m_serviceConnected; + bool m_permissionDenied; // IGridForm interface protected: @@ -177,6 +188,7 @@ protected: void handleDeleteRecord() override { + m_permissionDenied = false; connectService(); if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0) { @@ -190,8 +202,12 @@ protected: { QSharedPointer entity = m_tableModel->itemFromIndex(tableView()->currentIndex()); service()->erase(entity); - m_tableModel->removeRowAt(tableView()->currentIndex()); - emit dataChanged(); + + if (!m_permissionDenied) + { + m_tableModel->removeRowAt(tableView()->currentIndex()); + emit dataChanged(); + } } } }; diff --git a/core/igridform.h b/core/igridform.h index fb70ab6..01a556d 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -32,7 +32,7 @@ signals: void dataChanged(); public slots: - virtual void fillData() = 0; + virtual bool fillData() = 0; protected: virtual void handleNewRecord() = 0; diff --git a/core/iplugin.h b/core/iplugin.h index 8b695a5..1ae33bc 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -50,13 +50,14 @@ public: virtual QWidget *ui() { IGridForm *form = qobject_cast(m_ui); + bool filled = true; if (form != NULL) { - form->fillData(); + filled = form->fillData(); } - return m_ui; + return filled ? m_ui : NULL; } virtual QWidget *settingsUi() {