diff --git a/src/EditIndexDialog.cpp b/src/EditIndexDialog.cpp index 6591cf12..608654e5 100644 --- a/src/EditIndexDialog.cpp +++ b/src/EditIndexDialog.cpp @@ -241,3 +241,37 @@ void EditIndexDialog::updateSqlText() { ui->sqlTextEdit->setText(index.sql()); } + +void EditIndexDialog::moveColumnUp() +{ + moveCurrentColumn(false); +} + +void EditIndexDialog::moveColumnDown() +{ + moveCurrentColumn(true); +} + +void EditIndexDialog::moveCurrentColumn(bool down) +{ + // Get current row number and calculate row number after the movement. Check the values + int currentRow = ui->tableIndexColumns->currentRow(); + if(currentRow == -1) + return; + int newRow = currentRow + (down ? 1 : -1); + if(newRow < 0) + return; + if(newRow >= ui->tableIndexColumns->rowCount()) + return; + + // Get the column information, swap the columns, and save the new column list back in the index + auto columns = index.columns(); + std::swap(columns[currentRow], columns[newRow]); + index.setColumns(columns); + + // Update UI + updateColumnLists(); + + // Select old row at new position + ui->tableIndexColumns->selectRow(newRow); +} diff --git a/src/EditIndexDialog.h b/src/EditIndexDialog.h index a055da0b..2b2ee4ca 100644 --- a/src/EditIndexDialog.h +++ b/src/EditIndexDialog.h @@ -28,6 +28,8 @@ private slots: void checkInput(); void addToIndex(const QModelIndex& idx = QModelIndex()); void removeFromIndex(const QModelIndex& idx = QModelIndex()); + void moveColumnUp(); + void moveColumnDown(); private: DBBrowserDB& pdb; @@ -39,6 +41,7 @@ private: void updateColumnLists(); void updateSqlText(); + void moveCurrentColumn(bool down); }; #endif diff --git a/src/EditIndexDialog.ui b/src/EditIndexDialog.ui index 10586bcf..bb3a2cab 100644 --- a/src/EditIndexDialog.ui +++ b/src/EditIndexDialog.ui @@ -6,7 +6,7 @@ 0 0 - 686 + 703 543 @@ -17,7 +17,7 @@ :/icons/index_create:/icons/index_create - + @@ -63,6 +63,22 @@ + + + + For restricting the index to only a part of the table you can specify a WHERE clause here that selects the part of the table that should be indexed + + + Partial inde&x clause + + + editPartialClause + + + + + + @@ -138,17 +154,15 @@ - - - :/icons/run:/icons/run + + Qt::RightArrow - - - :/icons/resultset_previous.png:/icons/resultset_previous.png + + Qt::LeftArrow @@ -214,6 +228,50 @@ + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::UpArrow + + + + + + + Qt::DownArrow + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + @@ -229,22 +287,6 @@ - - - - For restricting the index to only a part of the table you can specify a WHERE clause here that selects the part of the table that should be indexed - - - Partial inde&x clause - - - editPartialClause - - - - - - @@ -288,8 +330,8 @@ accept() - 258 - 499 + 264 + 536 157 @@ -304,8 +346,8 @@ reject() - 326 - 499 + 332 + 536 286 @@ -384,8 +426,8 @@ addToIndex() - 417 - 248 + 406 + 266 385 @@ -400,8 +442,8 @@ removeFromIndex() - 417 - 286 + 406 + 304 350 @@ -457,6 +499,38 @@ + + buttonMoveColumnUp + clicked() + EditIndexDialog + moveColumnUp() + + + 676 + 241 + + + 700 + 212 + + + + + buttonMoveColumnDown + clicked() + EditIndexDialog + moveColumnDown() + + + 686 + 299 + + + 699 + 307 + + + tableChanged(QString) @@ -465,5 +539,7 @@ addToIndex(QModelIndex) removeFromIndex() removeFromIndex(QModelIndex) + moveColumnUp() + moveColumnDown() diff --git a/src/sqlitetypes.cpp b/src/sqlitetypes.cpp index 4bbb09be..6bca8f0c 100644 --- a/src/sqlitetypes.cpp +++ b/src/sqlitetypes.cpp @@ -1118,7 +1118,6 @@ bool Index::removeColumn(const QString& name) void Index::setColumns(const IndexedColumnVector& columns) { - clear(); m_columns = columns; }