mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-08 04:49:58 -05:00
add new field properties default value and check constraint
This commit is contained in:
+12
-12
@@ -49,11 +49,11 @@ EditTableDialog::~EditTableDialog()
|
|||||||
|
|
||||||
void EditTableDialog::updateColumnWidth()
|
void EditTableDialog::updateColumnWidth()
|
||||||
{
|
{
|
||||||
ui->treeWidget->setColumnWidth(kName, 200);
|
ui->treeWidget->setColumnWidth(kName, 190);
|
||||||
ui->treeWidget->setColumnWidth(kType, 80);
|
ui->treeWidget->setColumnWidth(kType, 80);
|
||||||
ui->treeWidget->setColumnWidth(kNotNull, 50);
|
ui->treeWidget->setColumnWidth(kNotNull, 30);
|
||||||
ui->treeWidget->setColumnWidth(kPrimaryKey, 50);
|
ui->treeWidget->setColumnWidth(kPrimaryKey, 30);
|
||||||
ui->treeWidget->setColumnWidth(kAutoIncrement, 50);
|
ui->treeWidget->setColumnWidth(kAutoIncrement, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditTableDialog::populateFields()
|
void EditTableDialog::populateFields()
|
||||||
@@ -87,6 +87,8 @@ void EditTableDialog::populateFields()
|
|||||||
tbitem->setCheckState(kNotNull, f->notnull() ? Qt::Checked : Qt::Unchecked);
|
tbitem->setCheckState(kNotNull, f->notnull() ? Qt::Checked : Qt::Unchecked);
|
||||||
tbitem->setCheckState(kPrimaryKey, m_table.primarykey().contains(f) ? Qt::Checked : Qt::Unchecked);
|
tbitem->setCheckState(kPrimaryKey, m_table.primarykey().contains(f) ? Qt::Checked : Qt::Unchecked);
|
||||||
tbitem->setCheckState(kAutoIncrement, f->autoIncrement() ? Qt::Checked : Qt::Unchecked);
|
tbitem->setCheckState(kAutoIncrement, f->autoIncrement() ? Qt::Checked : Qt::Unchecked);
|
||||||
|
tbitem->setText(kDefault, f->defaultValue());
|
||||||
|
tbitem->setText(kCheck, f->check());
|
||||||
ui->treeWidget->addTopLevelItem(tbitem);
|
ui->treeWidget->addTopLevelItem(tbitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +169,8 @@ void EditTableDialog::updateTableObject()
|
|||||||
f->setAutoIncrement(item->checkState(kAutoIncrement) == Qt::Checked);
|
f->setAutoIncrement(item->checkState(kAutoIncrement) == Qt::Checked);
|
||||||
if(item->checkState(kPrimaryKey) == Qt::Checked)
|
if(item->checkState(kPrimaryKey) == Qt::Checked)
|
||||||
pk.append(f);
|
pk.append(f);
|
||||||
|
f->setDefaultValue(item->text(kDefault));
|
||||||
|
f->setCheck(item->text(kCheck));
|
||||||
fields.append(f);
|
fields.append(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,14 +214,10 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
|||||||
sqlb::FieldPtr field = m_table.fields().at(index);
|
sqlb::FieldPtr field = m_table.fields().at(index);
|
||||||
switch(column)
|
switch(column)
|
||||||
{
|
{
|
||||||
case kName:
|
case kName: field->setName(item->text(column)); break;
|
||||||
{
|
|
||||||
field->setName(item->text(column));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kType:
|
case kType:
|
||||||
{
|
{
|
||||||
// we don't know which combobox got update
|
// we don't know which combobox got the update
|
||||||
// so we have to update all at once
|
// so we have to update all at once
|
||||||
// see updateTypes() SLOT
|
// see updateTypes() SLOT
|
||||||
}
|
}
|
||||||
@@ -246,6 +246,8 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
|||||||
field->setAutoIncrement(item->checkState(column) == Qt::Checked);
|
field->setAutoIncrement(item->checkState(column) == Qt::Checked);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case kDefault: field->setDefaultValue(item->text(column)); break;
|
||||||
|
case kCheck: field->setCheck(item->text(column)); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,14 +303,12 @@ void EditTableDialog::removeField()
|
|||||||
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->treeWidget->currentItem()->text(0));
|
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->treeWidget->currentItem()->text(0));
|
||||||
if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes)
|
if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
// TODO seems this doesn't work, db table is locked.
|
|
||||||
if(!pdb->dropColumn(curTable, ui->treeWidget->currentItem()->text(0)))
|
if(!pdb->dropColumn(curTable, ui->treeWidget->currentItem()->text(0)))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage);
|
QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage);
|
||||||
} else {
|
} else {
|
||||||
//relayout
|
//relayout
|
||||||
QString sTablesql = pdb->getTableSQL(curTable);
|
QString sTablesql = pdb->getTableSQL(curTable);
|
||||||
qDebug() << sTablesql;
|
|
||||||
m_table = sqlb::Table::parseSQL(sTablesql);
|
m_table = sqlb::Table::parseSQL(sTablesql);
|
||||||
populateFields();
|
populateFields();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ private:
|
|||||||
kType = 1,
|
kType = 1,
|
||||||
kNotNull = 2,
|
kNotNull = 2,
|
||||||
kPrimaryKey = 3,
|
kPrimaryKey = 3,
|
||||||
kAutoIncrement = 4
|
kAutoIncrement = 4,
|
||||||
|
kDefault = 5,
|
||||||
|
kCheck = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
void updateColumnWidth();
|
void updateColumnWidth();
|
||||||
|
|||||||
@@ -125,17 +125,42 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Not null</string>
|
<string>Not null</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Not null</string>
|
||||||
|
</property>
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
<string>PK</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
<string>Primary key</string>
|
<string>Primary key</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
<string>AI</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
<string>Autoincrement</string>
|
<string>Autoincrement</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Default</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Default value</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Check</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Check constraint</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
Reference in New Issue
Block a user