mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Bug #1925136: Rules editors: Moving multiple rules deselects all but one
This commit is contained in:
parent
06d82ad1c3
commit
1ff211dc3d
@ -9,13 +9,14 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from functools import partial
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAbstractItemView, QAbstractListModel, QApplication, QCheckBox, QComboBox,
|
QAbstractItemView, QAbstractListModel, QApplication, QCheckBox, QComboBox,
|
||||||
QDialog, QDialogButtonBox, QDoubleValidator, QFrame, QGridLayout, QIcon,
|
QDialog, QDialogButtonBox, QDoubleValidator, QFrame, QGridLayout, QIcon,
|
||||||
QIntValidator, QItemSelectionModel, QLabel, QLineEdit, QListView, QMenu,
|
QIntValidator, QItemSelectionModel, QLabel, QLineEdit, QListView, QMenu,
|
||||||
QPalette, QPushButton, QScrollArea, QSize, QSizePolicy, QSpacerItem,
|
QPalette, QPushButton, QScrollArea, QSize, QSizePolicy, QSpacerItem,
|
||||||
QStandardItem, QStandardItemModel, Qt, QToolButton, QVBoxLayout, QWidget,
|
QStandardItem, QStandardItemModel, Qt, QToolButton, QVBoxLayout, QWidget,
|
||||||
pyqtSignal
|
QItemSelection, pyqtSignal
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import as_unicode, prepare_string_for_xml, sanitize_file_name
|
from calibre import as_unicode, prepare_string_for_xml, sanitize_file_name
|
||||||
@ -942,12 +943,12 @@ class EditRules(QWidget): # {{{
|
|||||||
self.up_button = b = QToolButton(self)
|
self.up_button = b = QToolButton(self)
|
||||||
b.setIcon(QIcon(I('arrow-up.png')))
|
b.setIcon(QIcon(I('arrow-up.png')))
|
||||||
b.setToolTip(_('Move the selected rule up'))
|
b.setToolTip(_('Move the selected rule up'))
|
||||||
b.clicked.connect(self.move_up)
|
b.clicked.connect(partial(self.move_rows, moving_up=True))
|
||||||
g.addWidget(b, 0, 1, 1, 1, Qt.AlignmentFlag.AlignTop)
|
g.addWidget(b, 0, 1, 1, 1, Qt.AlignmentFlag.AlignTop)
|
||||||
self.down_button = b = QToolButton(self)
|
self.down_button = b = QToolButton(self)
|
||||||
b.setIcon(QIcon(I('arrow-down.png')))
|
b.setIcon(QIcon(I('arrow-down.png')))
|
||||||
b.setToolTip(_('Move the selected rule down'))
|
b.setToolTip(_('Move the selected rule down'))
|
||||||
b.clicked.connect(self.move_down)
|
b.clicked.connect(partial(self.move_rows, moving_up=False))
|
||||||
g.addWidget(b, 1, 1, 1, 1, Qt.AlignmentFlag.AlignBottom)
|
g.addWidget(b, 1, 1, 1, 1, Qt.AlignmentFlag.AlignBottom)
|
||||||
|
|
||||||
l.addLayout(g, l.rowCount(), 0, 1, 2)
|
l.addLayout(g, l.rowCount(), 0, 1, 2)
|
||||||
@ -1142,34 +1143,26 @@ class EditRules(QWidget): # {{{
|
|||||||
self.model.remove_rule(row)
|
self.model.remove_rule(row)
|
||||||
self.changed.emit()
|
self.changed.emit()
|
||||||
|
|
||||||
def move_up(self):
|
def move_rows(self, moving_up=True):
|
||||||
sm = self.rules_view.selectionModel()
|
sm = self.rules_view.selectionModel()
|
||||||
rows = sorted(list(sm.selectedRows()))
|
rows = sorted(list(sm.selectedRows()), reverse=not moving_up)
|
||||||
if rows:
|
if rows:
|
||||||
if rows[0].row() == 0:
|
if rows[0].row() == (0 if moving_up else self.model.rowCount() - 1):
|
||||||
return
|
return
|
||||||
sm.clear()
|
sm.clear()
|
||||||
|
indices_to_select = []
|
||||||
for idx in rows:
|
for idx in rows:
|
||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
idx = self.model.move(idx, -1)
|
idx = self.model.move(idx, -1 if moving_up else 1)
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle)
|
indices_to_select.append(idx)
|
||||||
self.rules_view.setCurrentIndex(idx)
|
if indices_to_select:
|
||||||
self.changed.emit()
|
new_selections = QItemSelection()
|
||||||
|
for idx in indices_to_select:
|
||||||
def move_down(self):
|
new_selections.merge(QItemSelection(idx, idx),
|
||||||
sm = self.rules_view.selectionModel()
|
QItemSelectionModel.SelectionFlag.Select)
|
||||||
rows = sorted(list(sm.selectedRows()))
|
sm.select(new_selections, QItemSelectionModel.SelectionFlag.Select)
|
||||||
if rows:
|
self.rules_view.scrollTo(indices_to_select[0])
|
||||||
if rows[-1].row() == self.model.rowCount() - 1:
|
|
||||||
return
|
|
||||||
sm.clear()
|
|
||||||
for idx in rows:
|
|
||||||
if idx.isValid():
|
|
||||||
idx = self.model.move(idx, 1)
|
|
||||||
if idx is not None:
|
|
||||||
sm.select(idx, QItemSelectionModel.SelectionFlag.Toggle)
|
|
||||||
self.rules_view.setCurrentIndex(idx)
|
|
||||||
self.changed.emit()
|
self.changed.emit()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user