diff --git a/sqlitebrowser/sqlitebrowser/editfieldform.cpp b/sqlitebrowser/sqlitebrowser/editfieldform.cpp index 24e56cb2..09982d6a 100644 --- a/sqlitebrowser/sqlitebrowser/editfieldform.cpp +++ b/sqlitebrowser/sqlitebrowser/editfieldform.cpp @@ -38,21 +38,37 @@ void editFieldForm::languageChange() retranslateUi(this); } - -void editFieldForm::setInitialValues(QString name, QString type) +void editFieldForm::setDB(DBBrowserDB &db) { - nameLineEdit->setText(name); + this->pdb = db; +} + +void editFieldForm::setInitialValues(bool is_new, QString table, QString fld_name, QString fld_type) +{ + + original_field_name = QString(fld_name); + + table_name = table; + nameLineEdit->setText(fld_name); + QList buttons = groupRadioTypes->buttons(); + for(int i = 0; i < buttons.size(); ++i){ + if( buttons.at(i)->property("field_type").toString() == fld_type){ + buttons.at(i)->setChecked(true); + return; + } + } + return; typeBox->clear(); - typeBox->insertItem(type); - QString tString = ""; - tString = "TEXT"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); - tString = "NUMERIC"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); - tString = "BLOB"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); - tString = "INTEGER PRIMARY KEY"; - if (type.compare(tString)!=0) typeBox->insertItem(tString); + typeBox->insertItem(fld_type); +// QString tString = ""; +// tString = "TEXT"; +// if (type.compare(tString)!=0) typeBox->insertItem(tString); +// tString = "NUMERIC"; +// if (type.compare(tString)!=0) typeBox->insertItem(tString); +// tString = "BLOB"; +// if (type.compare(tString)!=0) typeBox->insertItem(tString); +// tString = "INTEGER PRIMARY KEY"; +// if (type.compare(tString)!=0) typeBox->insertItem(tString); } void editFieldForm::confirmEdit() @@ -66,8 +82,14 @@ void editFieldForm::confirmEdit() QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field name" ); return; } - name = fieldname; - type = typeBox->currentText(); + field_name = fieldname; + field_type = typeBox->currentText(); + QString sql = QString("ALTER TABLE `%1` "); + qDebug(sql); + if(!pdb.executeSQL(sql)){ + qDebug(pdb.lastErrorMessage); + return; + } accept(); } @@ -83,7 +105,7 @@ void editFieldForm::getCustomType() { //QString nospaces = addForm->typeNameEdit->text().remove(" "); QString nospaces = addForm->typeNameEdit->text(); - setInitialValues(nameLineEdit->text(),nospaces ); + //setInitialValues( nameLineEdit->text(), nospaces ); enableSave(); } } @@ -91,4 +113,5 @@ void editFieldForm::getCustomType() void editFieldForm::on_radio_button_clicked(QAbstractButton *button){ qDebug("YES"); + //qDebug(button->property("field_type").toString()); } diff --git a/sqlitebrowser/sqlitebrowser/editfieldform.h b/sqlitebrowser/sqlitebrowser/editfieldform.h index 8ebe38dd..c097d8fe 100644 --- a/sqlitebrowser/sqlitebrowser/editfieldform.h +++ b/sqlitebrowser/sqlitebrowser/editfieldform.h @@ -14,6 +14,7 @@ #include #include + #include #include #include @@ -30,11 +31,16 @@ #include #include +#include "sqlitedb.h" + QT_BEGIN_NAMESPACE class Ui_editFieldForm { public: + + DBBrowserDB pdb; + QGridLayout *gridLayout; QVBoxLayout *vboxLayout; QLabel *lblFieldName; @@ -54,8 +60,9 @@ public: void setupUi(QDialog *editFieldForm) { - if (editFieldForm->objectName().isEmpty()) + if (editFieldForm->objectName().isEmpty()){ editFieldForm->setObjectName(QString::fromUtf8("editFieldForm")); + } editFieldForm->resize(352, 140); QVBoxLayout *mainVBoxLayout = new QVBoxLayout(); @@ -88,30 +95,35 @@ public: radioLayout->setContentsMargins(20, 10 ,10 ,0); groupRadioTypes = new QButtonGroup(); - + groupRadioTypes->setExclusive(true); QRadioButton *radioTEXT = new QRadioButton(); radioTEXT->setText(QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8)); + radioTEXT->setProperty("field_type", QVariant("TEXT")); radioLayout->addWidget(radioTEXT); groupRadioTypes->addButton(radioTEXT); QRadioButton *radioNUMERIC = new QRadioButton(); radioNUMERIC->setText(QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8)); + radioNUMERIC->setProperty("field_type", QVariant("NUMERIC")); radioLayout->addWidget(radioNUMERIC); groupRadioTypes->addButton(radioNUMERIC); QRadioButton *radioBLOB = new QRadioButton(); radioBLOB->setText(QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8)); + radioBLOB->setProperty("field_type", QVariant("BLOB")); radioLayout->addWidget(radioBLOB); //groupRadioTypes->addButton(radioBLOB); QRadioButton *radioINTPRIMARY = new QRadioButton(); radioINTPRIMARY->setText(QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8)); + radioINTPRIMARY->setProperty("field_type", QVariant("INTEGER PRIMARY KEY")); radioLayout->addWidget(radioINTPRIMARY); //groupRadioTypes->addButton(radioINTPRIMARY); QRadioButton *radioCustom = new QRadioButton(); radioCustom->setText(QApplication::translate("addFieldForm", "Custom", 0, QApplication::UnicodeUTF8)); + radioCustom->setProperty("field_type", QVariant("__custom__")); radioLayout->addWidget(radioCustom); //groupRadioTypes->addButton(radioCustom); @@ -139,27 +151,27 @@ public: gridLayout->addItem(spacer17, 1, 1, 1, 1); - hboxLayout = new QHBoxLayout(); - hboxLayout->setSpacing(6); - hboxLayout->setObjectName(QString::fromUtf8("hboxLayout")); - spacer15 = new QSpacerItem(41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - hboxLayout->addItem(spacer15); + //*** Bottom Button Layout + QHBoxLayout *bottomButtonBox = new QHBoxLayout(); + mainVBoxLayout->addLayout(bottomButtonBox); + bottomButtonBox->setSpacing(6); + bottomButtonBox->addStretch(10); + //** Cancel Button cancelButton = new QPushButton(editFieldForm); cancelButton->setObjectName(QString::fromUtf8("cancelButton")); cancelButton->setIcon(QIcon(":/icons/cancel")); - hboxLayout->addWidget(cancelButton); + bottomButtonBox->addWidget(cancelButton); + //** Save Button saveButton = new QPushButton(editFieldForm); saveButton->setObjectName(QString::fromUtf8("saveButton")); saveButton->setEnabled(false); saveButton->setIcon(QIcon(":/icons/save")); - - hboxLayout->addWidget(saveButton); + bottomButtonBox->addWidget(saveButton); - gridLayout->addLayout(hboxLayout, 2, 0, 1, 2); + // gridLayout->addLayout(hboxLayout, 2, 0, 1, 2); gridLayout1 = new QGridLayout(); gridLayout1->setSpacing(6); @@ -246,11 +258,15 @@ public: editFieldForm(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0); ~editFieldForm(); - QString name; - QString type; + void setDB(DBBrowserDB &db); + + QString table_name; + QString field_name; + QString field_type; + QString original_field_name; public slots: - virtual void setInitialValues( QString name, QString type ); + virtual void setInitialValues( bool is_new, QString table, QString fld_name, QString fld_type ); virtual void confirmEdit(); virtual void enableSave(); virtual void getCustomType(); diff --git a/sqlitebrowser/sqlitebrowser/edittableform.cpp b/sqlitebrowser/sqlitebrowser/edittableform.cpp index 0bf6fce0..dd607c9a 100644 --- a/sqlitebrowser/sqlitebrowser/edittableform.cpp +++ b/sqlitebrowser/sqlitebrowser/edittableform.cpp @@ -227,14 +227,14 @@ void editTableForm::editField() // return; // } else { editFieldForm * fieldForm = new editFieldForm( this, "editfield", TRUE ); - fieldForm->setInitialValues(item->text(0), item->text(1)); + fieldForm->setInitialValues(false, "TABLE_NAME", 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->name); - item->setText(1,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; diff --git a/sqlitebrowser/sqlitebrowser/form1.cpp b/sqlitebrowser/sqlitebrowser/form1.cpp index 4c1a74bd..df0a229e 100644 --- a/sqlitebrowser/sqlitebrowser/form1.cpp +++ b/sqlitebrowser/sqlitebrowser/form1.cpp @@ -1229,13 +1229,15 @@ void mainForm::on_edit_field(){ } QTreeWidgetItem *item = dbTreeWidget->currentItem(); editFieldForm *fieldForm = new editFieldForm( this, "editfield", true ); - fieldForm->setInitialValues(item->text(0), item->text(1)); + qDebug(item->text(2)); + fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(2)); + fieldForm->setDB(this->db); if (fieldForm->exec()) { //modified = true; //do the sql rename here //qDebug(fieldForm->name + fieldForm->type); - item->setText(0,fieldForm->name); - item->setText(1,fieldForm->type); + item->setText(0,fieldForm->field_name); + item->setText(2,fieldForm->field_type); } }