Various updates.

This commit is contained in:
Raoul Snyman 2011-10-27 14:08:05 +02:00
parent 84d085fe60
commit 07feab6ab6
13 changed files with 273 additions and 138 deletions

View File

@ -9,11 +9,13 @@ SOURCES += main.cpp \
mainwindow.cpp \ mainwindow.cpp \
registerdialog.cpp \ registerdialog.cpp \
tableform.cpp \ tableform.cpp \
sqlform.cpp sqlform.cpp \
lexerscheme.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
registerdialog.h \ registerdialog.h \
tableform.h \ tableform.h \
sqlform.h sqlform.h \
lexerscheme.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
registerdialog.ui \ registerdialog.ui \
tableform.ui \ tableform.ui \

View File

@ -1,6 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: IoSQL # Makefile for building: IoSQL
# Generated by qmake (2.01a) (Qt 4.7.2) on: Fri Jun 24 13:41:46 2011 # Generated by qmake (2.01a) (Qt 4.7.2) on: Tue Sep 6 09:52:18 2011
# Project: IoSQL.pro # Project: IoSQL.pro
# Template: app # Template: app
# Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro # Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile IoSQL.pro
@ -47,7 +47,8 @@ SOURCES = main.cpp \
mainwindow.cpp \ mainwindow.cpp \
registerdialog.cpp \ registerdialog.cpp \
tableform.cpp \ tableform.cpp \
sqlform.cpp moc_mainwindow.cpp \ sqlform.cpp \
lexerscheme.cpp moc_mainwindow.cpp \
moc_registerdialog.cpp \ moc_registerdialog.cpp \
moc_tableform.cpp \ moc_tableform.cpp \
moc_sqlform.cpp \ moc_sqlform.cpp \
@ -57,6 +58,7 @@ OBJECTS = main.o \
registerdialog.o \ registerdialog.o \
tableform.o \ tableform.o \
sqlform.o \ sqlform.o \
lexerscheme.o \
moc_mainwindow.o \ moc_mainwindow.o \
moc_registerdialog.o \ moc_registerdialog.o \
moc_tableform.o \ moc_tableform.o \
@ -171,7 +173,7 @@ qmake: FORCE
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/IoSQL1.0.0 || $(MKDIR) .tmp/IoSQL1.0.0 @$(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 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/IoSQL1.0.0/ && $(COPY_FILE) --parents mainwindow.h registerdialog.h tableform.h sqlform.h lexerscheme.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 lexerscheme.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 clean:compiler_clean
@ -285,6 +287,9 @@ sqlform.o: sqlform.cpp sqlform.h \
ui_sqlform.h ui_sqlform.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o sqlform.o sqlform.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o sqlform.o sqlform.cpp
lexerscheme.o: lexerscheme.cpp lexerscheme.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o lexerscheme.o lexerscheme.cpp
moc_mainwindow.o: moc_mainwindow.cpp moc_mainwindow.o: moc_mainwindow.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp

15
lexerscheme.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "lexerscheme.h"
LexerScheme::LexerScheme()
{
}
QColor LexerScheme::getColor(int style)
{
return colorMap[style];
}
void LexerScheme::setColor(int style, QColor color)
{
colorMap[style] = color;
}

21
lexerscheme.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef LEXERSCHEME_H
#define LEXERSCHEME_H
#include <QColor>
#include <QMap>
class LexerScheme
{
// Default colors
QColor defaultPaper;
QColor defaultColor;
// The rest of the colours
QMap<int, QColor> colorMap;
public:
LexerScheme();
QColor getColor(int style);
void setColor(int style, QColor color);
};
#endif // LEXERSCHEME_H

View File

@ -20,16 +20,8 @@ MainWindow::MainWindow(QWidget *parent) :
QCoreApplication::setOrganizationName("Saturn Laboratories"); QCoreApplication::setOrganizationName("Saturn Laboratories");
QCoreApplication::setOrganizationDomain("saturnlaboratories.co.za"); QCoreApplication::setOrganizationDomain("saturnlaboratories.co.za");
QCoreApplication::setApplicationName("IoSQL"); QCoreApplication::setApplicationName("IoSQL");
ui->setupUi(this); 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_WindowMapper = new QSignalMapper(this);
m_RegisterDialog = new RegisterDialog(this); m_RegisterDialog = new RegisterDialog(this);
m_QueryForm = new SqlForm(this); m_QueryForm = new SqlForm(this);
@ -37,7 +29,11 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_WindowMapper, SIGNAL(mapped(QWidget *)), connect(m_WindowMapper, SIGNAL(mapped(QWidget *)),
this, SLOT(setActiveSubWindow(QWidget *))); this, SLOT(setActiveSubWindow(QWidget *)));
QSettings settings; QSettings settings;
QStringList connectionList = settings.value("connectionList").toStringList(); //qDebug(qPrintable(settings.value("connectionList", QVariant("")).toString()));
QString connections = settings.value("connectionList", QVariant("")).toString();
if (!connections.isEmpty())
{
QStringList connectionList = connections.split(",");
for (int i = 0; i < connectionList.count(); i++) for (int i = 0; i < connectionList.count(); i++)
{ {
QMap<QString, QVariant> connectionMap = settings.value("connection " + connectionList.at(i)).toMap(); QMap<QString, QVariant> connectionMap = settings.value("connection " + connectionList.at(i)).toMap();
@ -51,6 +47,7 @@ MainWindow::MainWindow(QWidget *parent) :
connectionMap.value("password").toString() connectionMap.value("password").toString()
); );
} }
}
QMdiArea::ViewMode viewMode = QMdiArea::ViewMode(settings.value("window mode", QVariant(QMdiArea::SubWindowView)).toInt()); 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()); QTabWidget::TabPosition tabPosition = QTabWidget::TabPosition(settings.value("tab position", QVariant(QTabWidget::North)).toInt());
ui->MdiArea->setViewMode(viewMode); ui->MdiArea->setViewMode(viewMode);
@ -95,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->TabLocationEastAction->setChecked(true); ui->TabLocationEastAction->setChecked(true);
ui->TabLocationWestAction->setChecked(false); ui->TabLocationWestAction->setChecked(false);
} }
this->updateTabCloseButtons();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -147,10 +145,10 @@ bool MainWindow::setupConnection(QString connectionName, QString serverType, QSt
QStringList connectionList; QStringList connectionList;
if (settings.contains("connectionList")) if (settings.contains("connectionList"))
{ {
connectionList = settings.value("connectionList").toStringList(); connectionList = settings.value("connectionList").toString().split(",");
} }
connectionList.append(connectionName); connectionList.append(connectionName);
settings.setValue("connectionList", connectionList); settings.setValue("connectionList", connectionList.join(","));
} }
} }
else else
@ -161,6 +159,23 @@ bool MainWindow::setupConnection(QString connectionName, QString serverType, QSt
return ok; return ok;
} }
void MainWindow::updateTabCloseButtons()
{
if (ui->MdiArea->viewMode() != QMdiArea::TabbedView)
{
return;
}
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)));
}
}
}
void MainWindow::on_WindowMenu_aboutToShow() void MainWindow::on_WindowMenu_aboutToShow()
{ {
ui->WindowMenu->clear(); ui->WindowMenu->clear();
@ -274,8 +289,6 @@ void MainWindow::on_DatabaseTreeWidget_doubleClicked(QModelIndex index)
else if (item->parent() != 0 && item->childCount() == 0) else if (item->parent() != 0 && item->childCount() == 0)
{ {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 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); QString tableName = item->parent()->parent()->text(0) + "." + item->text(0);
QList<QMdiSubWindow *> windows = ui->MdiArea->subWindowList(); QList<QMdiSubWindow *> windows = ui->MdiArea->subWindowList();
bool foundWindow = false; bool foundWindow = false;
@ -292,6 +305,8 @@ void MainWindow::on_DatabaseTreeWidget_doubleClicked(QModelIndex index)
} }
if (!foundWindow) if (!foundWindow)
{ {
TableForm *tableForm = new TableForm(ui->MdiArea);
tableForm->setTable(item->parent()->parent()->text(0), item->text(0));
QMdiSubWindow *subWindow = ui->MdiArea->addSubWindow(tableForm); QMdiSubWindow *subWindow = ui->MdiArea->addSubWindow(tableForm);
subWindow->setWindowTitle(tableName); subWindow->setWindowTitle(tableName);
subWindow->setWindowIcon(QIcon(":/Table/images/table/icon.png")); subWindow->setWindowIcon(QIcon(":/Table/images/table/icon.png"));
@ -370,6 +385,7 @@ void MainWindow::on_ModeTabbedAction_triggered()
ui->ModeSubWindowsAction->setChecked(false); ui->ModeSubWindowsAction->setChecked(false);
ui->ModeTabbedAction->setChecked(true); ui->ModeTabbedAction->setChecked(true);
ui->TabLocationMenu->setEnabled(true); ui->TabLocationMenu->setEnabled(true);
this->updateTabCloseButtons();
} }
void MainWindow::on_TabLocationNorthAction_triggered() void MainWindow::on_TabLocationNorthAction_triggered()

View File

@ -16,13 +16,14 @@ class MainWindow : public QMainWindow {
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void loadConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password); 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); bool setupConnection(QString connectionName, QString serverType, QString serverName, int serverPort, QString databaseName, QString username, QString password);
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
private: private:
void updateTabCloseButtons();
Ui::MainWindow *ui; Ui::MainWindow *ui;
QSignalMapper *m_WindowMapper; QSignalMapper *m_WindowMapper;
RegisterDialog *m_RegisterDialog; RegisterDialog *m_RegisterDialog;

View File

@ -123,3 +123,20 @@ void RegisterDialog::setPassword(const QString password)
{ {
ui->PasswordLineEdit->setText(password); ui->PasswordLineEdit->setText(password);
} }
void RegisterDialog::on_TypeComboBox_currentIndexChanged(int index)
{
QString portNumber = ui->PortLineEdit->text();
if (index == 0 && (portNumber.isEmpty() || portNumber == "3306" || portNumber == "0"))
{
ui->PortLineEdit->setText("5432");
}
else if (index == 1 && (portNumber.isEmpty() || portNumber == "5432" || portNumber == "0"))
{
ui->PortLineEdit->setText("3306");
}
else if (index == 2 && (portNumber.isEmpty() || portNumber == "5432" || portNumber == "3306"))
{
ui->PortLineEdit->setText("0");
}
}

View File

@ -32,6 +32,8 @@ protected:
private slots: private slots:
void on_TypeComboBox_currentIndexChanged(int index);
private: private:
Ui::RegisterDialog *ui; Ui::RegisterDialog *ui;
}; };

View File

@ -52,7 +52,11 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="ServerLineEdit"/> <widget class="QLineEdit" name="ServerLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="PortLabel"> <widget class="QLabel" name="PortLabel">
@ -63,6 +67,9 @@
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="PortLineEdit"> <widget class="QLineEdit" name="PortLineEdit">
<property name="text">
<string>5432</string>
</property>
<property name="frame"> <property name="frame">
<bool>true</bool> <bool>true</bool>
</property> </property>

View File

@ -39,13 +39,17 @@ SqlForm::~SqlForm()
void SqlForm::reloadConnections() void SqlForm::reloadConnections()
{ {
QSettings settings; QSettings settings;
QStringList connectionList = settings.value("connectionList").toStringList(); QString connections = settings.value("connectionList", QVariant("")).toString();
if (!connections.isEmpty())
{
QStringList connectionList = connections.split(",");
m_ConnectionComboBox->clear(); m_ConnectionComboBox->clear();
for (int i = 0; i < connectionList.count(); i++) for (int i = 0; i < connectionList.count(); i++)
{ {
QMap<QString, QVariant> connectionMap = settings.value("connection " + connectionList.at(i)).toMap(); QMap<QString, QVariant> connectionMap = settings.value("connection " + connectionList.at(i)).toMap();
m_ConnectionComboBox->addItem(connectionMap.value("connectionName").toString()); m_ConnectionComboBox->addItem(connectionMap.value("connectionName").toString());
} }
}
} }
void SqlForm::changeEvent(QEvent *e) void SqlForm::changeEvent(QEvent *e)
@ -62,6 +66,8 @@ void SqlForm::changeEvent(QEvent *e)
void SqlForm::on_RunQueryAction_triggered() void SqlForm::on_RunQueryAction_triggered()
{ {
QCursor oldCursor = cursor();
setCursor(Qt::BusyCursor);
m_Database = QSqlDatabase::database(m_ConnectionComboBox->currentText()); m_Database = QSqlDatabase::database(m_ConnectionComboBox->currentText());
m_Database.open(); m_Database.open();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -79,6 +85,22 @@ void SqlForm::on_RunQueryAction_triggered()
query = ui->QueryTextEdit->text(); query = ui->QueryTextEdit->text();
} }
m_QueryModel->setQuery(query, m_Database); m_QueryModel->setQuery(query, m_Database);
/*QSqlError error = m_QueryModel->lastError();
QString errorMessage;
if (error == QSqlError::ConnectionError)
{
errorMessage = "Connection Error: ";
if (!error.driverText().isEmpty())
{
errorMessage = errorMessage + error.driverText();
}
if (!error.databaseText().isEmpty())
{
errorMessage = errorMessage + error.databaseText();
}
}*/
ui->ResultsTableView->setModel(m_QueryModel); ui->ResultsTableView->setModel(m_QueryModel);
ui->ResultsTableView->resizeColumnsToContents(); ui->ResultsTableView->resizeColumnsToContents();
setCursor(oldCursor);
} }

View File

@ -1,11 +1,7 @@
#include "tableform.h" #include "tableform.h"
#include "ui_tableform.h" #include "ui_tableform.h"
#include <QSqlDatabase> #include <QtSql>
#include <QSqlTableModel>
#include <QSqlQueryModel>
#include <QSqlRecord>
#include <QSqlField>
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include <QMainWindow> #include <QMainWindow>
#include <QStatusBar> #include <QStatusBar>
@ -49,69 +45,85 @@ void TableForm::changeEvent(QEvent *e)
} }
} }
void TableForm::setTable(const QString connectionName, const QString tableName) void TableForm::setColumns()
{ {
QMainWindow * mainWindow = qobject_cast<QMainWindow*>(window()); QSqlQuery query;
if (mainWindow) if (m_Database.driverName() == "QPSQL")
mainWindow->statusBar()->showMessage("Opening table \"" + tableName + "\"..."); {
QCoreApplication::processEvents(); query = QSqlQuery("SELECT * FROM \"" + m_TableName + "\" LIMIT 1", m_Database);
m_ConnectionName = connectionName; // SELECT column_name, column_default, is_nullable, data_type, character_maximum_length FROM information_schema.columns WHERE table_name = "" ORDER BY ordinal_position
m_TableName = tableName; }
m_Database = QSqlDatabase::database(m_ConnectionName); else if (m_Database.driverName() == "MYSQL")
m_DataModel = new QSqlTableModel(this, m_Database); {
m_DataModel->setTable(m_TableName); query = QSqlQuery("SELECT * FROM `" + m_TableName + "` LIMIT 1", m_Database);
m_DataModel->select(); // SELECT COLUMN_NAME AS column_name, COLUMN_DEFAULT AS column_default, IS_NULLABLE AS is_nullable, DATA_TYPE AS data_type, CHARACTER_MAXIMUM_LENGTH AS character_maximum_length FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "" ORDER BY ordinal_position
ui->DataTableView->setModel(m_DataModel); }
ui->DataTableView->resizeColumnsToContents(); else if (m_Database.driverName() == "SQLITE")
QSqlRecord record = m_DataModel->record(); {
query = QSqlQuery("SELECT * FROM '" + m_TableName + "'' LIMIT 1", m_Database);
// SELECT
}
QSqlRecord record = query.record();
ui->StructureTableWidget->setRowCount(record.count()); ui->StructureTableWidget->setRowCount(record.count());
for (int i = 0; i < record.count(); i++) for (int i = 0; i < record.count(); i++)
{ {
QSqlField field = record.field(i); QSqlField field = record.field(i);
QTableWidgetItem *nameItem = new QTableWidgetItem(field.name()); QTableWidgetItem *nameItem = new QTableWidgetItem(field.name());
QString typeName; QString typeName = QVariant::typeToName(field.type());
switch (field.type()) QTableWidgetItem *typeItem = new QTableWidgetItem(typeName + " - " + QString::number(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; QTableWidgetItem *sizeItem;
if (field.length() >= 0) if (field.length() >= 0)
{ {
sizeItem = new QTableWidgetItem(field.length()); sizeItem = new QTableWidgetItem(QString::number(field.length()));
} }
else if (field.precision() >= 0) else if (field.precision() >= 0)
{ {
sizeItem = new QTableWidgetItem(field.precision()); sizeItem = new QTableWidgetItem(QString::number(field.precision()));
} }
else else
{ {
sizeItem = new QTableWidgetItem(""); sizeItem = new QTableWidgetItem("");
} }
QTableWidgetItem *nullItem; QTableWidgetItem *nullItem;
if (field.requiredStatus()) if (field.requiredStatus() == 1)
{ {
nullItem = new QTableWidgetItem("not null"); nullItem = new QTableWidgetItem("not null");
} }
else else if (field.requiredStatus() == 0)
{ {
nullItem = new QTableWidgetItem("nullable"); nullItem = new QTableWidgetItem("nullable");
} }
else
{
nullItem = new QTableWidgetItem("unknown");
}
ui->StructureTableWidget->setItem(i, 0, nameItem); ui->StructureTableWidget->setItem(i, 0, nameItem);
ui->StructureTableWidget->setItem(i, 1, typeItem); ui->StructureTableWidget->setItem(i, 1, typeItem);
ui->StructureTableWidget->setItem(i, 2, sizeItem); ui->StructureTableWidget->setItem(i, 2, sizeItem);
ui->StructureTableWidget->setItem(i, 3, nullItem); ui->StructureTableWidget->setItem(i, 3, nullItem);
} }
ui->StructureTableWidget->resizeColumnsToContents(); ui->StructureTableWidget->resizeColumnsToContents();
}
void TableForm::setTable(const QString connectionName, const QString tableName)
{
QMainWindow * mainWindow = qobject_cast<QMainWindow*>(window());
if (mainWindow) if (mainWindow)
{
mainWindow->statusBar()->showMessage("Opening table \"" + tableName + "\"...");
}
QCoreApplication::processEvents();
m_ConnectionName = connectionName;
m_TableName = tableName;
m_Database = QSqlDatabase::database(m_ConnectionName);
this->setColumns();
m_DataModel = new QSqlTableModel(this, m_Database);
m_DataModel->setTable(m_TableName);
ui->DataTableView->setModel(m_DataModel);
if (mainWindow)
{
mainWindow->statusBar()->clearMessage(); mainWindow->statusBar()->clearMessage();
}
} }
void TableForm::on_DataCommitAction_triggered() void TableForm::on_DataCommitAction_triggered()
@ -126,15 +138,26 @@ void TableForm::on_DataCommitAction_triggered()
void TableForm::on_DataRefreshAction_triggered() void TableForm::on_DataRefreshAction_triggered()
{ {
QMainWindow * mainWindow = qobject_cast<QMainWindow*>(window());
if (mainWindow)
{
mainWindow->statusBar()->showMessage("Fetching results from \"" + m_TableName + "\"...");
}
m_DataModel->select(); m_DataModel->select();
ui->DataTableView->resizeColumnsToContents(); ui->DataTableView->resizeColumnsToContents();
if (mainWindow)
{
mainWindow->statusBar()->clearMessage();
}
} }
void TableForm::on_QueryRunAction_triggered() void TableForm::on_QueryRunAction_triggered()
{ {
QMainWindow * mainWindow = qobject_cast<QMainWindow*>(window()); QMainWindow * mainWindow = qobject_cast<QMainWindow*>(window());
if (mainWindow) if (mainWindow)
{
mainWindow->statusBar()->showMessage("Running query..."); mainWindow->statusBar()->showMessage("Running query...");
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QString query = ""; QString query = "";
@ -155,5 +178,7 @@ void TableForm::on_QueryRunAction_triggered()
ui->ResultsTableView->resizeColumnsToContents(); ui->ResultsTableView->resizeColumnsToContents();
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (mainWindow) if (mainWindow)
{
mainWindow->statusBar()->clearMessage(); mainWindow->statusBar()->clearMessage();
}
} }

View File

@ -16,6 +16,7 @@ public:
TableForm(QWidget *parent = 0); TableForm(QWidget *parent = 0);
~TableForm(); ~TableForm();
void setTable(const QString connectionName, const QString tableName); void setTable(const QString connectionName, const QString tableName);
void setColumns();
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);

View File

@ -29,70 +29,6 @@
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </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"> <widget class="QWidget" name="StructureTab">
<attribute name="title"> <attribute name="title">
<string>Structure</string> <string>Structure</string>
@ -159,6 +95,70 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<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="QueryTab"> <widget class="QWidget" name="QueryTab">
<attribute name="title"> <attribute name="title">
<string>Query</string> <string>Query</string>
@ -314,6 +314,7 @@
<class>QsciScintilla</class> <class>QsciScintilla</class>
<extends>QFrame</extends> <extends>QFrame</extends>
<header>Qsci/qsciscintilla.h</header> <header>Qsci/qsciscintilla.h</header>
<container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>