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);
|
||||
connect(m_ui.remove, &QPushButton::clicked,
|
||||
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,
|
||||
this, &RemoteFilterOptions::updateRemoveButton);
|
||||
updateRemoveButton();
|
||||
this, &RemoteFilterOptions::updateActionButtons);
|
||||
updateActionButtons();
|
||||
}
|
||||
|
||||
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());
|
||||
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
|
||||
|
||||
@@ -72,7 +72,9 @@ public:
|
||||
private:
|
||||
void addNewItem();
|
||||
void removeItem();
|
||||
void updateRemoveButton();
|
||||
void moveItemUp();
|
||||
void moveItemDown();
|
||||
void updateActionButtons();
|
||||
|
||||
RemoteHelpFilter *m_filter;
|
||||
Ui::RemoteFilterOptions m_ui;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>342</width>
|
||||
<height>182</height>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -60,7 +60,11 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@@ -90,6 +94,32 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
Reference in New Issue
Block a user