Fixed permission issues.

print
Josef Rokos 9 years ago
parent 7ae8c53a16
commit d93e470c10

@ -85,9 +85,12 @@ void MainWindow::openPlugin()
}
}
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()

@ -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());
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;

@ -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,10 +202,14 @@ protected:
{
QSharedPointer<T> entity = m_tableModel->itemFromIndex(tableView()->currentIndex());
service()->erase(entity);
if (!m_permissionDenied)
{
m_tableModel->removeRowAt(tableView()->currentIndex());
emit dataChanged();
}
}
}
};
#endif // GRIDFORM_H

@ -32,7 +32,7 @@ signals:
void dataChanged();
public slots:
virtual void fillData() = 0;
virtual bool fillData() = 0;
protected:
virtual void handleNewRecord() = 0;

@ -50,13 +50,14 @@ public:
virtual QWidget *ui() {
IGridForm *form = qobject_cast<IGridForm*>(m_ui);
bool filled = true;
if (form != NULL)
{
form->fillData();
filled = form->fillData();
}
return m_ui;
return filled ? m_ui : NULL;
}
virtual QWidget *settingsUi() {

Loading…
Cancel
Save