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);
|
||||
}
|
||||
|
||||
CatalogTablesPage *CatalogInspector::tablesPage()
|
||||
{
|
||||
return m_tablesPage;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ public:
|
|||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
CatalogTablesPage *tablesPage();
|
||||
private:
|
||||
QTabWidget *m_tabWidget = nullptr;
|
||||
CatalogTablesPage *m_tablesPage = nullptr;
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@
|
|||
#include <set>
|
||||
|
||||
|
||||
CrudTab::CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
||||
CrudTab::CrudTab(IDatabaseWindow *context, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_context(context)
|
||||
, ui(new Ui::CrudTab)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_db = open_database;
|
||||
m_db = context->openDatabase();
|
||||
|
||||
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_crudModel->setConfig(m_db, *m_table);
|
||||
m_context->setTitleForWidget(this, m_table->objectName(), "");
|
||||
}
|
||||
|
||||
void CrudTab::refresh()
|
||||
|
|
@ -116,33 +118,4 @@ void CrudTab::initActions()
|
|||
}
|
||||
}
|
||||
|
||||
//QList<QAction *> CrudTab::actions()
|
||||
//{
|
||||
// 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")
|
||||
// TODO refresh action
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define CRUDTAB_H
|
||||
|
||||
#include "catalog/PgClass.h"
|
||||
#include "IDatabaseWindow.h"
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
|
@ -16,7 +17,7 @@ class CrudModel;
|
|||
class CrudTab : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent = nullptr);
|
||||
explicit CrudTab(IDatabaseWindow *context, QWidget *parent = nullptr);
|
||||
~CrudTab() override;
|
||||
|
||||
void setConfig(Oid oid);
|
||||
|
|
@ -24,6 +25,7 @@ public slots:
|
|||
void refresh();
|
||||
private:
|
||||
Ui::CrudTab *ui;
|
||||
IDatabaseWindow *m_context;
|
||||
|
||||
std::shared_ptr<OpenDatabase> m_db;
|
||||
std::optional<PgClass> m_table;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "DatabaseWindow.h"
|
||||
#include "util.h"
|
||||
#include "CrudTab.h"
|
||||
#include "widgets/CatalogTablesPage.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "MasterController.h"
|
||||
#include "TaskExecutor.h"
|
||||
|
|
@ -14,7 +16,6 @@
|
|||
#include <QTableView>
|
||||
|
||||
#include "EditTableWidget.h"
|
||||
#include "CatalogInspector.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "QueryTool.h"
|
||||
|
||||
|
|
@ -65,6 +66,13 @@ void DatabaseWindow::newCreateTablePage()
|
|||
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)
|
||||
{
|
||||
// TODO should this call be this direct or should it go through module system
|
||||
|
|
@ -288,6 +296,15 @@ QAction *DatabaseWindow::seperator()
|
|||
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()
|
||||
|
|
@ -307,6 +324,11 @@ void DatabaseWindow::catalogLoaded()
|
|||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::tableSelected(Oid tableoid)
|
||||
{
|
||||
newCrudPage(tableoid);
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::on_actionAbout_triggered()
|
||||
{
|
||||
|
|
@ -414,23 +436,17 @@ void DatabaseWindow::on_actionClose_triggered()
|
|||
|
||||
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
|
||||
{
|
||||
auto ct = new CatalogInspector(m_database, this);
|
||||
addPage(ct, "information_schema");
|
||||
ct->setNamespaceFilter(NamespaceFilter::InformationSchema);
|
||||
createCatalogInspector("information_schema", NamespaceFilter::InformationSchema);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionInspectPgCatalog_triggered()
|
||||
{
|
||||
auto ct = new CatalogInspector(m_database, this);
|
||||
addPage(ct, "pg_catalog");
|
||||
ct->setNamespaceFilter(NamespaceFilter::PgCatalog);
|
||||
createCatalogInspector("pg_catalog", NamespaceFilter::PgCatalog);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionInspectUserSchemas_triggered()
|
||||
{
|
||||
auto ct = new CatalogInspector(m_database, this);
|
||||
addPage(ct, "Schema");
|
||||
ct->setNamespaceFilter(NamespaceFilter::User);
|
||||
createCatalogInspector("Schema", NamespaceFilter::User);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionNewSql_triggered()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include "ConnectionConfig.h"
|
||||
#include "CatalogInspector.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
#include "ControllableTask.h"
|
||||
|
|
@ -106,13 +107,16 @@ private:
|
|||
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
||||
|
||||
void newCreateTablePage();
|
||||
void newCrudPage(Oid tableoid);
|
||||
|
||||
void createActions();
|
||||
void initMenus();
|
||||
|
||||
QAction* seperator();
|
||||
void createCatalogInspector(QString caption, NamespaceFilter filter);
|
||||
private slots:
|
||||
void catalogLoaded();
|
||||
void tableSelected(Oid tableoid);
|
||||
// void tabWidget_tabCloseRequested(int index);
|
||||
// void tabWidget_currentChanged(int index);
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
|
|||
|
||||
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
|
||||
this, &CatalogTablesPage::tableListTable_layoutChanged);
|
||||
|
||||
connect(m_tableView, &QTableView::doubleClicked,
|
||||
this, &CatalogTablesPage::on_tableListTable_doubleClicked);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::retranslateUi(bool /*all*/)
|
||||
|
|
@ -136,13 +139,10 @@ void CatalogTablesPage::tableListTable_layoutChanged(const QList<QPersistentMode
|
|||
|
||||
void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
|
||||
auto row = m_tablesSortFilter->mapToSource(index).row();
|
||||
PgClass table = m_tablesModel->getTable(row);
|
||||
if (table.oid() != InvalidOid) {
|
||||
// context()->moduleAction("pglab.crudpage", "open", {
|
||||
// { "oid", table.oid() }
|
||||
// });
|
||||
tableSelected(table.oid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <QAbstractItemModel>
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
class CatalogConstraintPage;
|
||||
class CatalogIndexPage;
|
||||
|
|
@ -32,6 +33,9 @@ public:
|
|||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
|
||||
signals:
|
||||
void tableSelected(Oid tableoid);
|
||||
private:
|
||||
PgLabTableView *m_tableView = nullptr;
|
||||
TablesTableModel* m_tablesModel = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue