Skip to content

Commit 6321d14

Browse files
committed
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.
1 parent f06b63b commit 6321d14

4 files changed

Lines changed: 145 additions & 33 deletions

File tree

‎src/EditIndexDialog.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,37 @@ void EditIndexDialog::updateSqlText()
241241
{
242242
ui->sqlTextEdit->setText(index.sql());
243243
}
244+
245+
void EditIndexDialog::moveColumnUp()
246+
{
247+
moveCurrentColumn(false);
248+
}
249+
250+
void EditIndexDialog::moveColumnDown()
251+
{
252+
moveCurrentColumn(true);
253+
}
254+
255+
void EditIndexDialog::moveCurrentColumn(bool down)
256+
{
257+
// Get current row number and calculate row number after the movement. Check the values
258+
int currentRow = ui->tableIndexColumns->currentRow();
259+
if(currentRow == -1)
260+
return;
261+
int newRow = currentRow + (down ? 1 : -1);
262+
if(newRow < 0)
263+
return;
264+
if(newRow >= ui->tableIndexColumns->rowCount())
265+
return;
266+
267+
// Get the column information, swap the columns, and save the new column list back in the index
268+
auto columns = index.columns();
269+
std::swap(columns[currentRow], columns[newRow]);
270+
index.setColumns(columns);
271+
272+
// Update UI
273+
updateColumnLists();
274+
275+
// Select old row at new position
276+
ui->tableIndexColumns->selectRow(newRow);
277+
}

‎src/EditIndexDialog.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private slots:
2828
void checkInput();
2929
void addToIndex(const QModelIndex& idx = QModelIndex());
3030
void removeFromIndex(const QModelIndex& idx = QModelIndex());
31+
void moveColumnUp();
32+
void moveColumnDown();
3133

3234
private:
3335
DBBrowserDB& pdb;
@@ -39,6 +41,7 @@ private slots:
3941

4042
void updateColumnLists();
4143
void updateSqlText();
44+
void moveCurrentColumn(bool down);
4245
};
4346

4447
#endif

‎src/EditIndexDialog.ui‎

Lines changed: 108 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>686</width>
9+
<width>703</width>
1010
<height>543</height>
1111
</rect>
1212
</property>
@@ -17,7 +17,7 @@
1717
<iconset resource="icons/icons.qrc">
1818
<normaloff>:/icons/index_create</normaloff>:/icons/index_create</iconset>
1919
</property>
20-
<layout class="QVBoxLayout" name="verticalLayout_2">
20+
<layout class="QVBoxLayout" name="verticalLayout_3">
2121
<item>
2222
<layout class="QFormLayout" name="formLayout">
2323
<item row="0" column="0">
@@ -63,6 +63,22 @@
6363
</property>
6464
</widget>
6565
</item>
66+
<item row="3" column="0">
67+
<widget class="QLabel" name="label">
68+
<property name="toolTip">
69+
<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>
70+
</property>
71+
<property name="text">
72+
<string>Partial inde&amp;x clause</string>
73+
</property>
74+
<property name="buddy">
75+
<cstring>editPartialClause</cstring>
76+
</property>
77+
</widget>
78+
</item>
79+
<item row="3" column="1">
80+
<widget class="QLineEdit" name="editPartialClause"/>
81+
</item>
6682
<item row="4" column="0">
6783
<widget class="QLabel" name="labelIndexColumns">
6884
<property name="text">
@@ -138,17 +154,15 @@
138154
</item>
139155
<item>
140156
<widget class="QToolButton" name="buttonToIndex">
141-
<property name="icon">
142-
<iconset resource="icons/icons.qrc">
143-
<normaloff>:/icons/run</normaloff>:/icons/run</iconset>
157+
<property name="arrowType">
158+
<enum>Qt::RightArrow</enum>
144159
</property>
145160
</widget>
146161
</item>
147162
<item>
148163
<widget class="QToolButton" name="buttonFromIndex">
149-
<property name="icon">
150-
<iconset resource="icons/icons.qrc">
151-
<normaloff>:/icons/resultset_previous.png</normaloff>:/icons/resultset_previous.png</iconset>
164+
<property name="arrowType">
165+
<enum>Qt::LeftArrow</enum>
152166
</property>
153167
</widget>
154168
</item>
@@ -214,6 +228,50 @@
214228
</column>
215229
</widget>
216230
</item>
231+
<item>
232+
<layout class="QVBoxLayout" name="verticalLayout_2">
233+
<item>
234+
<spacer name="verticalSpacer_4">
235+
<property name="orientation">
236+
<enum>Qt::Vertical</enum>
237+
</property>
238+
<property name="sizeHint" stdset="0">
239+
<size>
240+
<width>20</width>
241+
<height>40</height>
242+
</size>
243+
</property>
244+
</spacer>
245+
</item>
246+
<item>
247+
<widget class="QToolButton" name="buttonMoveColumnUp">
248+
<property name="arrowType">
249+
<enum>Qt::UpArrow</enum>
250+
</property>
251+
</widget>
252+
</item>
253+
<item>
254+
<widget class="QToolButton" name="buttonMoveColumnDown">
255+
<property name="arrowType">
256+
<enum>Qt::DownArrow</enum>
257+
</property>
258+
</widget>
259+
</item>
260+
<item>
261+
<spacer name="verticalSpacer_3">
262+
<property name="orientation">
263+
<enum>Qt::Vertical</enum>
264+
</property>
265+
<property name="sizeHint" stdset="0">
266+
<size>
267+
<width>20</width>
268+
<height>40</height>
269+
</size>
270+
</property>
271+
</spacer>
272+
</item>
273+
</layout>
274+
</item>
217275
</layout>
218276
</widget>
219277
<widget class="SqlTextEdit" name="sqlTextEdit" native="true">
@@ -229,22 +287,6 @@
229287
</widget>
230288
</widget>
231289
</item>
232-
<item row="3" column="0">
233-
<widget class="QLabel" name="label">
234-
<property name="toolTip">
235-
<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>
236-
</property>
237-
<property name="text">
238-
<string>Partial inde&amp;x clause</string>
239-
</property>
240-
<property name="buddy">
241-
<cstring>editPartialClause</cstring>
242-
</property>
243-
</widget>
244-
</item>
245-
<item row="3" column="1">
246-
<widget class="QLineEdit" name="editPartialClause"/>
247-
</item>
248290
</layout>
249291
</item>
250292
<item>
@@ -288,8 +330,8 @@
288330
<slot>accept()</slot>
289331
<hints>
290332
<hint type="sourcelabel">
291-
<x>258</x>
292-
<y>499</y>
333+
<x>264</x>
334+
<y>536</y>
293335
</hint>
294336
<hint type="destinationlabel">
295337
<x>157</x>
@@ -304,8 +346,8 @@
304346
<slot>reject()</slot>
305347
<hints>
306348
<hint type="sourcelabel">
307-
<x>326</x>
308-
<y>499</y>
349+
<x>332</x>
350+
<y>536</y>
309351
</hint>
310352
<hint type="destinationlabel">
311353
<x>286</x>
@@ -384,8 +426,8 @@
384426
<slot>addToIndex()</slot>
385427
<hints>
386428
<hint type="sourcelabel">
387-
<x>417</x>
388-
<y>248</y>
429+
<x>406</x>
430+
<y>266</y>
389431
</hint>
390432
<hint type="destinationlabel">
391433
<x>385</x>
@@ -400,8 +442,8 @@
400442
<slot>removeFromIndex()</slot>
401443
<hints>
402444
<hint type="sourcelabel">
403-
<x>417</x>
404-
<y>286</y>
445+
<x>406</x>
446+
<y>304</y>
405447
</hint>
406448
<hint type="destinationlabel">
407449
<x>350</x>
@@ -457,6 +499,38 @@
457499
</hint>
458500
</hints>
459501
</connection>
502+
<connection>
503+
<sender>buttonMoveColumnUp</sender>
504+
<signal>clicked()</signal>
505+
<receiver>EditIndexDialog</receiver>
506+
<slot>moveColumnUp()</slot>
507+
<hints>
508+
<hint type="sourcelabel">
509+
<x>676</x>
510+
<y>241</y>
511+
</hint>
512+
<hint type="destinationlabel">
513+
<x>700</x>
514+
<y>212</y>
515+
</hint>
516+
</hints>
517+
</connection>
518+
<connection>
519+
<sender>buttonMoveColumnDown</sender>
520+
<signal>clicked()</signal>
521+
<receiver>EditIndexDialog</receiver>
522+
<slot>moveColumnDown()</slot>
523+
<hints>
524+
<hint type="sourcelabel">
525+
<x>686</x>
526+
<y>299</y>
527+
</hint>
528+
<hint type="destinationlabel">
529+
<x>699</x>
530+
<y>307</y>
531+
</hint>
532+
</hints>
533+
</connection>
460534
</connections>
461535
<slots>
462536
<slot>tableChanged(QString)</slot>
@@ -465,5 +539,7 @@
465539
<slot>addToIndex(QModelIndex)</slot>
466540
<slot>removeFromIndex()</slot>
467541
<slot>removeFromIndex(QModelIndex)</slot>
542+
<slot>moveColumnUp()</slot>
543+
<slot>moveColumnDown()</slot>
468544
</slots>
469545
</ui>

‎src/sqlitetypes.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,6 @@ bool Index::removeColumn(const QString& name)
11181118

11191119
void Index::setColumns(const IndexedColumnVector& columns)
11201120
{
1121-
clear();
11221121
m_columns = columns;
11231122
}
11241123

0 commit comments

Comments
 (0)