Initial Import.

This commit is contained in:
Raoul Snyman 2011-06-24 13:05:56 +02:00
commit ee9de66380
32 changed files with 2254 additions and 0 deletions

23
IoSQL.pro Normal file
View File

@ -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

26
IoSQL.qrc Normal file
View File

@ -0,0 +1,26 @@
<RCC>
<qresource prefix="/Table">
<file>images/table/delete-column.png</file>
<file>images/table/delete-row.png</file>
<file>images/table/commit.png</file>
<file>images/table/rollback.png</file>
<file>images/table/insert-column.png</file>
<file>images/table/insert-row.png</file>
<file>images/table/list.png</file>
<file>images/table/table.png</file>
<file>images/table/icon.png</file>
<file>images/run-build.png</file>
</qresource>
<qresource prefix="/Server">
<file>images/server-database-register.png</file>
<file>images/server-database-deregister.png</file>
<file>images/server-database-edit.png</file>
</qresource>
<qresource prefix="/View">
<file>images/view/list.png</file>
<file>images/view/view.png</file>
</qresource>
<qresource prefix="/General">
<file>images/general/refresh.png</file>
</qresource>
</RCC>

310
Makefile Normal file
View File

@ -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:

BIN
images/general/refresh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/run-build.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B

BIN
images/table/commit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/table/delete-row.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/table/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/table/insert-row.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 B

BIN
images/table/list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

BIN
images/table/rollback.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/table/table.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/view/list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

BIN
images/view/view.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

10
main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

498
mainwindow.cpp Normal file
View File

@ -0,0 +1,498 @@
#include <QtGui/QMdiSubWindow>
#include <QtGui/QMessageBox>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QDesktopServices>
#include <QTabBar>
#include <QSettings>
#include <QMap>
#include <QtDebug>
#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<QTabBar*> children = ui->MdiArea->findChildren<QTabBar *>();
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<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant> 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<QMdiSubWindow *> 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<QMdiSubWindow *>(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<QMdiSubWindow *> 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", "<h3>About IoSQL</h3>"
"<p>IoSQL is a light-weight database-independent data explorer.</p>"
"<p>Copyright &copy; 2010 Saturn Laboratories.</p>"
"<p>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.</p>"
"<p>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.</p>"
"<p>You should have received a copy of the GNU General Public License "
"along with this program. If not, see "
"<a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a></p>");
}
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<QString, QVariant> 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();
}

50
mainwindow.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtCore/QSignalMapper>
#include <QModelIndex>
#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

339
mainwindow.ui Normal file
View File

@ -0,0 +1,339 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>IoSQL Database Manager</string>
</property>
<property name="windowIcon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Server/images/server-database-register.png</normaloff>:/Server/images/server-database-register.png</iconset>
</property>
<widget class="QWidget" name="MdiWidget">
<layout class="QVBoxLayout" name="MdiLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QMdiArea" name="MdiArea">
<property name="viewMode">
<enum>QMdiArea::TabbedView</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="MenuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="DatabaseMenu">
<property name="title">
<string>&amp;Database</string>
</property>
<addaction name="DatabaseRegisterAction"/>
<addaction name="DatabaseEditAction"/>
<addaction name="DatabaseDeregisterAction"/>
<addaction name="separator"/>
<addaction name="DatabaseRunQueryAction"/>
<addaction name="separator"/>
<addaction name="DatabaseExitAction"/>
</widget>
<widget class="QMenu" name="WindowMenu">
<property name="title">
<string>&amp;Window</string>
</property>
<addaction name="WindowCascadeAction"/>
<addaction name="WindowTileAction"/>
</widget>
<widget class="QMenu" name="HelpMenu">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="HelpAboutAction"/>
<addaction name="HelpAboutQtAction"/>
</widget>
<widget class="QMenu" name="ViewMenu">
<property name="title">
<string>&amp;View</string>
</property>
<widget class="QMenu" name="TabLocationMenu">
<property name="title">
<string>Tab &amp;Location</string>
</property>
<addaction name="TabLocationNorthAction"/>
<addaction name="TabLocationSouthAction"/>
<addaction name="TabLocationEastAction"/>
<addaction name="TabLocationWestAction"/>
</widget>
<addaction name="ModeTabbedAction"/>
<addaction name="ModeSubWindowsAction"/>
<addaction name="separator"/>
<addaction name="TabLocationMenu"/>
</widget>
<addaction name="DatabaseMenu"/>
<addaction name="ViewMenu"/>
<addaction name="WindowMenu"/>
<addaction name="HelpMenu"/>
</widget>
<widget class="QToolBar" name="DatabaseToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="DatabaseRegisterAction"/>
<addaction name="DatabaseEditAction"/>
<addaction name="DatabaseDeregisterAction"/>
</widget>
<widget class="QStatusBar" name="StatusBar"/>
<widget class="QDockWidget" name="DatabaseDockWidget">
<property name="floating">
<bool>false</bool>
</property>
<property name="features">
<set>QDockWidget::AllDockWidgetFeatures</set>
</property>
<property name="windowTitle">
<string>Databases</string>
</property>
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="DatabaseDockContents">
<layout class="QVBoxLayout" name="DatabaseDockLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTreeWidget" name="DatabaseTreeWidget">
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="DatabaseRegisterAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Server/images/server-database-register.png</normaloff>:/Server/images/server-database-register.png</iconset>
</property>
<property name="text">
<string>&amp;Register</string>
</property>
<property name="toolTip">
<string>Register a database</string>
</property>
</action>
<action name="WindowCascadeAction">
<property name="text">
<string>&amp;Cascade</string>
</property>
<property name="toolTip">
<string>Cascade all the windows</string>
</property>
</action>
<action name="WindowTileAction">
<property name="text">
<string>Tile</string>
</property>
<property name="toolTip">
<string>Tile all the windows</string>
</property>
</action>
<action name="DatabaseDeregisterAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Server/images/server-database-deregister.png</normaloff>:/Server/images/server-database-deregister.png</iconset>
</property>
<property name="text">
<string>De-register</string>
</property>
<property name="toolTip">
<string>De-register database</string>
</property>
</action>
<action name="HelpAboutAction">
<property name="text">
<string>&amp;About</string>
</property>
<property name="toolTip">
<string>About IoSQL</string>
</property>
</action>
<action name="HelpAboutQtAction">
<property name="text">
<string>&amp;About Qt</string>
</property>
</action>
<action name="ModeTabbedAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Tabbed</string>
</property>
<property name="toolTip">
<string>Set the window mode to tabs</string>
</property>
</action>
<action name="ModeSubWindowsAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Sub-Windows</string>
</property>
<property name="toolTip">
<string>Set the window mode to Sub-Windows</string>
</property>
</action>
<action name="TabLocationNorthAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;North</string>
</property>
<property name="toolTip">
<string>Show tabs on the top</string>
</property>
</action>
<action name="TabLocationSouthAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;South</string>
</property>
<property name="toolTip">
<string>Show tabs on the bottom</string>
</property>
</action>
<action name="TabLocationEastAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;East</string>
</property>
<property name="toolTip">
<string>Show the tabs on the right</string>
</property>
</action>
<action name="TabLocationWestAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;West</string>
</property>
<property name="toolTip">
<string>Show the tabs on the left</string>
</property>
</action>
<action name="DatabaseEditAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Server/images/server-database-edit.png</normaloff>:/Server/images/server-database-edit.png</iconset>
</property>
<property name="text">
<string>&amp;Edit Registration</string>
</property>
<property name="toolTip">
<string>Edit database registration details</string>
</property>
</action>
<action name="DatabaseRunQueryAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/run-build.png</normaloff>:/Table/images/run-build.png</iconset>
</property>
<property name="text">
<string>Run &amp;Query</string>
</property>
</action>
<action name="DatabaseExitAction">
<property name="text">
<string>E&amp;xit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="IoSQL.qrc"/>
</resources>
<connections>
<connection>
<sender>WindowCascadeAction</sender>
<signal>triggered()</signal>
<receiver>MdiArea</receiver>
<slot>cascadeSubWindows()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>432</x>
<y>216</y>
</hint>
</hints>
</connection>
<connection>
<sender>WindowTileAction</sender>
<signal>triggered()</signal>
<receiver>MdiArea</receiver>
<slot>tileSubWindows()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>432</x>
<y>216</y>
</hint>
</hints>
</connection>
</connections>
</ui>

125
registerdialog.cpp Normal file
View File

@ -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);
}

39
registerdialog.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef REGISTERDIALOG_H
#define REGISTERDIALOG_H
#include <QDialog>
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

199
registerdialog.ui Normal file
View File

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RegisterDialog</class>
<widget class="QDialog" name="RegisterDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="RegisterLayout">
<property name="spacing">
<number>8</number>
</property>
<property name="margin">
<number>8</number>
</property>
<item>
<layout class="QFormLayout" name="DetailsLayout">
<property name="labelAlignment">
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="horizontalSpacing">
<number>8</number>
</property>
<property name="verticalSpacing">
<number>8</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="ConnectionLabel">
<property name="text">
<string>Connection Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="ConnectionLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="ServerLabel">
<property name="text">
<string>Server Address:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="ServerLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="PortLabel">
<property name="text">
<string>Server Port:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="PortLineEdit">
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="TypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>PostgreSQL</string>
</property>
</item>
<item>
<property name="text">
<string>MySQL</string>
</property>
</item>
<item>
<property name="text">
<string>SQLite</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="TypeLabel">
<property name="text">
<string>Server Type:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="DatabaseLabel">
<property name="text">
<string>Database:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="DatabaseLineEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="UsernameLabel">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="UsernameLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="PasswordLabel">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="PasswordLineEdit">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="SubmitButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>ConnectionLineEdit</tabstop>
<tabstop>TypeComboBox</tabstop>
<tabstop>ServerLineEdit</tabstop>
<tabstop>PortLineEdit</tabstop>
<tabstop>DatabaseLineEdit</tabstop>
<tabstop>UsernameLineEdit</tabstop>
<tabstop>PasswordLineEdit</tabstop>
<tabstop>SubmitButtonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>SubmitButtonBox</sender>
<signal>accepted()</signal>
<receiver>RegisterDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>SubmitButtonBox</sender>
<signal>rejected()</signal>
<receiver>RegisterDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

38
sqlform.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "sqlform.h"
#include "ui_sqlform.h"
#include <Qsci/qscilexersql.h>
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;
}
}

24
sqlform.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef SQLFORM_H
#define SQLFORM_H
#include <QDialog>
#include <Qsci/qsciscintilla.h>
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

50
sqlform.ui Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SqlForm</class>
<widget class="QDialog" name="SqlForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>530</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="SqlLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="SqlSplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QsciScintilla" name="QueryTextEdit">
<property name="toolTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
</widget>
<widget class="QTableView" name="ResultsTableView"/>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QsciScintilla</class>
<extends>QFrame</extends>
<header>Qsci/qsciscintilla.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

158
tableform.cpp Normal file
View File

@ -0,0 +1,158 @@
#include "tableform.h"
#include "ui_tableform.h"
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QSqlField>
#include <QTableWidgetItem>
#include <QMainWindow>
#include <QStatusBar>
#include <Qsci/qscilexersql.h>
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<QMainWindow*>(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<QMainWindow*>(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();
}

35
tableform.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef TABLEFORM_H
#define TABLEFORM_H
#include <QWidget>
#include <QSqlTableModel>
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

330
tableform.ui Normal file
View File

@ -0,0 +1,330 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TableForm</class>
<widget class="QWidget" name="TableForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>638</width>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="windowIcon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/table.png</normaloff>:/Table/images/table/table.png</iconset>
</property>
<layout class="QVBoxLayout" name="TableLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="TableTabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="DataTab">
<attribute name="title">
<string>Data</string>
</attribute>
<layout class="QVBoxLayout" name="DataLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="DataToolBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<addaction name="DataNewRecordAction"/>
<addaction name="DataRemoveAction"/>
<addaction name="separator"/>
<addaction name="DataCommitAction"/>
<addaction name="DataRollbackAction"/>
<addaction name="separator"/>
<addaction name="DataRefreshAction"/>
</widget>
</item>
<item>
<widget class="QTableView" name="DataTableView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>20</number>
</attribute>
<attribute name="verticalHeaderMinimumSectionSize">
<number>18</number>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="StructureTab">
<attribute name="title">
<string>Structure</string>
</attribute>
<layout class="QVBoxLayout" name="StructureLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="StructureToolBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<addaction name="StructureNewColumnAction"/>
</widget>
</item>
<item>
<widget class="QTableWidget" name="StructureTableWidget">
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>20</number>
</attribute>
<column>
<property name="text">
<string>Column</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>Not Null</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="QueryTab">
<attribute name="title">
<string>Query</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="QueryToolBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<addaction name="QueryRunAction"/>
</widget>
</item>
<item>
<widget class="QSplitter" name="QuerySplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QsciScintilla" name="QueryTextEdit">
<property name="toolTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
</widget>
<widget class="QTableView" name="ResultsTableView">
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>20</number>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
<action name="DataNewRecordAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/insert-row.png</normaloff>:/Table/images/table/insert-row.png</iconset>
</property>
<property name="text">
<string>New Record</string>
</property>
</action>
<action name="StructureNewColumnAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/insert-column.png</normaloff>:/Table/images/table/insert-column.png</iconset>
</property>
<property name="text">
<string>New Column</string>
</property>
<property name="toolTip">
<string>Add a new column</string>
</property>
</action>
<action name="DataRemoveAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/delete-row.png</normaloff>:/Table/images/table/delete-row.png</iconset>
</property>
<property name="text">
<string>Remove Record</string>
</property>
</action>
<action name="StructureRemoveAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/delete-column.png</normaloff>:/Table/images/table/delete-column.png</iconset>
</property>
<property name="text">
<string>Remove Column</string>
</property>
</action>
<action name="DataCommitAction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/commit.png</normaloff>:/Table/images/table/commit.png</iconset>
</property>
<property name="text">
<string>Commit</string>
</property>
</action>
<action name="DataRollbackAction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/table/rollback.png</normaloff>:/Table/images/table/rollback.png</iconset>
</property>
<property name="text">
<string>Rollback</string>
</property>
</action>
<action name="DataRefreshAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/General/images/general/refresh.png</normaloff>:/General/images/general/refresh.png</iconset>
</property>
<property name="text">
<string>Refresh</string>
</property>
</action>
<action name="QueryRunAction">
<property name="icon">
<iconset resource="IoSQL.qrc">
<normaloff>:/Table/images/run-build.png</normaloff>:/Table/images/run-build.png</iconset>
</property>
<property name="text">
<string>Run Query</string>
</property>
<property name="toolTip">
<string>Run an SQL query</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QsciScintilla</class>
<extends>QFrame</extends>
<header>Qsci/qsciscintilla.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>TableTabWidget</tabstop>
<tabstop>DataTableView</tabstop>
<tabstop>StructureTableWidget</tabstop>
<tabstop>QueryTextEdit</tabstop>
<tabstop>ResultsTableView</tabstop>
</tabstops>
<resources>
<include location="IoSQL.qrc"/>
</resources>
<connections/>
</ui>