Made a step in removing knowledge of DatabaseWindow from QueryTab as an effort to move
in the direction of a plugin system. DatabaseWindow now passes a Context to QueryTab and other pages that give those pages an API for passing information up the system without knowing anything about the sytem.
This commit is contained in:
parent
f6ea2ce0a6
commit
2a7e505dbf
13 changed files with 220 additions and 113 deletions
|
|
@ -5,8 +5,8 @@
|
||||||
#include "UserConfiguration.h"
|
#include "UserConfiguration.h"
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
CodeGenerator::CodeGenerator(QWidget *parent) :
|
CodeGenerator::CodeGenerator(IPluginContentWidgetContext *context, QWidget *parent) :
|
||||||
PlgPage(parent),
|
PluginContentWidget(context, parent),
|
||||||
ui(new Ui::CodeGenerator)
|
ui(new Ui::CodeGenerator)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define CODEGENERATOR_H
|
#define CODEGENERATOR_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PlgPage.h"
|
#include "PluginContentWidget.h"
|
||||||
#include "Pgsql_declare.h"
|
#include "Pgsql_declare.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -11,12 +11,12 @@ class CodeGenerator;
|
||||||
|
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class CodeGenerator : public PlgPage
|
class CodeGenerator : public PluginContentWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CodeGenerator(QWidget *parent = nullptr);
|
CodeGenerator(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
|
||||||
~CodeGenerator();
|
~CodeGenerator();
|
||||||
|
|
||||||
void Init(std::shared_ptr<PgDatabaseCatalog> catalog, QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
void Init(std::shared_ptr<PgDatabaseCatalog> catalog, QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
CrudTab::CrudTab(DatabaseWindow *parent)
|
CrudTab::CrudTab(IPluginContentWidgetContext *context, DatabaseWindow *parent)
|
||||||
: PlgPage(parent)
|
: PluginContentWidget(context, parent)
|
||||||
, ui(new Ui::CrudTab)
|
, ui(new Ui::CrudTab)
|
||||||
, m_window(parent)
|
, m_window(parent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "catalog/PgClass.h"
|
#include "catalog/PgClass.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PlgPage.h"
|
#include "PluginContentWidget.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
@ -15,12 +15,12 @@ class OpenDatabase;
|
||||||
class CrudModel;
|
class CrudModel;
|
||||||
class DatabaseWindow;
|
class DatabaseWindow;
|
||||||
|
|
||||||
class CrudTab : public PlgPage
|
class CrudTab : public PluginContentWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CrudTab(DatabaseWindow *parent = 0);
|
explicit CrudTab(IPluginContentWidgetContext *context, DatabaseWindow *parent = 0);
|
||||||
~CrudTab() override;
|
~CrudTab() override;
|
||||||
|
|
||||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,61 @@
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include "QueryTab.h"
|
#include "QueryTab.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "PlgPage.h"
|
#include "PluginContentWidget.h"
|
||||||
#include "CodeGenerator.h"
|
#include "CodeGenerator.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "CrudTab.h"
|
#include "CrudTab.h"
|
||||||
#include "WorkManager.h"
|
#include "WorkManager.h"
|
||||||
#include "ScopeGuard.h"
|
#include "ScopeGuard.h"
|
||||||
#include "EditTableWidget.h"
|
#include "EditTableWidget.h"
|
||||||
|
#include "IPluginContentWidgetContext.h"
|
||||||
|
|
||||||
namespace pg = Pgsql;
|
namespace pg = Pgsql;
|
||||||
|
|
||||||
|
namespace DatabaseWindow_details {
|
||||||
|
|
||||||
|
class DatabaseWindowContentContext: public IPluginContentWidgetContext {
|
||||||
|
public:
|
||||||
|
explicit DatabaseWindowContentContext(DatabaseWindow *window)
|
||||||
|
: m_window(window)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) override
|
||||||
|
{
|
||||||
|
m_window->setTabCaptionForWidget(content, caption, hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIcon(PluginContentWidget *content, const QString &iconname) override
|
||||||
|
{
|
||||||
|
m_window->setTabIcon(content, iconname);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<OpenDatabase> getDatabase() override
|
||||||
|
{
|
||||||
|
return m_window->getDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueueTask(TSQueue::t_Callable c) override
|
||||||
|
{
|
||||||
|
m_window->QueueTask(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void showStatusMessage(const QString &msg) override
|
||||||
|
{
|
||||||
|
m_window->statusBar()->showMessage(msg);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
DatabaseWindow *m_window;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
using namespace DatabaseWindow_details;
|
||||||
|
|
||||||
|
|
||||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
: ASyncWindow(parent)
|
: ASyncWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
|
, m_context(new DatabaseWindowContentContext(this))
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
@ -38,12 +79,13 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
DatabaseWindow::~DatabaseWindow()
|
DatabaseWindow::~DatabaseWindow()
|
||||||
{
|
{
|
||||||
loader.reset();
|
loader.reset();
|
||||||
|
delete m_context;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryTab* DatabaseWindow::newSqlPage()
|
QueryTab* DatabaseWindow::newSqlPage()
|
||||||
{
|
{
|
||||||
QueryTab *qt = new QueryTab(this);
|
QueryTab *qt = new QueryTab(m_context);
|
||||||
qt->setConfig(m_config, m_database->catalog());
|
qt->setConfig(m_config, m_database->catalog());
|
||||||
addPage(qt, "Tab");
|
addPage(qt, "Tab");
|
||||||
qt->newdoc();
|
qt->newdoc();
|
||||||
|
|
@ -59,14 +101,14 @@ void DatabaseWindow::newCreateTablePage()
|
||||||
|
|
||||||
void DatabaseWindow::newCrudPage(const PgClass &table)
|
void DatabaseWindow::newCrudPage(const PgClass &table)
|
||||||
{
|
{
|
||||||
CrudTab *ct = new CrudTab(this);
|
CrudTab *ct = new CrudTab(m_context, this);
|
||||||
ct->setConfig(m_database, table);
|
ct->setConfig(m_database, table);
|
||||||
addPage(ct, table.objectName());
|
addPage(ct, table.objectName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
||||||
{
|
{
|
||||||
auto cgtab = new CodeGenerator(this);
|
auto cgtab = new CodeGenerator(m_context, this);
|
||||||
cgtab->Init(m_database->catalog(), query, dbres);
|
cgtab->Init(m_database->catalog(), query, dbres);
|
||||||
addPage(cgtab, "Codegen");
|
addPage(cgtab, "Codegen");
|
||||||
}
|
}
|
||||||
|
|
@ -195,13 +237,13 @@ void DatabaseWindow::on_actionClose_triggered()
|
||||||
void DatabaseWindow::on_actionAbout_triggered()
|
void DatabaseWindow::on_actionAbout_triggered()
|
||||||
{
|
{
|
||||||
QMessageBox::about(this, "pgLab 0.1", tr(
|
QMessageBox::about(this, "pgLab 0.1", tr(
|
||||||
"Copyrights 2016-2017, Eelke Klein, All Rights Reserved.\n"
|
"Copyrights 2016-2018, Eelke Klein, All Rights Reserved.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
||||||
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
||||||
"FOR A PARTICULAR PURPOSE.\n"
|
"FOR A PARTICULAR PURPOSE.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"This program is dynamically linked with Qt 5.9 Copyright (C) 2017 "
|
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
|
||||||
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
||||||
"\n"
|
"\n"
|
||||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||||
|
|
@ -259,7 +301,7 @@ void DatabaseWindow::on_actionNew_SQL_triggered()
|
||||||
void DatabaseWindow::on_tabWidget_tabCloseRequested(int index)
|
void DatabaseWindow::on_tabWidget_tabCloseRequested(int index)
|
||||||
{
|
{
|
||||||
QWidget *widget = ui->tabWidget->widget(index);
|
QWidget *widget = ui->tabWidget->widget(index);
|
||||||
PlgPage *plg_page = dynamic_cast<PlgPage*>(widget);
|
PluginContentWidget *plg_page = dynamic_cast<PluginContentWidget*>(widget);
|
||||||
if (plg_page) {
|
if (plg_page) {
|
||||||
if (plg_page->canClose()) {
|
if (plg_page->canClose()) {
|
||||||
removePage(plg_page);
|
removePage(plg_page);
|
||||||
|
|
@ -325,7 +367,7 @@ void DatabaseWindow::on_actionCopy_as_raw_Cpp_string_triggered()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::addToolBarButtonsForPage(PlgPage *page)
|
void DatabaseWindow::addToolBarButtonsForPage(PluginContentWidget *page)
|
||||||
{
|
{
|
||||||
std::vector<QAction*> actions = page->getToolbarActions();
|
std::vector<QAction*> actions = page->getToolbarActions();
|
||||||
QList<QAction*> list;
|
QList<QAction*> list;
|
||||||
|
|
@ -335,7 +377,7 @@ void DatabaseWindow::addToolBarButtonsForPage(PlgPage *page)
|
||||||
ui->mainToolBar->addActions(list);
|
ui->mainToolBar->addActions(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::removeToolBarButtonsForPage(PlgPage *page)
|
void DatabaseWindow::removeToolBarButtonsForPage(PluginContentWidget *page)
|
||||||
{
|
{
|
||||||
std::vector<QAction*> actions = page->getToolbarActions();
|
std::vector<QAction*> actions = page->getToolbarActions();
|
||||||
for (auto act : actions) {
|
for (auto act : actions) {
|
||||||
|
|
@ -344,7 +386,7 @@ void DatabaseWindow::removeToolBarButtonsForPage(PlgPage *page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DatabaseWindow::addPage(PlgPage* page, QString caption)
|
void DatabaseWindow::addPage(PluginContentWidget* page, QString caption)
|
||||||
{
|
{
|
||||||
ui->tabWidget->addTab(page, caption);
|
ui->tabWidget->addTab(page, caption);
|
||||||
ui->tabWidget->setCurrentWidget(page);
|
ui->tabWidget->setCurrentWidget(page);
|
||||||
|
|
@ -352,7 +394,7 @@ void DatabaseWindow::addPage(PlgPage* page, QString caption)
|
||||||
//addToolBarButtonsForPage(page);
|
//addToolBarButtonsForPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::removePage(PlgPage *)
|
void DatabaseWindow::removePage(PluginContentWidget *)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -365,10 +407,10 @@ void DatabaseWindow::on_tabWidget_currentChanged(int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add buttons of new page
|
// add buttons of new page
|
||||||
PlgPage * page = nullptr;
|
PluginContentWidget * page = nullptr;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
QWidget *widget = ui->tabWidget->widget(index);
|
QWidget *widget = ui->tabWidget->widget(index);
|
||||||
page = dynamic_cast<PlgPage*>(widget);
|
page = dynamic_cast<PluginContentWidget*>(widget);
|
||||||
if (page) {
|
if (page) {
|
||||||
addToolBarButtonsForPage(page);
|
addToolBarButtonsForPage(page);
|
||||||
}
|
}
|
||||||
|
|
@ -384,3 +426,17 @@ void DatabaseWindow::on_actionGenerate_code_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
||||||
|
{
|
||||||
|
auto index = ui->tabWidget->indexOf(widget);
|
||||||
|
ui->tabWidget->setTabText(index, caption);
|
||||||
|
ui->tabWidget->setTabToolTip(index, hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
||||||
|
{
|
||||||
|
auto index = ui->tabWidget->indexOf(widget);
|
||||||
|
auto n = ":/icons/16x16/" + iconname;
|
||||||
|
ui->tabWidget->setTabIcon(index, QIcon(n));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,11 @@ class MasterController;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class OpenDatabase;
|
class OpenDatabase;
|
||||||
class PgClass;
|
class PgClass;
|
||||||
class PlgPage;
|
class PluginContentWidget;
|
||||||
|
|
||||||
|
namespace DatabaseWindow_details {
|
||||||
|
class DatabaseWindowContentContext;
|
||||||
|
}
|
||||||
|
|
||||||
/** This is the class for windows that handle tasks for a specific database/catalog
|
/** This is the class for windows that handle tasks for a specific database/catalog
|
||||||
*
|
*
|
||||||
|
|
@ -51,15 +55,18 @@ public:
|
||||||
void newCrudPage(const PgClass &table);
|
void newCrudPage(const PgClass &table);
|
||||||
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
||||||
|
|
||||||
|
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
|
||||||
|
void setTabIcon(QWidget *widget, const QString &iconname);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
DatabaseWindow_details::DatabaseWindowContentContext *m_context;
|
||||||
|
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
std::shared_ptr<OpenDatabase> m_database;
|
std::shared_ptr<OpenDatabase> m_database;
|
||||||
|
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
PlgPage *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
||||||
|
|
||||||
class QLoad : public QueuedBackgroundTask {
|
class QLoad : public QueuedBackgroundTask {
|
||||||
public:
|
public:
|
||||||
|
|
@ -99,12 +106,12 @@ private:
|
||||||
void catalogLoaded();
|
void catalogLoaded();
|
||||||
|
|
||||||
/// Called when a newly created page is added to the QTabWidget
|
/// Called when a newly created page is added to the QTabWidget
|
||||||
void addPage(PlgPage* page, QString caption);
|
void addPage(PluginContentWidget* page, QString caption);
|
||||||
/// Called when a page is completely removed from the QTabWidget
|
/// Called when a page is completely removed from the QTabWidget
|
||||||
void removePage(PlgPage *page);
|
void removePage(PluginContentWidget *page);
|
||||||
|
|
||||||
void addToolBarButtonsForPage(PlgPage *page);
|
void addToolBarButtonsForPage(PluginContentWidget *page);
|
||||||
void removeToolBarButtonsForPage(PlgPage *page);
|
void removeToolBarButtonsForPage(PluginContentWidget *page);
|
||||||
//class PageData
|
//class PageData
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
|
|
||||||
44
pglab/IPluginContentWidgetContext.h
Normal file
44
pglab/IPluginContentWidgetContext.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef IPLUGINCONTENTWIDGETCONTEXT_H
|
||||||
|
#define IPLUGINCONTENTWIDGETCONTEXT_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <memory>
|
||||||
|
#include "tsqueue.h"
|
||||||
|
|
||||||
|
class OpenDatabase;
|
||||||
|
class PluginContentWidget;
|
||||||
|
|
||||||
|
/** This class serves to isolate the plugin from the actual construct in which it is
|
||||||
|
* used.
|
||||||
|
*
|
||||||
|
* It provides functions for operating on the context without needing to many details.
|
||||||
|
*/
|
||||||
|
class IPluginContentWidgetContext {
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~IPluginContentWidgetContext() = default;
|
||||||
|
/** Tells the context what to use as a caption for this content widget.
|
||||||
|
*
|
||||||
|
* Depending on the context the caption might not be visible or used as the caption
|
||||||
|
* of a window or tab.
|
||||||
|
*/
|
||||||
|
virtual void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) = 0;
|
||||||
|
/** Tells the context what icon to use.
|
||||||
|
*
|
||||||
|
* In general the icon is used in a similar place as the caption.
|
||||||
|
* \param iconname Assumed to be the name of an iconresource. The system will look for different
|
||||||
|
* sizes under :/icons/<size>/iconname
|
||||||
|
*/
|
||||||
|
virtual void setIcon(PluginContentWidget *content, const QString &iconname) = 0;
|
||||||
|
|
||||||
|
/** Returns an OpenDatabase object the widget can use to access
|
||||||
|
* the database.
|
||||||
|
*/
|
||||||
|
virtual std::shared_ptr<OpenDatabase> getDatabase() = 0;
|
||||||
|
|
||||||
|
virtual void QueueTask(TSQueue::t_Callable c) = 0;
|
||||||
|
|
||||||
|
virtual void showStatusMessage(const QString &msg) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IPLUGINCONTENTWIDGETCONTEXT_H
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#include "PlgPage.h"
|
|
||||||
|
|
||||||
//PglPage::PglPage()
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::vector<QAction*> PlgPage::getToolbarActions()
|
|
||||||
{
|
|
||||||
return std::vector<QAction*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PlgPage::canClose()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
18
pglab/PluginContentWidget.cpp
Normal file
18
pglab/PluginContentWidget.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include "PluginContentWidget.h"
|
||||||
|
|
||||||
|
PluginContentWidget::PluginContentWidget(IPluginContentWidgetContext *context, QWidget* parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, m_context(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<QAction*> PluginContentWidget::getToolbarActions()
|
||||||
|
{
|
||||||
|
return std::vector<QAction*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginContentWidget::canClose()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class IPluginContentWidgetContext;
|
||||||
|
|
||||||
/// Provides a pluggable system for toolbar buttons and menu actions
|
/// Provides a pluggable system for toolbar buttons and menu actions
|
||||||
///
|
///
|
||||||
/// We will need several kind of actions
|
/// We will need several kind of actions
|
||||||
|
|
@ -15,13 +17,17 @@
|
||||||
/// Can we use same groupings for toolbars and menu's
|
/// Can we use same groupings for toolbars and menu's
|
||||||
/// How about additional toolbars?
|
/// How about additional toolbars?
|
||||||
///
|
///
|
||||||
class PlgPage: public QWidget{
|
class PluginContentWidget: public QWidget{
|
||||||
public:
|
public:
|
||||||
using QWidget::QWidget;
|
PluginContentWidget(IPluginContentWidgetContext *context, QWidget* parent = nullptr);
|
||||||
|
|
||||||
/// Returns the toolbar buttons for this page
|
/// Returns the toolbar buttons for this page
|
||||||
virtual std::vector<QAction*> getToolbarActions();
|
virtual std::vector<QAction*> getToolbarActions();
|
||||||
virtual bool canClose();
|
virtual bool canClose();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
IPluginContentWidgetContext *context() { return m_context; }
|
||||||
|
private:
|
||||||
|
IPluginContentWidgetContext *m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGLPAGE_H
|
#endif // PGLPAGE_H
|
||||||
|
|
@ -15,19 +15,18 @@
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include "ExplainTreeModelItem.h"
|
#include "ExplainTreeModelItem.h"
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#include "DatabaseWindow.h"
|
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "catalog/PgDatabaseCatalog.h"
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
#include "QueryParamListController.h"
|
#include "QueryParamListController.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "GlobalIoService.h"
|
#include "GlobalIoService.h"
|
||||||
#include "UserConfiguration.h"
|
#include "UserConfiguration.h"
|
||||||
|
#include "IPluginContentWidgetContext.h"
|
||||||
|
|
||||||
QueryTab::QueryTab(DatabaseWindow *win, QWidget *parent) :
|
QueryTab::QueryTab(IPluginContentWidgetContext *context_, QWidget *parent)
|
||||||
PlgPage(parent),
|
: PluginContentWidget(context_, parent)
|
||||||
ui(new Ui::QueryTab),
|
, ui(new Ui::QueryTab)
|
||||||
m_win(win),
|
, m_dbConnection(*getGlobalAsioIoService())
|
||||||
m_dbConnection(*getGlobalAsioIoService())
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
@ -37,7 +36,7 @@ QueryTab::QueryTab(DatabaseWindow *win, QWidget *parent) :
|
||||||
ui->queryEdit->setFont(UserConfiguration::instance()->codeFont());
|
ui->queryEdit->setFont(UserConfiguration::instance()->codeFont());
|
||||||
|
|
||||||
highlighter = new SqlSyntaxHighlighter(ui->queryEdit->document());
|
highlighter = new SqlSyntaxHighlighter(ui->queryEdit->document());
|
||||||
auto open_database = m_win->getDatabase();
|
auto open_database = context()-> getDatabase();
|
||||||
if (open_database) {
|
if (open_database) {
|
||||||
auto cat = open_database->catalog();
|
auto cat = open_database->catalog();
|
||||||
highlighter->setTypes(*cat->types());
|
highlighter->setTypes(*cat->types());
|
||||||
|
|
@ -64,7 +63,7 @@ void QueryTab::setConfig(const ConnectionConfig &config,
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
m_win->QueueTask([this]() { startConnect(); });
|
context()->QueueTask([this]() { startConnect(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QueryTab::canClose()
|
bool QueryTab::canClose()
|
||||||
|
|
@ -160,7 +159,7 @@ void QueryTab::execute()
|
||||||
|
|
||||||
auto cb = [this](Expected<std::shared_ptr<Pgsql::Result>> res, qint64 elapsedms)
|
auto cb = [this](Expected<std::shared_ptr<Pgsql::Result>> res, qint64 elapsedms)
|
||||||
{
|
{
|
||||||
m_win->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); });
|
context()->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (m_queryParamListController->empty())
|
if (m_queryParamListController->empty())
|
||||||
|
|
@ -203,7 +202,7 @@ void QueryTab::explain(bool analyze)
|
||||||
explain = ExplainRoot::createFromJson(root);
|
explain = ExplainRoot::createFromJson(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_win->QueueTask([this, explain]() { explain_ready(explain); });
|
context()->QueueTask([this, explain]() { explain_ready(explain); });
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +225,7 @@ void QueryTab::setFileName(const QString &filename)
|
||||||
m_fileName = filename;
|
m_fileName = filename;
|
||||||
QFileInfo fileInfo(filename);
|
QFileInfo fileInfo(filename);
|
||||||
QString fn(fileInfo.fileName());
|
QString fn(fileInfo.fileName());
|
||||||
setTabCaption(fn, m_fileName);
|
context()->setCaption(this, fn, m_fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QueryTab::continueWithoutSavingWarning()
|
bool QueryTab::continueWithoutSavingWarning()
|
||||||
|
|
@ -285,27 +284,23 @@ void QueryTab::queryTextChanged()
|
||||||
|
|
||||||
void QueryTab::connectionStateChanged(ASyncDBConnection::State state)
|
void QueryTab::connectionStateChanged(ASyncDBConnection::State state)
|
||||||
{
|
{
|
||||||
QTabWidget *tabwidget = getTabWidget();
|
QString iconname;
|
||||||
if (tabwidget) {
|
switch (state) {
|
||||||
int i = tabwidget->indexOf(this);
|
case ASyncDBConnection::State::NotConnected:
|
||||||
QString iconname;
|
case ASyncDBConnection::State::Connecting:
|
||||||
switch (state) {
|
iconname = "document_red.png";
|
||||||
case ASyncDBConnection::State::NotConnected:
|
break;
|
||||||
case ASyncDBConnection::State::Connecting:
|
case ASyncDBConnection::State::Connected:
|
||||||
iconname = ":/icons/16x16/document_red.png";
|
iconname = "document_green.png";
|
||||||
break;
|
break;
|
||||||
case ASyncDBConnection::State::Connected:
|
case ASyncDBConnection::State::QuerySend:
|
||||||
iconname = ":/icons/16x16/document_green.png";
|
case ASyncDBConnection::State::CancelSend:
|
||||||
break;
|
iconname = "document_yellow.png";
|
||||||
case ASyncDBConnection::State::QuerySend:
|
break;
|
||||||
case ASyncDBConnection::State::CancelSend:
|
case ASyncDBConnection::State::Terminating:
|
||||||
iconname = ":/icons/16x16/document_yellow.png";
|
break;
|
||||||
break;
|
|
||||||
case ASyncDBConnection::State::Terminating:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tabwidget->setTabIcon(i, QIcon(iconname));
|
|
||||||
}
|
}
|
||||||
|
context()->setIcon(this, iconname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -394,9 +389,7 @@ void QueryTab::explain_ready(ExplainRoot::SPtr explain)
|
||||||
ui->explainTreeView->setColumnWidth(6, 600);
|
ui->explainTreeView->setColumnWidth(6, 600);
|
||||||
ui->tabWidget->setCurrentWidget(ui->explainTab);
|
ui->tabWidget->setCurrentWidget(ui->explainTab);
|
||||||
|
|
||||||
auto w = dynamic_cast<QMainWindow*>(this->window());
|
context()->showStatusMessage(tr("Explain ready."));
|
||||||
if (w)
|
|
||||||
w->statusBar()->showMessage(tr("Explain ready."));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addLog("Explain no result");
|
addLog("Explain no result");
|
||||||
|
|
@ -423,26 +416,26 @@ std::string QueryTab::getCommandUtf8() const
|
||||||
return getCommand().toUtf8().data();
|
return getCommand().toUtf8().data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabWidget *QueryTab::getTabWidget()
|
//QTabWidget *QueryTab::getTabWidget()
|
||||||
{
|
//{
|
||||||
QWidget * w = parentWidget();
|
// QWidget * w = parentWidget();
|
||||||
QWidget * p = w->parentWidget();
|
// QWidget * p = w->parentWidget();
|
||||||
QTabWidget *tw = dynamic_cast<QTabWidget*>(p);
|
// QTabWidget *tw = dynamic_cast<QTabWidget*>(p);
|
||||||
return tw;
|
// return tw;
|
||||||
}
|
//}
|
||||||
|
|
||||||
void QueryTab::setTabCaption(const QString &caption, const QString &tooltip)
|
//void QueryTab::setTabCaption(const QString &caption, const QString &tooltip)
|
||||||
{
|
//{
|
||||||
QTabWidget *tabwidget = getTabWidget();
|
// QTabWidget *tabwidget = getTabWidget();
|
||||||
if (tabwidget) {
|
// if (tabwidget) {
|
||||||
int i = tabwidget->indexOf(this);
|
// int i = tabwidget->indexOf(this);
|
||||||
if (i >= 0) {
|
// if (i >= 0) {
|
||||||
tabwidget->setTabText(i, caption);
|
// tabwidget->setTabText(i, caption);
|
||||||
tabwidget->setTabToolTip(i, tooltip);
|
// tabwidget->setTabToolTip(i, tooltip);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qint64 elapsedms)
|
void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qint64 elapsedms)
|
||||||
{
|
{
|
||||||
|
|
@ -609,7 +602,7 @@ void QueryTab::generateCode()
|
||||||
}
|
}
|
||||||
if (resultList.size() == 1) {
|
if (resultList.size() == 1) {
|
||||||
std::shared_ptr<const Pgsql::Result> dbres = resultList[0]->GetPgsqlResult();
|
std::shared_ptr<const Pgsql::Result> dbres = resultList[0]->GetPgsqlResult();
|
||||||
m_win->newCodeGenPage(command, dbres);
|
//context()->newCodeGenPage(command, dbres);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include "tuplesresultwidget.h"
|
#include "tuplesresultwidget.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PlgPage.h"
|
#include "PluginContentWidget.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -22,7 +22,6 @@ namespace Pgsql {
|
||||||
class QTableView;
|
class QTableView;
|
||||||
|
|
||||||
class QTabWidget;
|
class QTabWidget;
|
||||||
class DatabaseWindow;
|
|
||||||
class SqlSyntaxHighlighter;
|
class SqlSyntaxHighlighter;
|
||||||
class ExplainRoot;
|
class ExplainRoot;
|
||||||
class QueryResultModel;
|
class QueryResultModel;
|
||||||
|
|
@ -32,11 +31,11 @@ class OpenDatabase;
|
||||||
class QueryParamListController;
|
class QueryParamListController;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class QueryTab : public PlgPage {
|
class QueryTab : public PluginContentWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QueryTab(DatabaseWindow *win, QWidget *parent = nullptr);
|
QueryTab(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
|
||||||
~QueryTab();
|
~QueryTab() override;
|
||||||
|
|
||||||
void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat);
|
void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat);
|
||||||
|
|
||||||
|
|
@ -69,7 +68,6 @@ private:
|
||||||
using ResultTabContainer = std::vector<TuplesResultWidget*>;
|
using ResultTabContainer = std::vector<TuplesResultWidget*>;
|
||||||
|
|
||||||
Ui::QueryTab *ui;
|
Ui::QueryTab *ui;
|
||||||
DatabaseWindow *m_win;
|
|
||||||
SqlSyntaxHighlighter* highlighter;
|
SqlSyntaxHighlighter* highlighter;
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
StopWatch m_stopwatch;
|
StopWatch m_stopwatch;
|
||||||
|
|
@ -101,8 +99,8 @@ private:
|
||||||
void explain_ready(ExplainRoot::SPtr explain);
|
void explain_ready(ExplainRoot::SPtr explain);
|
||||||
void query_ready(Expected<std::shared_ptr<Pgsql::Result>> dbres, qint64 elapsedms);
|
void query_ready(Expected<std::shared_ptr<Pgsql::Result>> dbres, qint64 elapsedms);
|
||||||
|
|
||||||
QTabWidget *getTabWidget();
|
//QTabWidget *getTabWidget();
|
||||||
void setTabCaption(const QString &caption, const QString &tooltip);
|
//void setTabCaption(const QString &caption, const QString &tooltip);
|
||||||
void clearResult();
|
void clearResult();
|
||||||
void markError(const Pgsql::ErrorDetails &details);
|
void markError(const Pgsql::ErrorDetails &details);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ SOURCES += main.cpp\
|
||||||
Module.cpp \
|
Module.cpp \
|
||||||
EditorGutter.cpp \
|
EditorGutter.cpp \
|
||||||
CodeEditor.cpp \
|
CodeEditor.cpp \
|
||||||
PlgPage.cpp \
|
|
||||||
PropertyProxyModel.cpp \
|
PropertyProxyModel.cpp \
|
||||||
CodeGenerator.cpp \
|
CodeGenerator.cpp \
|
||||||
UserConfiguration.cpp \
|
UserConfiguration.cpp \
|
||||||
|
|
@ -84,7 +83,8 @@ PropertyProxyModel.cpp \
|
||||||
SequenceModel.cpp \
|
SequenceModel.cpp \
|
||||||
SequencesPage.cpp \
|
SequencesPage.cpp \
|
||||||
DatabaseWindow.cpp \
|
DatabaseWindow.cpp \
|
||||||
PgLabTableView.cpp
|
PgLabTableView.cpp \
|
||||||
|
PluginContentWidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
|
|
@ -126,7 +126,6 @@ HEADERS += \
|
||||||
Module.h \
|
Module.h \
|
||||||
EditorGutter.h \
|
EditorGutter.h \
|
||||||
CodeEditor.h \
|
CodeEditor.h \
|
||||||
PlgPage.h \
|
|
||||||
AbstractCommand.h \
|
AbstractCommand.h \
|
||||||
PropertyProxyModel.h \
|
PropertyProxyModel.h \
|
||||||
CustomDataRole.h \
|
CustomDataRole.h \
|
||||||
|
|
@ -146,7 +145,9 @@ CustomDataRole.h \
|
||||||
SequenceModel.h \
|
SequenceModel.h \
|
||||||
SequencesPage.h \
|
SequencesPage.h \
|
||||||
DatabaseWindow.h \
|
DatabaseWindow.h \
|
||||||
PgLabTableView.h
|
PgLabTableView.h \
|
||||||
|
PluginContentWidget.h \
|
||||||
|
IPluginContentWidgetContext.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
ConnectionManagerWindow.ui \
|
ConnectionManagerWindow.ui \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue