mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-11 14:30:17 -05:00
Simplify and unify the dialog initialisation a bit
This commit is contained in:
+22
-22
@@ -4,38 +4,32 @@
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
EditFieldDialog::EditFieldDialog(QWidget* parent)
|
||||
EditFieldDialog::EditFieldDialog(DBBrowserDB* db, bool new_field, QString table, QString fld_name, QString fld_type, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::EditFieldDialog)
|
||||
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);
|
||||
|
||||
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__");
|
||||
}
|
||||
|
||||
EditFieldDialog::~EditFieldDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditFieldDialog::setInitialValues(DBBrowserDB *db, bool is_new, QString table, QString fld_name, QString fld_type)
|
||||
{
|
||||
pdb = db;
|
||||
original_field_name = QString(fld_name);
|
||||
table_name = table;
|
||||
ui->nameLineEdit->setText(fld_name);
|
||||
|
||||
this->is_new = is_new;
|
||||
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){
|
||||
@@ -51,9 +45,15 @@ void EditFieldDialog::setInitialValues(DBBrowserDB *db, bool is_new, QString tab
|
||||
ui->txtCustomType->setText(fld_type);
|
||||
}
|
||||
|
||||
// Check the current input values
|
||||
checkInput();
|
||||
}
|
||||
|
||||
EditFieldDialog::~EditFieldDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditFieldDialog::accept()
|
||||
{
|
||||
field_name = ui->nameLineEdit->text();
|
||||
|
||||
+10
-10
@@ -14,23 +14,23 @@ class EditFieldDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EditFieldDialog(QWidget* parent = 0);
|
||||
EditFieldDialog(DBBrowserDB* db, bool new_field, QString table, QString fld_name, QString fld_type, QWidget* parent = 0);
|
||||
~EditFieldDialog();
|
||||
|
||||
QString table_name;
|
||||
QString field_name;
|
||||
QString field_type;
|
||||
QString original_field_name;
|
||||
bool is_new;
|
||||
|
||||
public slots:
|
||||
virtual void setInitialValues( DBBrowserDB *db, bool is_new, QString table, QString fld_name, QString fld_type );
|
||||
virtual void accept();
|
||||
virtual void checkInput();
|
||||
|
||||
private:
|
||||
DBBrowserDB *pdb;
|
||||
Ui::EditFieldDialog *ui;
|
||||
Ui::EditFieldDialog* ui;
|
||||
DBBrowserDB* pdb;
|
||||
QString original_field_name;
|
||||
QString table_name;
|
||||
bool is_new;
|
||||
|
||||
public:
|
||||
QString field_name;
|
||||
QString field_type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+12
-21
@@ -5,24 +5,14 @@
|
||||
#include <QPushButton>
|
||||
#include "sqlitedb.h"
|
||||
|
||||
EditTableDialog::EditTableDialog(QWidget* parent)
|
||||
EditTableDialog::EditTableDialog(DBBrowserDB* db, QString tableName, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
pdb(0),
|
||||
ui(new Ui::EditTableDialog)
|
||||
ui(new Ui::EditTableDialog),
|
||||
pdb(db),
|
||||
curTable(tableName)
|
||||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
EditTableDialog::~EditTableDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditTableDialog::setActiveTable(DBBrowserDB * thedb, QString tableName)
|
||||
{
|
||||
// Set variables
|
||||
pdb = thedb;
|
||||
curTable = tableName;
|
||||
|
||||
// Editing an existing table?
|
||||
if(curTable != "")
|
||||
@@ -39,10 +29,13 @@ void EditTableDialog::setActiveTable(DBBrowserDB * thedb, QString tableName)
|
||||
checkInput();
|
||||
}
|
||||
|
||||
EditTableDialog::~EditTableDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditTableDialog::populateFields()
|
||||
{
|
||||
if (!pdb) return;
|
||||
|
||||
//make sure we are not using cached information
|
||||
pdb->updateSchema();
|
||||
|
||||
@@ -132,8 +125,7 @@ void EditTableDialog::editField()
|
||||
|
||||
// Show the edit dialog
|
||||
QTreeWidgetItem *item = ui->treeWidget->currentItem();
|
||||
EditFieldDialog dialog(this);
|
||||
dialog.setInitialValues(pdb, curTable == "", curTable, item->text(0), item->text(1));
|
||||
EditFieldDialog dialog(pdb, curTable == "", curTable, item->text(0), item->text(1), this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
item->setText(0, dialog.field_name);
|
||||
@@ -143,8 +135,7 @@ void EditTableDialog::editField()
|
||||
|
||||
void EditTableDialog::addField()
|
||||
{
|
||||
EditFieldDialog dialog(this);
|
||||
dialog.setInitialValues(pdb, true, curTable, QString(""), QString(""));
|
||||
EditFieldDialog dialog(pdb, true, curTable, "", "", this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
QTreeWidgetItem *tbitem = new QTreeWidgetItem(ui->treeWidget);
|
||||
|
||||
@@ -13,13 +13,10 @@ class EditTableDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EditTableDialog(QWidget* parent = 0);
|
||||
EditTableDialog(DBBrowserDB* pdb, QString tableName, QWidget* parent = 0);
|
||||
~EditTableDialog();
|
||||
|
||||
QString curTable;
|
||||
|
||||
public slots:
|
||||
virtual void setActiveTable( DBBrowserDB * thedb, QString tableName );
|
||||
virtual void populateFields();
|
||||
virtual void editField();
|
||||
virtual void addField();
|
||||
@@ -29,13 +26,12 @@ public slots:
|
||||
virtual void reject();
|
||||
virtual void checkInput();
|
||||
|
||||
protected:
|
||||
private:
|
||||
Ui::EditTableDialog* ui;
|
||||
DBBrowserDB* pdb;
|
||||
QString curTable;
|
||||
QStringList types;
|
||||
QStringList fields;
|
||||
DBBrowserDB *pdb;
|
||||
|
||||
private:
|
||||
Ui::EditTableDialog *ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+8
-17
@@ -558,8 +558,7 @@ void MainWindow::createTable()
|
||||
return;
|
||||
}
|
||||
|
||||
EditTableDialog dialog(this);
|
||||
dialog.setActiveTable(&db, "");
|
||||
EditTableDialog dialog(&db, "", this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
populateStructure();
|
||||
@@ -632,8 +631,7 @@ void MainWindow::editTable()
|
||||
}
|
||||
QString tableToEdit = ui->dbTreeWidget->currentItem()->text(0);
|
||||
|
||||
EditTableDialog dialog(this);
|
||||
dialog.setActiveTable(&db, tableToEdit);
|
||||
EditTableDialog dialog(&db, tableToEdit, this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
populateStructure();
|
||||
@@ -1010,24 +1008,17 @@ void MainWindow::changeTreeSelection()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addField(){
|
||||
//if( !dbTreeWidget->currentItem() ){
|
||||
// return;
|
||||
//}
|
||||
|
||||
EditFieldDialog dialog(this);
|
||||
dialog.setInitialValues(&db, true, ui->dbTreeWidget->currentItem()->text(0), "", "TEXT");
|
||||
void MainWindow::addField()
|
||||
{
|
||||
EditFieldDialog dialog(&db, true, ui->dbTreeWidget->currentItem()->text(0), "", "TEXT", this);
|
||||
if(dialog.exec())
|
||||
populateStructure();
|
||||
}
|
||||
|
||||
void MainWindow::editField(){
|
||||
if(!ui->dbTreeWidget->currentItem())
|
||||
return;
|
||||
|
||||
void MainWindow::editField()
|
||||
{
|
||||
QTreeWidgetItem *item = ui->dbTreeWidget->currentItem();
|
||||
EditFieldDialog dialog(this);
|
||||
dialog.setInitialValues(&db, false, item->parent()->text(0), item->text(0), item->text(2));
|
||||
EditFieldDialog dialog(&db, false, item->parent()->text(0), item->text(0), item->text(2), this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
item->setText(0, dialog.field_name);
|
||||
|
||||
Reference in New Issue
Block a user