diff --git a/mainwindow.cpp b/mainwindow.cpp index 5d6692d..60d05e3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,6 +4,9 @@ #include "QueryResultModel.h" #include "QueryExplainModel.h" #include "sqlhighlighter.h" +#include +#include +#include #include #include #include @@ -124,7 +127,7 @@ MainWindow::~MainWindow() { m_dbConnection.closeConnection(); m_dbConnection.setStateCallback(nullptr); - + delete ui; } void MainWindow::QueueTask(TSQueue::t_Callable c) @@ -378,3 +381,57 @@ void MainWindow::endTimer() updateTimer(); } } + +void MainWindow::on_actionLoad_SQL_triggered() +{ + // + QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory); + QString file_name = QFileDialog::getOpenFileName(this, + tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)")); + if ( ! file_name.isEmpty()) { + QFile file(file_name); + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream(&file); + ui->queryEdit->clear(); + while (!stream.atEnd()){ + QString line = stream.readLine(); + ui->queryEdit->append(line); + } + } + + + } +} + +void MainWindow::on_actionSave_SQL_triggered() +{ + QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory); + QString file_name = QFileDialog::getSaveFileName(this, + tr("Save query"), home_dir, tr("SQL file (*.sql)")); + if ( ! file_name.isEmpty()) { + QFile file(file_name); + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream(&file); + QString text = ui->queryEdit->toPlainText(); + stream << text; + } + } +} + +void MainWindow::on_actionExport_data_triggered() +{ + QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory); + QString file_name = QFileDialog::getSaveFileName(this, + tr("Export data"), home_dir, tr("CSV file (*.csv)")); + +} + +void MainWindow::on_actionClose_triggered() +{ + close(); +} + +void MainWindow::on_actionAbout_triggered() +{ + // +} diff --git a/mainwindow.h b/mainwindow.h index 1c3fe43..c0b9e0c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -57,7 +57,7 @@ private: void endTimer(); - std::unique_ptr ui; + Ui::MainWindow *ui; std::unique_ptr highlighter; ASyncDBConnection m_dbConnection; @@ -83,6 +83,11 @@ private slots: void addLog(QString s); void updateTimer(); + void on_actionLoad_SQL_triggered(); + void on_actionSave_SQL_triggered(); + void on_actionExport_data_triggered(); + void on_actionClose_triggered(); + void on_actionAbout_triggered(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index fe06e4c..66aaeb1 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -187,10 +187,22 @@ - test + File + + + + + + + + + Help + + + @@ -201,6 +213,31 @@ + + + Load SQL + + + + + Save SQL + + + + + Export data + + + + + Close + + + + + About + + diff --git a/ui_mainwindow.h b/ui_mainwindow.h index 2dbdaed..50859f2 100644 --- a/ui_mainwindow.h +++ b/ui_mainwindow.h @@ -36,6 +36,11 @@ QT_BEGIN_NAMESPACE class Ui_MainWindow { public: + QAction *actionLoad_SQL; + QAction *actionSave_SQL; + QAction *actionExport_data; + QAction *actionClose; + QAction *actionAbout; QWidget *centralWidget; QVBoxLayout *verticalLayout; QLineEdit *connectionStringEdit; @@ -57,6 +62,7 @@ public: QPlainTextEdit *edtLog; QMenuBar *menuBar; QMenu *menuTest; + QMenu *menuHelp; QToolBar *mainToolBar; QStatusBar *statusBar; @@ -65,6 +71,16 @@ public: if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QStringLiteral("MainWindow")); MainWindow->resize(726, 589); + actionLoad_SQL = new QAction(MainWindow); + actionLoad_SQL->setObjectName(QStringLiteral("actionLoad_SQL")); + actionSave_SQL = new QAction(MainWindow); + actionSave_SQL->setObjectName(QStringLiteral("actionSave_SQL")); + actionExport_data = new QAction(MainWindow); + actionExport_data->setObjectName(QStringLiteral("actionExport_data")); + actionClose = new QAction(MainWindow); + actionClose->setObjectName(QStringLiteral("actionClose")); + actionAbout = new QAction(MainWindow); + actionAbout->setObjectName(QStringLiteral("actionAbout")); centralWidget = new QWidget(MainWindow); centralWidget->setObjectName(QStringLiteral("centralWidget")); verticalLayout = new QVBoxLayout(centralWidget); @@ -168,6 +184,8 @@ public: menuBar->setGeometry(QRect(0, 0, 726, 25)); menuTest = new QMenu(menuBar); menuTest->setObjectName(QStringLiteral("menuTest")); + menuHelp = new QMenu(menuBar); + menuHelp->setObjectName(QStringLiteral("menuHelp")); MainWindow->setMenuBar(menuBar); mainToolBar = new QToolBar(MainWindow); mainToolBar->setObjectName(QStringLiteral("mainToolBar")); @@ -177,6 +195,13 @@ public: MainWindow->setStatusBar(statusBar); menuBar->addAction(menuTest->menuAction()); + menuBar->addAction(menuHelp->menuAction()); + menuTest->addAction(actionLoad_SQL); + menuTest->addAction(actionSave_SQL); + menuTest->addAction(actionExport_data); + menuTest->addSeparator(); + menuTest->addAction(actionClose); + menuHelp->addAction(actionAbout); retranslateUi(MainWindow); @@ -189,12 +214,18 @@ public: void retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", Q_NULLPTR)); + actionLoad_SQL->setText(QApplication::translate("MainWindow", "Load SQL", Q_NULLPTR)); + actionSave_SQL->setText(QApplication::translate("MainWindow", "Save SQL", Q_NULLPTR)); + actionExport_data->setText(QApplication::translate("MainWindow", "Export data", Q_NULLPTR)); + actionClose->setText(QApplication::translate("MainWindow", "Close", Q_NULLPTR)); + actionAbout->setText(QApplication::translate("MainWindow", "About", Q_NULLPTR)); tabWidget->setTabText(tabWidget->indexOf(messageTab), QApplication::translate("MainWindow", "Messages", Q_NULLPTR)); tabWidget->setTabText(tabWidget->indexOf(dataTab), QApplication::translate("MainWindow", "Data", Q_NULLPTR)); lblTimes->setText(QString()); tabWidget->setTabText(tabWidget->indexOf(explainTab), QApplication::translate("MainWindow", "Explain", Q_NULLPTR)); tabWidget->setTabText(tabWidget->indexOf(logTab), QApplication::translate("MainWindow", "Log", Q_NULLPTR)); - menuTest->setTitle(QApplication::translate("MainWindow", "test", Q_NULLPTR)); + menuTest->setTitle(QApplication::translate("MainWindow", "File", Q_NULLPTR)); + menuHelp->setTitle(QApplication::translate("MainWindow", "Help", Q_NULLPTR)); } // retranslateUi };