Extended the plugin system to allow for dynamic runtime bindings between modules.

As a test implementation, this allows the TablesPage to open a CrudTab for a table/view without
the need for TablesPage, CrudTab and DatabaseWindow to know anything about each other.
This commit is contained in:
eelke 2018-12-31 15:20:55 +01:00
parent f996703937
commit b0cd47ef46
17 changed files with 209 additions and 55 deletions

View file

@ -18,18 +18,17 @@
#include "plugin_support/PluginContentWidget.h"
#include "CodeGenerator.h"
#include "MasterController.h"
#include "CrudTab.h"
#include "WorkManager.h"
#include "ScopeGuard.h"
#include "EditTableWidget.h"
#include "IPluginContentWidgetContext.h"
#include "plugin_support/PluginContentWidgetContextBase.h"
#include "TaskExecutor.h"
namespace pg = Pgsql;
namespace DatabaseWindow_details {
class DatabaseWindowContentContext: public IPluginContentWidgetContext {
class DatabaseWindowContentContext: public PluginContentWidgetContextBase {
public:
explicit DatabaseWindowContentContext(DatabaseWindow *window)
: m_window(window)
@ -54,6 +53,11 @@ namespace DatabaseWindow_details {
{
m_window->statusBar()->showMessage(msg);
}
void addContentWidget(PluginContentWidget *widget) override
{
m_window->addPage(widget, "");
}
private:
DatabaseWindow *m_window;
};
@ -96,13 +100,6 @@ void DatabaseWindow::newCreateTablePage()
ui->tabWidget->addTab(w, "Create table");
}
void DatabaseWindow::newCrudPage(const PgClass &table)
{
CrudTab *ct = new CrudTab(m_context, this);
ct->setConfig(m_database, table);
addPage(ct, table.objectName());
}
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
{
auto cgtab = new CodeGenerator(m_context, this);
@ -110,7 +107,6 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::
addPage(cgtab, "Codegen");
}
QueryTab *DatabaseWindow::GetActiveQueryTab()
{
QWidget *widget = ui->tabWidget->currentWidget();
@ -143,16 +139,16 @@ void DatabaseWindow::catalogLoaded()
//SCOPE_EXIT { loadFuture = {}; };
m_database = loadWatcher.future().result();
auto tt = new TablesPage(this);
auto tt = new TablesPage(m_context, this);
tt->setCatalog(m_database->catalog());
ui->tabWidget->addTab(tt, "Tables");
auto pg_cat_tables = new TablesPage(this);
auto pg_cat_tables = new TablesPage(m_context, this);
pg_cat_tables->setNamespaceFilter(TablesTableModel::PgCatalog);
pg_cat_tables->setCatalog(m_database->catalog());
ui->tabWidget->addTab(pg_cat_tables, "pg_catalog");
auto info_schema_tables = new TablesPage(this);
auto info_schema_tables = new TablesPage(m_context, this);
info_schema_tables->setNamespaceFilter(TablesTableModel::InformationSchema);
info_schema_tables->setCatalog(m_database->catalog());
ui->tabWidget->addTab(info_schema_tables, "information_schema");