mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Add move field to top/bottom buttons to Edit Table dialog
See issue #1988.
This commit is contained in:
@@ -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<size_t>(newRow)], m_table.fields[static_cast<size_t>(currentRow)]);
|
||||
sqlb::Field temp = m_table.fields[static_cast<size_t>(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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<width>652</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -111,7 +111,7 @@
|
||||
<item>
|
||||
<widget class="QToolButton" name="addFieldButton">
|
||||
<property name="text">
|
||||
<string>Add field</string>
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
@@ -131,7 +131,7 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove field</string>
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
@@ -145,13 +145,36 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonMoveTop">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move to top</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/arrow_top</normaloff>:/icons/arrow_top</iconset>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::NoArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonMoveUp">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move field up</string>
|
||||
<string>Move up</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
@@ -171,7 +194,7 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move field down</string>
|
||||
<string>Move down</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
@@ -185,6 +208,26 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonMoveBottom">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move to bottom</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/arrow_bottom</normaloff>:/icons/arrow_bottom</iconset>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@@ -275,7 +318,7 @@
|
||||
<string>Check constraint</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Collation</string>
|
||||
</property>
|
||||
@@ -463,12 +506,18 @@
|
||||
<tabstop>buttonMore</tabstop>
|
||||
<tabstop>comboSchema</tabstop>
|
||||
<tabstop>checkWithoutRowid</tabstop>
|
||||
<tabstop>groupDefinition</tabstop>
|
||||
<tabstop>addFieldButton</tabstop>
|
||||
<tabstop>removeFieldButton</tabstop>
|
||||
<tabstop>buttonMoveTop</tabstop>
|
||||
<tabstop>buttonMoveUp</tabstop>
|
||||
<tabstop>buttonMoveDown</tabstop>
|
||||
<tabstop>buttonMoveBottom</tabstop>
|
||||
<tabstop>treeWidget</tabstop>
|
||||
<tabstop>sqlTextEdit</tabstop>
|
||||
<tabstop>buttonAddConstraint</tabstop>
|
||||
<tabstop>buttonRemoveConstraint</tabstop>
|
||||
<tabstop>tableConstraints</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="icons/icons.qrc"/>
|
||||
@@ -529,8 +578,8 @@
|
||||
<slot>addField()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>94</x>
|
||||
<y>253</y>
|
||||
<x>78</x>
|
||||
<y>255</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>79</x>
|
||||
@@ -545,8 +594,8 @@
|
||||
<slot>removeField()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>222</x>
|
||||
<y>253</y>
|
||||
<x>167</x>
|
||||
<y>255</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>249</x>
|
||||
@@ -613,8 +662,8 @@
|
||||
<y>78</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>117</x>
|
||||
<y>176</y>
|
||||
<x>138</x>
|
||||
<y>172</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@@ -625,8 +674,8 @@
|
||||
<slot>setWithoutRowid(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>344</x>
|
||||
<y>143</y>
|
||||
<x>485</x>
|
||||
<y>160</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>324</x>
|
||||
@@ -657,8 +706,8 @@
|
||||
<slot>changeSchema(QString)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>186</x>
|
||||
<y>155</y>
|
||||
<x>327</x>
|
||||
<y>139</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>647</x>
|
||||
@@ -673,8 +722,8 @@
|
||||
<slot>removeConstraint()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>186</x>
|
||||
<y>155</y>
|
||||
<x>295</x>
|
||||
<y>255</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>647</x>
|
||||
@@ -682,6 +731,38 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonMoveTop</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>EditTableDialog</receiver>
|
||||
<slot>moveTop()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>207</x>
|
||||
<y>240</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>202</x>
|
||||
<y>190</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonMoveBottom</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>EditTableDialog</receiver>
|
||||
<slot>moveBottom()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>530</x>
|
||||
<y>246</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>400</x>
|
||||
<y>186</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>fieldSelectionChanged()</slot>
|
||||
@@ -695,5 +776,7 @@
|
||||
<slot>setWithoutRowid(bool)</slot>
|
||||
<slot>changeSchema(QString)</slot>
|
||||
<slot>removeConstraint()</slot>
|
||||
<slot>moveTop()</slot>
|
||||
<slot>moveBottom()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
BIN
src/icons/bullet_arrow_bottom.png
Normal file
BIN
src/icons/bullet_arrow_bottom.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 229 B |
BIN
src/icons/bullet_arrow_top.png
Normal file
BIN
src/icons/bullet_arrow_top.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 230 B |
@@ -84,5 +84,7 @@
|
||||
<file alias="clear_cond_formats">clear_cond_formats.png</file>
|
||||
<file alias="edit_cond_formats">edit_cond_formats.png</file>
|
||||
<file alias="clear_sorting">clear_sorting.png</file>
|
||||
<file alias="arrow_bottom">bullet_arrow_bottom.png</file>
|
||||
<file alias="arrow_top">bullet_arrow_top.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Reference in New Issue
Block a user