From 2f95c2f096e5ac8eaef69154222551893a5569c5 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 12 Feb 2017 08:13:38 +0100 Subject: [PATCH] Started on window for managing the server. --- src/MasterController.cpp | 15 ++++++++++++- src/MasterController.h | 4 ++-- src/ServerWindow.cpp | 14 ++++++++++++ src/ServerWindow.h | 24 +++++++++++++++++++++ src/ServerWindow.ui | 37 ++++++++++++++++++++++++++++++++ src/SqlLexer.cpp | 1 + src/SqlLexer.h | 1 + src/connectionmanagerwindow.cpp | 8 ++++++- src/connectionmanagerwindow.h | 2 ++ src/connectionmanagerwindow.ui | 14 +++++++++++- src/icons/server_edit.png | Bin 0 -> 1495 bytes src/mainwindow.cpp | 11 ++++++++++ src/mainwindow.h | 12 +++++++++++ src/querytab.h | 3 +++ src/resources.qrc | 1 + src/src.pro | 9 +++++--- tests/auto/mycase/tst_mycase.h | 15 +++++++++++++ 17 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 src/ServerWindow.cpp create mode 100644 src/ServerWindow.h create mode 100644 src/ServerWindow.ui create mode 100644 src/icons/server_edit.png 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 0000000000000000000000000000000000000000..8f609e1b2429bb344083a481d7488b484637b604 GIT binary patch literal 1495 zcmV;|1t|K7P)}qt=+bF zzbxD4-~JY=2|GGtvt3tfy815BqMUDu75N7EB6J5X`1$*|LVq=BJ0AUJ_Wk;^2kjr*z~(KFO+ z+;Eswt(r)(zx1g63QeOsC%}1qdXh5>inJ;x@r}rkn@zw4U z<-`~l+^wB(w{@XwbUei(Zfr#Ks3`3H`ydv!Bp_q^(yY*RfWSrWH zF?umj^8uEtFQBpc1|)|QTQ_VJ;7!z9{6*M11r)7HDG-86iyvue6VN3)6ojLD(}T!b z_B=4Qkigdimygiw;mG{&8x(A=4+tJ41%g*#&ckUTD;pQ!%np^(-tbx+vX(CbVwV85 z0{jroEMwP&6clc*3JM-jgsQGm9RNQ5wi=8DJ%&JIHh5SBo~WIN8Ov^iziWa^*l~UW zindgS1P{Clh<*WKi zAvq~>2NFtiknz%UCb&tv%&_x(ie>P?8qjo;i9Y#fGAZ7Hb=Bjs>v}TM4e&xAc;k08 z6G!p6BrMrhWf{ExGNdR~T{D)Vcp6<3Po0Vk;3j`}8sN|N2A4Dx{}P9v5>~-n=a#?& z)&b2-!Q9+wblCJF?~!Tns2U#6os6W?Y&^7-PTw&v_JA`DJI=-;Ze;~*YO9#0!zy?` z2Sf_Is%kiL;A9P+oH@hyoHZR~J2qg{+=W2GtF+GFA@Bpn;rH`1V-dOd5cKX_V5&0c z^FROw=rly~%b%T%BNesC&&$T)A1)xxc^yf!S3|v40Zr+q(O!H}7mI>j4Um*}XdZ>^ z^}9Qe2-S01dUl5$AAT)_UcW?dAWT1Q3X8;mJ+v ze_6d3^u3sLo5n4En{fEJ)SMFM)%uN}?W?0ogB#S_f?T~sByMw_Au$l>dnENJlaW?4 xG9?HDgKmLt$9)^sUWA!9-g^e@@4){83;-*g0n7h@w?O~^002ovPDHLkV1jJ6z@GpB literal 0 HcmV?d00001 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)); +} +