commit ee9de663805c5f4f96390804c692a56aec2b32d8 Author: Raoul Snyman Date: Fri Jun 24 13:05:56 2011 +0200 Initial Import. diff --git a/IoSQL.pro b/IoSQL.pro new file mode 100644 index 0000000..a1da6f2 --- /dev/null +++ b/IoSQL.pro @@ -0,0 +1,23 @@ +# ------------------------------------------------- +# Project created by QtCreator 2010-02-10T18:56:54 +# ------------------------------------------------- +QT += network \ + sql +TARGET = IoSQL +TEMPLATE = app +SOURCES += main.cpp \ + mainwindow.cpp \ + registerdialog.cpp \ + tableform.cpp \ + sqlform.cpp +HEADERS += mainwindow.h \ + registerdialog.h \ + tableform.h \ + sqlform.h +FORMS += mainwindow.ui \ + registerdialog.ui \ + tableform.ui \ + sqlform.ui +RESOURCES += IoSQL.qrc +INCLUDEPATH += /usr/include/qt4/Qsci +LIBS += -lqscintilla2 diff --git a/IoSQL.qrc b/IoSQL.qrc new file mode 100644 index 0000000..0f2e64c --- /dev/null +++ b/IoSQL.qrc @@ -0,0 +1,26 @@ + + + images/table/delete-column.png + images/table/delete-row.png + images/table/commit.png + images/table/rollback.png + images/table/insert-column.png + images/table/insert-row.png + images/table/list.png + images/table/table.png + images/table/icon.png + images/run-build.png + + + images/server-database-register.png + images/server-database-deregister.png + images/server-database-edit.png + + + images/view/list.png + images/view/view.png + + + images/general/refresh.png + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bcf7429 --- /dev/null +++ b/Makefile @@ -0,0 +1,310 @@ +############################################################################# +# Makefile for building: IoSQL +# Generated by qmake (2.01a) (Qt 4.7.2) on: Wed Jun 22 13:31:58 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 +############################################################################# + +####### 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) +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 = +LIBS = $(SUBLIBS) -L/usr/lib -lqscintilla2 -lQtSql -lQtGui -lQtNetwork -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/bin/qmake +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = main.cpp \ + mainwindow.cpp \ + registerdialog.cpp \ + tableform.cpp \ + sqlform.cpp moc_mainwindow.cpp \ + moc_registerdialog.cpp \ + moc_tableform.cpp \ + moc_sqlform.cpp \ + qrc_IoSQL.cpp +OBJECTS = main.o \ + mainwindow.o \ + registerdialog.o \ + tableform.o \ + sqlform.o \ + moc_mainwindow.o \ + moc_registerdialog.o \ + moc_tableform.o \ + moc_sqlform.o \ + qrc_IoSQL.o +DIST = /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ + /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /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/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + IoSQL.pro +QMAKE_TARGET = IoSQL +DESTDIR = +TARGET = IoSQL + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): ui_mainwindow.h ui_registerdialog.h ui_tableform.h ui_sqlform.h $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: IoSQL.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ + /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /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/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/libQtSql.prl \ + /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 +/usr/share/qt4/mkspecs/common/g++.conf: +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/modules/qt_phonon.pri: +/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/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/default_post.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/share/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/libQtSql.prl: +/usr/lib/libQtGui.prl: +/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 + +dist: + @$(CHK_DIR_EXISTS) .tmp/IoSQL1.0.0 || $(MKDIR) .tmp/IoSQL1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/IoSQL1.0.0/ && $(COPY_FILE) --parents mainwindow.h registerdialog.h tableform.h sqlform.h .tmp/IoSQL1.0.0/ && $(COPY_FILE) --parents IoSQL.qrc .tmp/IoSQL1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp registerdialog.cpp tableform.cpp sqlform.cpp .tmp/IoSQL1.0.0/ && $(COPY_FILE) --parents mainwindow.ui registerdialog.ui tableform.ui sqlform.ui .tmp/IoSQL1.0.0/ && (cd `dirname .tmp/IoSQL1.0.0` && $(TAR) IoSQL1.0.0.tar IoSQL1.0.0 && $(COMPRESS) IoSQL1.0.0.tar) && $(MOVE) `dirname .tmp/IoSQL1.0.0`/IoSQL1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/IoSQL1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +check: first + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_mainwindow.cpp moc_registerdialog.cpp moc_tableform.cpp moc_sqlform.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_mainwindow.cpp moc_registerdialog.cpp moc_tableform.cpp moc_sqlform.cpp +moc_mainwindow.cpp: registerdialog.h \ + sqlform.h \ + mainwindow.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp + +moc_registerdialog.cpp: registerdialog.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) registerdialog.h -o moc_registerdialog.cpp + +moc_tableform.cpp: tableform.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) tableform.h -o moc_tableform.cpp + +moc_sqlform.cpp: sqlform.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) sqlform.h -o moc_sqlform.cpp + +compiler_rcc_make_all: qrc_IoSQL.cpp +compiler_rcc_clean: + -$(DEL_FILE) qrc_IoSQL.cpp +qrc_IoSQL.cpp: IoSQL.qrc \ + images/general/refresh.png \ + images/run-build.png \ + images/table/rollback.png \ + images/table/commit.png \ + images/table/table.png \ + images/table/list.png \ + images/table/icon.png \ + images/table/delete-column.png \ + images/table/insert-row.png \ + images/table/insert-column.png \ + images/table/delete-row.png \ + images/view/list.png \ + images/view/view.png \ + images/server-database-edit.png \ + images/server-database-register.png \ + images/server-database-deregister.png + /usr/bin/rcc -name IoSQL IoSQL.qrc -o qrc_IoSQL.cpp + +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: ui_mainwindow.h ui_registerdialog.h ui_tableform.h ui_sqlform.h +compiler_uic_clean: + -$(DEL_FILE) ui_mainwindow.h ui_registerdialog.h ui_tableform.h ui_sqlform.h +ui_mainwindow.h: mainwindow.ui + /usr/bin/uic-qt4 mainwindow.ui -o ui_mainwindow.h + +ui_registerdialog.h: registerdialog.ui + /usr/bin/uic-qt4 registerdialog.ui -o ui_registerdialog.h + +ui_tableform.h: tableform.ui + /usr/bin/uic-qt4 tableform.ui -o ui_tableform.h + +ui_sqlform.h: sqlform.ui + /usr/bin/uic-qt4 sqlform.ui -o ui_sqlform.h + +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean + +####### Compile + +main.o: main.cpp mainwindow.h \ + registerdialog.h \ + sqlform.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +mainwindow.o: mainwindow.cpp mainwindow.h \ + registerdialog.h \ + sqlform.h \ + ui_mainwindow.h \ + tableform.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp + +registerdialog.o: registerdialog.cpp registerdialog.h \ + ui_registerdialog.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o registerdialog.o registerdialog.cpp + +tableform.o: tableform.cpp tableform.h \ + ui_tableform.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o tableform.o tableform.cpp + +sqlform.o: sqlform.cpp sqlform.h \ + ui_sqlform.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o sqlform.o sqlform.cpp + +moc_mainwindow.o: moc_mainwindow.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp + +moc_registerdialog.o: moc_registerdialog.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_registerdialog.o moc_registerdialog.cpp + +moc_tableform.o: moc_tableform.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_tableform.o moc_tableform.cpp + +moc_sqlform.o: moc_sqlform.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_sqlform.o moc_sqlform.cpp + +qrc_IoSQL.o: qrc_IoSQL.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_IoSQL.o qrc_IoSQL.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/images/general/refresh.png b/images/general/refresh.png new file mode 100644 index 0000000..45b5535 Binary files /dev/null and b/images/general/refresh.png differ diff --git a/images/run-build.png b/images/run-build.png new file mode 100644 index 0000000..7d836b2 Binary files /dev/null and b/images/run-build.png differ diff --git a/images/server-database-deregister.png b/images/server-database-deregister.png new file mode 100644 index 0000000..f1bc49f Binary files /dev/null and b/images/server-database-deregister.png differ diff --git a/images/server-database-edit.png b/images/server-database-edit.png new file mode 100644 index 0000000..9c315f3 Binary files /dev/null and b/images/server-database-edit.png differ diff --git a/images/server-database-register.png b/images/server-database-register.png new file mode 100644 index 0000000..de59704 Binary files /dev/null and b/images/server-database-register.png differ diff --git a/images/table/commit.png b/images/table/commit.png new file mode 100644 index 0000000..16bdd61 Binary files /dev/null and b/images/table/commit.png differ diff --git a/images/table/delete-column.png b/images/table/delete-column.png new file mode 100644 index 0000000..33ee7fb Binary files /dev/null and b/images/table/delete-column.png differ diff --git a/images/table/delete-row.png b/images/table/delete-row.png new file mode 100644 index 0000000..a15c885 Binary files /dev/null and b/images/table/delete-row.png differ diff --git a/images/table/icon.png b/images/table/icon.png new file mode 100644 index 0000000..6e66f71 Binary files /dev/null and b/images/table/icon.png differ diff --git a/images/table/insert-column.png b/images/table/insert-column.png new file mode 100644 index 0000000..c9b0b2f Binary files /dev/null and b/images/table/insert-column.png differ diff --git a/images/table/insert-row.png b/images/table/insert-row.png new file mode 100644 index 0000000..71201f6 Binary files /dev/null and b/images/table/insert-row.png differ diff --git a/images/table/list.png b/images/table/list.png new file mode 100644 index 0000000..6ebc5e0 Binary files /dev/null and b/images/table/list.png differ diff --git a/images/table/rollback.png b/images/table/rollback.png new file mode 100644 index 0000000..d71461b Binary files /dev/null and b/images/table/rollback.png differ diff --git a/images/table/table.png b/images/table/table.png new file mode 100644 index 0000000..417dfb8 Binary files /dev/null and b/images/table/table.png differ diff --git a/images/view/list.png b/images/view/list.png new file mode 100644 index 0000000..1fb57d3 Binary files /dev/null and b/images/view/list.png differ diff --git a/images/view/view.png b/images/view/view.png new file mode 100644 index 0000000..f93afaf Binary files /dev/null and b/images/view/view.png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6e7efd9 --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..30e265c --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,498 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "tableform.h" +#include "registerdialog.h" +#include "sqlform.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + QCoreApplication::setOrganizationName("Saturn Laboratories"); + QCoreApplication::setOrganizationDomain("saturnlaboratories.co.za"); + QCoreApplication::setApplicationName("IoSQL"); + ui->setupUi(this); + QList children = ui->MdiArea->findChildren(); + Q_FOREACH (QTabBar* tab, children) + { + if (!tab->tabsClosable()) + { + tab->setTabsClosable(true); + connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); + } + } + m_WindowMapper = new QSignalMapper(this); + m_RegisterDialog = new RegisterDialog(this); + m_QueryForm = new SqlForm(this); + m_QueryForm->hide(); + connect(m_WindowMapper, SIGNAL(mapped(QWidget *)), + this, SLOT(setActiveSubWindow(QWidget *))); + QSettings settings; + QStringList connectionList = settings.value("connectionList").toStringList(); + for (int i = 0; i < connectionList.count(); i++) + { + QMap connectionMap = settings.value("connection " + connectionList.at(i)).toMap(); + loadConnection( + connectionMap.value("connectionName").toString(), + connectionMap.value("serverType").toString(), + connectionMap.value("serverName").toString(), + connectionMap.value("serverPort").toInt(), + connectionMap.value("databaseName").toString(), + connectionMap.value("username").toString(), + connectionMap.value("password").toString() + ); + } + QMdiArea::ViewMode viewMode = QMdiArea::ViewMode(settings.value("window mode", QVariant(QMdiArea::SubWindowView)).toInt()); + QTabWidget::TabPosition tabPosition = QTabWidget::TabPosition(settings.value("tab position", QVariant(QTabWidget::North)).toInt()); + ui->MdiArea->setViewMode(viewMode); + ui->MdiArea->setTabPosition(tabPosition); + if (viewMode == QMdiArea::SubWindowView) + { + ui->ModeSubWindowsAction->setChecked(true); + ui->ModeTabbedAction->setChecked(false); + ui->TabLocationMenu->setEnabled(false); + } + else + { + ui->ModeSubWindowsAction->setChecked(false); + ui->ModeTabbedAction->setChecked(true); + ui->TabLocationMenu->setEnabled(true); + } + if (tabPosition == QTabWidget::North) + { + ui->TabLocationNorthAction->setChecked(true); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(false); + ui->TabLocationWestAction->setChecked(false); + } + else if (tabPosition == QTabWidget::South) + { + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(true); + ui->TabLocationEastAction->setChecked(false); + ui->TabLocationWestAction->setChecked(false); + } + else if (tabPosition == QTabWidget::East) + { + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(true); + ui->TabLocationWestAction->setChecked(false); + } + else if (tabPosition == QTabWidget::West) + { + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(true); + ui->TabLocationWestAction->setChecked(false); + } +} + +MainWindow::~MainWindow() +{ + delete m_QueryForm; + delete m_WindowMapper; + delete m_RegisterDialog; + delete ui; +} + +void MainWindow::loadConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password) +{ + QSqlDatabase db = QSqlDatabase::addDatabase(serverType, connectionName); + db.setHostName(serverName); + db.setPort(serverPort); + db.setDatabaseName(databaseName); + db.setUserName(username); + db.setPassword(password); + 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) +{ + QSqlDatabase db = QSqlDatabase::addDatabase(serverType, connectionName); + db.setHostName(serverName); + db.setPort(serverPort); + db.setDatabaseName(databaseName); + db.setUserName(username); + db.setPassword(password); + bool ok = db.open(); + if (ok) + { + 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); + } + } + else + { + QSqlError error = QSqlDatabase::database(connectionName).lastError(); + QMessageBox::critical(this, "Error opening database", "Error occurred: " + error.text()); + } + return ok; +} + +void MainWindow::on_WindowMenu_aboutToShow() +{ + ui->WindowMenu->clear(); + ui->WindowMenu->addAction(ui->WindowCascadeAction); + ui->WindowMenu->addAction(ui->WindowTileAction); + ui->WindowMenu->addSeparator(); + QList windows = ui->MdiArea->subWindowList(); + if (!windows.isEmpty()) + { + ui->WindowMenu->addSeparator(); + for (int i = 0; i < windows.size(); ++i) + { + QMdiSubWindow *child = windows.at(i); + QString text; + if (i < 9) + { + text = tr("&%1 %2").arg(i + 1).arg(child->windowTitle()); + } + else + { + text = tr("%1").arg(child->windowTitle()); + } + QAction *action = ui->WindowMenu->addAction(text); + action->setCheckable(true); + action->setChecked(child == ui->MdiArea->activeSubWindow()); + connect(action, SIGNAL(triggered()), m_WindowMapper, SLOT(map())); + m_WindowMapper->setMapping(action, child); + } + } + } + +void MainWindow::setActiveSubWindow(QWidget *window) +{ + if (!window) + return; + ui->MdiArea->setActiveSubWindow(qobject_cast(window)); +} + +void MainWindow::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void MainWindow::on_DatabaseRegisterAction_triggered() +{ + if (m_RegisterDialog->exec()) + { + setupConnection( + m_RegisterDialog->connectionName(), + m_RegisterDialog->serverType(), + m_RegisterDialog->serverName(), + m_RegisterDialog->serverPort(), + m_RegisterDialog->database(), + m_RegisterDialog->username(), + m_RegisterDialog->password() + ); + } +} + +void MainWindow::on_DatabaseTreeWidget_doubleClicked(QModelIndex index) +{ + QTreeWidgetItem *item = ui->DatabaseTreeWidget->currentItem(); + if (item->parent() == 0 && item->childCount() == 0) + { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + QSqlDatabase db = QSqlDatabase::database(item->text(0)); + bool ok = db.open(); + if (ok) + { + /* Get the list of tables */ + QTreeWidgetItem *tablesItem = new QTreeWidgetItem(item, QStringList("Tables")); + tablesItem->setIcon(0, QIcon(":/Table/images/table/list.png")); + item->addChild(tablesItem); + QStringList tables = db.tables(); + tables.sort(); + for (int i = 0; i < tables.count(); i++) + { + QTreeWidgetItem *table = new QTreeWidgetItem(tablesItem, QStringList(tables.at(i))); + table->setIcon(0, QIcon(":/Table/images/table/table.png")); + tablesItem->addChild(table); + } + /* Get the list of views */ + QTreeWidgetItem *viewsItem = new QTreeWidgetItem(item, QStringList("Views")); + viewsItem->setIcon(0, QIcon(":/View/images/view/list.png")); + item->addChild(viewsItem); + QStringList views = db.tables(QSql::Views); + views.sort(); + for (int i = 0; i < views.count(); i++) + { + QTreeWidgetItem *view = new QTreeWidgetItem(viewsItem, QStringList(views.at(i))); + view->setIcon(0, QIcon(":/View/images/view/view.png")); + viewsItem->addChild(view); + } + QApplication::restoreOverrideCursor(); + } + else + { + QApplication::restoreOverrideCursor(); + QSqlError error = db.lastError(); + QMessageBox::critical(this, "Error opening database", "Error occurred: " + error.text()); + } + } + else if (item->parent() != 0 && item->childCount() == 0) + { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + TableForm *tableForm = new TableForm(ui->MdiArea); + tableForm->setTable(item->parent()->parent()->text(0), item->text(0)); + QString tableName = item->parent()->parent()->text(0) + "." + item->text(0); + QList windows = ui->MdiArea->subWindowList(); + bool foundWindow = false; + if (!windows.isEmpty()) + { + for (int i = 0; i < windows.size(); ++i) + { + if (windows.at(i)->windowTitle() == tableName) + { + ui->MdiArea->setActiveSubWindow(windows.at(i)); + foundWindow = true; + } + } + } + if (!foundWindow) + { + QMdiSubWindow *subWindow = ui->MdiArea->addSubWindow(tableForm); + subWindow->setWindowTitle(tableName); + subWindow->setWindowIcon(QIcon(":/Table/images/table/icon.png")); + subWindow->showMaximized(); + } + QApplication::restoreOverrideCursor(); + } +} + + +void MainWindow::on_DatabaseDeregisterAction_triggered() +{ + QTreeWidgetItem *item = ui->DatabaseTreeWidget->currentItem(); + if (item != 0 && item->parent() == 0 && item->childCount() == 0) + { + if (QMessageBox::question(this, "De-register Database", "Are you sure you want to de-register \"" + item->text(0) + "\"?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + QString connectionName = item->text(0); + QSettings settings; + if (settings.contains("connection " + connectionName)) + { + settings.remove("connection " + connectionName); + QStringList connectionList; + if (settings.contains("connectionList")) + { + connectionList = settings.value("connectionList").toStringList(); + } + connectionList.removeAt(connectionList.indexOf(connectionName)); + settings.setValue("connectionList", connectionList); + } + delete item; + } + } +} + +void MainWindow::on_HelpAboutQtAction_triggered() +{ + QMessageBox::aboutQt(this); +} + +void MainWindow::on_HelpAboutAction_triggered() +{ + QMessageBox::about(this, "About IoSQL", "

About IoSQL

" + "

IoSQL is a light-weight database-independent data explorer.

" + "

Copyright © 2010 Saturn Laboratories.

" + "

This program is free software: you can redistribute it and/or modify it " + "under the terms of the GNU General Public License as published by the Free " + "Software Foundation, either version 3 of the License, or (at your option) " + "any later version.

" + "

This program is distributed in the hope that it will be useful, " + "but WITHOUT ANY WARRANTY; without even the implied warranty of " + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + "GNU General Public License for more details.

" + "

You should have received a copy of the GNU General Public License " + "along with this program. If not, see " + "http://www.gnu.org/licenses/

"); +} + +void MainWindow::on_ModeSubWindowsAction_triggered() +{ + ui->MdiArea->setViewMode(QMdiArea::SubWindowView); + QSettings settings; + settings.setValue("window mode", QVariant(QMdiArea::SubWindowView)); + ui->ModeSubWindowsAction->setChecked(true); + ui->ModeTabbedAction->setChecked(false); + ui->TabLocationMenu->setEnabled(false); +} + +void MainWindow::on_ModeTabbedAction_triggered() +{ + ui->MdiArea->setViewMode(QMdiArea::TabbedView); + ui->MdiArea->setDocumentMode(true); + QSettings settings; + settings.setValue("window mode", QVariant(QMdiArea::TabbedView)); + ui->ModeSubWindowsAction->setChecked(false); + ui->ModeTabbedAction->setChecked(true); + ui->TabLocationMenu->setEnabled(true); +} + +void MainWindow::on_TabLocationNorthAction_triggered() +{ + ui->MdiArea->setTabPosition(QTabWidget::North); + QSettings settings; + settings.setValue("tab position", QVariant(QTabWidget::North)); + ui->TabLocationNorthAction->setChecked(true); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(false); + ui->TabLocationWestAction->setChecked(false); +} + +void MainWindow::on_TabLocationSouthAction_triggered() +{ + ui->MdiArea->setTabPosition(QTabWidget::South); + QSettings settings; + settings.setValue("tab position", QVariant(QTabWidget::South)); + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(true); + ui->TabLocationEastAction->setChecked(false); + ui->TabLocationWestAction->setChecked(false); +} + +void MainWindow::on_TabLocationEastAction_triggered() +{ + ui->MdiArea->setTabPosition(QTabWidget::East); + QSettings settings; + settings.setValue("tab position", QVariant(QTabWidget::East)); + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(true); + ui->TabLocationWestAction->setChecked(false); +} + +void MainWindow::on_TabLocationWestAction_triggered() +{ + ui->MdiArea->setTabPosition(QTabWidget::West); + QSettings settings; + settings.setValue("tab position", QVariant(QTabWidget::West)); + ui->TabLocationNorthAction->setChecked(false); + ui->TabLocationSouthAction->setChecked(false); + ui->TabLocationEastAction->setChecked(false); + ui->TabLocationWestAction->setChecked(true); +} + +void MainWindow::on_DatabaseEditAction_triggered() +{ + QTreeWidgetItem *item = ui->DatabaseTreeWidget->currentItem(); + if (item != 0 && item->parent() == 0 && item->childCount() == 0) + { + QString oldConnectionName = item->text(0); + QSettings settings; + QMap connectionMap = settings.value("connection " + oldConnectionName).toMap(); + m_RegisterDialog->setConnectionName(oldConnectionName); + m_RegisterDialog->setServerType(connectionMap.value("serverType", QVariant("")).toString()); + m_RegisterDialog->setServerName(connectionMap.value("serverName", QVariant("")).toString()); + m_RegisterDialog->setServerPort(connectionMap.value("serverPort", QVariant(0)).toInt()); + m_RegisterDialog->setDatabase(connectionMap.value("databaseName", QVariant("")).toString()); + m_RegisterDialog->setUsername(connectionMap.value("username", QVariant("")).toString()); + m_RegisterDialog->setPassword(connectionMap.value("password", QVariant("")).toString()); + if (m_RegisterDialog->exec()) + { + QString connectionName = m_RegisterDialog->connectionName(); + QString serverType = m_RegisterDialog->serverType(); + QString serverName = m_RegisterDialog->serverName(); + int serverPort = m_RegisterDialog->serverPort(); + QString database = m_RegisterDialog->database(); + QString username = m_RegisterDialog->username(); + QString password = m_RegisterDialog->password(); + QSqlDatabase db = QSqlDatabase::database(connectionName); + if (connectionName != oldConnectionName || serverType != db.driverName()) + { + QSqlDatabase::removeDatabase(oldConnectionName); + db = QSqlDatabase::addDatabase(serverType, connectionName); + } + db.setHostName(serverName); + db.setPort(serverPort); + db.setDatabaseName(database); + db.setUserName(username); + db.setPassword(password); + connectionMap.insert("connectionName", connectionName); + connectionMap.insert("serverType", serverType); + connectionMap.insert("serverName", serverName); + connectionMap.insert("serverPort", serverPort); + connectionMap.insert("databaseName", database); + connectionMap.insert("username", username); + connectionMap.insert("password", password); + settings.remove("connection " + oldConnectionName); + settings.setValue("connection " + connectionName, connectionMap); + item->setText(0, connectionName); + } + } +} + +void MainWindow::on_DatabaseRunQueryAction_triggered() +{ + m_QueryForm->show(); +} + +void MainWindow::closeTab(int i) +{ + QMdiSubWindow *sub = ui->MdiArea->subWindowList()[i]; + QWidget *win = sub->widget(); + win->close(); + ui->MdiArea->setActiveSubWindow(sub); + ui->MdiArea->closeActiveSubWindow(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..e5520d7 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,50 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "registerdialog.h" +#include "sqlform.h" + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow { + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); +void loadConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password); +bool setupConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::MainWindow *ui; + QSignalMapper *m_WindowMapper; + RegisterDialog *m_RegisterDialog; + SqlForm *m_QueryForm; + +private slots: + void setActiveSubWindow(QWidget *window); + void closeTab(int i); + void on_DatabaseRunQueryAction_triggered(); + void on_DatabaseEditAction_triggered(); + void on_TabLocationWestAction_triggered(); + void on_TabLocationEastAction_triggered(); + void on_TabLocationSouthAction_triggered(); + void on_TabLocationNorthAction_triggered(); + void on_ModeTabbedAction_triggered(); + void on_ModeSubWindowsAction_triggered(); + void on_HelpAboutAction_triggered(); + void on_HelpAboutQtAction_triggered(); + void on_DatabaseDeregisterAction_triggered(); + void on_DatabaseTreeWidget_doubleClicked(QModelIndex index); + void on_DatabaseRegisterAction_triggered(); + void on_WindowMenu_aboutToShow(); +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..4df7da1 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,339 @@ + + + MainWindow + + + + 0 + 0 + 600 + 400 + + + + IoSQL Database Manager + + + + :/Server/images/server-database-register.png:/Server/images/server-database-register.png + + + + + 0 + + + 0 + + + + + QMdiArea::TabbedView + + + + + + + + + 0 + 0 + 600 + 21 + + + + + &Database + + + + + + + + + + + + &Window + + + + + + + &Help + + + + + + + &View + + + + Tab &Location + + + + + + + + + + + + + + + + + + + TopToolBarArea + + + false + + + + + + + + + false + + + QDockWidget::AllDockWidgetFeatures + + + Databases + + + 1 + + + + + 0 + + + 0 + + + + + + 22 + 22 + + + + true + + + true + + + true + + + + 1 + + + + + + + + + + + :/Server/images/server-database-register.png:/Server/images/server-database-register.png + + + &Register + + + Register a database + + + + + &Cascade + + + Cascade all the windows + + + + + Tile + + + Tile all the windows + + + + + + :/Server/images/server-database-deregister.png:/Server/images/server-database-deregister.png + + + De-register + + + De-register database + + + + + &About + + + About IoSQL + + + + + &About Qt + + + + + true + + + &Tabbed + + + Set the window mode to tabs + + + + + true + + + &Sub-Windows + + + Set the window mode to Sub-Windows + + + + + true + + + &North + + + Show tabs on the top + + + + + true + + + &South + + + Show tabs on the bottom + + + + + true + + + &East + + + Show the tabs on the right + + + + + true + + + &West + + + Show the tabs on the left + + + + + + :/Server/images/server-database-edit.png:/Server/images/server-database-edit.png + + + &Edit Registration + + + Edit database registration details + + + + + + :/Table/images/run-build.png:/Table/images/run-build.png + + + Run &Query + + + + + E&xit + + + + + + + + + + WindowCascadeAction + triggered() + MdiArea + cascadeSubWindows() + + + -1 + -1 + + + 432 + 216 + + + + + WindowTileAction + triggered() + MdiArea + tileSubWindows() + + + -1 + -1 + + + 432 + 216 + + + + + diff --git a/registerdialog.cpp b/registerdialog.cpp new file mode 100644 index 0000000..a982dba --- /dev/null +++ b/registerdialog.cpp @@ -0,0 +1,125 @@ +#include "registerdialog.h" +#include "ui_registerdialog.h" + +RegisterDialog::RegisterDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::RegisterDialog) +{ + ui->setupUi(this); + QValidator *validator = new QIntValidator(0, 999999, this); + ui->PortLineEdit->setValidator(validator); +} + +RegisterDialog::~RegisterDialog() +{ + delete ui; +} + +void RegisterDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +QString RegisterDialog::connectionName() +{ + return ui->ConnectionLineEdit->text(); +} + +void RegisterDialog::setConnectionName(const QString connectionName) +{ + ui->ConnectionLineEdit->setText(connectionName); +} + +QString RegisterDialog::serverType() +{ + QString typeName = ui->TypeComboBox->currentText(); + if (typeName == "PostgreSQL") + { + return "QPSQL"; + } + else if (typeName == "MySQL") + { + return "QMYSQL"; + } + else if (typeName == "SQLite") + { + return "QSQLITE"; + } + return ""; +} + +void RegisterDialog::setServerType(const QString serverType) +{ + int typeIndex = 0; + if (serverType == "QPSQL") + { + typeIndex = ui->TypeComboBox->findText("PostgreSQL"); + } + else if (serverType == "QMYSQL") + { + typeIndex = ui->TypeComboBox->findText("MySQL"); + } + else if (serverType == "QSQLITE") + { + typeIndex = ui->TypeComboBox->findText("SQLite"); + } + ui->TypeComboBox->setCurrentIndex(typeIndex); +} + +QString RegisterDialog::serverName() +{ + return ui->ServerLineEdit->text(); +} + +void RegisterDialog::setServerName(const QString serverName) +{ + ui->ServerLineEdit->setText(serverName); +} + +int RegisterDialog::serverPort() +{ + QString port = ui->PortLineEdit->text(); + return port.toInt(); +} + +void RegisterDialog::setServerPort(const int port) +{ + ui->PortLineEdit->setText(QString::number(port)); +} + +QString RegisterDialog::database() +{ + return ui->DatabaseLineEdit->text(); +} + +void RegisterDialog::setDatabase(const QString database) +{ + ui->DatabaseLineEdit->setText(database); +} + +QString RegisterDialog::username() +{ + return ui->UsernameLineEdit->text(); +} + +void RegisterDialog::setUsername(const QString username) +{ + ui->UsernameLineEdit->setText(username); +} + +QString RegisterDialog::password() +{ + return ui->PasswordLineEdit->text(); +} + +void RegisterDialog::setPassword(const QString password) +{ + ui->PasswordLineEdit->setText(password); +} diff --git a/registerdialog.h b/registerdialog.h new file mode 100644 index 0000000..58fd9fb --- /dev/null +++ b/registerdialog.h @@ -0,0 +1,39 @@ +#ifndef REGISTERDIALOG_H +#define REGISTERDIALOG_H + +#include + +namespace Ui { + class RegisterDialog; +} + +class RegisterDialog : public QDialog { + Q_OBJECT +public: + RegisterDialog(QWidget *parent = 0); + ~RegisterDialog(); + QString connectionName(); + void setConnectionName(const QString connectionName); + QString serverType(); + void setServerType(const QString serverType); + QString serverName(); + void setServerName(const QString serverName); + int serverPort(); + void setServerPort(const int port); + QString database(); + void setDatabase(const QString database); + QString username(); + void setUsername(const QString username); + QString password(); + void setPassword(const QString password); + +protected: + void changeEvent(QEvent *e); + +private slots: + +private: + Ui::RegisterDialog *ui; +}; + +#endif // REGISTERDIALOG_H diff --git a/registerdialog.ui b/registerdialog.ui new file mode 100644 index 0000000..7b5f06f --- /dev/null +++ b/registerdialog.ui @@ -0,0 +1,199 @@ + + + RegisterDialog + + + + 0 + 0 + 361 + 281 + + + + Dialog + + + + 8 + + + 8 + + + + + Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 8 + + + 8 + + + + + Connection Name: + + + + + + + + + + Server Address: + + + + + + + + + + Server Port: + + + + + + + true + + + + + + + + 0 + 0 + + + + + PostgreSQL + + + + + MySQL + + + + + SQLite + + + + + + + + Server Type: + + + + + + + Database: + + + + + + + + + + Username: + + + + + + + + + + Password: + + + + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + ConnectionLineEdit + TypeComboBox + ServerLineEdit + PortLineEdit + DatabaseLineEdit + UsernameLineEdit + PasswordLineEdit + SubmitButtonBox + + + + + SubmitButtonBox + accepted() + RegisterDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + SubmitButtonBox + rejected() + RegisterDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sqlform.cpp b/sqlform.cpp new file mode 100644 index 0000000..c400cf9 --- /dev/null +++ b/sqlform.cpp @@ -0,0 +1,38 @@ +#include "sqlform.h" +#include "ui_sqlform.h" +#include + +SqlForm::SqlForm(QWidget *parent) : + QDialog(parent), + ui(new Ui::SqlForm) +{ + QsciLexerSQL *lexer = new QsciLexerSQL(); + lexer->setDefaultPaper(QColor(255, 255, 255)); + lexer->setDefaultColor(QColor(0, 0, 0)); + lexer->setDefaultFont(QFont("monospace")); + for (int i = -1; i < 23; i++) + { + lexer->setPaper(QColor(255, 255, 255), i); + //lexer->setDefaultColor(QColor(0, 0, 0)); + lexer->setFont(QFont("monospace"), i); + } + ui->setupUi(this); + ui->QueryTextEdit->setLexer(lexer); +} + +SqlForm::~SqlForm() +{ + delete ui; +} + +void SqlForm::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/sqlform.h b/sqlform.h new file mode 100644 index 0000000..2db42bb --- /dev/null +++ b/sqlform.h @@ -0,0 +1,24 @@ +#ifndef SQLFORM_H +#define SQLFORM_H + +#include +#include + +namespace Ui { + class SqlForm; +} + +class SqlForm : public QDialog { + Q_OBJECT +public: + SqlForm(QWidget *parent = 0); + ~SqlForm(); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::SqlForm *ui; +}; + +#endif // SQLFORM_H diff --git a/sqlform.ui b/sqlform.ui new file mode 100644 index 0000000..b39c10d --- /dev/null +++ b/sqlform.ui @@ -0,0 +1,50 @@ + + + SqlForm + + + + 0 + 0 + 530 + 430 + + + + Form + + + + 0 + + + 0 + + + + + Qt::Vertical + + + + + + + + + + + + + + + + + QsciScintilla + QFrame +
Qsci/qsciscintilla.h
+
+
+ + +
diff --git a/tableform.cpp b/tableform.cpp new file mode 100644 index 0000000..21c3464 --- /dev/null +++ b/tableform.cpp @@ -0,0 +1,158 @@ +#include "tableform.h" +#include "ui_tableform.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +TableForm::TableForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TableForm) +{ + QsciLexerSQL *lexer = new QsciLexerSQL(); + lexer->setDefaultPaper(QColor(255, 255, 255)); + lexer->setDefaultColor(QColor(0, 0, 0)); + lexer->setDefaultFont(QFont("monospace")); + for (int i = -1; i < 23; i++) + { + lexer->setPaper(QColor(255, 255, 255), i); + //lexer->setDefaultColor(QColor(0, 0, 0)); + lexer->setFont(QFont("monospace"), i); + } + ui->setupUi(this); + ui->QueryTextEdit->setLexer(lexer); + m_QueryModel = 0; +} + +TableForm::~TableForm() +{ + delete m_QueryModel; + delete m_DataModel; + delete ui; +} + +void TableForm::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void TableForm::setTable(const QString connectionName, const QString tableName) +{ + QMainWindow * mainWindow = qobject_cast(window()); + if (mainWindow) + mainWindow->statusBar()->showMessage("Opening table \"" + tableName + "\"..."); + QCoreApplication::processEvents(); + m_ConnectionName = connectionName; + m_TableName = tableName; + m_Database = QSqlDatabase::database(m_ConnectionName); + m_DataModel = new QSqlTableModel(this, m_Database); + m_DataModel->setTable(m_TableName); + m_DataModel->select(); + ui->DataTableView->setModel(m_DataModel); + ui->DataTableView->resizeColumnsToContents(); + QSqlRecord record = m_DataModel->record(); + ui->StructureTableWidget->setRowCount(record.count()); + for (int i = 0; i < record.count(); i++) + { + QSqlField field = record.field(i); + QTableWidgetItem *nameItem = new QTableWidgetItem(field.name()); + QString typeName; + switch (field.type()) + { + case QVariant::String: typeName = "varchar"; break; + case QVariant::Int: typeName = "integer"; break; + case QVariant::Date: typeName = "date"; break; + case QVariant::DateTime: typeName = "datetime"; break; + case QVariant::Bool: typeName = "boolean"; break; + case QVariant::ByteArray: typeName = "byte array"; break; + case QVariant::LongLong: typeName = "bigint"; break; + default: typeName = "unknown"; break; + } + QTableWidgetItem *typeItem = new QTableWidgetItem(typeName); + QTableWidgetItem *sizeItem; + if (field.length() >= 0) + { + sizeItem = new QTableWidgetItem(field.length()); + } + else if (field.precision() >= 0) + { + sizeItem = new QTableWidgetItem(field.precision()); + } + else + { + sizeItem = new QTableWidgetItem(""); + } + QTableWidgetItem *nullItem; + if (field.requiredStatus()) + { + nullItem = new QTableWidgetItem("not null"); + } + else + { + nullItem = new QTableWidgetItem("nullable"); + } + ui->StructureTableWidget->setItem(i, 0, nameItem); + ui->StructureTableWidget->setItem(i, 1, typeItem); + ui->StructureTableWidget->setItem(i, 2, sizeItem); + ui->StructureTableWidget->setItem(i, 3, nullItem); + } + ui->StructureTableWidget->resizeColumnsToContents(); + if (mainWindow) + mainWindow->statusBar()->clearMessage(); +} + +void TableForm::on_DataCommitAction_triggered() +{ + if (m_DataModel) + { + m_DataModel->database().commit(); + } + ui->DataCommitAction->setEnabled(false); + ui->DataRollbackAction->setEnabled(false); +} + +void TableForm::on_DataRefreshAction_triggered() +{ + m_DataModel->select(); + ui->DataTableView->resizeColumnsToContents(); +} + +void TableForm::on_QueryRunAction_triggered() +{ + QMainWindow * mainWindow = qobject_cast(window()); + if (mainWindow) + mainWindow->statusBar()->showMessage("Running query..."); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + 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(); + QApplication::restoreOverrideCursor(); + if (mainWindow) + mainWindow->statusBar()->clearMessage(); +} diff --git a/tableform.h b/tableform.h new file mode 100644 index 0000000..06a4c33 --- /dev/null +++ b/tableform.h @@ -0,0 +1,35 @@ +#ifndef TABLEFORM_H +#define TABLEFORM_H + +#include +#include + +namespace Ui { + class TableForm; +} + +class TableForm : public QWidget { + Q_OBJECT +public: + TableForm(QWidget *parent = 0); + ~TableForm(); + void setTable(const QString connectionName, const QString tableName); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::TableForm *ui; + QSqlDatabase m_Database; + QSqlTableModel *m_DataModel; + QSqlQueryModel *m_QueryModel; + QString m_ConnectionName; + QString m_TableName; + +private slots: + void on_QueryRunAction_triggered(); + void on_DataRefreshAction_triggered(); + void on_DataCommitAction_triggered(); +}; + +#endif // TABLEFORM_H diff --git a/tableform.ui b/tableform.ui new file mode 100644 index 0000000..3df074d --- /dev/null +++ b/tableform.ui @@ -0,0 +1,330 @@ + + + TableForm + + + + 0 + 0 + 638 + 440 + + + + Form + + + + :/Table/images/table/table.png:/Table/images/table/table.png + + + + 0 + + + 0 + + + + + 0 + + + + Data + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 22 + 22 + + + + + + + + + + + + + + + true + + + false + + + 20 + + + 18 + + + + + + + + Structure + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 0 + + + + + + + + + false + + + 20 + + + + Column + + + + + Type + + + + + Size + + + + + Not Null + + + + + + + + + Query + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 0 + + + + + + + + + Qt::Vertical + + + + + + + + + + + + false + + + 20 + + + + + + + + + + + + + :/Table/images/table/insert-row.png:/Table/images/table/insert-row.png + + + New Record + + + + + + :/Table/images/table/insert-column.png:/Table/images/table/insert-column.png + + + New Column + + + Add a new column + + + + + + :/Table/images/table/delete-row.png:/Table/images/table/delete-row.png + + + Remove Record + + + + + + :/Table/images/table/delete-column.png:/Table/images/table/delete-column.png + + + Remove Column + + + + + false + + + + :/Table/images/table/commit.png:/Table/images/table/commit.png + + + Commit + + + + + false + + + + :/Table/images/table/rollback.png:/Table/images/table/rollback.png + + + Rollback + + + + + + :/General/images/general/refresh.png:/General/images/general/refresh.png + + + Refresh + + + + + + :/Table/images/run-build.png:/Table/images/run-build.png + + + Run Query + + + Run an SQL query + + + F5 + + + + + + QsciScintilla + QFrame +
Qsci/qsciscintilla.h
+
+
+ + TableTabWidget + DataTableView + StructureTableWidget + QueryTextEdit + ResultsTableView + + + + + +