Fixed permission issues.

print
Josef Rokos 9 years ago
parent 7ae8c53a16
commit d93e470c10

@ -85,9 +85,12 @@ void MainWindow::openPlugin()
} }
} }
ui->tabWidget->addTab(plugin->ui(), plugin->pluginIcon(), plugin->pluginName()); if (plugin->ui() != NULL)
ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); {
ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); 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() void MainWindow::on_actionOpen_database_triggered()

@ -38,12 +38,14 @@ public slots:
if (!m_serviceConnected) if (!m_serviceConnected)
{ {
this->connect(service(), &IService::dbError, [this](QString msg) { 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; m_saved = false;
}); });
this->connect(service(), &IService::permissionDenied, [this](QString permission) { this->connect(service(), &IService::permissionDenied, [this](QString permission) {
QMessageBox::critical(this, "Permission denied", permission.toStdString().c_str()); if (permission != PERM_DELETE) {
m_saved = false; QMessageBox::critical(this, this->tr("Permission denied"), permission.toStdString().c_str());
m_saved = false;
}
}); });
this->connect(service(), &IService::dataChanged, [this]() { this->connect(service(), &IService::dataChanged, [this]() {
m_saved = true; m_saved = true;

@ -22,6 +22,7 @@ public:
IGridForm(parent) IGridForm(parent)
{ {
m_serviceConnected = false; m_serviceConnected = false;
m_permissionDenied = false;
m_tableModel = NULL; m_tableModel = NULL;
m_formHandler = new DefaultFormHandler(); m_formHandler = new DefaultFormHandler();
@ -80,12 +81,13 @@ public:
} }
public slots: public slots:
void fillData() { bool fillData() {
if (m_tableModel == NULL) { if (m_tableModel == NULL) {
Q_ASSERT(false); Q_ASSERT(false);
return; return false;
} }
m_permissionDenied = false;
connectService(); connectService();
m_tableModel->setData(service()->all()); 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))); connect(tableView()->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(widthChanged(int,int,int)));
hideColumns(hide); hideColumns(hide);
return !m_permissionDenied;
} }
private: private:
@ -140,12 +144,19 @@ private:
connect(service(), &IService::dbErrorDelete, [this](QString msg) { connect(service(), &IService::dbErrorDelete, [this](QString msg) {
QMessageBox::critical(this, tr("Database error"), tr(msg.toStdString().c_str())); 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; m_serviceConnected = true;
} }
} }
bool m_serviceConnected; bool m_serviceConnected;
bool m_permissionDenied;
// IGridForm interface // IGridForm interface
protected: protected:
@ -177,6 +188,7 @@ protected:
void handleDeleteRecord() override void handleDeleteRecord() override
{ {
m_permissionDenied = false;
connectService(); connectService();
if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0) if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0)
{ {
@ -190,8 +202,12 @@ protected:
{ {
QSharedPointer<T> entity = m_tableModel->itemFromIndex(tableView()->currentIndex()); QSharedPointer<T> entity = m_tableModel->itemFromIndex(tableView()->currentIndex());
service()->erase(entity); service()->erase(entity);
m_tableModel->removeRowAt(tableView()->currentIndex());
emit dataChanged(); if (!m_permissionDenied)
{
m_tableModel->removeRowAt(tableView()->currentIndex());
emit dataChanged();
}
} }
} }
}; };

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

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

Loading…
Cancel
Save