Merge branch 'refresh-crudtab' into 'master'

Crud page has now reload action.

See merge request eelke/pgLab!10
This commit is contained in:
Eelke Klein 2019-10-13 05:35:47 +00:00
commit e891ec9d54
4 changed files with 71 additions and 51 deletions

View file

@ -106,16 +106,3 @@ void CrudTab::headerCustomContextMenu(const QPoint &pos)
auto horizontal_header = ui->tableView->horizontalHeader();
menu->popup(horizontal_header->mapToGlobal(pos));
}
void CrudTab::initActions()
{
{
auto ac = new QAction(QIcon(":/icons/script_go.png"), tr("Refresh"), this);
ac->setShortcut(QKeySequence(Qt::Key_F5));
connect(ac, &QAction::triggered, this, &CrudTab::refresh);
m_refreshAction = ac;
}
}
// TODO refresh action

View file

@ -31,29 +31,13 @@ private:
std::optional<PgClass> m_table;
CrudModel *m_crudModel = nullptr;
QAction *m_refreshAction = nullptr;
void initActions();
// virtual QList<QAction *> actions() override;
private slots:
void on_actionRemove_rows_triggered();
void headerCustomContextMenu(const QPoint &pos);
};
//class CrudPageModule: public PluginModule {
// Q_OBJECT
//public:
// using PluginModule::PluginModule;
// void init();
//private slots:
//private:
// void moduleAction_open(IPluginContentWidgetContext* context, const ModuleActionParameters &params);
//};
#endif // CRUDTAB_H

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);

View file

@ -15,6 +15,7 @@ namespace Pgsql {
class Connection;
}
class CrudTab;
class MasterController;
class QCloseEvent;
class OpenDatabase;
@ -48,6 +49,7 @@ public:
virtual void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres) override;
QueryTool *GetActiveQueryTool();
CrudTab *GetActiveCrud();
private:
QTabWidget *m_tabWidget = nullptr;
QToolBar *m_mainToolBar = nullptr;
@ -79,6 +81,7 @@ private:
QAction *actionOpenSql = nullptr;
QAction *actionPasteLangString = nullptr;
QAction *actionRefreshCatalog = nullptr;
QAction *actionRefreshCrud = nullptr;
QAction *actionSaveSql = nullptr;
QAction *actionSaveSqlAs = nullptr;
QAction *actionSaveCopyOfSqlAs = nullptr;
@ -89,6 +92,7 @@ private:
QMenu *menuHelp = nullptr;
QMenu *menuQuery = nullptr;
QMenu *menuCatalog = nullptr;
QMenu *menuCrud = nullptr;
QMenu *menuWindow = nullptr;
@ -109,15 +113,14 @@ private:
QFutureWatcher<LoadCatalog::Result> loadWatcher;
void newCreateTablePage();
void newCrudPage(Oid tableoid);
void createActions();
void initMenus();
QAction* seperator();
void createCatalogInspector(QString caption, NamespaceFilter filter);
void newCreateTablePage();
void newCrudPage(Oid tableoid);
void newCatalogInspectorPage(QString caption, NamespaceFilter filter);
void closeTab(int index);
private slots:
void catalogLoaded();
@ -143,11 +146,13 @@ private slots:
void on_actionOpenSql_triggered();
void on_actionPasteLangString_triggered();
void on_actionRefreshCatalog_triggered();
void on_actionRefreshCrud_triggered();
void on_actionSaveSql_triggered();
void on_actionSaveSqlAs_triggered();
void on_actionSaveCopyOfSqlAs_triggered();
void on_actionShowConnectionManager_triggered();
void on_m_tabWidget_tabCloseRequested(int index);
void on_m_tabWidget_currentChanged(int index);
// IDatabaseWindow interface
public: