Add buttons for changing the column order in Edit Index dialog

Add two buttons for moving index columns up or down in the Edit Index
dialog.
This commit is contained in:
Martin Kleusberg
2017-05-14 20:48:02 +02:00
parent f06b63bc66
commit 6321d14dd6
4 changed files with 145 additions and 33 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>686</width>
<width>703</width>
<height>543</height>
</rect>
</property>
@@ -17,7 +17,7 @@
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/index_create</normaloff>:/icons/index_create</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
@@ -63,6 +63,22 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>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</string>
</property>
<property name="text">
<string>Partial inde&amp;x clause</string>
</property>
<property name="buddy">
<cstring>editPartialClause</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="editPartialClause"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelIndexColumns">
<property name="text">
@@ -138,17 +154,15 @@
</item>
<item>
<widget class="QToolButton" name="buttonToIndex">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/run</normaloff>:/icons/run</iconset>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonFromIndex">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/resultset_previous.png</normaloff>:/icons/resultset_previous.png</iconset>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
@@ -214,6 +228,50 @@
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonMoveColumnUp">
<property name="arrowType">
<enum>Qt::UpArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonMoveColumnDown">
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="SqlTextEdit" name="sqlTextEdit" native="true">
@@ -229,22 +287,6 @@
</widget>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>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</string>
</property>
<property name="text">
<string>Partial inde&amp;x clause</string>
</property>
<property name="buddy">
<cstring>editPartialClause</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="editPartialClause"/>
</item>
</layout>
</item>
<item>
@@ -288,8 +330,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>258</x>
<y>499</y>
<x>264</x>
<y>536</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@@ -304,8 +346,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>326</x>
<y>499</y>
<x>332</x>
<y>536</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@@ -384,8 +426,8 @@
<slot>addToIndex()</slot>
<hints>
<hint type="sourcelabel">
<x>417</x>
<y>248</y>
<x>406</x>
<y>266</y>
</hint>
<hint type="destinationlabel">
<x>385</x>
@@ -400,8 +442,8 @@
<slot>removeFromIndex()</slot>
<hints>
<hint type="sourcelabel">
<x>417</x>
<y>286</y>
<x>406</x>
<y>304</y>
</hint>
<hint type="destinationlabel">
<x>350</x>
@@ -457,6 +499,38 @@
</hint>
</hints>
</connection>
<connection>
<sender>buttonMoveColumnUp</sender>
<signal>clicked()</signal>
<receiver>EditIndexDialog</receiver>
<slot>moveColumnUp()</slot>
<hints>
<hint type="sourcelabel">
<x>676</x>
<y>241</y>
</hint>
<hint type="destinationlabel">
<x>700</x>
<y>212</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonMoveColumnDown</sender>
<signal>clicked()</signal>
<receiver>EditIndexDialog</receiver>
<slot>moveColumnDown()</slot>
<hints>
<hint type="sourcelabel">
<x>686</x>
<y>299</y>
</hint>
<hint type="destinationlabel">
<x>699</x>
<y>307</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>tableChanged(QString)</slot>
@@ -465,5 +539,7 @@
<slot>addToIndex(QModelIndex)</slot>
<slot>removeFromIndex()</slot>
<slot>removeFromIndex(QModelIndex)</slot>
<slot>moveColumnUp()</slot>
<slot>moveColumnDown()</slot>
</slots>
</ui>

View File

@@ -1118,7 +1118,6 @@ bool Index::removeColumn(const QString& name)
void Index::setColumns(const IndexedColumnVector& columns)
{
clear();
m_columns = columns;
}