Added menu items for saving, loading, export data, closing window and about.
Saving and loading of SQL and close is implemented.
This commit is contained in:
parent
2db661b7a6
commit
cc5bbab0f5
4 changed files with 134 additions and 4 deletions
|
|
@ -4,6 +4,9 @@
|
||||||
#include "QueryResultModel.h"
|
#include "QueryResultModel.h"
|
||||||
#include "QueryExplainModel.h"
|
#include "QueryExplainModel.h"
|
||||||
#include "sqlhighlighter.h"
|
#include "sqlhighlighter.h"
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QTextStream>
|
||||||
#include <QTextTable>
|
#include <QTextTable>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
@ -124,7 +127,7 @@ MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
m_dbConnection.closeConnection();
|
m_dbConnection.closeConnection();
|
||||||
m_dbConnection.setStateCallback(nullptr);
|
m_dbConnection.setStateCallback(nullptr);
|
||||||
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::QueueTask(TSQueue::t_Callable c)
|
void MainWindow::QueueTask(TSQueue::t_Callable c)
|
||||||
|
|
@ -378,3 +381,57 @@ void MainWindow::endTimer()
|
||||||
updateTimer();
|
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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ private:
|
||||||
void endTimer();
|
void endTimer();
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<Ui::MainWindow> ui;
|
Ui::MainWindow *ui;
|
||||||
std::unique_ptr<SqlHighlighter> highlighter;
|
std::unique_ptr<SqlHighlighter> highlighter;
|
||||||
|
|
||||||
ASyncDBConnection m_dbConnection;
|
ASyncDBConnection m_dbConnection;
|
||||||
|
|
@ -83,6 +83,11 @@ private slots:
|
||||||
|
|
||||||
void addLog(QString s);
|
void addLog(QString s);
|
||||||
void updateTimer();
|
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
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,22 @@
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuTest">
|
<widget class="QMenu" name="menuTest">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>test</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
|
<addaction name="actionLoad_SQL"/>
|
||||||
|
<addaction name="actionSave_SQL"/>
|
||||||
|
<addaction name="actionExport_data"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionClose"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuHelp">
|
||||||
|
<property name="title">
|
||||||
|
<string>Help</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionAbout"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuTest"/>
|
<addaction name="menuTest"/>
|
||||||
|
<addaction name="menuHelp"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="mainToolBar">
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
<attribute name="toolBarArea">
|
<attribute name="toolBarArea">
|
||||||
|
|
@ -201,6 +213,31 @@
|
||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusBar"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
|
<action name="actionLoad_SQL">
|
||||||
|
<property name="text">
|
||||||
|
<string>Load SQL</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave_SQL">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save SQL</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionExport_data">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export data</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionClose">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionAbout">
|
||||||
|
<property name="text">
|
||||||
|
<string>About</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ QT_BEGIN_NAMESPACE
|
||||||
class Ui_MainWindow
|
class Ui_MainWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
QAction *actionLoad_SQL;
|
||||||
|
QAction *actionSave_SQL;
|
||||||
|
QAction *actionExport_data;
|
||||||
|
QAction *actionClose;
|
||||||
|
QAction *actionAbout;
|
||||||
QWidget *centralWidget;
|
QWidget *centralWidget;
|
||||||
QVBoxLayout *verticalLayout;
|
QVBoxLayout *verticalLayout;
|
||||||
QLineEdit *connectionStringEdit;
|
QLineEdit *connectionStringEdit;
|
||||||
|
|
@ -57,6 +62,7 @@ public:
|
||||||
QPlainTextEdit *edtLog;
|
QPlainTextEdit *edtLog;
|
||||||
QMenuBar *menuBar;
|
QMenuBar *menuBar;
|
||||||
QMenu *menuTest;
|
QMenu *menuTest;
|
||||||
|
QMenu *menuHelp;
|
||||||
QToolBar *mainToolBar;
|
QToolBar *mainToolBar;
|
||||||
QStatusBar *statusBar;
|
QStatusBar *statusBar;
|
||||||
|
|
||||||
|
|
@ -65,6 +71,16 @@ public:
|
||||||
if (MainWindow->objectName().isEmpty())
|
if (MainWindow->objectName().isEmpty())
|
||||||
MainWindow->setObjectName(QStringLiteral("MainWindow"));
|
MainWindow->setObjectName(QStringLiteral("MainWindow"));
|
||||||
MainWindow->resize(726, 589);
|
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 = new QWidget(MainWindow);
|
||||||
centralWidget->setObjectName(QStringLiteral("centralWidget"));
|
centralWidget->setObjectName(QStringLiteral("centralWidget"));
|
||||||
verticalLayout = new QVBoxLayout(centralWidget);
|
verticalLayout = new QVBoxLayout(centralWidget);
|
||||||
|
|
@ -168,6 +184,8 @@ public:
|
||||||
menuBar->setGeometry(QRect(0, 0, 726, 25));
|
menuBar->setGeometry(QRect(0, 0, 726, 25));
|
||||||
menuTest = new QMenu(menuBar);
|
menuTest = new QMenu(menuBar);
|
||||||
menuTest->setObjectName(QStringLiteral("menuTest"));
|
menuTest->setObjectName(QStringLiteral("menuTest"));
|
||||||
|
menuHelp = new QMenu(menuBar);
|
||||||
|
menuHelp->setObjectName(QStringLiteral("menuHelp"));
|
||||||
MainWindow->setMenuBar(menuBar);
|
MainWindow->setMenuBar(menuBar);
|
||||||
mainToolBar = new QToolBar(MainWindow);
|
mainToolBar = new QToolBar(MainWindow);
|
||||||
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
|
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
|
||||||
|
|
@ -177,6 +195,13 @@ public:
|
||||||
MainWindow->setStatusBar(statusBar);
|
MainWindow->setStatusBar(statusBar);
|
||||||
|
|
||||||
menuBar->addAction(menuTest->menuAction());
|
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);
|
retranslateUi(MainWindow);
|
||||||
|
|
||||||
|
|
@ -189,12 +214,18 @@ public:
|
||||||
void retranslateUi(QMainWindow *MainWindow)
|
void retranslateUi(QMainWindow *MainWindow)
|
||||||
{
|
{
|
||||||
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", Q_NULLPTR));
|
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(messageTab), QApplication::translate("MainWindow", "Messages", Q_NULLPTR));
|
||||||
tabWidget->setTabText(tabWidget->indexOf(dataTab), QApplication::translate("MainWindow", "Data", Q_NULLPTR));
|
tabWidget->setTabText(tabWidget->indexOf(dataTab), QApplication::translate("MainWindow", "Data", Q_NULLPTR));
|
||||||
lblTimes->setText(QString());
|
lblTimes->setText(QString());
|
||||||
tabWidget->setTabText(tabWidget->indexOf(explainTab), QApplication::translate("MainWindow", "Explain", Q_NULLPTR));
|
tabWidget->setTabText(tabWidget->indexOf(explainTab), QApplication::translate("MainWindow", "Explain", Q_NULLPTR));
|
||||||
tabWidget->setTabText(tabWidget->indexOf(logTab), QApplication::translate("MainWindow", "Log", 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
|
} // retranslateUi
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue