mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-22 21:48:24 -05:00
Get rid of addfieldform
Get rid of the addFieldForm class and dialog and use the editFieldForm instead. Also fix the window caption of the editFieldForm dialogs called by the editTableForm to show the correct table name.
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
#include "addfieldform.h"
|
||||
|
||||
#include <qvariant.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qimage.h>
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include "sqlitedb.h"
|
||||
#include "addfieldtypeform.h"
|
||||
/*
|
||||
* Constructs a addFieldForm as a child of 'parent', with the
|
||||
* name 'name' and widget flags set to 'f'.
|
||||
*
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
addFieldForm::addFieldForm(QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
addFieldForm::~addFieldForm()
|
||||
{
|
||||
// no need to delete child widgets, Qt does it all for us
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the strings of the subwidgets using the current
|
||||
* language.
|
||||
*/
|
||||
void addFieldForm::languageChange()
|
||||
{
|
||||
retranslateUi(this);
|
||||
}
|
||||
|
||||
void addFieldForm::setInitialValues(QString name, QString type)
|
||||
{
|
||||
nameLineEdit->setText(name);
|
||||
typeBox->clear();
|
||||
typeBox->addItem(type);
|
||||
QString tString = "";
|
||||
if (type.compare(tString)!=0) typeBox->addItem(tString);
|
||||
tString = "TEXT";
|
||||
if (type.compare(tString)!=0) typeBox->addItem(tString);
|
||||
tString = "NUMERIC";
|
||||
if (type.compare(tString)!=0) typeBox->addItem(tString);
|
||||
tString = "BLOB";
|
||||
if (type.compare(tString)!=0) typeBox->addItem(tString);
|
||||
tString = "INTEGER PRIMARY KEY";
|
||||
if (type.compare(tString)!=0) typeBox->addItem(tString);
|
||||
}
|
||||
|
||||
void addFieldForm::confirmAddField()
|
||||
{
|
||||
QString fieldname = nameLineEdit->text();
|
||||
if (fieldname.isEmpty()) {
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Field name can not be empty" );
|
||||
return;
|
||||
}
|
||||
if (fieldname.contains(" ")>0) {
|
||||
QMessageBox::warning( this, QApplication::applicationName(), "Spaces are not allowed in the field name" );
|
||||
return;
|
||||
}
|
||||
fname = fieldname;
|
||||
ftype = typeBox->currentText();
|
||||
accept();
|
||||
}
|
||||
|
||||
void addFieldForm::getCustomType()
|
||||
{
|
||||
addFieldTypeForm * addForm = new addFieldTypeForm( this );
|
||||
addForm->setModal(true);
|
||||
if (addForm->exec())
|
||||
{
|
||||
//QString nospaces = addForm->typeNameEdit->text().remove(" ");
|
||||
QString nospaces = addForm->typeNameEdit->text();
|
||||
setInitialValues(nameLineEdit->text(),nospaces );
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
#ifndef ADDFIELDFORM_H
|
||||
#define ADDFIELDFORM_H
|
||||
|
||||
#include <qvariant.h>
|
||||
|
||||
/* QT_BEGIN_NAMESPACE and QT_END_NAMESPACE weren't introduced into QT right away... */
|
||||
#ifndef QT_BEGIN_NAMESPACE
|
||||
#define QT_BEGIN_NAMESPACE
|
||||
#endif
|
||||
|
||||
#ifndef QT_END_NAMESPACE
|
||||
#define QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QButtonGroup>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QRadioButton>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Ui_addFieldForm
|
||||
{
|
||||
public:
|
||||
QGridLayout *gridLayout;
|
||||
QSpacerItem *spacer17;
|
||||
QHBoxLayout *hboxLayout;
|
||||
QSpacerItem *spacer15;
|
||||
QPushButton *cancelButton;
|
||||
QPushButton *createButton;
|
||||
QVBoxLayout *vboxLayout;
|
||||
QLabel *textLabel1;
|
||||
QLabel *textLabel2;
|
||||
QVBoxLayout *vboxLayout1;
|
||||
QLineEdit *nameLineEdit;
|
||||
QHBoxLayout *hboxLayout1;
|
||||
QComboBox *typeBox;
|
||||
QToolButton *typeButton;
|
||||
|
||||
void setupUi(QDialog *addFieldForm)
|
||||
{
|
||||
if (addFieldForm->objectName().isEmpty()){
|
||||
addFieldForm->setObjectName(QString::fromUtf8("addFieldForm"));
|
||||
}
|
||||
addFieldForm->resize(338, 136);
|
||||
gridLayout = new QGridLayout(addFieldForm);
|
||||
gridLayout->setSpacing(6);
|
||||
gridLayout->setContentsMargins(11, 11, 11, 11);
|
||||
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
|
||||
spacer17 = new QSpacerItem(20, 16, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
|
||||
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);
|
||||
|
||||
//** Cancel Button
|
||||
cancelButton = new QPushButton(addFieldForm);
|
||||
cancelButton->setIcon(QIcon(":/icons/cancel"));
|
||||
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
|
||||
hboxLayout->addWidget(cancelButton);
|
||||
|
||||
//** Create Button
|
||||
createButton = new QPushButton(addFieldForm);
|
||||
createButton->setObjectName(QString::fromUtf8("createButton"));
|
||||
createButton->setDefault(true);
|
||||
createButton->setIcon(QIcon(":/icons/save"));
|
||||
hboxLayout->addWidget(createButton);
|
||||
|
||||
|
||||
gridLayout->addLayout(hboxLayout, 2, 0, 1, 2);
|
||||
|
||||
vboxLayout = new QVBoxLayout();
|
||||
vboxLayout->setSpacing(6);
|
||||
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
|
||||
textLabel1 = new QLabel(addFieldForm);
|
||||
textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
|
||||
textLabel1->setWordWrap(false);
|
||||
|
||||
vboxLayout->addWidget(textLabel1);
|
||||
|
||||
textLabel2 = new QLabel(addFieldForm);
|
||||
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
|
||||
textLabel2->setWordWrap(false);
|
||||
|
||||
vboxLayout->addWidget(textLabel2);
|
||||
|
||||
|
||||
gridLayout->addLayout(vboxLayout, 0, 0, 1, 1);
|
||||
|
||||
vboxLayout1 = new QVBoxLayout();
|
||||
vboxLayout1->setSpacing(6);
|
||||
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
|
||||
nameLineEdit = new QLineEdit(addFieldForm);
|
||||
nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
|
||||
|
||||
vboxLayout1->addWidget(nameLineEdit);
|
||||
|
||||
hboxLayout1 = new QHBoxLayout();
|
||||
hboxLayout1->setSpacing(6);
|
||||
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
|
||||
typeBox = new QComboBox(addFieldForm);
|
||||
typeBox->setObjectName(QString::fromUtf8("typeBox"));
|
||||
|
||||
hboxLayout1->addWidget(typeBox);
|
||||
|
||||
//**** Field Types Radios
|
||||
QVBoxLayout *radioLayout = new QVBoxLayout();
|
||||
vboxLayout1->addLayout(radioLayout);
|
||||
|
||||
QRadioButton *radioTEXT = new QRadioButton();
|
||||
radioTEXT->setText(QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8));
|
||||
radioLayout->addWidget(radioTEXT);
|
||||
|
||||
QRadioButton *radioNUMERIC = new QRadioButton();
|
||||
radioNUMERIC->setText(QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8));
|
||||
radioLayout->addWidget(radioNUMERIC);
|
||||
|
||||
QRadioButton *radioBLOB = new QRadioButton();
|
||||
radioBLOB->setText(QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8));
|
||||
radioLayout->addWidget(radioBLOB);
|
||||
|
||||
|
||||
QRadioButton *radioINTPRIMARY = new QRadioButton();
|
||||
radioINTPRIMARY->setText(QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8));
|
||||
radioLayout->addWidget(radioINTPRIMARY);
|
||||
|
||||
|
||||
QRadioButton *radioCustom = new QRadioButton();
|
||||
radioCustom->setText(QApplication::translate("addFieldForm", "Custom", 0, QApplication::UnicodeUTF8));
|
||||
radioLayout->addWidget(radioCustom);
|
||||
|
||||
typeButton = new QToolButton(addFieldForm);
|
||||
typeButton->setObjectName(QString::fromUtf8("typeButton"));
|
||||
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(typeButton->sizePolicy().hasHeightForWidth());
|
||||
typeButton->setSizePolicy(sizePolicy);
|
||||
|
||||
hboxLayout1->addWidget(typeButton);
|
||||
|
||||
|
||||
vboxLayout1->addLayout(hboxLayout1);
|
||||
|
||||
|
||||
gridLayout->addLayout(vboxLayout1, 0, 1, 1, 1);
|
||||
|
||||
|
||||
|
||||
retranslateUi(addFieldForm);
|
||||
QObject::connect(cancelButton, SIGNAL(clicked()), addFieldForm, SLOT(reject()));
|
||||
QObject::connect(createButton, SIGNAL(clicked()), addFieldForm, SLOT(confirmAddField()));
|
||||
QObject::connect(typeButton, SIGNAL(clicked()), addFieldForm, SLOT(getCustomType()));
|
||||
|
||||
QMetaObject::connectSlotsByName(addFieldForm);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *addFieldForm)
|
||||
{
|
||||
addFieldForm->setWindowTitle(QApplication::translate("addFieldForm", "Add database field", 0, QApplication::UnicodeUTF8));
|
||||
cancelButton->setText(QApplication::translate("addFieldForm", "Cancel", 0, QApplication::UnicodeUTF8));
|
||||
createButton->setText(QApplication::translate("addFieldForm", "Create", 0, QApplication::UnicodeUTF8));
|
||||
textLabel1->setText(QApplication::translate("addFieldForm", "Field name:", 0, QApplication::UnicodeUTF8));
|
||||
textLabel2->setText(QApplication::translate("addFieldForm", "Field type:", 0, QApplication::UnicodeUTF8));
|
||||
typeBox->clear();
|
||||
typeBox->insertItems(0, QStringList()
|
||||
<< QString()
|
||||
<< QApplication::translate("addFieldForm", "TEXT", 0, QApplication::UnicodeUTF8)
|
||||
<< QApplication::translate("addFieldForm", "NUMERIC", 0, QApplication::UnicodeUTF8)
|
||||
<< QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8)
|
||||
<< QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8)
|
||||
);
|
||||
typeButton->setText(QApplication::translate("addFieldForm", "...", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
typeButton->setProperty("toolTip", QVariant(QApplication::translate("addFieldForm", "Custom type", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
typeButton->setProperty("whatsThis", QVariant(QApplication::translate("addFieldForm", "Click this button to enter a new type for the field", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class addFieldForm: public Ui_addFieldForm {};
|
||||
} // namespace Ui
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class addFieldForm : public QDialog, public Ui::addFieldForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
addFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
~addFieldForm();
|
||||
|
||||
QString fname;
|
||||
QString ftype;
|
||||
|
||||
public slots:
|
||||
virtual void setInitialValues( QString name, QString type );
|
||||
virtual void confirmAddField();
|
||||
virtual void getCustomType();
|
||||
|
||||
protected slots:
|
||||
virtual void languageChange();
|
||||
|
||||
};
|
||||
|
||||
#endif // ADDFIELDFORM_H
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include "qmessagebox.h"
|
||||
#include "addfieldform.h"
|
||||
#include "editfieldform.h"
|
||||
/*
|
||||
* Constructs a createTableForm as a child of 'parent', with the
|
||||
* name 'name' and widget flags set to 'f'.
|
||||
@@ -113,14 +113,14 @@ void createTableForm::confirmCreate()
|
||||
void createTableForm::addField()
|
||||
{
|
||||
//TODO maybe embedd locally
|
||||
addFieldForm * addForm = new addFieldForm( this );
|
||||
editFieldForm * addForm = new editFieldForm( this );
|
||||
addForm->setModal(true);
|
||||
addForm->setInitialValues(QString(""),QString(""));
|
||||
addForm->setInitialValues(true, QString(""), QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
QTreeWidgetItem *newItem = new QTreeWidgetItem();
|
||||
newItem->setText(0, addForm->fname);
|
||||
newItem->setText(1, addForm->ftype);
|
||||
newItem->setText(0, addForm->field_name);
|
||||
newItem->setText(1, addForm->field_type);
|
||||
newItem->setIcon(0, QIcon(":/icons/field"));
|
||||
treeWidget->addTopLevelItem(newItem);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include "renametableform.h"
|
||||
#include "addfieldform.h"
|
||||
#include "editfieldform.h"
|
||||
/*
|
||||
* Constructs a editTableForm as a child of 'parent', with the
|
||||
@@ -229,7 +228,7 @@ void editTableForm::editField()
|
||||
// } else {
|
||||
editFieldForm * fieldForm = new editFieldForm( this );
|
||||
fieldForm->setModal(true);
|
||||
fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(1));
|
||||
fieldForm->setInitialValues(false, curTable, item->text(0), item->text(1));
|
||||
if (fieldForm->exec())
|
||||
{
|
||||
modified = true;
|
||||
@@ -335,17 +334,17 @@ void editTableForm::editField()
|
||||
|
||||
void editTableForm::addField()
|
||||
{
|
||||
addFieldForm * addForm = new addFieldForm( this );
|
||||
editFieldForm * addForm = new editFieldForm( this );
|
||||
addForm->setModal(true);
|
||||
addForm->setInitialValues(QString(""),QString(""));
|
||||
addForm->setInitialValues(true, curTable, QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
modified = true;
|
||||
|
||||
//Q3ListViewItem * tbitem = new Q3ListViewItem( fieldListView);
|
||||
QTreeWidgetItem *tbitem = new QTreeWidgetItem();
|
||||
tbitem->setText( 0, addForm->fname);
|
||||
tbitem->setText( 1, addForm->ftype);
|
||||
tbitem->setText( 0, addForm->field_name);
|
||||
tbitem->setText( 1, addForm->field_name);
|
||||
//do the sql creation here
|
||||
modified = true;
|
||||
//do the sql rename here
|
||||
|
||||
Reference in New Issue
Block a user