From 91e036dd744540bc8c024aa449387d7cc6594bea Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 22 Sep 2019 21:18:35 +0200 Subject: [PATCH] Add move field to top/bottom buttons to Edit Table dialog See issue #1988. --- src/EditTableDialog.cpp | 34 +++++++-- src/EditTableDialog.h | 12 ++- src/EditTableDialog.ui | 119 +++++++++++++++++++++++++----- src/icons/bullet_arrow_bottom.png | Bin 0 -> 229 bytes src/icons/bullet_arrow_top.png | Bin 0 -> 230 bytes src/icons/icons.qrc | 2 + 6 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 src/icons/bullet_arrow_bottom.png create mode 100644 src/icons/bullet_arrow_top.png 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 0000000000000000000000000000000000000000..1a28d8250035963143465ead45faaae79de6dcbd GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-$B_jGX#(Kw&{<9vg>5sw;c`@i>p z_kaC=>wowE^MCGt=k0FV8~^>E{g3+d|7HJ+|I4@QcRd)^xi$V8^Vx_G`+r6+RSGlL znKt8REw4uuU$^wNG<`ek&pG#xJ(Hh0`*ZlR^+%Epor$llpY=cF-^u@z|Ed2wufXdW aBfwxkOHd_T*GCNK1O`u6KbLh*2~7Ys?Or1Q literal 0 HcmV?d00001 diff --git a/src/icons/bullet_arrow_top.png b/src/icons/bullet_arrow_top.png new file mode 100644 index 0000000000000000000000000000000000000000..0ce86d2b2bc8eb047ca749fff00716b15c5bd9a8 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-%s@N{tu(Kvs0!a}YF0}=J!QSUY7M7z;-RJ$7n8*6-IkwdUVS%nn(+HZ=IM>KhySVgJojLZytKsQlJks9 zg>q@PUpbdv;&|+P!{NQ{65)mBh3B(*yP58!PISKz-O48F^~6K0e}RJHfr*NaZ|Z(M akrr=d7xdAvd!`9=1B0ilpUXO@geCyB6I2-h literal 0 HcmV?d00001 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