Add seperate actions for adding and removing connection groups.

This commit is contained in:
eelke 2019-09-01 06:42:21 +02:00
parent dbb6e1ab01
commit 521d3cdaac
10 changed files with 105 additions and 4 deletions

View file

@ -8,6 +8,8 @@
#include "BackupDialog.h"
#include "PasswordPromptDialog.h"
#include "ConnectionConfigurationWidget.h"
#include <QInputDialog>
#include <QMessageBox>
ConnectionController::ConnectionController(MasterController *parent)
@ -52,6 +54,14 @@ namespace {
return dynamic_cast<ConnectionConfig*>(node);
}
ConnectionGroup* getGroupFromModelIndex(QModelIndex index)
{
if (!index.isValid())
return nullptr;
auto node = static_cast<ConnectionNode*>(index.internalPointer());
return dynamic_cast<ConnectionGroup*>(node);
}
}
@ -103,6 +113,34 @@ void ConnectionController::editConnection(QModelIndex index)
}
}
void ConnectionController::addGroup()
{
auto result = QInputDialog::getText(nullptr, tr("Add new connection group"),
tr("Group name"));
if (!result.isEmpty()) {
auto res = m_connectionTreeModel->addGroup(result);
if (std::holds_alternative<QSqlError>(res)) {
QMessageBox::critical(nullptr, tr("Add group failed"),
tr("Failed to add group.\n") +
std::get<QSqlError>(res).text());
}
}
}
void ConnectionController::removeGroup(QModelIndex index)
{
auto group = getGroupFromModelIndex(index);
if (group) {
auto btn = QMessageBox::question(nullptr, tr("Connection group"),
tr("Remove the selected group and all connections contained in the group?"),
QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No),
QMessageBox::NoButton);
if (btn == QMessageBox::Yes) {
m_connectionTreeModel->removeGroup(index.row());
}
}
}
void ConnectionController::openServerWindowForConnection(QModelIndex index)
{
auto config = getConfigFromModelIndex(index);