More aggressive saving of changes to the connections. Also remove connection
now removes the connection from the file.
This commit is contained in:
parent
ea30dd9c0e
commit
163bb1d513
11 changed files with 258 additions and 8 deletions
|
|
@ -119,7 +119,9 @@ bool ConnectionListModel::setData(const QModelIndex &index, const QVariant &valu
|
|||
if (role == Qt::EditRole) {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
ConnectionConfig& cfg = m_connections.at(row).m_config;
|
||||
auto& elem = m_connections.at(row);
|
||||
elem.m_dirty = true;
|
||||
ConnectionConfig& cfg = elem.m_config;
|
||||
if (col > 0) {
|
||||
result = true;
|
||||
}
|
||||
|
|
@ -200,9 +202,16 @@ bool ConnectionListModel::removeRows(int row, int count, const QModelIndex &pare
|
|||
{
|
||||
bool result = false;
|
||||
if (row >= 0 && row < m_connections.size()) {
|
||||
|
||||
beginRemoveRows(parent, row, row + count -1);
|
||||
SCOPE_EXIT { endRemoveRows(); };
|
||||
|
||||
auto f = m_connections.begin() + row;
|
||||
m_connections.erase(f, f + count);
|
||||
auto l = f + count;
|
||||
deleteFromIni(f, l);
|
||||
m_connections.erase(f, l);
|
||||
result = true;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -242,10 +251,35 @@ void ConnectionListModel::save()
|
|||
{
|
||||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
for (auto e : m_connections) {
|
||||
for (auto& e : m_connections) {
|
||||
settings.beginGroup(e.m_uuid.toString());
|
||||
SCOPE_EXIT { settings.endGroup(); };
|
||||
|
||||
SaveConnectionConfig(settings, e.m_config);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionListModel::save(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_connections.size()) {
|
||||
auto& e = m_connections[index];
|
||||
if (e.m_dirty) {
|
||||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
settings.beginGroup(e.m_uuid.toString());
|
||||
SaveConnectionConfig(settings, e.m_config);
|
||||
settings.sync();
|
||||
e.m_dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionListModel::deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end)
|
||||
{
|
||||
QString file_name = iniFileName();
|
||||
QSettings settings(file_name, QSettings::IniFormat);
|
||||
for (auto i = begin; i != end; ++i) {
|
||||
settings.remove(i->m_uuid.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,12 @@ public:
|
|||
|
||||
void load();
|
||||
void save();
|
||||
|
||||
void save(int index);
|
||||
private:
|
||||
class LijstElem {
|
||||
public:
|
||||
QUuid m_uuid;
|
||||
bool m_dirty = false;
|
||||
ConnectionConfig m_config;
|
||||
|
||||
LijstElem(const QUuid id, const ConnectionConfig &cfg)
|
||||
|
|
@ -44,6 +45,7 @@ private:
|
|||
using t_Connections = std::vector<LijstElem>;
|
||||
t_Connections m_connections;
|
||||
|
||||
void deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end);
|
||||
static QString iniFileName();
|
||||
|
||||
static QString makeLongDescription(const ConnectionConfig &cfg);
|
||||
|
|
|
|||
|
|
@ -38,14 +38,19 @@ void ConnectionManagerWindow::on_actionAdd_Connection_triggered()
|
|||
ConnectionConfig c;
|
||||
c.setName("new");
|
||||
m_listModel->add(c);
|
||||
|
||||
// Select the new row
|
||||
auto idx = m_listModel->index(m_listModel->rowCount() - 1, 0);
|
||||
ui->listView->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
void ConnectionManagerWindow::on_currentChanged(const QModelIndex ¤t,
|
||||
const QModelIndex &previous)
|
||||
{
|
||||
int currow = current.row();
|
||||
|
||||
m_listModel->save(prevSelection);
|
||||
m_mapper->setCurrentIndex(currow);
|
||||
prevSelection = currow;
|
||||
}
|
||||
|
||||
void ConnectionManagerWindow::on_actionDelete_connection_triggered()
|
||||
|
|
@ -75,6 +80,7 @@ void ConnectionManagerWindow::on_actionConnect_triggered()
|
|||
// Open a window for this connection, maybe we should first check the connection?
|
||||
auto ci = ui->listView->selectionModel()->currentIndex();
|
||||
auto cc = m_listModel->get(ci.row());
|
||||
m_listModel->save(ci.row());
|
||||
if (cc.valid()) {
|
||||
auto w = new MainWindow;
|
||||
w->setAttribute( Qt::WA_DeleteOnClose );
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ private:
|
|||
ConnectionListModel *m_listModel = nullptr;
|
||||
QDataWidgetMapper *m_mapper = nullptr;
|
||||
|
||||
int prevSelection = -1;
|
||||
|
||||
void setupWidgetMappings();
|
||||
};
|
||||
|
||||
|
|
|
|||
14
databaseoverviewform.cpp
Normal file
14
databaseoverviewform.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include "databaseoverviewform.h"
|
||||
#include "ui_databaseoverviewform.h"
|
||||
|
||||
DatabaseOverviewForm::DatabaseOverviewForm(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::DatabaseOverviewForm)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
DatabaseOverviewForm::~DatabaseOverviewForm()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
22
databaseoverviewform.h
Normal file
22
databaseoverviewform.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef DATABASEOVERVIEWFORM_H
|
||||
#define DATABASEOVERVIEWFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class DatabaseOverviewForm;
|
||||
}
|
||||
|
||||
class DatabaseOverviewForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatabaseOverviewForm(QWidget *parent = 0);
|
||||
~DatabaseOverviewForm();
|
||||
|
||||
private:
|
||||
Ui::DatabaseOverviewForm *ui;
|
||||
};
|
||||
|
||||
#endif // DATABASEOVERVIEWFORM_H
|
||||
80
databaseoverviewform.ui
Normal file
80
databaseoverviewform.ui
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DatabaseOverviewForm</class>
|
||||
<widget class="QWidget" name="DatabaseOverviewForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>733</width>
|
||||
<height>618</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Schema filter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabTables">
|
||||
<attribute name="title">
|
||||
<string>Tables</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabSequences">
|
||||
<attribute name="title">
|
||||
<string>Sequences</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Functions</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabDomains">
|
||||
<attribute name="title">
|
||||
<string>Domains</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabCollations">
|
||||
<attribute name="title">
|
||||
<string>Collations</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabFTS">
|
||||
<attribute name="title">
|
||||
<string>FTS</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -17,6 +17,9 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
|
|
|
|||
8
dbschema_database.cpp
Normal file
8
dbschema_database.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "dbschema_database.h"
|
||||
|
||||
using namespace dbschema;
|
||||
|
||||
Database::Database()
|
||||
{
|
||||
|
||||
}
|
||||
74
dbschema_database.h
Normal file
74
dbschema_database.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#ifndef DBSCHEMA_DATABASE_H
|
||||
#define DBSCHEMA_DATABASE_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace dbschema {
|
||||
|
||||
class Role {
|
||||
public:
|
||||
int oid;
|
||||
QString rolname;
|
||||
bool super;
|
||||
bool inherit;
|
||||
bool createrole;
|
||||
bool createdb;
|
||||
bool canlogin;
|
||||
bool replication;
|
||||
bool bypassRls;
|
||||
int connLimit;
|
||||
QDateTime validUntil;
|
||||
};
|
||||
|
||||
class Server {
|
||||
public:
|
||||
|
||||
private:
|
||||
using t_RoleList = std::map<int, Role*>;
|
||||
// tablespaces
|
||||
};
|
||||
|
||||
class Schema {
|
||||
int oid;
|
||||
QString schema;
|
||||
};
|
||||
|
||||
class Table {
|
||||
public:
|
||||
int oid;
|
||||
Schema *schema;
|
||||
QString tableName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Holds all the definitions from a single database
|
||||
|
||||
This class is responsible for cleaning up all dynamically allocated objects.
|
||||
*/
|
||||
class Database {
|
||||
public:
|
||||
Database();
|
||||
~Database();
|
||||
|
||||
Database(const Database &) = delete;
|
||||
Database& operator=(const Database &) = delete;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
using t_SchemaList = std::map<int, Schema*>;
|
||||
using t_TableList = std::map<int, Table*>;
|
||||
|
||||
t_SchemaList m_schemas; // Alphabetically ordered
|
||||
t_TableList m_tables;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DBSCHEMA_DATABASE_H
|
||||
11
pglab.pro
11
pglab.pro
|
|
@ -34,7 +34,9 @@ SOURCES += main.cpp\
|
|||
connectionmanagerwindow.cpp \
|
||||
connectionlistmodel.cpp \
|
||||
connectionconfig.cpp \
|
||||
backuprestore.cpp
|
||||
backuprestore.cpp \
|
||||
databaseoverviewform.cpp \
|
||||
dbschema_database.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
serverproperties.h \
|
||||
|
|
@ -54,12 +56,15 @@ HEADERS += mainwindow.h \
|
|||
connectionlistmodel.h \
|
||||
connectionconfig.h \
|
||||
scopeguard.h \
|
||||
expected.h
|
||||
expected.h \
|
||||
databaseoverviewform.h \
|
||||
dbschema_database.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
serverproperties.ui \
|
||||
databasewindow.ui \
|
||||
connectionmanagerwindow.ui
|
||||
connectionmanagerwindow.ui \
|
||||
databaseoverviewform.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue