GUI improvements in Edit Table Dialog

- Avoid editing data in checkable columns or columns with combo-boxes
- Select items to allow navigation with cursor keys in each row
- More edit triggers for editable columns
- Icons for primary and foreign key columns
- Dialog width increased so more columns fit

See issue #598
This commit is contained in:
mgrojo
2020-08-05 14:34:27 +02:00
parent fc78fc2f3c
commit de28943ec5
2 changed files with 51 additions and 19 deletions

View File

@@ -17,6 +17,15 @@
Q_DECLARE_METATYPE(sqlb::ConstraintPtr)
// Styled Item Delegate for non-editable columns
class NoEditDelegate: public QStyledItemDelegate {
public:
explicit NoEditDelegate(QObject* parent=nullptr): QStyledItemDelegate(parent) {}
QWidget* createEditor(QWidget* /* parent */, const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const override {
return nullptr;
}
};
EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, bool createTable, QWidget* parent)
: QDialog(parent),
ui(new Ui::EditTableDialog),
@@ -35,6 +44,13 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
// Set item delegate for foreign key column
m_fkEditorDelegate = new ForeignKeyEditorDelegate(db, m_table, this);
ui->treeWidget->setItemDelegateForColumn(kForeignKey, m_fkEditorDelegate);
// Disallow edition of checkable columns or columns with combo-boxes
ui->treeWidget->setItemDelegateForColumn(kType, new NoEditDelegate(this));
ui->treeWidget->setItemDelegateForColumn(kNotNull, new NoEditDelegate(this));
ui->treeWidget->setItemDelegateForColumn(kPrimaryKey, new NoEditDelegate(this));
ui->treeWidget->setItemDelegateForColumn(kAutoIncrement, new NoEditDelegate(this));
ui->treeWidget->setItemDelegateForColumn(kUnique, new NoEditDelegate(this));
ui->treeWidget->setItemDelegateForColumn(kCollation, new NoEditDelegate(this));
// Set up popup menu for adding constraints
QMenu* constraint_menu = new QMenu(this);
@@ -207,6 +223,7 @@ void EditTableDialog::populateFields()
typeBox->setCurrentIndex(index);
typeBox->installEventFilter(this);
connect(typeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypeAndCollation()));
ui->treeWidget->setItemWidget(tbitem, kType, typeBox);
tbitem->setCheckState(kNotNull, f.notnull() ? Qt::Checked : Qt::Unchecked);
@@ -353,7 +370,7 @@ void EditTableDialog::accept()
}
void EditTableDialog::reject()
{
{
// Then rollback to our savepoint
pdb.revertToSavepoint(m_sRestorePointName);
@@ -880,6 +897,7 @@ void EditTableDialog::moveBottom()
void EditTableDialog::moveCurrentField(MoveFieldDirection dir)
{
int currentRow = ui->treeWidget->currentIndex().row();
int currentCol = ui->treeWidget->currentIndex().column();
int newRow;
if(dir == MoveUp)
newRow = currentRow - 1;
@@ -916,7 +934,7 @@ void EditTableDialog::moveCurrentField(MoveFieldDirection dir)
ui->treeWidget->setItemWidget(item, kCollation, newCombo[1]);
// Select the old item at its new position
ui->treeWidget->setCurrentIndex(ui->treeWidget->currentIndex().sibling(newRow, 0));
ui->treeWidget->setCurrentIndex(ui->treeWidget->currentIndex().sibling(newRow, currentCol));
// Finally update the table SQL
sqlb::Field temp = m_table.fields[static_cast<size_t>(currentRow)];

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<width>800</width>
<height>600</height>
</rect>
</property>
@@ -257,6 +257,12 @@
<height>140</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
@@ -285,6 +291,10 @@
<property name="toolTip">
<string>Primary key</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_key</normaloff>:/icons/field_key</iconset>
</property>
</column>
<column>
<property name="text">
@@ -327,6 +337,10 @@
<property name="text">
<string>Foreign Key</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/field_fk</normaloff>:/icons/field_fk</iconset>
</property>
</column>
</widget>
</item>
@@ -578,8 +592,8 @@
<slot>addField()</slot>
<hints>
<hint type="sourcelabel">
<x>78</x>
<y>255</y>
<x>82</x>
<y>248</y>
</hint>
<hint type="destinationlabel">
<x>79</x>
@@ -594,8 +608,8 @@
<slot>removeField()</slot>
<hints>
<hint type="sourcelabel">
<x>167</x>
<y>255</y>
<x>178</x>
<y>248</y>
</hint>
<hint type="destinationlabel">
<x>249</x>
@@ -626,8 +640,8 @@
<slot>moveUp()</slot>
<hints>
<hint type="sourcelabel">
<x>343</x>
<y>253</y>
<x>400</x>
<y>248</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
@@ -642,8 +656,8 @@
<slot>moveDown()</slot>
<hints>
<hint type="sourcelabel">
<x>481</x>
<y>253</y>
<x>519</x>
<y>248</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
@@ -662,8 +676,8 @@
<y>78</y>
</hint>
<hint type="destinationlabel">
<x>138</x>
<y>172</y>
<x>159</x>
<y>167</y>
</hint>
</hints>
</connection>
@@ -674,8 +688,8 @@
<slot>setWithoutRowid(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>485</x>
<y>160</y>
<x>640</x>
<y>156</y>
</hint>
<hint type="destinationlabel">
<x>324</x>
@@ -706,8 +720,8 @@
<slot>changeSchema(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>327</x>
<y>139</y>
<x>482</x>
<y>135</y>
</hint>
<hint type="destinationlabel">
<x>647</x>
@@ -722,8 +736,8 @@
<slot>removeConstraint()</slot>
<hints>
<hint type="sourcelabel">
<x>295</x>
<y>255</y>
<x>119</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>647</x>