diff --git a/connectionlistmodel.cpp b/connectionlistmodel.cpp index 7b7e02c..6a0f087 100644 --- a/connectionlistmodel.cpp +++ b/connectionlistmodel.cpp @@ -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()); + } +} + diff --git a/connectionlistmodel.h b/connectionlistmodel.h index 4397b63..83c2a98 100644 --- a/connectionlistmodel.h +++ b/connectionlistmodel.h @@ -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; t_Connections m_connections; + void deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end); static QString iniFileName(); static QString makeLongDescription(const ConnectionConfig &cfg); diff --git a/connectionmanagerwindow.cpp b/connectionmanagerwindow.cpp index c36850a..0b2cb26 100644 --- a/connectionmanagerwindow.cpp +++ b/connectionmanagerwindow.cpp @@ -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 ); diff --git a/connectionmanagerwindow.h b/connectionmanagerwindow.h index da73943..b6ed175 100644 --- a/connectionmanagerwindow.h +++ b/connectionmanagerwindow.h @@ -34,6 +34,8 @@ private: ConnectionListModel *m_listModel = nullptr; QDataWidgetMapper *m_mapper = nullptr; + int prevSelection = -1; + void setupWidgetMappings(); }; diff --git a/databaseoverviewform.cpp b/databaseoverviewform.cpp new file mode 100644 index 0000000..cbc4c58 --- /dev/null +++ b/databaseoverviewform.cpp @@ -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; +} diff --git a/databaseoverviewform.h b/databaseoverviewform.h new file mode 100644 index 0000000..ea7a733 --- /dev/null +++ b/databaseoverviewform.h @@ -0,0 +1,22 @@ +#ifndef DATABASEOVERVIEWFORM_H +#define DATABASEOVERVIEWFORM_H + +#include + +namespace Ui { +class DatabaseOverviewForm; +} + +class DatabaseOverviewForm : public QWidget +{ + Q_OBJECT + +public: + explicit DatabaseOverviewForm(QWidget *parent = 0); + ~DatabaseOverviewForm(); + +private: + Ui::DatabaseOverviewForm *ui; +}; + +#endif // DATABASEOVERVIEWFORM_H diff --git a/databaseoverviewform.ui b/databaseoverviewform.ui new file mode 100644 index 0000000..8e1fcf6 --- /dev/null +++ b/databaseoverviewform.ui @@ -0,0 +1,80 @@ + + + DatabaseOverviewForm + + + + 0 + 0 + 733 + 618 + + + + Form + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Schema filter + + + + + + + + + + + + + 0 + + + + Tables + + + + + Sequences + + + + + Functions + + + + + Domains + + + + + Collations + + + + + FTS + + + + + + + + + diff --git a/databasewindow.ui b/databasewindow.ui index 516bae8..e3b9de2 100644 --- a/databasewindow.ui +++ b/databasewindow.ui @@ -17,6 +17,9 @@ + + 0 + Tab 1 diff --git a/dbschema_database.cpp b/dbschema_database.cpp new file mode 100644 index 0000000..09b6029 --- /dev/null +++ b/dbschema_database.cpp @@ -0,0 +1,8 @@ +#include "dbschema_database.h" + +using namespace dbschema; + +Database::Database() +{ + +} diff --git a/dbschema_database.h b/dbschema_database.h new file mode 100644 index 0000000..5b30eb9 --- /dev/null +++ b/dbschema_database.h @@ -0,0 +1,74 @@ +#ifndef DBSCHEMA_DATABASE_H +#define DBSCHEMA_DATABASE_H + +#include +#include +#include + + +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; + // 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; + using t_TableList = std::map; + + t_SchemaList m_schemas; // Alphabetically ordered + t_TableList m_tables; + + + }; + +} + +#endif // DBSCHEMA_DATABASE_H diff --git a/pglab.pro b/pglab.pro index 1bf2282..57cb70b 100644 --- a/pglab.pro +++ b/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