Idea of moving db to form

This commit is contained in:
Peter Mash Morgan
2010-10-05 13:28:22 +01:00
parent a2e3ba633d
commit 3f8129b811
4 changed files with 78 additions and 37 deletions
+39 -16
View File
@@ -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<QAbstractButton *> 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());
}
+31 -15
View File
@@ -14,6 +14,7 @@
#include <Qt3Support/Q3MimeSourceFactory>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
@@ -30,11 +31,16 @@
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>
#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();
@@ -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;
+5 -3
View File
@@ -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);
}
}