Crud page has now reload action.

F5 key is bound to the execute query, reload catalog and reload crud
actions. By using addAction to add these actions to the relevant pages
the ambiguity of the shortcut is resolved.
This commit is contained in:
eelke 2019-10-13 07:31:48 +02:00
parent 4278fe6ff4
commit 1a208a6a2d
4 changed files with 71 additions and 51 deletions

View file

@ -63,19 +63,6 @@ void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
m_tabWidget->setTabIcon(index, QIcon(n));
}
void DatabaseWindow::newCreateTablePage()
{
auto w = new EditTableWidget(m_database, this);
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)
{
auto cgtab = new CodeGenerator(this);
@ -90,6 +77,13 @@ QueryTool *DatabaseWindow::GetActiveQueryTool()
return qt;
}
CrudTab *DatabaseWindow::GetActiveCrud()
{
auto widget = m_tabWidget->currentWidget();
auto ct = dynamic_cast<CrudTab*>(widget);
return ct;
}
void DatabaseWindow::setConfig(const ConnectionConfig &config)
{
m_config = config;
@ -158,6 +152,7 @@ void DatabaseWindow::createActions()
auto action = actionExecuteQuery = new QAction(icon, tr("Execute query"), this);
action->setObjectName("actionExecuteQuery");
action->setShortcut(QKeySequence(Qt::Key_F5));
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
}
{
QIcon icon;
@ -225,8 +220,16 @@ void DatabaseWindow::createActions()
{
QIcon icon;
auto action = actionRefreshCatalog = new QAction(icon, tr("Refresh"), this);
action->setShortcut(QKeySequence(Qt::Key_F5));
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
action->setObjectName("actionRefreshCatalog");
}
{
auto action = actionRefreshCrud = new QAction(QIcon(), tr("Refresh"), this);
action->setShortcut(QKeySequence(Qt::Key_F5));
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
action->setObjectName("actionRefreshCrud");
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On);
@ -289,6 +292,11 @@ void DatabaseWindow::initMenus()
actionRefreshCatalog
});
menuCrud = mb->addMenu(tr("CRUD"));
menuCrud->addActions({
actionRefreshCrud
});
menuWindow = mb->addMenu(tr("Window"));
menuWindow->addActions({
actionInspectUserSchemas,
@ -315,14 +323,29 @@ QAction *DatabaseWindow::seperator()
return ac;
}
void DatabaseWindow::createCatalogInspector(QString caption, NamespaceFilter filter)
void DatabaseWindow::newCreateTablePage()
{
auto w = new EditTableWidget(m_database, this);
m_tabWidget->addTab(w, "Create table");
}
void DatabaseWindow::newCrudPage(Oid tableoid)
{
CrudTab *ct = new CrudTab(this, this);
ct->addAction(actionRefreshCrud);
addPage(ct, "crud");
ct->setConfig(tableoid);
}
void DatabaseWindow::newCatalogInspectorPage(QString caption, NamespaceFilter filter)
{
auto ct = new CatalogInspector(m_database, this);
ct->addAction(actionRefreshCatalog);
addPage(ct, caption);
ct->setNamespaceFilter(filter);
connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected);
}
void DatabaseWindow::closeTab(int index)
@ -467,22 +490,23 @@ void DatabaseWindow::on_actionGenerateCode_triggered()
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
{
createCatalogInspector("information_schema", NamespaceFilter::InformationSchema);
newCatalogInspectorPage("information_schema", NamespaceFilter::InformationSchema);
}
void DatabaseWindow::on_actionInspectPgCatalog_triggered()
{
createCatalogInspector("pg_catalog", NamespaceFilter::PgCatalog);
newCatalogInspectorPage("pg_catalog", NamespaceFilter::PgCatalog);
}
void DatabaseWindow::on_actionInspectUserSchemas_triggered()
{
createCatalogInspector("Schema", NamespaceFilter::User);
newCatalogInspectorPage("Schema", NamespaceFilter::User);
}
void DatabaseWindow::on_actionNewSql_triggered()
{
auto *ct = new QueryTool(this, this);
ct->addAction(actionExecuteQuery);
addPage(ct, "query");
ct->newdoc();
}
@ -516,6 +540,14 @@ void DatabaseWindow::on_actionRefreshCatalog_triggered()
m_database->refresh();
}
void DatabaseWindow::on_actionRefreshCrud_triggered()
{
auto crud = GetActiveCrud();
if (crud) {
crud->refresh();
}
}
void DatabaseWindow::on_actionSaveSql_triggered()
{
auto query_tool = GetActiveQueryTool();
@ -550,6 +582,18 @@ void DatabaseWindow::on_m_tabWidget_tabCloseRequested(int index)
closeTab(index);
}
void DatabaseWindow::on_m_tabWidget_currentChanged(int)
{
auto widget = m_tabWidget->currentWidget();
auto qt = dynamic_cast<QueryTool*>(widget);
auto ct = dynamic_cast<CrudTab*>(widget);
auto ci = dynamic_cast<CatalogInspector*>(widget);
menuQuery->menuAction()->setVisible(qt != nullptr);
menuCatalog->menuAction()->setVisible(ci != nullptr);
menuCrud->menuAction()->setVisible(ct != nullptr);
}
void DatabaseWindow::setTitleForWidget(QWidget *widget, QString title, QString hint)
{
int i = m_tabWidget->indexOf(widget);