ConnectionManager overhaul

- connection settings are now changed by seperate component currently called in a seperate window
- old settings pane on the right of the connections had been removed
- new edit config button added between new connection and remove connection
This commit is contained in:
eelke 2019-08-24 20:47:32 +02:00
parent 78247c7abe
commit b09e8a6d4b
20 changed files with 836 additions and 733 deletions

View file

@ -1,8 +1,7 @@
#include "ConnectionManagerWindow.h"
#include "ui_ConnectionManagerWindow.h"
//#include "mainwindow.h"
#include "MasterController.h"
#include <QDataWidgetMapper>
#include "ConnectionController.h"
#include <QMessageBox>
#include <QStandardItemModel>
#include "ConnectionListModel.h"
@ -30,43 +29,17 @@ ConnectionManagerWindow::ConnectionManagerWindow(MasterController *master, QWidg
{
ui->setupUi(this);
ui->listView->setModel(m_connectionController->getConnectionListModel());
setupWidgetMappings();
connect(ui->listView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(on_currentChanged(QModelIndex,QModelIndex)));
}
ConnectionManagerWindow::~ConnectionManagerWindow()
{
delete ui;
delete m_mapper;
}
void ConnectionManagerWindow::on_actionAdd_Connection_triggered()
{
auto clm = m_connectionController->getConnectionListModel();
clm->newItem();
// Select the new row
auto idx = clm->index(clm->rowCount() - 1, 0);
ui->listView->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Select);
}
void ConnectionManagerWindow::on_currentChanged(const QModelIndex &current,
const QModelIndex &)
{
int currow = current.row();
auto clm = m_connectionController->getConnectionListModel();
if (prevSelection)
clm->save(*prevSelection);
m_mapper->setCurrentIndex(currow);
if (currow >= 0)
prevSelection = static_cast<size_t>(currow);
else
prevSelection.reset();
m_connectionController->createConnection();
}
void ConnectionManagerWindow::on_actionDelete_connection_triggered()
@ -82,33 +55,18 @@ void ConnectionManagerWindow::on_actionDelete_connection_triggered()
}
}
void ConnectionManagerWindow::setupWidgetMappings()
{
auto clm = m_connectionController->getConnectionListModel();
m_mapper = new QDataWidgetMapper(this);
m_mapper->setModel(clm);
m_mapper->addMapping(ui->edtName, 1);
m_mapper->addMapping(ui->edtHost, 2);
m_mapper->addMapping(ui->spinPort, 3);
m_mapper->addMapping(ui->edtUser, 4);
m_mapper->addMapping(ui->edtDbname, 6);
m_mapper->toFirst();
}
void ConnectionManagerWindow::on_actionConnect_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
if (ci.isValid()) {
auto r = static_cast<size_t>(ci.row());
m_connectionController->openSqlWindowForConnection(r);
m_connectionController->openSqlWindowForConnection(ci.row());
}
}
void ConnectionManagerWindow::on_actionQuit_application_triggered()
{
auto res = QMessageBox::question(this, "pglab",
tr("Close ALL windows?"), QMessageBox::Yes, QMessageBox::No);
tr("Close all windows?"), QMessageBox::Yes, QMessageBox::No);
if (res == QMessageBox::Yes) {
QApplication::quit();
}
@ -129,7 +87,12 @@ void ConnectionManagerWindow::on_actionManage_server_triggered()
void ConnectionManagerWindow::on_listView_activated(const QModelIndex &index)
{
if (index.isValid()) {
auto r = static_cast<size_t>(index.row());
m_connectionController->openSqlWindowForConnection(r);
m_connectionController->openSqlWindowForConnection(index.row());
}
}
void ConnectionManagerWindow::on_actionConfigure_connection_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
m_connectionController->editConnection(ci.row());
}