Make double clicking on table in CatalogInspector open crud for selected table/view.
This commit is contained in:
parent
1a2ec6a224
commit
6fdf631fac
8 changed files with 53 additions and 47 deletions
|
|
@ -75,3 +75,8 @@ void CatalogInspector::setNamespaceFilter(NamespaceFilter filter)
|
||||||
}
|
}
|
||||||
// context()->setCaption(this, caption, hint);
|
// context()->setCaption(this, caption, hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CatalogTablesPage *CatalogInspector::tablesPage()
|
||||||
|
{
|
||||||
|
return m_tablesPage;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ public:
|
||||||
|
|
||||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||||
void setNamespaceFilter(NamespaceFilter filter);
|
void setNamespaceFilter(NamespaceFilter filter);
|
||||||
|
|
||||||
|
CatalogTablesPage *tablesPage();
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_tabWidget = nullptr;
|
QTabWidget *m_tabWidget = nullptr;
|
||||||
CatalogTablesPage *m_tablesPage = nullptr;
|
CatalogTablesPage *m_tablesPage = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,14 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
CrudTab::CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
CrudTab::CrudTab(IDatabaseWindow *context, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_context(context)
|
||||||
, ui(new Ui::CrudTab)
|
, ui(new Ui::CrudTab)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_db = open_database;
|
m_db = context->openDatabase();
|
||||||
|
|
||||||
SetTableViewDefault(ui->tableView);
|
SetTableViewDefault(ui->tableView);
|
||||||
|
|
||||||
|
|
@ -50,6 +51,7 @@ void CrudTab::setConfig(Oid oid) //std::shared_ptr<OpenDatabase> db, const PgCla
|
||||||
{
|
{
|
||||||
m_table = *m_db->catalog()->classes()->getByKey(oid);
|
m_table = *m_db->catalog()->classes()->getByKey(oid);
|
||||||
m_crudModel->setConfig(m_db, *m_table);
|
m_crudModel->setConfig(m_db, *m_table);
|
||||||
|
m_context->setTitleForWidget(this, m_table->objectName(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrudTab::refresh()
|
void CrudTab::refresh()
|
||||||
|
|
@ -116,33 +118,4 @@ void CrudTab::initActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//QList<QAction *> CrudTab::actions()
|
// TODO refresh action
|
||||||
//{
|
|
||||||
// return { m_refreshAction };
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
//void CrudPageModule::init()
|
|
||||||
//{
|
|
||||||
// registerModuleAction("open",
|
|
||||||
// [this] (IPluginContentWidgetContext* context,
|
|
||||||
// const ModuleActionParameters ¶ms)
|
|
||||||
// {
|
|
||||||
// moduleAction_open(context, params);
|
|
||||||
// });
|
|
||||||
//}
|
|
||||||
|
|
||||||
//void CrudPageModule::moduleAction_open(
|
|
||||||
// IPluginContentWidgetContext* context,
|
|
||||||
// const ModuleActionParameters ¶ms
|
|
||||||
// )
|
|
||||||
//{
|
|
||||||
// // create new widget for specified table
|
|
||||||
// // hand widget to context for display
|
|
||||||
// CrudTab *ct = new CrudTab(context, this);
|
|
||||||
// context->addContentWidget(ct); // maybe CrudTab should do this
|
|
||||||
// ct->setConfig(params.at("oid").toUInt());
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//REGISTER_PLUGIN_MODULE_CAT(CrudPageModule, "CRUD tool", "pglab.crudpage", "database")
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define CRUDTAB_H
|
#define CRUDTAB_H
|
||||||
|
|
||||||
#include "catalog/PgClass.h"
|
#include "catalog/PgClass.h"
|
||||||
|
#include "IDatabaseWindow.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
@ -16,7 +17,7 @@ class CrudModel;
|
||||||
class CrudTab : public QWidget {
|
class CrudTab : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent = nullptr);
|
explicit CrudTab(IDatabaseWindow *context, QWidget *parent = nullptr);
|
||||||
~CrudTab() override;
|
~CrudTab() override;
|
||||||
|
|
||||||
void setConfig(Oid oid);
|
void setConfig(Oid oid);
|
||||||
|
|
@ -24,6 +25,7 @@ public slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
private:
|
private:
|
||||||
Ui::CrudTab *ui;
|
Ui::CrudTab *ui;
|
||||||
|
IDatabaseWindow *m_context;
|
||||||
|
|
||||||
std::shared_ptr<OpenDatabase> m_db;
|
std::shared_ptr<OpenDatabase> m_db;
|
||||||
std::optional<PgClass> m_table;
|
std::optional<PgClass> m_table;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "DatabaseWindow.h"
|
#include "DatabaseWindow.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "CrudTab.h"
|
||||||
|
#include "widgets/CatalogTablesPage.h"
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "TaskExecutor.h"
|
#include "TaskExecutor.h"
|
||||||
|
|
@ -14,7 +16,6 @@
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
||||||
#include "EditTableWidget.h"
|
#include "EditTableWidget.h"
|
||||||
#include "CatalogInspector.h"
|
|
||||||
#include "CodeGenerator.h"
|
#include "CodeGenerator.h"
|
||||||
#include "QueryTool.h"
|
#include "QueryTool.h"
|
||||||
|
|
||||||
|
|
@ -65,6 +66,13 @@ void DatabaseWindow::newCreateTablePage()
|
||||||
m_tabWidget->addTab(w, "Create table");
|
m_tabWidget->addTab(w, "Create table");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::newCrudPage(Oid tableoid)
|
||||||
|
{
|
||||||
|
CrudTab *ct = new CrudTab(this, this);
|
||||||
|
addPage(ct, "crud");
|
||||||
|
ct->setConfig(tableoid);
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
||||||
{
|
{
|
||||||
// TODO should this call be this direct or should it go through module system
|
// TODO should this call be this direct or should it go through module system
|
||||||
|
|
@ -288,6 +296,15 @@ QAction *DatabaseWindow::seperator()
|
||||||
return ac;
|
return ac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::createCatalogInspector(QString caption, NamespaceFilter filter)
|
||||||
|
{
|
||||||
|
auto ct = new CatalogInspector(m_database, this);
|
||||||
|
addPage(ct, caption);
|
||||||
|
ct->setNamespaceFilter(filter);
|
||||||
|
|
||||||
|
connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DatabaseWindow::catalogLoaded()
|
void DatabaseWindow::catalogLoaded()
|
||||||
|
|
@ -307,6 +324,11 @@ void DatabaseWindow::catalogLoaded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::tableSelected(Oid tableoid)
|
||||||
|
{
|
||||||
|
newCrudPage(tableoid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DatabaseWindow::on_actionAbout_triggered()
|
void DatabaseWindow::on_actionAbout_triggered()
|
||||||
{
|
{
|
||||||
|
|
@ -414,23 +436,17 @@ void DatabaseWindow::on_actionClose_triggered()
|
||||||
|
|
||||||
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
|
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
|
||||||
{
|
{
|
||||||
auto ct = new CatalogInspector(m_database, this);
|
createCatalogInspector("information_schema", NamespaceFilter::InformationSchema);
|
||||||
addPage(ct, "information_schema");
|
|
||||||
ct->setNamespaceFilter(NamespaceFilter::InformationSchema);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::on_actionInspectPgCatalog_triggered()
|
void DatabaseWindow::on_actionInspectPgCatalog_triggered()
|
||||||
{
|
{
|
||||||
auto ct = new CatalogInspector(m_database, this);
|
createCatalogInspector("pg_catalog", NamespaceFilter::PgCatalog);
|
||||||
addPage(ct, "pg_catalog");
|
|
||||||
ct->setNamespaceFilter(NamespaceFilter::PgCatalog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::on_actionInspectUserSchemas_triggered()
|
void DatabaseWindow::on_actionInspectUserSchemas_triggered()
|
||||||
{
|
{
|
||||||
auto ct = new CatalogInspector(m_database, this);
|
createCatalogInspector("Schema", NamespaceFilter::User);
|
||||||
addPage(ct, "Schema");
|
|
||||||
ct->setNamespaceFilter(NamespaceFilter::User);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::on_actionNewSql_triggered()
|
void DatabaseWindow::on_actionNewSql_triggered()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include "ConnectionConfig.h"
|
#include "ConnectionConfig.h"
|
||||||
|
#include "CatalogInspector.h"
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "Pgsql_Connection.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "ControllableTask.h"
|
#include "ControllableTask.h"
|
||||||
|
|
@ -106,13 +107,16 @@ private:
|
||||||
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
||||||
|
|
||||||
void newCreateTablePage();
|
void newCreateTablePage();
|
||||||
|
void newCrudPage(Oid tableoid);
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void initMenus();
|
void initMenus();
|
||||||
|
|
||||||
QAction* seperator();
|
QAction* seperator();
|
||||||
|
void createCatalogInspector(QString caption, NamespaceFilter filter);
|
||||||
private slots:
|
private slots:
|
||||||
void catalogLoaded();
|
void catalogLoaded();
|
||||||
|
void tableSelected(Oid tableoid);
|
||||||
// void tabWidget_tabCloseRequested(int index);
|
// void tabWidget_tabCloseRequested(int index);
|
||||||
// void tabWidget_currentChanged(int index);
|
// void tabWidget_currentChanged(int index);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
|
||||||
|
|
||||||
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
|
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
|
||||||
this, &CatalogTablesPage::tableListTable_layoutChanged);
|
this, &CatalogTablesPage::tableListTable_layoutChanged);
|
||||||
|
|
||||||
|
connect(m_tableView, &QTableView::doubleClicked,
|
||||||
|
this, &CatalogTablesPage::on_tableListTable_doubleClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CatalogTablesPage::retranslateUi(bool /*all*/)
|
void CatalogTablesPage::retranslateUi(bool /*all*/)
|
||||||
|
|
@ -136,13 +139,10 @@ void CatalogTablesPage::tableListTable_layoutChanged(const QList<QPersistentMode
|
||||||
|
|
||||||
void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto row = m_tablesSortFilter->mapToSource(index).row();
|
auto row = m_tablesSortFilter->mapToSource(index).row();
|
||||||
PgClass table = m_tablesModel->getTable(row);
|
PgClass table = m_tablesModel->getTable(row);
|
||||||
if (table.oid() != InvalidOid) {
|
if (table.oid() != InvalidOid) {
|
||||||
// context()->moduleAction("pglab.crudpage", "open", {
|
tableSelected(table.oid());
|
||||||
// { "oid", table.oid() }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include "Pgsql_oids.h"
|
||||||
|
|
||||||
class CatalogConstraintPage;
|
class CatalogConstraintPage;
|
||||||
class CatalogIndexPage;
|
class CatalogIndexPage;
|
||||||
|
|
@ -32,6 +33,9 @@ public:
|
||||||
void setNamespaceFilter(NamespaceFilter filter);
|
void setNamespaceFilter(NamespaceFilter filter);
|
||||||
|
|
||||||
void retranslateUi(bool all = true);
|
void retranslateUi(bool all = true);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void tableSelected(Oid tableoid);
|
||||||
private:
|
private:
|
||||||
PgLabTableView *m_tableView = nullptr;
|
PgLabTableView *m_tableView = nullptr;
|
||||||
TablesTableModel* m_tablesModel = nullptr;
|
TablesTableModel* m_tablesModel = nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue