diff --git a/src/MasterController.cpp b/src/MasterController.cpp index dc91936..47f9f23 100644 --- a/src/MasterController.cpp +++ b/src/MasterController.cpp @@ -2,6 +2,7 @@ #include "connectionmanagerwindow.h" #include "connectionlistmodel.h" #include "MainWindow.h" +#include "ServerWindow.h" MasterController::MasterController(QObject *parent) : QObject(parent) @@ -27,7 +28,7 @@ void MasterController::showConnectionManager() m_connectionManagerWindow->show(); } -void MasterController::openWindowForConnection(int connection_index) +void MasterController::openSqlWindowForConnection(int connection_index) { auto cc = m_connectionListModel->get(connection_index); m_connectionListModel->save(connection_index); @@ -39,3 +40,15 @@ void MasterController::openWindowForConnection(int connection_index) } } + +void MasterController::openServerWindowForConnection(int connection_index) +{ + auto cc = m_connectionListModel->get(connection_index); + m_connectionListModel->save(connection_index); + if (cc.valid()) { + auto w = new ServerWindow(this, nullptr); + w->setAttribute( Qt::WA_DeleteOnClose ); + //w->setConfig(cc.get()); + w->show(); + } +} diff --git a/src/MasterController.h b/src/MasterController.h index d1a465b..0e95e79 100644 --- a/src/MasterController.h +++ b/src/MasterController.h @@ -25,8 +25,8 @@ public: } void showConnectionManager(); - - void openWindowForConnection(int connection_index); + void openSqlWindowForConnection(int connection_index); + void openServerWindowForConnection(int connection_index); signals: diff --git a/src/ServerWindow.cpp b/src/ServerWindow.cpp new file mode 100644 index 0000000..4952415 --- /dev/null +++ b/src/ServerWindow.cpp @@ -0,0 +1,14 @@ +#include "ServerWindow.h" +#include "ui_ServerWindow.h" + +ServerWindow::ServerWindow(MasterController *master, QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ServerWindow) +{ + ui->setupUi(this); +} + +ServerWindow::~ServerWindow() +{ + delete ui; +} diff --git a/src/ServerWindow.h b/src/ServerWindow.h new file mode 100644 index 0000000..1be401b --- /dev/null +++ b/src/ServerWindow.h @@ -0,0 +1,24 @@ +#ifndef SERVERWINDOW_H +#define SERVERWINDOW_H + +#include + +namespace Ui { +class ServerWindow; +} + +class MasterController; + +class ServerWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit ServerWindow(MasterController *master, QWidget *parent = 0); + ~ServerWindow(); + +private: + Ui::ServerWindow *ui; +}; + +#endif // SERVERWINDOW_H diff --git a/src/ServerWindow.ui b/src/ServerWindow.ui new file mode 100644 index 0000000..2f7495c --- /dev/null +++ b/src/ServerWindow.ui @@ -0,0 +1,37 @@ + + + ServerWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + + + + + 0 + 0 + 800 + 23 + + + + + + + + diff --git a/src/SqlLexer.cpp b/src/SqlLexer.cpp index 525cc04..aac2fa0 100644 --- a/src/SqlLexer.cpp +++ b/src/SqlLexer.cpp @@ -131,3 +131,4 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent } return false; } + diff --git a/src/SqlLexer.h b/src/SqlLexer.h index 488fee4..666e121 100644 --- a/src/SqlLexer.h +++ b/src/SqlLexer.h @@ -38,6 +38,7 @@ private: QString m_block; int m_pos = 0; LexerState m_state; + }; #endif // SQLLEXER_H diff --git a/src/connectionmanagerwindow.cpp b/src/connectionmanagerwindow.cpp index 231febd..2a23929 100644 --- a/src/connectionmanagerwindow.cpp +++ b/src/connectionmanagerwindow.cpp @@ -86,7 +86,7 @@ void ConnectionManagerWindow::setupWidgetMappings() void ConnectionManagerWindow::on_actionConnect_triggered() { auto ci = ui->listView->selectionModel()->currentIndex(); - m_masterController->openWindowForConnection(ci.row()); + m_masterController->openSqlWindowForConnection(ci.row()); } void ConnectionManagerWindow::on_actionQuit_application_triggered() @@ -104,3 +104,9 @@ void ConnectionManagerWindow::on_actionBackup_database_triggered() { // BACKUP } + +void ConnectionManagerWindow::on_actionManage_server_triggered() +{ + auto ci = ui->listView->selectionModel()->currentIndex(); + m_masterController->openServerWindowForConnection(ci.row()); +} diff --git a/src/connectionmanagerwindow.h b/src/connectionmanagerwindow.h index f0180d4..df9c4dd 100644 --- a/src/connectionmanagerwindow.h +++ b/src/connectionmanagerwindow.h @@ -34,6 +34,8 @@ private slots: void on_actionBackup_database_triggered(); + void on_actionManage_server_triggered(); + private: Ui::ConnectionManagerWindow *ui; QDataWidgetMapper *m_mapper = nullptr; diff --git a/src/connectionmanagerwindow.ui b/src/connectionmanagerwindow.ui index dc4095d..dbded97 100644 --- a/src/connectionmanagerwindow.ui +++ b/src/connectionmanagerwindow.ui @@ -194,7 +194,7 @@ 0 0 800 - 22 + 23 @@ -223,6 +223,8 @@ false + + @@ -274,6 +276,16 @@ Backup database + + + + :/icons/server_edit.png + + + + Manage server + + diff --git a/src/icons/server_edit.png b/src/icons/server_edit.png new file mode 100644 index 0000000..8f609e1 Binary files /dev/null and b/src/icons/server_edit.png differ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7da0ae0..14cc8d0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -197,6 +197,17 @@ void MainWindow::on_actionCancel_triggered() void MainWindow::closeEvent(QCloseEvent *event) { // TODO collect which files need saving + std::vector files_to_save; + int n = ui->tabWidget->count(); + for (int i = 0; i < n; ++i) { + QWidget *w = ui->tabWidget->widget(i); + QueryTab *qt = dynamic_cast(w); + if (qt) { + if (qt->isChanged()) { + files_to_save.push_back(qt->fileName()); + } + } + } // if (!m_queryTextChanged || continueWithoutSaving()) { // event->accept(); // } diff --git a/src/mainwindow.h b/src/mainwindow.h index 9f53cb2..d20c1f7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -55,6 +55,18 @@ private: MasterController *m_masterController; +// class OpenDocumentController { +// public: + +// private: + +// QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); +// QDir dir(path); +// if (!dir.exists()) { +// dir.mkpath("."); +// } + +// }; QueryTab *GetActiveQueryTab(); diff --git a/src/querytab.h b/src/querytab.h index 7e79085..1aa3456 100644 --- a/src/querytab.h +++ b/src/querytab.h @@ -50,6 +50,9 @@ public: void copyQueryAsCString(); void exportData(const QString &filename); + + QString fileName() const { return m_fileName; } + bool isChanged() const { return m_queryTextChanged; } private: // struct ResultTab { diff --git a/src/resources.qrc b/src/resources.qrc index 86bb166..657d688 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -19,5 +19,6 @@ icons/backups.png icons/page_white_copy.png icons/token_shortland_character.png + icons/server_edit.png diff --git a/src/src.pro b/src/src.pro index 1034bd4..fc37558 100644 --- a/src/src.pro +++ b/src/src.pro @@ -51,7 +51,8 @@ SOURCES += main.cpp\ ParamListModel.cpp \ MainWindow.cpp \ SqlSyntaxHighlighter.cpp \ - SqlLexer.cpp + SqlLexer.cpp \ + ServerWindow.cpp HEADERS += \ sqlparser.h \ @@ -89,7 +90,8 @@ HEADERS += \ ParamListModel.h \ MainWindow.h \ SqlSyntaxHighlighter.h \ - SqlLexer.h + SqlLexer.h \ + ServerWindow.h FORMS += mainwindow.ui \ databasewindow.ui \ @@ -97,7 +99,8 @@ FORMS += mainwindow.ui \ databaseinspectorwidget.ui \ tuplesresultwidget.ui \ querytab.ui \ - backupdialog.ui + backupdialog.ui \ + ServerWindow.ui RESOURCES += \ resources.qrc diff --git a/tests/auto/mycase/tst_mycase.h b/tests/auto/mycase/tst_mycase.h index 0f278e8..bb6df80 100644 --- a/tests/auto/mycase/tst_mycase.h +++ b/tests/auto/mycase/tst_mycase.h @@ -26,3 +26,18 @@ TEST(mycase, lexer) ASSERT_THAT( out, Eq(QString("SELECT")) ); } +TEST(mycase, lexer_quote_in_string) +{ + QString input = " 'abc''def' "; + SqlLexer lexer(input, LexerState::Null); + + int startpos, length; + BasicTokenType tokentype; + QString out; + lexer.nextBasicToken(startpos, length, tokentype, out); + + ASSERT_THAT(startpos, Eq(1)); + ASSERT_THAT(length, Eq(10)); + ASSERT_THAT(tokentype, Eq(BasicTokenType::QuotedString)); +} +