Most of menu is back in its original state before the plugin experiment.

This commit is contained in:
eelke 2019-08-15 19:32:33 +02:00
parent b0fa02455c
commit e2fa613a49
2 changed files with 237 additions and 101 deletions

View file

@ -71,7 +71,14 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::
// auto cgtab = new CodeGenerator(context(), pluginModule(), this); // auto cgtab = new CodeGenerator(context(), pluginModule(), this);
// cgtab->Init(m_database->catalog(), query, dbres); // cgtab->Init(m_database->catalog(), query, dbres);
// addPage(cgtab, "Codegen"); // addPage(cgtab, "Codegen");
// //
}
QueryTool *DatabaseWindow::GetActiveQueryTool()
{
auto widget = m_tabWidget->currentWidget();
auto qt = dynamic_cast<QueryTool*>(widget);
return qt;
} }
void DatabaseWindow::setConfig(const ConnectionConfig &config) void DatabaseWindow::setConfig(const ConnectionConfig &config)
@ -109,6 +116,37 @@ void DatabaseWindow::createActions()
action->setObjectName("actionClose"); action->setObjectName("actionClose");
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
} }
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/page_white_copy.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionCopy = new QAction(icon, tr("Copy"), this);
action->setObjectName("actionCopy");
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionCopyAsCString = new QAction(icon, tr("Copy as C string"), this);
action->setObjectName("actionCopyAsCString");
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C));
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionCopyAsRawCppString = new QAction(icon, tr("Copy as raw C++-string"), this);
action->setObjectName("actionCopyAsRawCppString");
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C));
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/table_save.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionExportData = new QAction(icon, tr("Export data"), this);
action->setObjectName("actionExportData");
}
{
auto action = actionGenerateCode = new QAction(tr("Generate code"), this);
action->setObjectName("actionGenerateCode");
}
{ {
QIcon icon; QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On); icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On);
@ -141,72 +179,170 @@ void DatabaseWindow::createActions()
action->setObjectName("actionOpenSql"); action->setObjectName("actionOpenSql");
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
} }
{
// { QIcon icon;
// auto ca = makeContextAction<QueryTool>(tr("Save SQL"), &QueryTool::save); icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On);
// ca->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); auto action = actionSaveSql = new QAction(icon, tr("Save query"), this);
// ca->setMenuLocation(MenuPath("File/Save")); action->setObjectName("actionSaveSql");
// ca->setToolbarLocation(ToolbarLocation("main", "save")); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// // how we tell the system we want this to become a menu button with this as it's default action }
// registerContextAction(ca); {
// } auto action = actionSaveSqlAs = new QAction(tr("Save query as"), this);
// { action->setObjectName("actionSaveSqlAs");
// auto ca = makeContextAction<QueryTool>(tr("Save SQL as"), &QueryTool::saveAs); }
// ca->setMenuLocation(MenuPath("File/Save")); {
// ca->setToolbarLocation(ToolbarLocation("main", "save")); auto action = actionSaveCopyOfSqlAs = new QAction(tr("Save copy of query as"), this);
// // how we tell the system we want this to become a secondary action for the previous button? action->setObjectName("actionSaveCopyOfSqlAs");
// registerContextAction(ca); }
// } {
// { auto action = actionShowConnectionManager = new QAction(tr("Show connection manager"), this);
// auto ca = makeContextAction<QueryTool>(tr("Save copy of SQL as"), &QueryTool::saveCopyAs); action->setObjectName("actionShowConnectionManager");
// ca->setMenuLocation(MenuPath("File/Save")); }
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
// // how we tell the system we want this to become a secondary action for the previous button?
// registerContextAction(ca);
// }
} }
void DatabaseWindow::initMenus() void DatabaseWindow::initMenus()
{ {
auto seperator = new QAction(this);
seperator->setSeparator(true);
auto mb = new QMenuBar(this); auto mb = new QMenuBar(this);
menuFile = mb->addMenu(tr("File")); menuFile = mb->addMenu(tr("File"));
menuFile->addActions({ menuFile->addActions({
actionNewSql, actionNewSql,
actionOpenSql, actionOpenSql,
seperator, seperator(),
actionInspectUserSchemas, actionSaveSql,
actionInspectPgCatalog, actionSaveSqlAs,
actionInspectInformationSchema, actionSaveCopyOfSqlAs,
seperator, seperator(),
actionClose actionInspectUserSchemas,
actionInspectPgCatalog,
actionInspectInformationSchema,
seperator(),
actionExportData,
seperator(),
actionClose
}); });
menuEdit = mb->addMenu(tr("edit"));
menuEdit->addActions({
actionCopy,
actionCopyAsCString,
actionCopyAsRawCppString,
actionGenerateCode
});
menuWindow = mb->addMenu(tr("Window"));
menuWindow->addActions({
actionShowConnectionManager
});
menuHelp = mb->addMenu(tr("Help")); menuHelp = mb->addMenu(tr("Help"));
menuHelp->addActions({ menuHelp->addActions({
seperator, seperator(),
actionAbout actionAbout
}); });
setMenuBar(mb); setMenuBar(mb);
} }
QAction *DatabaseWindow::seperator()
{
auto ac = new QAction(this);
ac->setSeparator(true);
return ac;
}
void DatabaseWindow::catalogLoaded()
{
try {
m_database = loadWatcher.future().result();
for (auto f : { "user", "pg_catalog", "information_schema" }) {
// TODO open inspector windows
}
newCreateTablePage();
} catch (const OpenDatabaseException &ex) {
QMessageBox::critical(this, "Error reading database", ex.text());
close();
}
}
void DatabaseWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "pgLab 0.1", tr(
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n"
"\n"
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
"FOR A PARTICULAR PURPOSE.\n"
"\n"
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
"\n"
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
"attribution 3.0 license."
));
}
void DatabaseWindow::on_actionCopy_triggered()
{
QWidget *w = QApplication::focusWidget();
QTableView *tv = dynamic_cast<QTableView*>(w);
if (tv) {
copySelectionToClipboard(tv);
}
else {
const QMetaObject *meta = w->metaObject();
int i = meta->indexOfSlot("copy");
if (i != -1) {
QMetaMethod method = meta->method(i);
method.invoke(w, Qt::AutoConnection);
}
}
}
void DatabaseWindow::on_actionCopyAsCString_triggered()
{
auto query_tool = GetActiveQueryTool();
if (query_tool) {
query_tool->copyQueryAsCString();
}
}
void DatabaseWindow::on_actionCopyAsRawCppString_triggered()
{
auto query_tool = GetActiveQueryTool();
if (query_tool) {
query_tool->copyQueryAsRawCppString();
}
}
void DatabaseWindow::on_actionExportData_triggered()
{
auto query_tool = GetActiveQueryTool();
if (query_tool) {
query_tool->exportData();
}
}
void DatabaseWindow::on_actionGenerateCode_triggered()
{
auto query_tool = GetActiveQueryTool();
if (query_tool) {
query_tool->generateCode();
}
}
void DatabaseWindow::on_actionClose_triggered() void DatabaseWindow::on_actionClose_triggered()
{ {
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex()); m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
} }
void DatabaseWindow::on_actionNewSql_triggered()
{
auto *ct = new QueryTool(m_database, this);
addPage(ct, "query");
ct->newdoc();
}
void DatabaseWindow::on_actionInspectInformationSchema_triggered() void DatabaseWindow::on_actionInspectInformationSchema_triggered()
{ {
auto ct = new CatalogInspector(m_database, this); auto ct = new CatalogInspector(m_database, this);
@ -228,6 +364,13 @@ void DatabaseWindow::on_actionInspectUserSchemas_triggered()
ct->setNamespaceFilter(NamespaceFilter::User); ct->setNamespaceFilter(NamespaceFilter::User);
} }
void DatabaseWindow::on_actionNewSql_triggered()
{
auto *ct = new QueryTool(m_database, this);
addPage(ct, "query");
ct->newdoc();
}
void DatabaseWindow::on_actionOpenSql_triggered() void DatabaseWindow::on_actionOpenSql_triggered()
{ {
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory); QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
@ -235,69 +378,41 @@ void DatabaseWindow::on_actionOpenSql_triggered()
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)")); tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
if ( ! file_name.isEmpty()) { if ( ! file_name.isEmpty()) {
auto *ct = new QueryTool(m_database, this); auto *ct = new QueryTool(m_database, this);
addPage(ct, ""); if (ct->load(file_name)) {
if (!ct->load(file_name)) { addPage(ct, "");
// TODO load has failed remove widget or never add it? }
else {
delete ct;
} }
} }
} }
void DatabaseWindow::catalogLoaded() void DatabaseWindow::on_actionSaveSql_triggered()
{ {
try { auto query_tool = GetActiveQueryTool();
m_database = loadWatcher.future().result(); if (query_tool) {
query_tool->save();
for (auto f : { "user", "pg_catalog", "information_schema" }) {
// TODO open inspector windows
}
newCreateTablePage();
} catch (const OpenDatabaseException &ex) {
QMessageBox::critical(this, "Error reading database", ex.text());
close();
} }
} }
void DatabaseWindow::on_actionAbout_triggered() void DatabaseWindow::on_actionSaveSqlAs_triggered()
{ {
QMessageBox::about(this, "pgLab 0.1", tr( auto query_tool = GetActiveQueryTool();
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n" if (query_tool) {
"\n" query_tool->saveAs();
"The program is provided AS IS with NO WARRANTY OF ANY KIND, " }
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
"FOR A PARTICULAR PURPOSE.\n"
"\n"
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
"\n"
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
"attribution 3.0 license."
));
} }
void DatabaseWindow::on_actionShow_connection_manager_triggered() void DatabaseWindow::on_actionSaveCopyOfSqlAs_triggered()
{
auto query_tool = GetActiveQueryTool();
if (query_tool) {
query_tool->saveCopyAs();
}
}
void DatabaseWindow::on_actionShowConnectionManager_triggered()
{ {
m_masterController->showConnectionManager(); m_masterController->showConnectionManager();
} }
void DatabaseWindow::on_actionCopy_triggered()
{
// What should be copied?
QWidget *w = QApplication::focusWidget();
QTableView *tv = dynamic_cast<QTableView*>(w);
if (tv) {
copySelectionToClipboard(tv);
}
else {
const QMetaObject *meta = w->metaObject();
int i = meta->indexOfSlot("copy");
if (i != -1) {
QMetaMethod method = meta->method(i);
method.invoke(w, Qt::AutoConnection);
}
}
}

View file

@ -16,6 +16,7 @@ namespace Pgsql {
class MasterController; class MasterController;
class QCloseEvent; class QCloseEvent;
class OpenDatabase; class OpenDatabase;
class QueryTool;
class PgClass; class PgClass;
class QAction; class QAction;
@ -44,6 +45,8 @@ public:
void addPage(QWidget* page, QString caption); void addPage(QWidget* page, QString caption);
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres); void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
QueryTool *GetActiveQueryTool();
private: private:
QTabWidget *m_tabWidget = nullptr; QTabWidget *m_tabWidget = nullptr;
QToolBar *m_mainToolBar = nullptr; QToolBar *m_mainToolBar = nullptr;
@ -59,15 +62,25 @@ private:
// Standard actions // Standard actions
QAction *actionAbout = nullptr; QAction *actionAbout = nullptr;
QAction *actionClose = nullptr; QAction *actionClose = nullptr;
QAction *actionCopy = nullptr;
QAction *actionCopyAsCString = nullptr;
QAction *actionCopyAsRawCppString = nullptr;
QAction *actionExportData = nullptr;
QAction *actionGenerateCode = nullptr;
QAction *actionInspectInformationSchema = nullptr; ///< Create or switch to pgcatalog tab QAction *actionInspectInformationSchema = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionInspectPgCatalog = nullptr; ///< Create or switch to pgcatalog tab QAction *actionInspectPgCatalog = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionInspectUserSchemas = nullptr; ///< Create or switch to pgcatalog tab QAction *actionInspectUserSchemas = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionNewSql = nullptr; QAction *actionNewSql = nullptr;
QAction *actionOpenSql = nullptr; QAction *actionOpenSql = nullptr;
QAction *actionSaveSql = nullptr;
QAction *actionSaveSqlAs = nullptr;
QAction *actionSaveCopyOfSqlAs = nullptr;
QAction *actionShowConnectionManager = nullptr;
QMenu *menuEdit = nullptr;
QMenu *menuFile = nullptr; QMenu *menuFile = nullptr;
QMenu *menuHelp = nullptr; QMenu *menuHelp = nullptr;
QMenu *menuWindow = nullptr;
class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> { class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> {
@ -92,20 +105,28 @@ private:
void createActions(); void createActions();
void initMenus(); void initMenus();
QAction* seperator();
private slots: private slots:
void catalogLoaded(); void catalogLoaded();
// void tabWidget_tabCloseRequested(int index); // void tabWidget_tabCloseRequested(int index);
// void tabWidget_currentChanged(int index); // void tabWidget_currentChanged(int index);
void on_actionAbout_triggered();
void on_actionClose_triggered(); void on_actionClose_triggered();
void on_actionNewSql_triggered(); void on_actionCopy_triggered();
void on_actionCopyAsCString_triggered();
void on_actionCopyAsRawCppString_triggered();
void on_actionExportData_triggered();
void on_actionGenerateCode_triggered();
void on_actionInspectInformationSchema_triggered(); void on_actionInspectInformationSchema_triggered();
void on_actionInspectPgCatalog_triggered(); void on_actionInspectPgCatalog_triggered();
void on_actionInspectUserSchemas_triggered(); void on_actionInspectUserSchemas_triggered();
void on_actionNewSql_triggered();
void on_actionOpenSql_triggered(); void on_actionOpenSql_triggered();
void on_actionAbout_triggered(); void on_actionSaveSql_triggered();
void on_actionShow_connection_manager_triggered(); void on_actionSaveSqlAs_triggered();
void on_actionCopy_triggered(); void on_actionSaveCopyOfSqlAs_triggered();
void on_actionShowConnectionManager_triggered();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H