From 949f5b9859ac4d36efbe71cef8b8135fdbc63c70 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Tue, 5 Oct 2010 06:51:26 +0100 Subject: [PATCH] Totally changes the layout Added icons Setup treeview --- sqlitebrowser/sqlitebrowser/edittableform.cpp | 931 ++++++++++-------- sqlitebrowser/sqlitebrowser/edittableform.h | 177 ++-- 2 files changed, 610 insertions(+), 498 deletions(-) diff --git a/sqlitebrowser/sqlitebrowser/edittableform.cpp b/sqlitebrowser/sqlitebrowser/edittableform.cpp index 4d064f7c..63c55549 100644 --- a/sqlitebrowser/sqlitebrowser/edittableform.cpp +++ b/sqlitebrowser/sqlitebrowser/edittableform.cpp @@ -64,135 +64,142 @@ void editTableForm::populateFields() fields= pdb->getTableFields(curTable); types= pdb->getTableTypes(curTable); - fieldListView->clear(); - fieldListView->setSorting (-1, FALSE); - Q3ListViewItem * lasttbitem = 0; + treeWidget->model()->removeRows(0, treeWidget->model()->rowCount()); QStringList::Iterator tt = types.begin(); for ( QStringList::Iterator ct = fields.begin(); ct != fields.end(); ++ct ) { - Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView, lasttbitem); - tbitem->setText( 0, *ct ); - tbitem->setText( 1, *tt ); - lasttbitem = tbitem; + QTreeWidgetItem *fldItem = new QTreeWidgetItem(); + //Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView, lasttbitem); + fldItem->setText( 0, *ct ); + fldItem->setText( 1, *tt ); + //lasttbitem = tbitem; + treeWidget->addTopLevelItem(fldItem); ++tt; } } void editTableForm::renameTable() { - renameTableForm * renTableForm = new renameTableForm( this, "renametable", TRUE ); + renameTableForm * renTableForm = new renameTableForm( this, "renametable", 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; + //qDebug(newName); + //QString sql; //do the sql rename here //if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback; - - 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); + QString sql = QString("ALTER TABLE %1 RENAME TO %2").arg(curTable, newName); + qDebug(sql); + return; + } +// 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::editField() { - Q3ListViewItem * item = fieldListView->selectedItem(); - if (item==0) { - //should never happen, the button would not be active, but... + //Q3ListViewItem * item = fieldListView->selectedItem(); + if( !treeWidget->currentItem()){ return; - } else { + } + QTreeWidgetItem *item = treeWidget->currentItem(); + //if (item==0) { + //should never happen, the button would not be active, but... + // return; + // } else { editFieldForm * fieldForm = new editFieldForm( this, "editfield", TRUE ); - fieldForm->setInitialValues(item->text(0),item->text(1)); + fieldForm->setInitialValues(item->text(0), item->text(1)); if (fieldForm->exec()) { modified = true; @@ -200,111 +207,112 @@ void editTableForm::editField() //qDebug(fieldForm->name + fieldForm->type); item->setText(0,fieldForm->name); item->setText(1,fieldForm->type); - + } //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() { - addFieldForm * addForm = new addFieldForm( this, "addfield", TRUE ); + addFieldForm * addForm = new addFieldForm( this, "addfield", TRUE ); addForm->setInitialValues(QString(""),QString("")); if (addForm->exec()) { modified = true; - Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView); + //Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView); + QTreeWidgetItem *tbitem = new QTreeWidgetItem(); tbitem->setText( 0, addForm->fname); tbitem->setText( 1, addForm->ftype); //do the sql creation here @@ -312,119 +320,216 @@ void editTableForm::addField() //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; - {//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; + // {//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; - 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(curTable); - sql.append(";"); - if (!pdb->executeSQL(sql)) goto rollback; + // 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.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(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); - } + // 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(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() { - Q3ListViewItem * remitem = fieldListView->selectedItem(); - if (remitem==0) { - //should never happen, the button would not be active, but... + if(!treeWidget->currentItem()){ return; - } else { + } + //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(remitem->text(0)); + msg.append(treeWidget->currentItem()->text(0)); msg.append("? \n All data currently stored in this field will be lost"); if (QMessageBox::warning( this, applicationName, @@ -433,131 +538,127 @@ void editTableForm::removeField() QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ){ //delete field here + + } /*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() { - Q3ListViewItem * item = fieldListView->selectedItem(); - if (item==0) { - renameFieldButton->setEnabled(false); - removeFieldButton->setEnabled(false); - } else { - renameFieldButton->setEnabled(true); - removeFieldButton->setEnabled(true); - } + renameFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection()); + removeFieldButton->setEnabled(treeWidget->selectionModel()->hasSelection()); } diff --git a/sqlitebrowser/sqlitebrowser/edittableform.h b/sqlitebrowser/sqlitebrowser/edittableform.h index d7667efc..ef2cccba 100644 --- a/sqlitebrowser/sqlitebrowser/edittableform.h +++ b/sqlitebrowser/sqlitebrowser/edittableform.h @@ -14,13 +14,19 @@ #include #include +#include +#include +#include +#include +#include + #include #include #include #include #include #include -#include +//#include #include #include #include @@ -34,101 +40,112 @@ QT_BEGIN_NAMESPACE class Ui_editTableForm { public: - QGridLayout *gridLayout; - QVBoxLayout *vboxLayout; - QLineEdit *tableLine; - Q3ListView *fieldListView; - QVBoxLayout *vboxLayout1; - QPushButton *renameTableButton; - QSpacerItem *spacer31; - QPushButton *renameFieldButton; - QPushButton *removeFieldButton; - QPushButton *addFieldButton; - QHBoxLayout *hboxLayout; - QSpacerItem *spacer34; + // QGridLayout *gridLayout; + //QVBoxLayout *vboxLayout; + + + QLabel *tableLine; + + QTreeWidget *treeWidget; + + QToolButton *renameTableButton; + + QToolButton *renameFieldButton; + QToolButton *removeFieldButton; + QToolButton *addFieldButton; + QPushButton *closeButton; void setupUi(QDialog *editTableForm) { - if (editTableForm->objectName().isEmpty()) + if (editTableForm->objectName().isEmpty()){ editTableForm->setObjectName(QString::fromUtf8("editTableForm")); - editTableForm->resize(428, 266); - gridLayout = new QGridLayout(editTableForm); - gridLayout->setSpacing(6); - gridLayout->setContentsMargins(11, 11, 11, 11); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - vboxLayout = new QVBoxLayout(); - vboxLayout->setSpacing(6); - vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); - tableLine = new QLineEdit(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->setFocusPolicy(Qt::NoFocus); - tableLine->setReadOnly(true); + tableLine->setStyleSheet("font-weight: bold; border: 1px solid #dddddd; background-color: white;"); + grpTableLayout->addWidget(tableLine); - vboxLayout->addWidget(tableLine); - - fieldListView = new Q3ListView(editTableForm); - fieldListView->addColumn(QApplication::translate("editTableForm", "Field name", 0, QApplication::UnicodeUTF8)); - fieldListView->header()->setClickEnabled(true, fieldListView->header()->count() - 1); - fieldListView->header()->setResizeEnabled(true, fieldListView->header()->count() - 1); - fieldListView->addColumn(QApplication::translate("editTableForm", "Field type", 0, QApplication::UnicodeUTF8)); - fieldListView->header()->setClickEnabled(true, fieldListView->header()->count() - 1); - fieldListView->header()->setResizeEnabled(true, fieldListView->header()->count() - 1); - fieldListView->setObjectName(QString::fromUtf8("fieldListView")); - fieldListView->setResizePolicy(Q3ScrollView::Manual); - fieldListView->setResizeMode(Q3ListView::AllColumns); - - vboxLayout->addWidget(fieldListView); - - - gridLayout->addLayout(vboxLayout, 0, 0, 1, 1); - - vboxLayout1 = new QVBoxLayout(); - vboxLayout1->setSpacing(6); - vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1")); - renameTableButton = new QPushButton(editTableForm); + //** Rename Table + renameTableButton = new QToolButton(editTableForm); renameTableButton->setObjectName(QString::fromUtf8("renameTableButton")); + renameTableButton->setIcon(QIcon(":/icons/table_modify")); + renameTableButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + grpTableLayout->addWidget(renameTableButton); - vboxLayout1->addWidget(renameTableButton); - spacer31 = new QSpacerItem(20, 23, QSizePolicy::Minimum, QSizePolicy::Expanding); + //****************************************** + //** Fields Group Box + QGroupBox *grpFields = new QGroupBox(); + mainVBoxLayout->addWidget(grpFields); + grpFields->setTitle("Fields"); + QVBoxLayout *grpFieldsLayout = new QVBoxLayout(); + grpFields->setLayout(grpFieldsLayout); + grpFieldsLayout->setSpacing(0); - vboxLayout1->addItem(spacer31); + //** Fields Toolbar ** + QToolBar *toolBar = new QToolBar(); + grpFieldsLayout->addWidget(toolBar); - renameFieldButton = new QPushButton(editTableForm); + //** 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); - vboxLayout1->addWidget(renameFieldButton); - - removeFieldButton = new QPushButton(editTableForm); + //** 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); - vboxLayout1->addWidget(removeFieldButton); - - addFieldButton = new QPushButton(editTableForm); - addFieldButton->setObjectName(QString::fromUtf8("addFieldButton")); - - vboxLayout1->addWidget(addFieldButton); + //**** 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); - gridLayout->addLayout(vboxLayout1, 0, 1, 1, 1); - - hboxLayout = new QHBoxLayout(); - hboxLayout->setSpacing(6); - hboxLayout->setObjectName(QString::fromUtf8("hboxLayout")); - spacer34 = new QSpacerItem(161, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - hboxLayout->addItem(spacer34); - + //*** Bottom button box + QHBoxLayout *bottomButtonBox = new QHBoxLayout(); + mainVBoxLayout->addLayout(bottomButtonBox); + bottomButtonBox->addStretch(10); closeButton = new QPushButton(editTableForm); closeButton->setObjectName(QString::fromUtf8("closeButton")); - - hboxLayout->addWidget(closeButton); - - - gridLayout->addLayout(hboxLayout, 1, 0, 1, 2); + bottomButtonBox->addWidget(closeButton); retranslateUi(editTableForm); @@ -137,7 +154,7 @@ public: 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(fieldListView, SIGNAL(selectionChanged()), editTableForm, SLOT(fieldSelectionChanged())); + QObject::connect(treeWidget, SIGNAL(itemSelectionChanged()), editTableForm, SLOT(fieldSelectionChanged())); QMetaObject::connectSlotsByName(editTableForm); } // setupUi @@ -145,15 +162,9 @@ public: void retranslateUi(QDialog *editTableForm) { editTableForm->setWindowTitle(QApplication::translate("editTableForm", "Edit table definition", 0, QApplication::UnicodeUTF8)); - fieldListView->header()->setLabel(0, QApplication::translate("editTableForm", "Field name", 0, QApplication::UnicodeUTF8)); - fieldListView->header()->setLabel(1, QApplication::translate("editTableForm", "Field type", 0, QApplication::UnicodeUTF8)); - fieldListView->clear(); + treeWidget->headerItem()->setText(0, QApplication::translate("editTableForm", "Field name", 0, QApplication::UnicodeUTF8)); + treeWidget->headerItem()->setText(1, QApplication::translate("editTableForm", "Field type", 0, QApplication::UnicodeUTF8)); - Q3ListViewItem *__item = new Q3ListViewItem(fieldListView); - __item->setText(0, QApplication::translate("editTableForm", "New Item", 0, QApplication::UnicodeUTF8)); - __item->setText(1, QString()); - __item->setPixmap(0, QPixmap()); - __item->setPixmap(1, QPixmap()); 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));