forked from qt-creator/qt-creator
RemoteFilterOptions: Add ability to re-order items in the list widget
Change-Id: Iada4b63f13ba1e6875b414eb6ee710209b0b75df Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -53,9 +53,13 @@ RemoteFilterOptions::RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *pare
|
|||||||
this, &RemoteFilterOptions::addNewItem);
|
this, &RemoteFilterOptions::addNewItem);
|
||||||
connect(m_ui.remove, &QPushButton::clicked,
|
connect(m_ui.remove, &QPushButton::clicked,
|
||||||
this, &RemoteFilterOptions::removeItem);
|
this, &RemoteFilterOptions::removeItem);
|
||||||
|
connect(m_ui.moveUp, &QPushButton::clicked,
|
||||||
|
this, &RemoteFilterOptions::moveItemUp);
|
||||||
|
connect(m_ui.moveDown, &QPushButton::clicked,
|
||||||
|
this, &RemoteFilterOptions::moveItemDown);
|
||||||
connect(m_ui.listWidget, &QListWidget::currentItemChanged,
|
connect(m_ui.listWidget, &QListWidget::currentItemChanged,
|
||||||
this, &RemoteFilterOptions::updateRemoveButton);
|
this, &RemoteFilterOptions::updateActionButtons);
|
||||||
updateRemoveButton();
|
updateActionButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteFilterOptions::addNewItem()
|
void RemoteFilterOptions::addNewItem()
|
||||||
@@ -76,9 +80,32 @@ void RemoteFilterOptions::removeItem()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteFilterOptions::updateRemoveButton()
|
void RemoteFilterOptions::moveItemUp()
|
||||||
|
{
|
||||||
|
const int row = m_ui.listWidget->currentRow();
|
||||||
|
if (row > 0) {
|
||||||
|
QListWidgetItem *item = m_ui.listWidget->takeItem(row);
|
||||||
|
m_ui.listWidget->insertItem(row - 1, item);
|
||||||
|
m_ui.listWidget->setCurrentRow(row - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoteFilterOptions::moveItemDown()
|
||||||
|
{
|
||||||
|
const int row = m_ui.listWidget->currentRow();
|
||||||
|
if (row >= 0 && row < m_ui.listWidget->count() - 1) {
|
||||||
|
QListWidgetItem *item = m_ui.listWidget->takeItem(row);
|
||||||
|
m_ui.listWidget->insertItem(row + 1, item);
|
||||||
|
m_ui.listWidget->setCurrentRow(row + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoteFilterOptions::updateActionButtons()
|
||||||
{
|
{
|
||||||
m_ui.remove->setEnabled(m_ui.listWidget->currentItem());
|
m_ui.remove->setEnabled(m_ui.listWidget->currentItem());
|
||||||
|
const int row = m_ui.listWidget->currentRow();
|
||||||
|
m_ui.moveUp->setEnabled(row > 0);
|
||||||
|
m_ui.moveDown->setEnabled(row >= 0 && row < m_ui.listWidget->count() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- RemoteHelpFilter
|
// -- RemoteHelpFilter
|
||||||
|
|||||||
@@ -72,7 +72,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void addNewItem();
|
void addNewItem();
|
||||||
void removeItem();
|
void removeItem();
|
||||||
void updateRemoveButton();
|
void moveItemUp();
|
||||||
|
void moveItemDown();
|
||||||
|
void updateActionButtons();
|
||||||
|
|
||||||
RemoteHelpFilter *m_filter;
|
RemoteHelpFilter *m_filter;
|
||||||
Ui::RemoteFilterOptions m_ui;
|
Ui::RemoteFilterOptions m_ui;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>342</width>
|
<width>600</width>
|
||||||
<height>182</height>
|
<height>400</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -60,7 +60,11 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="listWidget"/>
|
<widget class="QListWidget" name="listWidget">
|
||||||
|
<property name="dragDropMode">
|
||||||
|
<enum>QAbstractItemView::InternalMove</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
@@ -90,6 +94,32 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="moveUp">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>21</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Move Up</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="moveDown">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>21</width>
|
||||||
|
<height>21</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Move Down</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
Reference in New Issue
Block a user