diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..e4d56b9 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,16 @@ +moc_mainwindow.cpp +moc_mainwindow.o +moc_registerdialog.cpp +moc_registerdialog.o +moc_sqlform.cpp +moc_sqlform.o +moc_tableform.cpp +moc_tableform.o +ui_mainwindow.h +ui_registerdialog.h +ui_sqlform.h +ui_tableform.h +IoSQL +qrc_IoSQL.cpp +qrc_IoSQL.o +IoSQL.pro.user diff --git a/Makefile b/Makefile index bcf7429..dc68a2c 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,21 @@ ############################################################################# # Makefile for building: IoSQL -# Generated by qmake (2.01a) (Qt 4.7.2) on: Wed Jun 22 13:31:58 2011 +# Generated by qmake (2.01a) (Qt 4.7.2) on: Fri Jun 24 13:41:46 2011 # Project: IoSQL.pro # Template: app -# Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro +# Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro ############################################################################# ####### Compiler, tools and options CC = gcc CXX = g++ -DEFINES = -DQT_SQL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) -CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) +DEFINES = -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtSql -I/usr/include/qt4 -I/usr/include/qt4/Qsci -I. -I. LINK = g++ -LFLAGS = +LFLAGS = -Wl,-O1 LIBS = $(SUBLIBS) -L/usr/lib -lqscintilla2 -lQtSql -lQtGui -lQtNetwork -lQtCore -lpthread AR = ar cqs RANLIB = @@ -72,7 +72,7 @@ DIST = /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/features/qt_config.prf \ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/debug.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ /usr/share/qt4/mkspecs/features/default_post.prf \ /usr/share/qt4/mkspecs/features/warn_on.prf \ /usr/share/qt4/mkspecs/features/qt.prf \ @@ -125,7 +125,7 @@ Makefile: IoSQL.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/ /usr/share/qt4/mkspecs/features/qt_config.prf \ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/debug.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ /usr/share/qt4/mkspecs/features/default_post.prf \ /usr/share/qt4/mkspecs/features/warn_on.prf \ /usr/share/qt4/mkspecs/features/qt.prf \ @@ -140,7 +140,7 @@ Makefile: IoSQL.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/ /usr/lib/libQtGui.prl \ /usr/lib/libQtNetwork.prl \ /usr/lib/libQtCore.prl - $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro + $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro /usr/share/qt4/mkspecs/common/g++.conf: /usr/share/qt4/mkspecs/common/unix.conf: /usr/share/qt4/mkspecs/common/linux.conf: @@ -151,7 +151,7 @@ Makefile: IoSQL.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/ /usr/share/qt4/mkspecs/features/qt_config.prf: /usr/share/qt4/mkspecs/features/exclusive_builds.prf: /usr/share/qt4/mkspecs/features/default_pre.prf: -/usr/share/qt4/mkspecs/features/debug.prf: +/usr/share/qt4/mkspecs/features/release.prf: /usr/share/qt4/mkspecs/features/default_post.prf: /usr/share/qt4/mkspecs/features/warn_on.prf: /usr/share/qt4/mkspecs/features/qt.prf: @@ -167,7 +167,7 @@ Makefile: IoSQL.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/ /usr/lib/libQtNetwork.prl: /usr/lib/libQtCore.prl: qmake: FORCE - @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro + @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro dist: @$(CHK_DIR_EXISTS) .tmp/IoSQL1.0.0 || $(MKDIR) .tmp/IoSQL1.0.0 diff --git a/mainwindow.cpp b/mainwindow.cpp index 30e265c..2f7d6f7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -116,26 +116,6 @@ void MainWindow::loadConnection(QString connectionName, QString serverType, QStr QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(connectionName)); item->setIcon(0, QIcon(":/Server/images/server-database-register.png")); ui->DatabaseTreeWidget->addTopLevelItem(item); - QSettings settings; - if (!settings.contains("connection " + connectionName)) - { - QMap connectionMap; - connectionMap.insert("connectionName", connectionName); - connectionMap.insert("serverType", serverType); - connectionMap.insert("serverName", serverName); - connectionMap.insert("serverPort", serverPort); - connectionMap.insert("databaseName", databaseName); - connectionMap.insert("username", username); - connectionMap.insert("password", password); - settings.setValue("connection " + connectionName, connectionMap); - QStringList connectionList; - if (settings.contains("connectionList")) - { - connectionList = settings.value("connectionList").toStringList(); - } - connectionList.append(connectionName); - settings.setValue("connectionList", connectionList); - } } bool MainWindow::setupConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password) @@ -244,6 +224,7 @@ void MainWindow::on_DatabaseRegisterAction_triggered() m_RegisterDialog->username(), m_RegisterDialog->password() ); + m_QueryForm->reloadConnections(); } } @@ -343,6 +324,7 @@ void MainWindow::on_DatabaseDeregisterAction_triggered() } delete item; } + m_QueryForm->reloadConnections(); } } @@ -480,6 +462,7 @@ void MainWindow::on_DatabaseEditAction_triggered() settings.setValue("connection " + connectionName, connectionMap); item->setText(0, connectionName); } + m_QueryForm->reloadConnections(); } } diff --git a/sqlform.cpp b/sqlform.cpp index c400cf9..ed12c22 100644 --- a/sqlform.cpp +++ b/sqlform.cpp @@ -1,5 +1,10 @@ #include "sqlform.h" #include "ui_sqlform.h" +#include +#include +#include +#include +#include #include SqlForm::SqlForm(QWidget *parent) : @@ -18,13 +23,31 @@ SqlForm::SqlForm(QWidget *parent) : } ui->setupUi(this); ui->QueryTextEdit->setLexer(lexer); + m_ConnectionComboBox = new QComboBox(this); + reloadConnections(); + ui->QueryToolBar->addWidget(m_ConnectionComboBox); + m_QueryModel = 0; } SqlForm::~SqlForm() { + delete m_ConnectionComboBox; + delete m_QueryModel; delete ui; } +void SqlForm::reloadConnections() +{ + QSettings settings; + QStringList connectionList = settings.value("connectionList").toStringList(); + m_ConnectionComboBox->clear(); + for (int i = 0; i < connectionList.count(); i++) + { + QMap connectionMap = settings.value("connection " + connectionList.at(i)).toMap(); + m_ConnectionComboBox->addItem(connectionMap.value("connectionName").toString()); + } +} + void SqlForm::changeEvent(QEvent *e) { QWidget::changeEvent(e); @@ -36,3 +59,26 @@ void SqlForm::changeEvent(QEvent *e) break; } } + +void SqlForm::on_RunQueryAction_triggered() +{ + m_Database = QSqlDatabase::database(m_ConnectionComboBox->currentText()); + m_Database.open(); + QCoreApplication::processEvents(); + QString query = ""; + if (m_QueryModel == 0) + { + m_QueryModel = new QSqlQueryModel; + } + if (ui->QueryTextEdit->hasSelectedText()) + { + query = ui->QueryTextEdit->selectedText(); + } + else + { + query = ui->QueryTextEdit->text(); + } + m_QueryModel->setQuery(query, m_Database); + ui->ResultsTableView->setModel(m_QueryModel); + ui->ResultsTableView->resizeColumnsToContents(); +} diff --git a/sqlform.h b/sqlform.h index 2db42bb..40311e7 100644 --- a/sqlform.h +++ b/sqlform.h @@ -2,6 +2,9 @@ #define SQLFORM_H #include +#include +#include +#include #include namespace Ui { @@ -13,12 +16,19 @@ class SqlForm : public QDialog { public: SqlForm(QWidget *parent = 0); ~SqlForm(); + void reloadConnections(); protected: void changeEvent(QEvent *e); +private slots: + void on_RunQueryAction_triggered(); + private: Ui::SqlForm *ui; + QSqlDatabase m_Database; + QSqlQueryModel *m_QueryModel; + QComboBox *m_ConnectionComboBox; }; #endif // SQLFORM_H diff --git a/sqlform.ui b/sqlform.ui index b39c10d..fb80cc9 100644 --- a/sqlform.ui +++ b/sqlform.ui @@ -20,6 +20,30 @@ 0 + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 0 + + + + + + @@ -37,6 +61,21 @@ + + + + :/Table/images/run-build.png:/Table/images/run-build.png + + + Run Query + + + Run the selected SQL query. + + + F5 + + @@ -45,6 +84,8 @@
Qsci/qsciscintilla.h
- + + + diff --git a/tableform.cpp b/tableform.cpp index 21c3464..b50cae6 100644 --- a/tableform.cpp +++ b/tableform.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/tableform.h b/tableform.h index 06a4c33..c3370e7 100644 --- a/tableform.h +++ b/tableform.h @@ -2,7 +2,9 @@ #define TABLEFORM_H #include +#include #include +#include namespace Ui { class TableForm;