When files are dropped on a database window open them as sql files.
This commit is contained in:
parent
b04b947633
commit
6d08b40309
3 changed files with 55 additions and 22 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
#include <QMimeData>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
@ -44,6 +45,8 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
initMenus();
|
initMenus();
|
||||||
|
|
||||||
QMetaObject::connectSlotsByName(this);
|
QMetaObject::connectSlotsByName(this);
|
||||||
|
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseWindow::~DatabaseWindow() = default;
|
DatabaseWindow::~DatabaseWindow() = default;
|
||||||
|
|
@ -397,15 +400,30 @@ void DatabaseWindow::closeTab(int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::openSqlFile(QString file_name)
|
||||||
|
{
|
||||||
|
if ( ! file_name.isEmpty()) {
|
||||||
|
auto *ct = new QueryTool(this, this);
|
||||||
|
if (ct->load(file_name)) {
|
||||||
|
ct->addAction(actionExecuteQuery);
|
||||||
|
addPage(ct, ct->title());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete ct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseWindow::catalogLoaded()
|
void DatabaseWindow::catalogLoaded()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
m_database = loadWatcher.future().result();
|
m_database = loadWatcher.future().result();
|
||||||
|
|
||||||
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
||||||
// // TODO open inspector windows
|
// // TODO open inspector windows
|
||||||
// }
|
// }
|
||||||
// newCreateTablePage();
|
// newCreateTablePage();
|
||||||
on_actionNewSql_triggered();
|
on_actionNewSql_triggered();
|
||||||
} catch (const OpenDatabaseException &ex) {
|
} catch (const OpenDatabaseException &ex) {
|
||||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||||
|
|
@ -557,16 +575,7 @@ void DatabaseWindow::on_actionOpenSql_triggered()
|
||||||
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
||||||
QString file_name = QFileDialog::getOpenFileName(this,
|
QString file_name = QFileDialog::getOpenFileName(this,
|
||||||
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()) {
|
openSqlFile(file_name);
|
||||||
auto *ct = new QueryTool(this, this);
|
|
||||||
if (ct->load(file_name)) {
|
|
||||||
ct->addAction(actionExecuteQuery);
|
|
||||||
addPage(ct, ct->title());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
delete ct;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::on_actionPasteLangString_triggered()
|
void DatabaseWindow::on_actionPasteLangString_triggered()
|
||||||
|
|
@ -664,3 +673,19 @@ void DatabaseWindow::showStatusBarMessage(QString message)
|
||||||
{
|
{
|
||||||
statusBar()->showMessage(message);
|
statusBar()->showMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasUrls()) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
foreach (const QUrl &url, event->mimeData()->urls()) {
|
||||||
|
QString file_name = url.toLocalFile();
|
||||||
|
qDebug() << "Dropped file:" << file_name;
|
||||||
|
openSqlFile(file_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,8 @@ private:
|
||||||
void newCatalogInspectorPage(QString caption, NamespaceFilter filter);
|
void newCatalogInspectorPage(QString caption, NamespaceFilter filter);
|
||||||
void newServerInspectorPage();
|
void newServerInspectorPage();
|
||||||
void closeTab(int index);
|
void closeTab(int index);
|
||||||
|
void openSqlFile(QString file_name);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void catalogLoaded();
|
void catalogLoaded();
|
||||||
void tableSelected(Oid tableoid);
|
void tableSelected(Oid tableoid);
|
||||||
|
|
@ -167,6 +169,11 @@ public:
|
||||||
virtual void setIconForWidget(QWidget *widget, QIcon icon) override;
|
virtual void setIconForWidget(QWidget *widget, QIcon icon) override;
|
||||||
virtual std::shared_ptr<OpenDatabase> openDatabase() override;
|
virtual std::shared_ptr<OpenDatabase> openDatabase() override;
|
||||||
virtual void showStatusBarMessage(QString message) override;
|
virtual void showStatusBarMessage(QString message) override;
|
||||||
|
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
virtual void dropEvent(QDropEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged);
|
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged);
|
||||||
|
ui->queryEdit->setAcceptDrops(false);
|
||||||
|
|
||||||
m_queryParamListController = new QueryParamListController(ui->paramTableView, m_context->openDatabase(), this);
|
m_queryParamListController = new QueryParamListController(ui->paramTableView, m_context->openDatabase(), this);
|
||||||
connect(ui->addButton, &QPushButton::clicked, m_queryParamListController,
|
connect(ui->addButton, &QPushButton::clicked, m_queryParamListController,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue