Add seperate actions for adding and removing connection groups.
This commit is contained in:
parent
dbb6e1ab01
commit
521d3cdaac
10 changed files with 105 additions and 4 deletions
|
|
@ -8,6 +8,8 @@
|
||||||
#include "BackupDialog.h"
|
#include "BackupDialog.h"
|
||||||
#include "PasswordPromptDialog.h"
|
#include "PasswordPromptDialog.h"
|
||||||
#include "ConnectionConfigurationWidget.h"
|
#include "ConnectionConfigurationWidget.h"
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
ConnectionController::ConnectionController(MasterController *parent)
|
ConnectionController::ConnectionController(MasterController *parent)
|
||||||
|
|
@ -52,6 +54,14 @@ namespace {
|
||||||
return dynamic_cast<ConnectionConfig*>(node);
|
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)
|
void ConnectionController::openServerWindowForConnection(QModelIndex index)
|
||||||
{
|
{
|
||||||
auto config = getConfigFromModelIndex(index);
|
auto config = getConfigFromModelIndex(index);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ public:
|
||||||
/// Starts the form for editing a conncetion.
|
/// Starts the form for editing a conncetion.
|
||||||
/// This function returns immidiatly!
|
/// This function returns immidiatly!
|
||||||
void editConnection(QModelIndex index);
|
void editConnection(QModelIndex index);
|
||||||
|
void addGroup();
|
||||||
|
void removeGroup(QModelIndex index);
|
||||||
private:
|
private:
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
ConnectionList *m_connectionList = nullptr;
|
ConnectionList *m_connectionList = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -726,6 +726,28 @@ std::variant<int, QSqlError> ConnectionTreeModel::addGroup(QString group_name)
|
||||||
return { err };
|
return { err };
|
||||||
}
|
}
|
||||||
return q.lastInsertId().toInt();
|
return q.lastInsertId().toInt();
|
||||||
|
std::optional<QSqlError> ConnectionTreeModel::removeGroup(int row)
|
||||||
|
{
|
||||||
|
beginRemoveRows({}, row, row);
|
||||||
|
SCOPE_EXIT { endRemoveRows(); };
|
||||||
|
auto id = m_groups[row]->conngroup_id;
|
||||||
|
QSqlQuery q(m_db);
|
||||||
|
q.prepare("DELETE FROM connection WHERE conngroup_id=:id");
|
||||||
|
q.bindValue(":id", id);
|
||||||
|
if (!q.exec()) {
|
||||||
|
auto err = q.lastError();
|
||||||
|
return { err };
|
||||||
|
}
|
||||||
|
q.prepare("DELETE FROM conngroup WHERE conngroup_id=:id");
|
||||||
|
q.bindValue(":id", id);
|
||||||
|
if (!q.exec()) {
|
||||||
|
auto err = q.lastError();
|
||||||
|
return { err };
|
||||||
|
}
|
||||||
|
|
||||||
|
m_groups.remove(row);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<QSqlError> ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
std::optional<QSqlError> ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,9 @@ public:
|
||||||
/** Save changed config, group is not allowed to change
|
/** Save changed config, group is not allowed to change
|
||||||
*/
|
*/
|
||||||
void save(const ConnectionConfig &cc);
|
void save(const ConnectionConfig &cc);
|
||||||
|
/// Create a new group in the DB and place in the tree
|
||||||
|
std::variant<int, QSqlError> addGroup(QString group_name);
|
||||||
|
std::optional<QSqlError> removeGroup(int row);
|
||||||
private:
|
private:
|
||||||
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;
|
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;
|
||||||
|
|
||||||
|
|
@ -71,9 +74,6 @@ private:
|
||||||
std::tuple<int, int> findConfig(const QUuid uuid) const;
|
std::tuple<int, int> findConfig(const QUuid uuid) const;
|
||||||
int findGroup(QString name) const;
|
int findGroup(QString name) const;
|
||||||
|
|
||||||
/// Create a new group in the DB and place in the tree
|
|
||||||
/// dataChanged is sent by this function
|
|
||||||
std::variant<int, QSqlError> addGroup(QString group_name);
|
|
||||||
std::optional<QSqlError> saveToDb(const ConnectionConfig &cc);
|
std::optional<QSqlError> saveToDb(const ConnectionConfig &cc);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,3 +89,14 @@ void ConnectionManagerWindow::on_actionConfigure_connection_triggered()
|
||||||
auto ci = ui->treeView->selectionModel()->currentIndex();
|
auto ci = ui->treeView->selectionModel()->currentIndex();
|
||||||
m_connectionController->editConnection(ci);
|
m_connectionController->editConnection(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionManagerWindow::on_actionAdd_group_triggered()
|
||||||
|
{
|
||||||
|
m_connectionController->addGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionManagerWindow::on_actionRemove_group_triggered()
|
||||||
|
{
|
||||||
|
auto ci = ui->treeView->selectionModel()->currentIndex();
|
||||||
|
m_connectionController->removeGroup(ci);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ private slots:
|
||||||
|
|
||||||
void on_actionConfigure_connection_triggered();
|
void on_actionConfigure_connection_triggered();
|
||||||
|
|
||||||
|
void on_actionAdd_group_triggered();
|
||||||
|
|
||||||
|
void on_actionRemove_group_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConnectionManagerWindow *ui;
|
Ui::ConnectionManagerWindow *ui;
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,14 @@ QToolButton {
|
||||||
</attribute>
|
</attribute>
|
||||||
<addaction name="actionConnect"/>
|
<addaction name="actionConnect"/>
|
||||||
<addaction name="actionManage_server"/>
|
<addaction name="actionManage_server"/>
|
||||||
|
<addaction name="actionBackup_database"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionAdd_group"/>
|
||||||
|
<addaction name="actionRemove_group"/>
|
||||||
<addaction name="actionAdd_Connection"/>
|
<addaction name="actionAdd_Connection"/>
|
||||||
<addaction name="actionConfigure_connection"/>
|
<addaction name="actionConfigure_connection"/>
|
||||||
<addaction name="actionDelete_connection"/>
|
<addaction name="actionDelete_connection"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionBackup_database"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionAdd_Connection">
|
<action name="actionAdd_Connection">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
|
|
@ -142,6 +144,26 @@ QToolButton {
|
||||||
<string>Configure connection</string>
|
<string>Configure connection</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionAdd_group">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normalon>:/icons/folder_add.png</normalon>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Add group</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRemove_group">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normalon>:/icons/folder_delete.png</normalon>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove group</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="resources.qrc"/>
|
<include location="resources.qrc"/>
|
||||||
|
|
|
||||||
BIN
pglab/icons/folder_add.png
Normal file
BIN
pglab/icons/folder_add.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
pglab/icons/folder_delete.png
Normal file
BIN
pglab/icons/folder_delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
|
|
@ -29,5 +29,7 @@
|
||||||
<file>icons/constraints/unique.png</file>
|
<file>icons/constraints/unique.png</file>
|
||||||
<file>icons/constraints/index.png</file>
|
<file>icons/constraints/index.png</file>
|
||||||
<file>icons/server_configuration.png</file>
|
<file>icons/server_configuration.png</file>
|
||||||
|
<file>icons/folder_add.png</file>
|
||||||
|
<file>icons/folder_delete.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue