Introduced the MasterController as part of working on loading catalogue information.
Need a central piece to manage the catalogue data per database to prevent loading this multiple times. MasterController is now also used to enable reopening the connection manager from a query window after the connection manager has been closed.
This commit is contained in:
parent
b6d986051b
commit
6370050204
36 changed files with 769 additions and 71 deletions
|
|
@ -1,20 +1,22 @@
|
|||
#include "connectionmanagerwindow.h"
|
||||
#include "ui_connectionmanagerwindow.h"
|
||||
#include "mainwindow.h"
|
||||
#include "MasterController.h"
|
||||
#include <QDataWidgetMapper>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include "connectionlistmodel.h"
|
||||
|
||||
ConnectionManagerWindow::ConnectionManagerWindow(QWidget *parent)
|
||||
ConnectionManagerWindow::ConnectionManagerWindow(MasterController *master, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::ConnectionManagerWindow)
|
||||
, m_listModel(new ConnectionListModel(this))
|
||||
// , m_listModel(new ConnectionListModel(this))
|
||||
, m_masterController(master)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->listView->setModel(m_listModel);
|
||||
ui->listView->setModel(m_masterController->getConnectionListModel());
|
||||
|
||||
setupWidgetMappings();
|
||||
|
||||
|
|
@ -26,10 +28,10 @@ ConnectionManagerWindow::ConnectionManagerWindow(QWidget *parent)
|
|||
|
||||
ConnectionManagerWindow::~ConnectionManagerWindow()
|
||||
{
|
||||
m_listModel->save();
|
||||
// m_listModel->save();
|
||||
|
||||
delete ui;
|
||||
delete m_listModel;
|
||||
// delete m_listModel;
|
||||
delete m_mapper;
|
||||
}
|
||||
|
||||
|
|
@ -37,10 +39,13 @@ void ConnectionManagerWindow::on_actionAdd_Connection_triggered()
|
|||
{
|
||||
ConnectionConfig c;
|
||||
c.setName("new");
|
||||
m_listModel->add(c);
|
||||
//m_listModel->add(c);
|
||||
|
||||
auto clm = m_masterController->getConnectionListModel();
|
||||
clm->add(c);
|
||||
|
||||
// Select the new row
|
||||
auto idx = m_listModel->index(m_listModel->rowCount() - 1, 0);
|
||||
auto idx = clm->index(clm->rowCount() - 1, 0);
|
||||
ui->listView->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +53,8 @@ void ConnectionManagerWindow::on_currentChanged(const QModelIndex ¤t,
|
|||
const QModelIndex &previous)
|
||||
{
|
||||
int currow = current.row();
|
||||
m_listModel->save(prevSelection);
|
||||
auto clm = m_masterController->getConnectionListModel();
|
||||
clm->save(prevSelection);
|
||||
m_mapper->setCurrentIndex(currow);
|
||||
prevSelection = currow;
|
||||
}
|
||||
|
|
@ -57,15 +63,17 @@ void ConnectionManagerWindow::on_actionDelete_connection_triggered()
|
|||
{
|
||||
auto ci = ui->listView->selectionModel()->currentIndex();
|
||||
if (ci.isValid()) {
|
||||
m_listModel->removeRow(ci.row());
|
||||
auto clm = m_masterController->getConnectionListModel();
|
||||
clm->removeRow(ci.row());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConnectionManagerWindow::setupWidgetMappings()
|
||||
{
|
||||
auto clm = m_masterController->getConnectionListModel();
|
||||
m_mapper = new QDataWidgetMapper(this);
|
||||
m_mapper->setModel(m_listModel);
|
||||
m_mapper->setModel(clm);
|
||||
m_mapper->addMapping(ui->edtName, 1);
|
||||
m_mapper->addMapping(ui->edtHost, 2);
|
||||
m_mapper->addMapping(ui->spinPort, 3);
|
||||
|
|
@ -77,12 +85,19 @@ void ConnectionManagerWindow::setupWidgetMappings()
|
|||
|
||||
void ConnectionManagerWindow::on_actionConnect_triggered()
|
||||
{
|
||||
// Open a window for this connection, maybe we should first check the connection?
|
||||
// maybe we should first check the connection?
|
||||
|
||||
// Have we loaded the catalogue?
|
||||
// If not do so now
|
||||
|
||||
|
||||
auto clm = m_masterController->getConnectionListModel();
|
||||
// Open a window for this connection,
|
||||
auto ci = ui->listView->selectionModel()->currentIndex();
|
||||
auto cc = m_listModel->get(ci.row());
|
||||
m_listModel->save(ci.row());
|
||||
auto cc = clm->get(ci.row());
|
||||
clm->save(ci.row());
|
||||
if (cc.valid()) {
|
||||
auto w = new MainWindow;
|
||||
auto w = new MainWindow(m_masterController, nullptr);
|
||||
w->setAttribute( Qt::WA_DeleteOnClose );
|
||||
w->setConfig(cc.get());
|
||||
w->show();
|
||||
|
|
@ -99,3 +114,8 @@ void ConnectionManagerWindow::on_actionQuit_application_triggered()
|
|||
|
||||
//closeAllWindows();
|
||||
}
|
||||
|
||||
void ConnectionManagerWindow::on_actionBackup_database_triggered()
|
||||
{
|
||||
// BACKUP
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue