diff --git a/src/EditFieldDialog.cpp b/src/EditFieldDialog.cpp deleted file mode 100644 index f6022412..00000000 --- a/src/EditFieldDialog.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "EditFieldDialog.h" -#include "ui_EditFieldDialog.h" -#include "sqlitedb.h" -#include -#include - -EditFieldDialog::EditFieldDialog(DBBrowserDB* db, bool new_field, const QString& table, const QString& fld_name, const QString& fld_type, QWidget* parent) - : QDialog(parent), - ui(new Ui::EditFieldDialog), - pdb(db), - original_field_name(fld_name), - table_name(table), - is_new(new_field) -{ - // Create window and set its properties - ui->setupUi(this); - - setWindowIcon(QIcon(is_new ? ":/icons/field_add" : ":/icons/field_edit")); - if(table == "") - setWindowTitle(tr("Add new field to new table")); - else - setWindowTitle(is_new ? tr("New Field in '%1'").arg(table_name) : tr("Change Field in '%1'").arg(table_name)); - - // Associate the radio buttons with their relative SQL data type - ui->radioTEXT->setProperty("field_type", "TEXT"); - ui->radioNUMERIC->setProperty("field_type", "NUMERIC"); - ui->radioBLOB->setProperty("field_type", "BLOB"); - ui->radioINTPRIMARY->setProperty("field_type", "INTEGER PRIMARY KEY"); - ui->radioCustom->setProperty("field_type", "__custom__"); - - // Set the current settings - ui->nameLineEdit->setText(fld_name); - QList buttons = ui->groupRadioTypes->buttons(); - bool custom = true; - for(int i = 0; i < buttons.size(); ++i){ - if( buttons.at(i)->property("field_type").toString() == fld_type.toUpper()){ - buttons.at(i)->setChecked(true); - custom = false; - break; - } - } - if(custom) - { - ui->radioCustom->setChecked(true); - ui->txtCustomType->setText(fld_type); - } - - // Check the current input values - checkInput(); -} - -EditFieldDialog::~EditFieldDialog() -{ - delete ui; -} - -void EditFieldDialog::accept() -{ - field_name = ui->nameLineEdit->text(); - field_type = ui->groupRadioTypes->checkedButton()->property("field_type").toString(); - if(field_type == "__custom__") - field_type = ui->txtCustomType->text(); - - // Only change DB when dialog was not opened for a newly created table, i.e. table name is "" - if(table_name != "") - { - bool ok; - if(is_new) - ok = pdb->createColumn(table_name, field_name, field_type); - else - ok = pdb->renameColumn(table_name, original_field_name, field_name, field_type); - if(!ok){ - QMessageBox::warning(this, QApplication::applicationName(), pdb->lastErrorMessage); - qDebug(pdb->lastErrorMessage.toUtf8()); - return; - } - } - QDialog::accept(); -} - -void EditFieldDialog::checkInput() -{ - ui->nameLineEdit->setText(ui->nameLineEdit->text().trimmed()); - bool valid = true; - if(ui->nameLineEdit->text().isEmpty() || ui->nameLineEdit->text().contains(" ")) - valid = false; - if(ui->radioCustom->isChecked() && ui->txtCustomType->text().isEmpty()) - valid = false; - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); -} diff --git a/src/EditFieldDialog.h b/src/EditFieldDialog.h deleted file mode 100644 index 50080959..00000000 --- a/src/EditFieldDialog.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __EDITFIELDDIALOG_H__ -#define __EDITFIELDDIALOG_H__ - -#include - -class DBBrowserDB; - -namespace Ui { -class EditFieldDialog; -} - -class EditFieldDialog : public QDialog -{ - Q_OBJECT - -public: - explicit EditFieldDialog(DBBrowserDB* db, bool new_field, const QString& table, const QString& fld_name, const QString& fld_type, QWidget* parent = 0); - ~EditFieldDialog(); - - QString getFieldName() { return field_name; } - QString getFieldType() { return field_type; } - -private slots: - virtual void accept(); - virtual void checkInput(); - -private: - Ui::EditFieldDialog* ui; - DBBrowserDB* pdb; - QString original_field_name; - QString table_name; - bool is_new; - QString field_name; - QString field_type; -}; - -#endif diff --git a/src/EditFieldDialog.ui b/src/EditFieldDialog.ui deleted file mode 100644 index fd61b6ec..00000000 --- a/src/EditFieldDialog.ui +++ /dev/null @@ -1,234 +0,0 @@ - - - EditFieldDialog - - - - 0 - 0 - 450 - 214 - - - - Dialog - - - - - - - - <html><head/><body><p>Field name:</p></body></html> - - - nameLineEdit - - - - - - - - - - Field type: - - - radioTEXT - - - - - - - - - TEXT - - - true - - - groupRadioTypes - - - - - - - NUMERIC - - - groupRadioTypes - - - - - - - BLOB - - - groupRadioTypes - - - - - - - INTEGER PRIMARY KEY - - - groupRadioTypes - - - - - - - Custom - - - groupRadioTypes - - - - - - - false - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - nameLineEdit - radioTEXT - radioNUMERIC - radioBLOB - radioINTPRIMARY - radioCustom - buttonBox - - - - - buttonBox - accepted() - EditFieldDialog - accept() - - - 243 - 209 - - - 157 - 213 - - - - - buttonBox - rejected() - EditFieldDialog - reject() - - - 311 - 209 - - - 286 - 213 - - - - - radioCustom - toggled(bool) - txtCustomType - setEnabled(bool) - - - 137 - 142 - - - 138 - 167 - - - - - nameLineEdit - textChanged(QString) - EditFieldDialog - checkInput() - - - 354 - 24 - - - 446 - 33 - - - - - txtCustomType - textChanged(QString) - EditFieldDialog - checkInput() - - - 215 - 162 - - - 29 - 154 - - - - - groupRadioTypes - buttonClicked(int) - EditFieldDialog - checkInput() - - - -1 - -1 - - - 224 - 106 - - - - - - checkInput() - - - - - diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a6731373..8e36e82e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -14,7 +14,6 @@ #include "CreateIndexDialog.h" #include "AboutDialog.h" #include "EditTableDialog.h" -#include "EditFieldDialog.h" #include "ImportCsvDialog.h" #include "ExportCsvDialog.h" #include "PreferencesDialog.h" @@ -81,12 +80,8 @@ void MainWindow::init() // Create popup menus popupTableMenu = new QMenu(this); popupTableMenu->addAction(ui->editModifyTableAction); - popupTableMenu->addAction(ui->editAddFieldActionPopup); popupTableMenu->addSeparator(); popupTableMenu->addAction(ui->editDeleteObjectAction); - popupFieldMenu = new QMenu(this); - popupFieldMenu->addAction(ui->editModifyFieldActionPopup); - popupFieldMenu->addAction(ui->editDeleteFieldActionPopup); // Set state of checkable menu actions ui->sqlLogAction->setChecked(!ui->dockLog->isHidden()); @@ -951,8 +946,6 @@ void MainWindow::createTreeContextMenu(const QPoint &qPoint) if(cItem->text(1) == "table" || cItem->text(1) == "view" || cItem->text(1) == "trigger" || cItem->text(1) == "index") popupTableMenu->exec(ui->dbTreeWidget->mapToGlobal(qPoint)); - else if(cItem->text(1) == "field") - popupFieldMenu->exec(ui->dbTreeWidget->mapToGlobal(qPoint)); } //** Tree selection changed void MainWindow::changeTreeSelection() @@ -960,9 +953,6 @@ void MainWindow::changeTreeSelection() // Just assume first that something's selected that can not be edited at all ui->editDeleteObjectAction->setEnabled(false); ui->editModifyTableAction->setEnabled(false); - ui->editAddFieldActionPopup->setEnabled(false); - ui->editModifyFieldActionPopup->setEnabled(false); - ui->editDeleteFieldActionPopup->setEnabled(false); if(ui->dbTreeWidget->currentItem() == 0) return; @@ -983,47 +973,11 @@ void MainWindow::changeTreeSelection() { ui->editDeleteObjectAction->setEnabled(true); ui->editModifyTableAction->setEnabled(true); - ui->editAddFieldActionPopup->setEnabled(true); - } else if(ui->dbTreeWidget->currentItem()->text(1) == "field" && ui->dbTreeWidget->currentItem()->parent()->text(1) == "table") { - ui->editModifyFieldActionPopup->setEnabled(true); - ui->editDeleteFieldActionPopup->setEnabled(true); } else if(ui->dbTreeWidget->currentItem()->text(1) == "view" || ui->dbTreeWidget->currentItem()->text(1) == "trigger" || ui->dbTreeWidget->currentItem()->text(1) == "index") { ui->editDeleteObjectAction->setEnabled(true); } } -void MainWindow::addField() -{ - EditFieldDialog dialog(&db, true, ui->dbTreeWidget->currentItem()->text(0), "", "TEXT", this); - if(dialog.exec()) - populateStructure(); -} - -void MainWindow::editField() -{ - QTreeWidgetItem *item = ui->dbTreeWidget->currentItem(); - EditFieldDialog dialog(&db, false, item->parent()->text(0), item->text(0), item->text(2), this); - if(dialog.exec()) - { - item->setText(0, dialog.getFieldName()); - item->setText(2, dialog.getFieldType()); - } -} - -void MainWindow::deleteField() -{ - if(!ui->dbTreeWidget->currentItem()) - return; - - // Ask user wether he really wants to delete that column first - QString msg = tr("Are you sure you want to delete the field '%1'?\nAll data currently stored in this field will be lost.").arg(ui->dbTreeWidget->currentItem()->text(0)); - if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) - { - db.dropColumn(ui->dbTreeWidget->currentItem()->parent()->text(0), ui->dbTreeWidget->currentItem()->text(0)); - delete ui->dbTreeWidget->currentItem(); - } -} - void MainWindow::openRecentFile() { QAction *action = qobject_cast(sender()); diff --git a/src/MainWindow.h b/src/MainWindow.h index 3a2eb283..53812d3a 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -55,7 +55,6 @@ private: QStandardItemModel *browseTableModel; QStandardItemModel *queryResultListModel; QMenu *popupTableMenu; - QMenu *popupFieldMenu; QMenu *recentFilesMenu; QLabel* statusEncodingLabel; @@ -97,9 +96,6 @@ public slots: private slots: virtual void createTreeContextMenu(const QPoint & qPoint); virtual void changeTreeSelection(); - virtual void addField(); - virtual void editField(); - virtual void deleteField(); virtual void fileOpen(); virtual void fileNew(); virtual void populateStructure(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index de2be14d..363d2a12 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -37,10 +37,6 @@ - - - - @@ -910,7 +906,6 @@ - @@ -1242,7 +1237,7 @@ :/icons/table_delete:/icons/table_delete - Delete Object + Delete Table... Delete Object @@ -1342,51 +1337,6 @@ &About... - - - false - - - - :/icons/field_add:/icons/field_add - - - Add Field - - - Add Field - - - - - false - - - - :/icons/table_delete:/icons/table_delete - - - Delete Field - - - Delete Field - - - - - false - - - - :/icons/field_edit:/icons/field_edit - - - Modify Field - - - Modify Field - - &Recently opened @@ -1846,22 +1796,6 @@ - - editAddFieldActionPopup - activated() - MainWindow - addField() - - - -1 - -1 - - - 399 - 299 - - - fileExportSQLAction activated() @@ -1942,22 +1876,6 @@ - - editModifyFieldActionPopup - activated() - MainWindow - editField() - - - -1 - -1 - - - 399 - 299 - - - viewDBToolbarAction toggled(bool) @@ -1990,22 +1908,6 @@ - - editDeleteFieldActionPopup - activated() - MainWindow - deleteField() - - - -1 - -1 - - - 399 - 299 - - - buttonBoxPragmas rejected() diff --git a/src/src.pro b/src/src.pro index fef68295..9c34b53d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -14,7 +14,6 @@ HEADERS += \ MainWindow.h \ SQLiteSyntaxHighlighter.h \ CreateIndexDialog.h \ - EditFieldDialog.h \ AboutDialog.h \ EditTableDialog.h \ PreferencesDialog.h \ @@ -35,7 +34,6 @@ SOURCES += \ MainWindow.cpp \ SQLiteSyntaxHighlighter.cpp \ CreateIndexDialog.cpp \ - EditFieldDialog.cpp \ EditTableDialog.cpp \ PreferencesDialog.cpp \ AboutDialog.cpp \ @@ -81,7 +79,6 @@ FORMS += \ MainWindow.ui \ CreateIndexDialog.ui \ AboutDialog.ui \ - EditFieldDialog.ui \ EditTableDialog.ui \ PreferencesDialog.ui \ FindDialog.ui \