Remove the editfield dialog and the edit options outside of edittable dialog

This commit is contained in:
Peinthor Rene
2013-03-18 17:48:35 +01:00
parent 1b0d5a2ff9
commit 5289adaab8
7 changed files with 1 additions and 513 deletions

View File

@@ -1,90 +0,0 @@
#include "EditFieldDialog.h"
#include "ui_EditFieldDialog.h"
#include "sqlitedb.h"
#include <QPushButton>
#include <QMessageBox>
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<QAbstractButton *> 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);
}

View File

@@ -1,37 +0,0 @@
#ifndef __EDITFIELDDIALOG_H__
#define __EDITFIELDDIALOG_H__
#include <QDialog>
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

View File

@@ -1,234 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditFieldDialog</class>
<widget class="QDialog" name="EditFieldDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>214</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Field name:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="buddy">
<cstring>nameLineEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Field type:</string>
</property>
<property name="buddy">
<cstring>radioTEXT</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioTEXT">
<property name="text">
<string>TEXT</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioNUMERIC">
<property name="text">
<string>NUMERIC</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioBLOB">
<property name="text">
<string>BLOB</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioINTPRIMARY">
<property name="text">
<string>INTEGER PRIMARY KEY</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioCustom">
<property name="text">
<string>Custom</string>
</property>
<attribute name="buttonGroup">
<string notr="true">groupRadioTypes</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtCustomType">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>nameLineEdit</tabstop>
<tabstop>radioTEXT</tabstop>
<tabstop>radioNUMERIC</tabstop>
<tabstop>radioBLOB</tabstop>
<tabstop>radioINTPRIMARY</tabstop>
<tabstop>radioCustom</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditFieldDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>243</x>
<y>209</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditFieldDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>311</x>
<y>209</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioCustom</sender>
<signal>toggled(bool)</signal>
<receiver>txtCustomType</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>137</x>
<y>142</y>
</hint>
<hint type="destinationlabel">
<x>138</x>
<y>167</y>
</hint>
</hints>
</connection>
<connection>
<sender>nameLineEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>354</x>
<y>24</y>
</hint>
<hint type="destinationlabel">
<x>446</x>
<y>33</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtCustomType</sender>
<signal>textChanged(QString)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
<x>29</x>
<y>154</y>
</hint>
</hints>
</connection>
<connection>
<sender>groupRadioTypes</sender>
<signal>buttonClicked(int)</signal>
<receiver>EditFieldDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>224</x>
<y>106</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>checkInput()</slot>
</slots>
<buttongroups>
<buttongroup name="groupRadioTypes"/>
</buttongroups>
</ui>

View File

@@ -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<QAction *>(sender());

View File

@@ -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();

View File

@@ -37,10 +37,6 @@
<addaction name="editCreateTableAction"/>
<addaction name="editModifyTableAction"/>
<addaction name="editDeleteObjectAction"/>
<addaction name="separator"/>
<addaction name="editAddFieldActionPopup"/>
<addaction name="editModifyFieldActionPopup"/>
<addaction name="editDeleteFieldActionPopup"/>
</widget>
</item>
<item>
@@ -910,7 +906,6 @@
</property>
<addaction name="editCreateTableAction"/>
<addaction name="editModifyTableAction"/>
<addaction name="separator"/>
<addaction name="editDeleteObjectAction"/>
<addaction name="separator"/>
<addaction name="editCreateIndexAction"/>
@@ -1242,7 +1237,7 @@
<normaloff>:/icons/table_delete</normaloff>:/icons/table_delete</iconset>
</property>
<property name="text">
<string>Delete Object</string>
<string>Delete Table...</string>
</property>
<property name="toolTip">
<string>Delete Object</string>
@@ -1342,51 +1337,6 @@
<string>&amp;About...</string>
</property>
</action>
<action name="editAddFieldActionPopup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_add</normaloff>:/icons/field_add</iconset>
</property>
<property name="text">
<string>Add Field</string>
</property>
<property name="toolTip">
<string>Add Field</string>
</property>
</action>
<action name="editDeleteFieldActionPopup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/table_delete</normaloff>:/icons/table_delete</iconset>
</property>
<property name="text">
<string>Delete Field</string>
</property>
<property name="toolTip">
<string>Delete Field</string>
</property>
</action>
<action name="editModifyFieldActionPopup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_edit</normaloff>:/icons/field_edit</iconset>
</property>
<property name="text">
<string>Modify Field</string>
</property>
<property name="toolTip">
<string>Modify Field</string>
</property>
</action>
<action name="actionRecent_y_opened">
<property name="text">
<string>&amp;Recently opened</string>
@@ -1846,22 +1796,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>editAddFieldActionPopup</sender>
<signal>activated()</signal>
<receiver>MainWindow</receiver>
<slot>addField()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>fileExportSQLAction</sender>
<signal>activated()</signal>
@@ -1942,22 +1876,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>editModifyFieldActionPopup</sender>
<signal>activated()</signal>
<receiver>MainWindow</receiver>
<slot>editField()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>viewDBToolbarAction</sender>
<signal>toggled(bool)</signal>
@@ -1990,22 +1908,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>editDeleteFieldActionPopup</sender>
<signal>activated()</signal>
<receiver>MainWindow</receiver>
<slot>deleteField()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBoxPragmas</sender>
<signal>rejected()</signal>

View File

@@ -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 \