From bab3683e180d2b2f77a2bf9feedc6c61163d9515 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Mon, 31 Dec 2012 15:56:33 +0100 Subject: [PATCH] Create Qt Designer form for editTableForm dialog --- src/edittableform.cpp | 1027 ++++++++++++++++++----------------------- src/edittableform.h | 181 +------- src/edittableform.ui | 281 +++++++++++ src/src.pro | 3 +- 4 files changed, 734 insertions(+), 758 deletions(-) create mode 100644 src/edittableform.ui diff --git a/src/edittableform.cpp b/src/edittableform.cpp index 6e4d325d..25ef4efa 100644 --- a/src/edittableform.cpp +++ b/src/edittableform.cpp @@ -1,13 +1,9 @@ #include "edittableform.h" - -#include -#include -#include -#include -#include - +#include "ui_edittableform.h" #include "renametableform.h" #include "editfieldform.h" +#include + /* * Constructs a editTableForm as a child of 'parent', with the * name 'name' and widget flags set to 'f'. @@ -16,9 +12,10 @@ * true to construct a modal dialog. */ editTableForm::editTableForm(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl) + : QDialog(parent, fl), + ui(new Ui::editTableForm) { - setupUi(this); + ui->setupUi(this); init(); } @@ -28,16 +25,7 @@ editTableForm::editTableForm(QWidget* parent, Qt::WindowFlags fl) */ editTableForm::~editTableForm() { - // no need to delete child widgets, Qt does it all for us -} - -/* - * Sets the strings of the subwidgets using the current - * language. - */ -void editTableForm::languageChange() -{ - retranslateUi(this); + delete ui; } void editTableForm::init() @@ -51,7 +39,7 @@ void editTableForm::setActiveTable(DBBrowserDB * thedb, QString tableName) pdb = thedb; curTable = tableName; populateFields(); - tableLine->setText(curTable); + ui->editTableName->setText(curTable); } void editTableForm::populateFields() @@ -63,632 +51,505 @@ void editTableForm::populateFields() fields= pdb->getTableFields(curTable); types= pdb->getTableTypes(curTable); - treeWidget->model()->removeRows(0, treeWidget->model()->rowCount()); + ui->treeWidget->model()->removeRows(0, ui->treeWidget->model()->rowCount()); QStringList::Iterator tt = types.begin(); for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { QTreeWidgetItem *fldItem = new QTreeWidgetItem(); - //Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView, lasttbitem); fldItem->setText( 0, *ct ); fldItem->setText( 1, *tt ); - //lasttbitem = tbitem; - treeWidget->addTopLevelItem(fldItem); + ui->treeWidget->addTopLevelItem(fldItem); ++tt; } } -void editTableForm::renameTable() +void editTableForm::accept() { - renameTableForm * renTableForm = new renameTableForm( this ); - renTableForm->setModal(true); - renTableForm->setTableName(curTable); - if (renTableForm->exec()) - { - QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time - modified = true; - QString newName = renTableForm->getTableName(); - //qDebug(newName); - //QString sql; - //do the sql rename here - //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))){ - // goto rollback; - //} - QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName); - //qDebug(sql); - if (!pdb->executeSQL(sql)){ - //qDebug("OOPS"); - //qDebug( pdb->lastErrorMessage); - QApplication::restoreOverrideCursor(); - statusBar->showMessage(pdb->lastErrorMessage, 5000); - QString error("Error renaming table. Message from database engine:\n"); - error.append(pdb->lastErrorMessage).append("\n\n").append(sql); - //error.append("").arg(pdb->lastErrorMessage).arg(sql); - //error.append(pdb->lastErrorMessage); - QMessageBox::warning( this, QApplication::applicationName(), error ); - return; - } - + // Rename table + QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time + modified = true; + QString newName = ui->editTableName->text(); + QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName); + if (!pdb->executeSQL(sql)){ QApplication::restoreOverrideCursor(); - statusBar->showMessage(QString("Renamed %1 to %2").arg(curTable, newName), 5000); - //} - //sQApplication::restoreOverrideCursor(); // restore original cursor - //QString error = "Error renaming table. Message from database engine: "; - //error.append(pdb->lastErrorMessage); - // QMessageBox::warning( this, applicationName, error ); - // pdb->executeSQ(QString("DROP TABLE TEMP_TABLE;")); - // //pdb->executeSQL(QString("ROLLBACK;")); - setActiveTable(pdb, curTable); - tableLine->setText(newName); - return; - - // WTF is below ??? + QString error("Error renaming table. Message from database engine:\n"); + error.append(pdb->lastErrorMessage).append("\n\n").append(sql); + QMessageBox::warning( this, QApplication::applicationName(), error ); + } else { + QApplication::restoreOverrideCursor(); + QDialog::accept(); } -// sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; -// Q3ListViewItemIterator it( fieldListView ); -// Q3ListViewItem * item; -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO TEMP_TABLE SELECT "; -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(" FROM "); -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "DROP TABLE "; -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "CREATE TABLE "; -// sql.append(newName); -// sql.append(" ("); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO "; -// sql.append(newName); -// sql.append(" SELECT "); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(" FROM TEMP_TABLE;"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; -// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; -// -// setActiveTable(pdb, newName); -// } -// -// //everything ok, just return -// QApplication::restoreOverrideCursor(); // restore original cursor -// return; -// - // rollback: - // QApplication::restoreOverrideCursor(); // restore original cursor - //QString error = "Error renaming table. Message from database engine: "; - //error.append(pdb->lastErrorMessage); - // QMessageBox::warning( this, applicationName, error ); -// pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;")); -// //pdb->executeSQL(QString("ROLLBACK;")); -// setActiveTable(pdb, curTable); } +void editTableForm::checkInput() +{ + ui->editTableName->setText(ui->editTableName->text().trimmed()); + bool valid = true; + if(ui->editTableName->text().isEmpty() || ui->editTableName->text().contains(" ")) + valid = false; + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); +} void editTableForm::editField() { - //Q3ListViewItem * item = fieldListView->selectedItem(); - if( !treeWidget->currentItem()){ + if( !ui->treeWidget->currentItem()){ return; } - QTreeWidgetItem *item = treeWidget->currentItem(); - //if (item==0) { - //should never happen, the button would not be active, but... - // return; - // } else { - editFieldForm * fieldForm = new editFieldForm( this ); - fieldForm->setModal(true); - fieldForm->setInitialValues(false, curTable, item->text(0), item->text(1)); - if (fieldForm->exec()) - { - modified = true; - //do the sql rename here - //qDebug(fieldForm->name + fieldForm->type); - item->setText(0,fieldForm->field_name); - item->setText(1,fieldForm->field_name); - } - //not until nested transaction are supported - //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; + QTreeWidgetItem *item = ui->treeWidget->currentItem(); + editFieldForm * fieldForm = new editFieldForm( this ); + fieldForm->setModal(true); + fieldForm->setInitialValues(false, curTable, item->text(0), item->text(1)); + if (fieldForm->exec()) + { + modified = true; + //do the sql rename here + //qDebug(fieldForm->name + fieldForm->type); + item->setText(0,fieldForm->field_name); + item->setText(1,fieldForm->field_name); + } + //not until nested transaction are supported + //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; -// QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; -// Q3ListViewItemIterator it( fieldListView ); -// Q3ListViewItem * item; -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO TEMP_TABLE SELECT "; -// for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { -// sql.append( *ct ); -// if (*ct != fields.last()) -// { -// sql.append(", "); -// } -// } -// -// sql.append(" FROM "); -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "DROP TABLE "; -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "CREATE TABLE "; -// sql.append(curTable); -// sql.append(" ("); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO "; -// sql.append(curTable); -// sql.append(" SELECT "); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(" FROM TEMP_TABLE;"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; -// //not until nested transaction are supported -// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; -// -// setActiveTable(pdb, curTable); -// } -// //everything ok, just return -// QApplication::restoreOverrideCursor(); // restore original cursor -// return; -// -// rollback: -// QApplication::restoreOverrideCursor(); // restore original cursor -// QString error = "Error editing field. Message from database engine: "; -// error.append(pdb->lastErrorMessage); -// QMessageBox::warning( this, applicationName, error ); -// //not until nested transaction are supported -// //pdb->executeSQL(QString("ROLLBACK;")); -// setActiveTable(pdb, curTable); + // QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; + // Q3ListViewItemIterator it( fieldListView ); + // Q3ListViewItem * item; + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // sql.append(" "); + // sql.append(item->text(1)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "INSERT INTO TEMP_TABLE SELECT "; + // for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { + // sql.append( *ct ); + // if (*ct != fields.last()) + // { + // sql.append(", "); + // } + // } + // + // sql.append(" FROM "); + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "DROP TABLE "; + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "CREATE TABLE "; + // sql.append(curTable); + // sql.append(" ("); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // sql.append(" "); + // sql.append(item->text(1)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "INSERT INTO "; + // sql.append(curTable); + // sql.append(" SELECT "); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(" FROM TEMP_TABLE;"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; + // //not until nested transaction are supported + // //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; + // + // setActiveTable(pdb, curTable); + // } + // //everything ok, just return + // QApplication::restoreOverrideCursor(); // restore original cursor + // return; + // + // rollback: + // QApplication::restoreOverrideCursor(); // restore original cursor + // QString error = "Error editing field. Message from database engine: "; + // error.append(pdb->lastErrorMessage); + // QMessageBox::warning( this, applicationName, error ); + // //not until nested transaction are supported + // //pdb->executeSQL(QString("ROLLBACK;")); + // setActiveTable(pdb, curTable); //} } void editTableForm::addField() { - editFieldForm * addForm = new editFieldForm( this ); - addForm->setModal(true); - addForm->setInitialValues(true, curTable, QString(""),QString("")); + editFieldForm * addForm = new editFieldForm( this ); + addForm->setModal(true); + addForm->setInitialValues(true, curTable, QString(""),QString("")); if (addForm->exec()) - { + { modified = true; - //Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView); QTreeWidgetItem *tbitem = new QTreeWidgetItem(); tbitem->setText( 0, addForm->field_name); tbitem->setText( 1, addForm->field_name); - //do the sql creation here + //do the sql creation here modified = true; - //do the sql rename here - //qDebug(fieldForm->name + fieldForm->type); + //do the sql rename here + //qDebug(fieldForm->name + fieldForm->type); QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; } - // Q3ListViewItemIterator it( fieldListView ); - // Q3ListViewItem * item; + // Q3ListViewItemIterator it( fieldListView ); + // Q3ListViewItem * item; - //not until nested transaction are supported - //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; + //not until nested transaction are supported + //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; - // {//nest for MSVC support -// for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { -// sql.append( *ct ); -// if (*ct != fields.last()) -// { -// sql.append(", "); -// } -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO TEMP_TABLE SELECT "; -// for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) { -// sql.append( *ct1 ); -// if (*ct1 != fields.last()) -// { -// sql.append(", "); -// } -// } -// } -// -// sql.append(" FROM "); -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "DROP TABLE "; -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "CREATE TABLE "; -// sql.append(curTable); -// sql.append(" ("); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// {//nest for MSVC support -// -// sql = "INSERT INTO "; -// sql.append(curT for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { - //sql.append( *ct ); - //if (*ct != fields.last()) - // { - // sql.append(", "); - // } + // {//nest for MSVC support + // for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { + // sql.append( *ct ); + // if (*ct != fields.last()) + // { + // sql.append(", "); + // } + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "INSERT INTO TEMP_TABLE SELECT "; + // for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) { + // sql.append( *ct1 ); + // if (*ct1 != fields.last()) + // { + // sql.append(", "); + // } + // } + // } + // + // sql.append(" FROM "); + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "DROP TABLE "; + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "CREATE TABLE "; + // sql.append(curTable); + // sql.append(" ("); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // sql.append(" "); + // sql.append(item->text(1)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // {//nest for MSVC support + // + // sql = "INSERT INTO "; + // sql.append(curT for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { + //sql.append( *ct ); + //if (*ct != fields.last()) + // { + // sql.append(", "); + // } //} //sql.append(");"); - // if (!pdb->executeSQL(sql)) goto rollback; + // if (!pdb->executeSQL(sql)) goto rollback; - // sql = "INSERT INTO TEMP_TABLE SELECT "; - // for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) { - // sql.append( *ct1 ); - // if (*ct1 != fields.last()) - // { - // sql.append(", "); - // } - // } -//} + // sql = "INSERT INTO TEMP_TABLE SELECT "; + // for ( QStringList::Iterator ct1 = fields.begin(); ct1 != fields.end(); ++ct1 ) { + // sql.append( *ct1 ); + // if (*ct1 != fields.last()) + // { + // sql.append(", "); + // } + // } + //} - // sql.append(" FROM "); - // sql.append(";"); + // sql.append(" FROM "); + // sql.append(";"); //if (!pdb->executeSQL(sql)) goto rollback; - //// sql = "DROP TABLE "; - // sql.append(curTable); - // sql.append(";"); - // if (!pdb->executeSQL(sql)) goto rollback; + //// sql = "DROP TABLE "; + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; - // sql = "CREATE TABLE "; - // sql.append(curTable); - // sql.append(" ("); - // it = Q3ListViewItemIterator( fieldListView ); - // while ( it.current() ) { - // item = it.current(); - // sql.append(item->text(0)); + // sql = "CREATE TABLE "; + // sql.append(curTable); + // sql.append(" ("); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); /// sql.append(" "); - // sql.append(item->text(1)); + // sql.append(item->text(1)); // if (item->nextSibling() != 0) // { - // sql.append(", "); + // sql.append(", "); // } - // ++it; - // } + // ++it; + // } //sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -//{//nest for MSVC support -// -// sql = "INSERT INTO "; -// sql.append(curTable); -// sql.append("("); -// for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) { -// sql.append( *ct2 ); -// if (*ct2 != fields.last()) -// { -// sql.append(", "); -// } -// } -//} -//{//nest for MSVC support -// -// sql.append(") SELECT "); -// for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) { -// sql.append( *ct3 ); -// if (*ct3 != fields.last()) -// { -// sql.append(", "); -// } -// } -//} -// -// sql.append(" FROM TEMP_TABLE;"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; -// //not until nested transaction are supported -// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; -// -// setActiveTable(pdb, curTable); -// -// QApplication::restoreOverrideCursor(); // restore original cursor -//return; -// -//rollback: -// QApplication::restoreOverrideCursor(); // restore original cursor -// QString error = "Error adding field. Message from database engine: "; -// error.append(pdb->lastErrorMessage); -// QMessageBox::warning( this, applicationName, error ); -// -// //not until nested transaction are supported -// //pdb->executeSQL(QString("ROLLBACK;")); -// setActiveTable(pdb, curTable);able); -// sql.append("("); -// for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) { -// sql.append( *ct2 ); -// if (*ct2 != fields.last()) -// { -// sql.append(", "); -// } -// } -// } -// {//nest for MSVC support -// -// sql.append(") SELECT "); -// for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) { -// sql.append( *ct3 ); -// if (*ct3 != fields.last()) -// { -// sql.append(", "); -// } -// } -// } -// -// sql.append(" FROM TEMP_TABLE;"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; -// //not until nested transaction are supported -// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; -// -// setActiveTable(pdb, curTable); -// -// QApplication::restoreOverrideCursor(); // restore original cursor -// return; -// -// rollback: -// QApplication::restoreOverrideCursor(); // restore original cursor -// QString error = "Error adding field. Message from database engine: "; -// error.append(pdb->lastErrorMessage); -// QMessageBox::warning( this, applicationName, error ); -// -// //not until nested transaction are supported -// //pdb->executeSQL(QString("ROLLBACK;")); -// setActiveTable(pdb, curTable); - //s} + // if (!pdb->executeSQL(sql)) goto rollback; + //{//nest for MSVC support + // + // sql = "INSERT INTO "; + // sql.append(curTable); + // sql.append("("); + // for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) { + // sql.append( *ct2 ); + // if (*ct2 != fields.last()) + // { + // sql.append(", "); + // } + // } + //} + //{//nest for MSVC support + // + // sql.append(") SELECT "); + // for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) { + // sql.append( *ct3 ); + // if (*ct3 != fields.last()) + // { + // sql.append(", "); + // } + // } + //} + // + // sql.append(" FROM TEMP_TABLE;"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; + // //not until nested transaction are supported + // //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; + // + // setActiveTable(pdb, curTable); + // + // QApplication::restoreOverrideCursor(); // restore original cursor + //return; + // + //rollback: + // QApplication::restoreOverrideCursor(); // restore original cursor + // QString error = "Error adding field. Message from database engine: "; + // error.append(pdb->lastErrorMessage); + // QMessageBox::warning( this, applicationName, error ); + // + // //not until nested transaction are supported + // //pdb->executeSQL(QString("ROLLBACK;")); + // setActiveTable(pdb, curTable);able); + // sql.append("("); + // for ( QStringList::Iterator ct2 = fields.begin(); ct2 != fields.end(); ++ct2 ) { + // sql.append( *ct2 ); + // if (*ct2 != fields.last()) + // { + // sql.append(", "); + // } + // } + // } + // {//nest for MSVC support + // + // sql.append(") SELECT "); + // for ( QStringList::Iterator ct3 = fields.begin(); ct3 != fields.end(); ++ct3 ) { + // sql.append( *ct3 ); + // if (*ct3 != fields.last()) + // { + // sql.append(", "); + // } + // } + // } + // + // sql.append(" FROM TEMP_TABLE;"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; + // //not until nested transaction are supported + // //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; + // + // setActiveTable(pdb, curTable); + // + // QApplication::restoreOverrideCursor(); // restore original cursor + // return; + // + // rollback: + // QApplication::restoreOverrideCursor(); // restore original cursor + // QString error = "Error adding field. Message from database engine: "; + // error.append(pdb->lastErrorMessage); + // QMessageBox::warning( this, applicationName, error ); + // + // //not until nested transaction are supported + // //pdb->executeSQL(QString("ROLLBACK;")); + // setActiveTable(pdb, curTable); + //s} } void editTableForm::removeField() { - if(!treeWidget->currentItem()){ + if(!ui->treeWidget->currentItem()){ return; } - //remItem = - //Q3ListViewItem * remitem = fieldListView->selectedItem(); - // if (remitem==0) { - //should never happen, the button would not be active, but... - // return; - //} else { - QString msg = "Are you sure you want to delete field "; - msg.append(treeWidget->currentItem()->text(0)); - msg.append("? \n All data currently stored in this field will be lost"); - if (QMessageBox::warning( this, QApplication::applicationName(), - msg, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No | QMessageBox::Escape ) + QString msg = "Are you sure you want to delete field "; + msg.append(ui->treeWidget->currentItem()->text(0)); + msg.append("? \n All data currently stored in this field will be lost"); + + if (QMessageBox::warning( this, QApplication::applicationName(), + msg, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ){ - //delete field here + //delete field here - } - /*fields= pdb->getTableFields(curTable); + } + /*fields= pdb->getTableFields(curTable); types= pdb->getTableTypes(curTable);*/ - //modified = true; - // delete remitem; -// QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; -// Q3ListViewItemIterator it( fieldListView ); -// Q3ListViewItem * item; -// -// //not until nested transaction are supported -// // if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; -// -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO TEMP_TABLE SELECT "; -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// -// sql.append(" FROM "); -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "DROP TABLE "; -// sql.append(curTable); -// sql.append(";"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "CREATE TABLE "; -// sql.append(curTable); -// sql.append(" ("); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// sql.append(" "); -// sql.append(item->text(1)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(");"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// sql = "INSERT INTO "; -// sql.append(curTable); -// sql.append("("); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(") SELECT "); -// it = Q3ListViewItemIterator( fieldListView ); -// while ( it.current() ) { -// item = it.current(); -// sql.append(item->text(0)); -// if (item->nextSibling() != 0) -// { -// sql.append(", "); -// } -// ++it; -// } -// sql.append(" FROM TEMP_TABLE;"); -// if (!pdb->executeSQL(sql)) goto rollback; -// -// if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; -// //not until nested transaction are supported -// //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; -// -// setActiveTable(pdb, curTable); -// -// QApplication::restoreOverrideCursor(); // restore original cursor -// return; -// -// rollback: -// QApplication::restoreOverrideCursor(); // restore original cursor -// QString error = "Error removing field. Message from database engine: "; -// error.append(pdb->lastErrorMessage); -// QMessageBox::warning( this, applicationName, error ); -// -// //not until nested transaction are supported -// //pdb->executeSQL(QString("ROLLBACK;")); -// setActiveTable(pdb, curTable); -// } -// //} + //modified = true; + // delete remitem; + // QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE("; + // Q3ListViewItemIterator it( fieldListView ); + // Q3ListViewItem * item; + // + // //not until nested transaction are supported + // // if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; + // + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // sql.append(" "); + // sql.append(item->text(1)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "INSERT INTO TEMP_TABLE SELECT "; + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // + // sql.append(" FROM "); + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "DROP TABLE "; + // sql.append(curTable); + // sql.append(";"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "CREATE TABLE "; + // sql.append(curTable); + // sql.append(" ("); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // sql.append(" "); + // sql.append(item->text(1)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(");"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // sql = "INSERT INTO "; + // sql.append(curTable); + // sql.append("("); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(") SELECT "); + // it = Q3ListViewItemIterator( fieldListView ); + // while ( it.current() ) { + // item = it.current(); + // sql.append(item->text(0)); + // if (item->nextSibling() != 0) + // { + // sql.append(", "); + // } + // ++it; + // } + // sql.append(" FROM TEMP_TABLE;"); + // if (!pdb->executeSQL(sql)) goto rollback; + // + // if (!pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"))) goto rollback; + // //not until nested transaction are supported + // //if (!pdb->executeSQL(QString("COMMIT;"))) goto rollback; + // + // setActiveTable(pdb, curTable); + // + // QApplication::restoreOverrideCursor(); // restore original cursor + // return; + // + // rollback: + // QApplication::restoreOverrideCursor(); // restore original cursor + // QString error = "Error removing field. Message from database engine: "; + // error.append(pdb->lastErrorMessage); + // QMessageBox::warning( this, applicationName, error ); + // + // //not until nested transaction are supported + // //pdb->executeSQL(QString("ROLLBACK;")); + // setActiveTable(pdb, curTable); + // } + // //} } void editTableForm::fieldSelectionChanged() { - renameFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection()); - removeFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection()); + ui->renameFieldButton->setEnabled(ui->treeWidget->selectionModel()->hasSelection()); + ui->removeFieldButton->setEnabled(ui->treeWidget->selectionModel()->hasSelection()); } - - diff --git a/src/edittableform.h b/src/edittableform.h index 9bda7963..237efafa 100644 --- a/src/edittableform.h +++ b/src/edittableform.h @@ -1,179 +1,14 @@ #ifndef EDITTABLEFORM_H #define EDITTABLEFORM_H -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include "sqlitedb.h" -QT_BEGIN_NAMESPACE - -class Ui_editTableForm -{ -public: - // QGridLayout *gridLayout; - //QVBoxLayout *vboxLayout; - - - QLabel *tableLine; - - QTreeWidget *treeWidget; - - QToolButton *renameTableButton; - - QToolButton *renameFieldButton; - QToolButton *removeFieldButton; - QToolButton *addFieldButton; - - QPushButton *closeButton; - - QStatusBar *statusBar; - - void setupUi(QDialog *editTableForm) - { - if (editTableForm->objectName().isEmpty()){ - editTableForm->setObjectName(QString::fromUtf8("editTableForm")); - } - editTableForm->setWindowIcon(QIcon(":/icons/table")); - //TODO remember sizes - editTableForm->resize(500, 500); - - QVBoxLayout *mainVBoxLayout = new QVBoxLayout(); - editTableForm->setLayout(mainVBoxLayout); - mainVBoxLayout->setSpacing(10); - int m = 10; - mainVBoxLayout->setContentsMargins(m,m,m,m); - - //****************************************** - //** Table Group Box - QGroupBox *grpTable = new QGroupBox(); - mainVBoxLayout->addWidget(grpTable); - grpTable->setTitle("Table"); - QHBoxLayout *grpTableLayout = new QHBoxLayout(); - grpTable->setLayout(grpTableLayout); - grpTableLayout->setSpacing(0); - - //** Table Text - tableLine = new QLabel(editTableForm); - tableLine->setObjectName(QString::fromUtf8("tableLine")); - tableLine->setStyleSheet("font-weight: bold; border: 1px solid #dddddd; background-color: white;"); - grpTableLayout->addWidget(tableLine); - - //** Rename Table - renameTableButton = new QToolButton(editTableForm); - renameTableButton->setObjectName(QString::fromUtf8("renameTableButton")); - renameTableButton->setIcon(QIcon(":/icons/table_modify")); - renameTableButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - grpTableLayout->addWidget(renameTableButton); - - - //****************************************** - //** Fields Group Box - QGroupBox *grpFields = new QGroupBox(); - mainVBoxLayout->addWidget(grpFields); - grpFields->setTitle("Fields"); - QVBoxLayout *grpFieldsLayout = new QVBoxLayout(); - grpFields->setLayout(grpFieldsLayout); - grpFieldsLayout->setSpacing(0); - - //** Fields Toolbar ** - QToolBar *toolBar = new QToolBar(); - grpFieldsLayout->addWidget(toolBar); - - //** Add Field - addFieldButton = new QToolButton(editTableForm); - addFieldButton->setObjectName(QString::fromUtf8("addFieldButton")); - addFieldButton->setIcon(QIcon(":/icons/field_add")); - addFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolBar->addWidget(addFieldButton); - - //** Rename Field - renameFieldButton = new QToolButton(editTableForm); - renameFieldButton->setObjectName(QString::fromUtf8("renameFieldButton")); - renameFieldButton->setEnabled(false); - renameFieldButton->setIcon(QIcon(":/icons/field_edit")); - renameFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolBar->addWidget(renameFieldButton); - - //** Remove Field - removeFieldButton = new QToolButton(editTableForm); - removeFieldButton->setObjectName(QString::fromUtf8("removeFieldButton")); - removeFieldButton->setEnabled(false); - removeFieldButton->setIcon(QIcon(":/icons/field_delete")); - removeFieldButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolBar->addWidget(removeFieldButton); - - //**** Tree Widget - treeWidget = new QTreeWidget(); - grpFieldsLayout->addWidget(treeWidget); - treeWidget->headerItem()->setText(0, QApplication::translate("createTableForm", "Field name", 0, QApplication::UnicodeUTF8)); - treeWidget->headerItem()->setText(1, QApplication::translate("createTableForm", "Field type", 0, QApplication::UnicodeUTF8)); - treeWidget->setRootIsDecorated(false); - treeWidget->setAlternatingRowColors(true); - - - //*** Bottom button box - QHBoxLayout *bottomButtonBox = new QHBoxLayout(); - mainVBoxLayout->addLayout(bottomButtonBox); - bottomButtonBox->addStretch(10); - closeButton = new QPushButton(editTableForm); - closeButton->setObjectName(QString::fromUtf8("closeButton")); - bottomButtonBox->addWidget(closeButton); - - statusBar = new QStatusBar(); - mainVBoxLayout->addWidget(statusBar); - - retranslateUi(editTableForm); - QObject::connect(closeButton, SIGNAL(clicked()), editTableForm, SLOT(accept())); - QObject::connect(renameTableButton, SIGNAL(clicked()), editTableForm, SLOT(renameTable())); - QObject::connect(removeFieldButton, SIGNAL(clicked()), editTableForm, SLOT(removeField())); - QObject::connect(addFieldButton, SIGNAL(clicked()), editTableForm, SLOT(addField())); - QObject::connect(renameFieldButton, SIGNAL(clicked()), editTableForm, SLOT(editField())); - QObject::connect(treeWidget, SIGNAL(itemSelectionChanged()), editTableForm, SLOT(fieldSelectionChanged())); - - QMetaObject::connectSlotsByName(editTableForm); - } // setupUi - - void retranslateUi(QDialog *editTableForm) - { - editTableForm->setWindowTitle(QApplication::translate("editTableForm", "Edit table definition", 0, QApplication::UnicodeUTF8)); - treeWidget->headerItem()->setText(0, QApplication::translate("editTableForm", "Field name", 0, QApplication::UnicodeUTF8)); - treeWidget->headerItem()->setText(1, QApplication::translate("editTableForm", "Field type", 0, QApplication::UnicodeUTF8)); - - renameTableButton->setText(QApplication::translate("editTableForm", "Rename table", 0, QApplication::UnicodeUTF8)); - renameFieldButton->setText(QApplication::translate("editTableForm", "Edit field", 0, QApplication::UnicodeUTF8)); - removeFieldButton->setText(QApplication::translate("editTableForm", "Remove field", 0, QApplication::UnicodeUTF8)); - addFieldButton->setText(QApplication::translate("editTableForm", "Add field", 0, QApplication::UnicodeUTF8)); - closeButton->setText(QApplication::translate("editTableForm", "Close", 0, QApplication::UnicodeUTF8)); - } // retranslateUi - -}; - namespace Ui { - class editTableForm: public Ui_editTableForm {}; -} // namespace Ui +class editTableForm; +} -QT_END_NAMESPACE - -class editTableForm : public QDialog, public Ui::editTableForm +class editTableForm : public QDialog { Q_OBJECT @@ -187,23 +22,21 @@ public: public slots: virtual void setActiveTable( DBBrowserDB * thedb, QString tableName ); virtual void populateFields(); - virtual void renameTable(); virtual void editField(); virtual void addField(); virtual void removeField(); virtual void fieldSelectionChanged(); + virtual void accept(); + virtual void checkInput(); protected: QStringList types; QStringList fields; DBBrowserDB * pdb; -protected slots: - virtual void languageChange(); - private: void init(); - + Ui::editTableForm *ui; }; #endif // EDITTABLEFORM_H diff --git a/src/edittableform.ui b/src/edittableform.ui new file mode 100644 index 00000000..15a5ca43 --- /dev/null +++ b/src/edittableform.ui @@ -0,0 +1,281 @@ + + + editTableForm + + + + 0 + 0 + 414 + 405 + + + + Edit table definition + + + + :/icons/table:/icons/table + + + + + + Table + + + + + + + 75 + true + + + + + + + + + + + Fields + + + + + + + + Add field + + + + :/icons/field_add:/icons/field_add + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + false + + + Edit field + + + + :/icons/field_edit:/icons/field_edit + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + false + + + Remove field + + + + :/icons/field_delete:/icons/field_delete + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Field name + + + + + Field type + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + editTableName + addFieldButton + renameFieldButton + removeFieldButton + treeWidget + buttonBox + + + + + + + buttonBox + accepted() + editTableForm + accept() + + + 252 + 400 + + + 157 + 274 + + + + + buttonBox + rejected() + editTableForm + reject() + + + 320 + 400 + + + 286 + 274 + + + + + treeWidget + itemSelectionChanged() + editTableForm + fieldSelectionChanged() + + + 116 + 193 + + + 411 + 181 + + + + + addFieldButton + clicked() + editTableForm + addField() + + + 57 + 106 + + + 79 + 65 + + + + + renameFieldButton + clicked() + editTableForm + editField() + + + 136 + 108 + + + 161 + 65 + + + + + removeFieldButton + clicked() + editTableForm + removeField() + + + 276 + 111 + + + 249 + 63 + + + + + editTableName + textChanged(QString) + editTableForm + checkInput() + + + 62 + 48 + + + 115 + 3 + + + + + + fieldSelectionChanged() + addField() + editField() + removeField() + checkInput() + + diff --git a/src/src.pro b/src/src.pro index 30174420..6051e418 100644 --- a/src/src.pro +++ b/src/src.pro @@ -82,4 +82,5 @@ FORMS += \ dialogabout.ui \ preferencesform.ui \ mainwindow.ui \ - editfieldform.ui + editfieldform.ui \ + edittableform.ui