diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index d4ac98bf..9cc3d882 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -845,24 +845,46 @@ void EditTableDialog::fieldSelectionChanged() if(hasSelection) { ui->buttonMoveUp->setEnabled(ui->treeWidget->selectionModel()->currentIndex().row() != 0); + ui->buttonMoveTop->setEnabled(ui->buttonMoveUp->isEnabled()); ui->buttonMoveDown->setEnabled(ui->treeWidget->selectionModel()->currentIndex().row() != ui->treeWidget->topLevelItemCount() - 1); + ui->buttonMoveBottom->setEnabled(ui->buttonMoveDown->isEnabled()); } } void EditTableDialog::moveUp() { - moveCurrentField(false); + moveCurrentField(MoveUp); } void EditTableDialog::moveDown() { - moveCurrentField(true); + moveCurrentField(MoveDown); } -void EditTableDialog::moveCurrentField(bool down) +void EditTableDialog::moveTop() +{ + moveCurrentField(MoveTop); +} + +void EditTableDialog::moveBottom() +{ + moveCurrentField(MoveBottom); +} + +void EditTableDialog::moveCurrentField(MoveFieldDirection dir) { int currentRow = ui->treeWidget->currentIndex().row(); - int newRow = currentRow + (down ? 1 : -1); + int newRow; + if(dir == MoveUp) + newRow = currentRow - 1; + else if(dir == MoveDown) + newRow = currentRow + 1; + else if(dir == MoveTop) + newRow = 0; + else if(dir == MoveBottom) + newRow = ui->treeWidget->topLevelItemCount() - 1; + else + return; // Save the comboboxes first by making copies QComboBox* newCombo[2]; @@ -891,7 +913,9 @@ void EditTableDialog::moveCurrentField(bool down) ui->treeWidget->setCurrentIndex(ui->treeWidget->currentIndex().sibling(newRow, 0)); // Finally update the table SQL - std::swap(m_table.fields[static_cast(newRow)], m_table.fields[static_cast(currentRow)]); + sqlb::Field temp = m_table.fields[static_cast(currentRow)]; + m_table.fields.erase(m_table.fields.begin() + currentRow); + m_table.fields.insert(m_table.fields.begin() + newRow, temp); // Update the SQL preview updateSqlText(); diff --git a/src/EditTableDialog.h b/src/EditTableDialog.h index 3cc29d16..2e9fdbf2 100644 --- a/src/EditTableDialog.h +++ b/src/EditTableDialog.h @@ -50,10 +50,18 @@ private: kConstraintSql = 3 }; + enum MoveFieldDirection + { + MoveUp, + MoveDown, + MoveTop, + MoveBottom + }; + void updateColumnWidth(); void updateSqlText(); - void moveCurrentField(bool down); + void moveCurrentField(MoveFieldDirection dir); private slots: void populateFields(); @@ -71,6 +79,8 @@ private slots: void updateTypeAndCollation(); void moveUp(); void moveDown(); + void moveTop(); + void moveBottom(); void setWithoutRowid(bool without_rowid); void changeSchema(const QString& schema); void removeConstraint(); diff --git a/src/EditTableDialog.ui b/src/EditTableDialog.ui index 7abf5a21..a4cf5053 100644 --- a/src/EditTableDialog.ui +++ b/src/EditTableDialog.ui @@ -6,7 +6,7 @@ 0 0 - 650 + 652 600 @@ -111,7 +111,7 @@ - Add field + Add @@ -131,7 +131,7 @@ false - Remove field + Remove @@ -145,13 +145,36 @@ + + + + false + + + Move to top + + + + :/icons/arrow_top:/icons/arrow_top + + + Qt::ToolButtonTextBesideIcon + + + true + + + Qt::NoArrow + + + false - Move field up + Move up @@ -171,7 +194,7 @@ false - Move field down + Move down @@ -185,6 +208,26 @@ + + + + false + + + Move to bottom + + + + :/icons/arrow_bottom:/icons/arrow_bottom + + + Qt::ToolButtonTextBesideIcon + + + true + + + @@ -275,7 +318,7 @@ Check constraint - + Collation @@ -463,12 +506,18 @@ buttonMore comboSchema checkWithoutRowid + groupDefinition addFieldButton removeFieldButton + buttonMoveTop buttonMoveUp buttonMoveDown + buttonMoveBottom treeWidget sqlTextEdit + buttonAddConstraint + buttonRemoveConstraint + tableConstraints @@ -529,8 +578,8 @@ addField() - 94 - 253 + 78 + 255 79 @@ -545,8 +594,8 @@ removeField() - 222 - 253 + 167 + 255 249 @@ -613,8 +662,8 @@ 78 - 117 - 176 + 138 + 172 @@ -625,8 +674,8 @@ setWithoutRowid(bool) - 344 - 143 + 485 + 160 324 @@ -657,8 +706,8 @@ changeSchema(QString) - 186 - 155 + 327 + 139 647 @@ -673,8 +722,8 @@ removeConstraint() - 186 - 155 + 295 + 255 647 @@ -682,6 +731,38 @@ + + buttonMoveTop + clicked() + EditTableDialog + moveTop() + + + 207 + 240 + + + 202 + 190 + + + + + buttonMoveBottom + clicked() + EditTableDialog + moveBottom() + + + 530 + 246 + + + 400 + 186 + + + fieldSelectionChanged() @@ -695,5 +776,7 @@ setWithoutRowid(bool) changeSchema(QString) removeConstraint() + moveTop() + moveBottom() diff --git a/src/icons/bullet_arrow_bottom.png b/src/icons/bullet_arrow_bottom.png new file mode 100644 index 00000000..1a28d825 Binary files /dev/null and b/src/icons/bullet_arrow_bottom.png differ diff --git a/src/icons/bullet_arrow_top.png b/src/icons/bullet_arrow_top.png new file mode 100644 index 00000000..0ce86d2b Binary files /dev/null and b/src/icons/bullet_arrow_top.png differ diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc index 86caabe3..ce7ceebf 100644 --- a/src/icons/icons.qrc +++ b/src/icons/icons.qrc @@ -84,5 +84,7 @@ clear_cond_formats.png edit_cond_formats.png clear_sorting.png + bullet_arrow_bottom.png + bullet_arrow_top.png