mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Merge editTableForm and createTableForm
Add the functionality needed to create new tables to the editTableForm dialog. Delete the createTableForm as it is no longer needed, also delete its semi-finished replacement createTableDialog. Fix not working add column function and as usual some other bugs here and there.
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
#include "createtabledialog.h"
|
||||
#include "ui_createtabledialog.h"
|
||||
|
||||
CreateTableDialog::CreateTableDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CreateTableDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
CreateTableDialog::~CreateTableDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef CREATETABLEDIALOG_H
|
||||
#define CREATETABLEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class CreateTableDialog;
|
||||
}
|
||||
|
||||
class CreateTableDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CreateTableDialog(QWidget *parent = 0);
|
||||
~CreateTableDialog();
|
||||
|
||||
private:
|
||||
Ui::CreateTableDialog *ui;
|
||||
};
|
||||
|
||||
#endif // CREATETABLEDIALOG_H
|
||||
@@ -1,183 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateTableDialog</class>
|
||||
<widget class="QDialog" name="CreateTableDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>466</width>
|
||||
<height>364</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelTableName">
|
||||
<property name="text">
|
||||
<string>Table name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditTableName"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelFieldName">
|
||||
<property name="text">
|
||||
<string>Field name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ButAddField">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>35</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/add</normaloff>:/icons/add</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelDataType">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Data type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBoxDataType">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>INTEGER</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>TEXT</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>REAL</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BLOB</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxNotNull">
|
||||
<property name="text">
|
||||
<string>Not NULL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<resources>
|
||||
<include location="icons/icons.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CreateTableDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CreateTableDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -1,138 +0,0 @@
|
||||
#include "createtableform.h"
|
||||
#include <QMessageBox>
|
||||
#include "editfieldform.h"
|
||||
/*
|
||||
* Constructs a createTableForm 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.
|
||||
*/
|
||||
createTableForm::createTableForm(DBBrowserDB *db, QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl),
|
||||
pdb(db)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
createTableForm::~createTableForm()
|
||||
{
|
||||
// no need to delete child widgets, Qt does it all for us
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the strings of the subwidgets using the current
|
||||
* language.
|
||||
*/
|
||||
void createTableForm::languageChange()
|
||||
{
|
||||
retranslateUi(this);
|
||||
}
|
||||
|
||||
void createTableForm::init()
|
||||
{
|
||||
}
|
||||
|
||||
//** Create The Table
|
||||
void createTableForm::confirmCreate()
|
||||
{
|
||||
bool ok = true;
|
||||
QString tabname = tablenameLineEdit->text();
|
||||
if (tabname.isEmpty()) {
|
||||
ok = false;
|
||||
statusBar->showMessage("Please enter a name for the table", 4000);
|
||||
tablenameLineEdit->setFocus();
|
||||
return;
|
||||
}
|
||||
if (tabname.contains(" ")>0) {
|
||||
ok = false;
|
||||
statusBar->showMessage("Spaces are not allowed in the table name", 4000);
|
||||
tablenameLineEdit->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (treeWidget->invisibleRootItem()->childCount() == 0) {
|
||||
ok = false;
|
||||
statusBar->showMessage("No fields defined", 4000);
|
||||
return;
|
||||
}
|
||||
|
||||
/*check field names for empty or illegal names
|
||||
TODO: move to add
|
||||
|
||||
for (int r=0; r<fieldsTable->numRows();r++){
|
||||
QString rowname = fieldsTable->text(r, 0);
|
||||
if (rowname.isEmpty()) {
|
||||
ok = false;
|
||||
QMessageBox::warning( this, applicationName, "Empty field names are not allowed" );
|
||||
break;
|
||||
}
|
||||
if (rowname.contains(" ")>0) {
|
||||
ok = false;
|
||||
QMessageBox::warning( this, applicationName, "Spaces are not allowed in the field names" );
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (!ok){
|
||||
return;
|
||||
}
|
||||
|
||||
if (ok){
|
||||
//QString esc("\"");
|
||||
// #TODO The colnames need to be escaped eg create table 'group'
|
||||
createStatement = "CREATE TABLE ";
|
||||
//createStatement.append(esc).append(tabname).append(esc);
|
||||
createStatement.append(tabname);
|
||||
createStatement.append(" (");
|
||||
for(int i = 0; i < treeWidget->invisibleRootItem()->childCount(); i++){
|
||||
QTreeWidgetItem *item = treeWidget->invisibleRootItem()->child(i);
|
||||
//createStatement.append(esc).append(item->text(0)).append(esc);
|
||||
createStatement.append( item->text(0) );
|
||||
createStatement.append(" ");
|
||||
createStatement.append(item->text(1));
|
||||
if(i < treeWidget->invisibleRootItem()->childCount() -1){
|
||||
createStatement.append(", ");
|
||||
}
|
||||
}
|
||||
createStatement.append(");");
|
||||
accept();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void createTableForm::addField()
|
||||
{
|
||||
//TODO maybe embedd locally
|
||||
editFieldForm * addForm = new editFieldForm( this );
|
||||
addForm->setModal(true);
|
||||
addForm->setInitialValues(pdb, true, QString(""), QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
QTreeWidgetItem *newItem = new QTreeWidgetItem();
|
||||
newItem->setText(0, addForm->field_name);
|
||||
newItem->setText(1, addForm->field_type);
|
||||
newItem->setIcon(0, QIcon(":/icons/field"));
|
||||
treeWidget->addTopLevelItem(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void createTableForm::deleteField()
|
||||
{
|
||||
if( !treeWidget->currentItem() ){
|
||||
return;
|
||||
}
|
||||
treeWidget->invisibleRootItem()->removeChild(treeWidget->currentItem());
|
||||
}
|
||||
|
||||
|
||||
void createTableForm::fieldSelectionChanged()
|
||||
{
|
||||
buttonDeleteField->setEnabled( treeWidget->selectionModel()->hasSelection() );
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
#ifndef CREATETABLEFORM_H
|
||||
#define CREATETABLEFORM_H
|
||||
|
||||
#include <QtGui/QGroupBox>
|
||||
#include <QtGui/QTreeWidget>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QStatusBar>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
|
||||
class DBBrowserDB;
|
||||
|
||||
class Ui_createTableForm
|
||||
{
|
||||
public:
|
||||
QVBoxLayout *mainVBoxLayout;
|
||||
|
||||
QHBoxLayout *topTableLayout;
|
||||
|
||||
QGroupBox *groupBoxFields;
|
||||
QVBoxLayout *groupBoxLayout;
|
||||
QLabel *textLabel1;
|
||||
QLineEdit *tablenameLineEdit;
|
||||
|
||||
QTreeWidget *treeWidget;
|
||||
|
||||
QHBoxLayout *fieldActionsButtonLayout;
|
||||
QPushButton *buttonAddField;
|
||||
QPushButton *buttonDeleteField;
|
||||
|
||||
QHBoxLayout *bottomButtonLayout;
|
||||
QPushButton *buttonCreate;
|
||||
QPushButton *buttonCancel;
|
||||
|
||||
QStatusBar *statusBar;
|
||||
|
||||
void setupUi(QDialog *createTableForm)
|
||||
{
|
||||
if (createTableForm->objectName().isEmpty()){
|
||||
createTableForm->setObjectName(QString::fromUtf8("createTableForm"));
|
||||
}
|
||||
createTableForm->setWindowIcon(QIcon(":/icons/db_new"));
|
||||
|
||||
createTableForm->resize(309, 320);
|
||||
|
||||
//** Main Layout
|
||||
mainVBoxLayout = new QVBoxLayout(createTableForm);
|
||||
mainVBoxLayout->setSpacing(10);
|
||||
mainVBoxLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mainVBoxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
|
||||
|
||||
//**** Top Table Box ****
|
||||
topTableLayout = new QHBoxLayout();
|
||||
topTableLayout->setSpacing(10);
|
||||
topTableLayout->setContentsMargins(10,10,10,10);
|
||||
//topTableLayout->setObjectName(QString::fromUtf8("hboxLayout"));
|
||||
textLabel1 = new QLabel(createTableForm);
|
||||
//textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
|
||||
textLabel1->setWordWrap(false);
|
||||
|
||||
topTableLayout->addWidget(textLabel1);
|
||||
|
||||
tablenameLineEdit = new QLineEdit(createTableForm);
|
||||
//tablenameLineEdit->setObjectName(QString::fromUtf8("tablenameLineEdit"));
|
||||
|
||||
topTableLayout->addWidget(tablenameLineEdit);
|
||||
|
||||
|
||||
mainVBoxLayout->addLayout(topTableLayout);
|
||||
|
||||
//**** Fields GroupBox
|
||||
groupBoxFields = new QGroupBox(createTableForm);
|
||||
groupBoxFields->setObjectName(QString::fromUtf8("groupBox1"));
|
||||
groupBoxLayout = new QVBoxLayout();
|
||||
groupBoxFields->setLayout(groupBoxLayout);
|
||||
|
||||
treeWidget = new QTreeWidget();
|
||||
groupBoxLayout->addWidget(treeWidget);
|
||||
treeWidget->headerItem()->setText(0, QApplication::translate("createTableForm", "Field name", 0, QApplication::UnicodeUTF8));
|
||||
treeWidget->headerItem()->setText(1, QApplication::translate("createTableForm", "Field type", 0, QApplication::UnicodeUTF8));
|
||||
treeWidget->setRootIsDecorated(false);
|
||||
treeWidget->setAlternatingRowColors(true);
|
||||
|
||||
//** Field Action Buttons Box
|
||||
fieldActionsButtonLayout = new QHBoxLayout();
|
||||
fieldActionsButtonLayout->setSpacing(6);
|
||||
fieldActionsButtonLayout->setObjectName(QString::fromUtf8("hboxLayout1"));
|
||||
fieldActionsButtonLayout->addStretch(10); // force right
|
||||
|
||||
//*** Delete Field Button
|
||||
buttonDeleteField = new QPushButton(groupBoxFields);
|
||||
buttonDeleteField->setObjectName(QString::fromUtf8("buttonDeleteField"));
|
||||
buttonDeleteField->setEnabled(false);
|
||||
buttonDeleteField->setIcon(QIcon(":/icons/field_delete"));
|
||||
fieldActionsButtonLayout->addWidget(buttonDeleteField);
|
||||
|
||||
//*** Add Field Button
|
||||
buttonAddField = new QPushButton(groupBoxFields);
|
||||
buttonAddField->setObjectName(QString::fromUtf8("buttonAddField"));
|
||||
buttonAddField->setIcon(QIcon(":/icons/field_add"));
|
||||
fieldActionsButtonLayout->addWidget(buttonAddField);
|
||||
|
||||
groupBoxLayout->addLayout(fieldActionsButtonLayout);
|
||||
|
||||
mainVBoxLayout->addWidget(groupBoxFields);
|
||||
|
||||
//***************************************
|
||||
//*** Bottom Dialog action Buttons
|
||||
bottomButtonLayout = new QHBoxLayout();
|
||||
bottomButtonLayout->setSpacing(6);
|
||||
//bottomButtonLayout->setObjectName(QString::fromUtf8("hboxLayout2"));
|
||||
bottomButtonLayout->addStretch(10); // force right
|
||||
|
||||
//** Cancel Button
|
||||
buttonCancel = new QPushButton(createTableForm);
|
||||
//buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
|
||||
buttonCancel->setIcon(QIcon(":/icons/cancel"));
|
||||
bottomButtonLayout->addWidget(buttonCancel);
|
||||
|
||||
//** Create Button
|
||||
buttonCreate = new QPushButton(createTableForm);
|
||||
//buttonCreate->setObjectName(QString::fromUtf8("buttonCreate"));
|
||||
buttonCreate->setIcon(QIcon(":/icons/save"));
|
||||
bottomButtonLayout->addWidget(buttonCreate);
|
||||
mainVBoxLayout->addLayout(bottomButtonLayout);
|
||||
|
||||
statusBar = new QStatusBar();
|
||||
mainVBoxLayout->addWidget(statusBar);
|
||||
|
||||
//** Setup
|
||||
retranslateUi(createTableForm);
|
||||
QObject::connect(buttonCancel, SIGNAL(clicked()), createTableForm, SLOT(reject()));
|
||||
QObject::connect(buttonCreate, SIGNAL(clicked()), createTableForm, SLOT(confirmCreate()));
|
||||
QObject::connect(buttonAddField, SIGNAL(clicked()), createTableForm, SLOT(addField()));
|
||||
QObject::connect(buttonDeleteField, SIGNAL(clicked()), createTableForm, SLOT(deleteField()));
|
||||
QObject::connect(treeWidget, SIGNAL(itemSelectionChanged()), createTableForm, SLOT(fieldSelectionChanged()));
|
||||
|
||||
QMetaObject::connectSlotsByName(createTableForm);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *createTableForm)
|
||||
{
|
||||
createTableForm->setWindowTitle(QApplication::translate("createTableForm", "Create Table", 0, QApplication::UnicodeUTF8));
|
||||
textLabel1->setText(QApplication::translate("createTableForm", "Table name:", 0, QApplication::UnicodeUTF8));
|
||||
tablenameLineEdit->setText(QString());
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
tablenameLineEdit->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Enter the name for the new table", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
tablenameLineEdit->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "Use this control to enter the name of the table to be created.", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
groupBoxFields->setTitle(QApplication::translate("createTableForm", "Define fields:", 0, QApplication::UnicodeUTF8));
|
||||
|
||||
buttonAddField->setText(QApplication::translate("createTableForm", "Add", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonAddField->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Add a new field definition", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
buttonAddField->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "This button is used to add a new field definition to your table", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
buttonDeleteField->setText(QApplication::translate("createTableForm", "Delete", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonDeleteField->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Delete current field definition", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
buttonDeleteField->setProperty("whatsThis", QVariant(QApplication::translate("createTableForm", "This button is used to delete the currently selected field definition from your table", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
buttonCreate->setText(QApplication::translate("createTableForm", "Create", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonCreate->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Create the table", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
buttonCancel->setText(QApplication::translate("createTableForm", "Cancel", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createTableForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class createTableForm: public Ui_createTableForm {};
|
||||
} // namespace Ui
|
||||
|
||||
class createTableForm : public QDialog, public Ui::createTableForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
createTableForm( DBBrowserDB *db = 0, QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
~createTableForm();
|
||||
|
||||
QString createStatement;
|
||||
|
||||
public slots:
|
||||
virtual void confirmCreate();
|
||||
virtual void addField();
|
||||
virtual void deleteField();
|
||||
virtual void fieldSelectionChanged();
|
||||
|
||||
protected slots:
|
||||
virtual void languageChange();
|
||||
|
||||
private:
|
||||
void init();
|
||||
DBBrowserDB *pdb;
|
||||
|
||||
};
|
||||
|
||||
#endif // CREATETABLEFORM_H
|
||||
@@ -39,8 +39,10 @@ void editTableForm::setActiveTable(DBBrowserDB * thedb, QString tableName)
|
||||
{
|
||||
pdb = thedb;
|
||||
curTable = tableName;
|
||||
populateFields();
|
||||
if(curTable != "")
|
||||
populateFields();
|
||||
ui->editTableName->setText(curTable);
|
||||
checkInput();
|
||||
}
|
||||
|
||||
void editTableForm::populateFields()
|
||||
@@ -65,22 +67,49 @@ void editTableForm::populateFields()
|
||||
|
||||
void editTableForm::accept()
|
||||
{
|
||||
// Rename table if necessary
|
||||
if(ui->editTableName->text() != curTable)
|
||||
// Are we editing an already existing table or designing a new one? In the first case there is a table name set,
|
||||
// in the latter the current table name is empty
|
||||
if(curTable == "")
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
|
||||
// Creation of new table
|
||||
|
||||
// Build SQL statement from what the use entered
|
||||
QString sql = QString("CREATE TABLE `%1` (").arg(ui->editTableName->text());
|
||||
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
|
||||
sql.append(QString("%1 %2,").arg(ui->treeWidget->topLevelItem(i)->text(0)).arg(ui->treeWidget->topLevelItem(i)->text(1)));
|
||||
sql.remove(sql.count() - 1, 1); // Remove last comma
|
||||
sql.append(");");
|
||||
|
||||
// Execute it
|
||||
modified = true;
|
||||
QString newName = ui->editTableName->text();
|
||||
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
|
||||
if (!pdb->executeSQL(sql)){
|
||||
QApplication::restoreOverrideCursor();
|
||||
QString error("Error renaming table. Message from database engine:\n");
|
||||
QString error("Error creating table. Message from database engine:\n");
|
||||
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
QApplication::restoreOverrideCursor();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Editing of old table
|
||||
|
||||
// Rename table if necessary
|
||||
if(ui->editTableName->text() != curTable)
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
|
||||
modified = true;
|
||||
QString newName = ui->editTableName->text();
|
||||
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
|
||||
if (!pdb->executeSQL(sql)){
|
||||
QApplication::restoreOverrideCursor();
|
||||
QString error("Error renaming table. Message from database engine:\n");
|
||||
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
return;
|
||||
} else {
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@@ -101,12 +130,10 @@ void editTableForm::editField()
|
||||
QTreeWidgetItem *item = ui->treeWidget->currentItem();
|
||||
editFieldForm * fieldForm = new editFieldForm( this );
|
||||
fieldForm->setModal(true);
|
||||
fieldForm->setInitialValues(pdb, false, curTable, item->text(0), item->text(1));
|
||||
fieldForm->setInitialValues(pdb, curTable == "", curTable, 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->field_name);
|
||||
item->setText(1,fieldForm->field_type);
|
||||
}
|
||||
@@ -212,16 +239,11 @@ void editTableForm::addField()
|
||||
addForm->setInitialValues(pdb, true, curTable, QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
modified = true;
|
||||
|
||||
QTreeWidgetItem *tbitem = new QTreeWidgetItem();
|
||||
QTreeWidgetItem *tbitem = new QTreeWidgetItem(ui->treeWidget);
|
||||
tbitem->setText( 0, addForm->field_name);
|
||||
tbitem->setText( 1, addForm->field_name);
|
||||
//do the sql creation here
|
||||
tbitem->setText( 1, addForm->field_type);
|
||||
modified = true;
|
||||
//do the sql rename here
|
||||
//qDebug(fieldForm->name + fieldForm->type);
|
||||
QString sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
|
||||
ui->treeWidget->addTopLevelItem(tbitem);
|
||||
|
||||
}
|
||||
// Q3ListViewItemIterator it( fieldListView );
|
||||
@@ -317,7 +339,7 @@ void editTableForm::addField()
|
||||
// while ( it.current() ) {
|
||||
// item = it.current();
|
||||
// sql.append(item->text(0));
|
||||
/// sql.append(" ");
|
||||
// sql.append(" ");
|
||||
// sql.append(item->text(1));
|
||||
// if (item->nextSibling() != 0)
|
||||
// {
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QScrollBar>
|
||||
#include "createtableform.h"
|
||||
#include "createindexform.h"
|
||||
#include "deletetableform.h"
|
||||
#include "deleteindexform.h"
|
||||
@@ -575,7 +574,6 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showrecord( int dec )
|
||||
{
|
||||
updateTableView(dec);
|
||||
@@ -587,21 +585,16 @@ void MainWindow::createTable()
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
return;
|
||||
}
|
||||
createTableForm * tableForm = new createTableForm(&db, this);
|
||||
|
||||
editTableForm * tableForm = new editTableForm(this);
|
||||
tableForm->setActiveTable(&db, "");
|
||||
tableForm->setModal(true);
|
||||
if ( tableForm->exec() ) {
|
||||
if (!db.executeSQL(tableForm->createStatement)){
|
||||
QString error = "Error: could not create the table. Message from database engine: ";
|
||||
error.append(db.lastErrorMessage);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
if(tableForm->exec()) {
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::createIndex()
|
||||
{
|
||||
if (!db.isOpen()){
|
||||
|
||||
@@ -17,7 +17,6 @@ HEADERS += \
|
||||
sqlite_source/sqlite3.h \
|
||||
choosetableform.h \
|
||||
createindexform.h \
|
||||
createtableform.h \
|
||||
deleteindexform.h \
|
||||
deletetableform.h \
|
||||
editfieldform.h \
|
||||
@@ -28,7 +27,6 @@ HEADERS += \
|
||||
importcsvform.h \
|
||||
preferencesform.h \
|
||||
mainwindow.h \
|
||||
createtabledialog.h \
|
||||
SQLLogDock.h \
|
||||
sqlitesyntaxhighlighter.h \
|
||||
dialogabout.h
|
||||
@@ -40,7 +38,6 @@ SOURCES += \
|
||||
sqlite_source/sqlite3.c \
|
||||
choosetableform.cpp \
|
||||
createindexform.cpp \
|
||||
createtableform.cpp \
|
||||
deleteindexform.cpp \
|
||||
deletetableform.cpp \
|
||||
editfieldform.cpp \
|
||||
@@ -51,7 +48,6 @@ SOURCES += \
|
||||
importcsvform.cpp \
|
||||
preferencesform.cpp \
|
||||
mainwindow.cpp \
|
||||
createtabledialog.cpp \
|
||||
SQLLogDock.cpp \
|
||||
sqlitesyntaxhighlighter.cpp \
|
||||
dialogabout.cpp
|
||||
@@ -76,7 +72,6 @@ mac {
|
||||
RESOURCES += icons/icons.qrc
|
||||
|
||||
FORMS += \
|
||||
createtabledialog.ui \
|
||||
dialogabout.ui \
|
||||
preferencesform.ui \
|
||||
mainwindow.ui \
|
||||
|
||||
Reference in New Issue
Block a user