mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
9c53adfbb9
commit
c73d1a4f0d
@ -93,9 +93,9 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.bool_no_icon = QIcon(I('list_remove.png'))
|
self.bool_no_icon = QIcon(I('list_remove.png'))
|
||||||
self.bool_blank_icon = QIcon(I('blank.png'))
|
self.bool_blank_icon = QIcon(I('blank.png'))
|
||||||
self.device_connected = False
|
self.device_connected = False
|
||||||
self.rows_to_highlight = []
|
self.ids_to_highlight = []
|
||||||
self.rows_to_highlight_set = set()
|
self.ids_to_highlight_set = set()
|
||||||
self.current_highlighted_row = None
|
self.current_highlighted_idx = None
|
||||||
self.highlight_only = False
|
self.highlight_only = False
|
||||||
self.read_config()
|
self.read_config()
|
||||||
|
|
||||||
@ -131,9 +131,9 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.book_on_device = func
|
self.book_on_device = func
|
||||||
|
|
||||||
def set_database(self, db):
|
def set_database(self, db):
|
||||||
self.rows_to_highlight = []
|
self.ids_to_highlight = []
|
||||||
self.rows_to_highlight_set = set()
|
self.ids_to_highlight_set = set()
|
||||||
self.current_highlighted_row = None
|
self.current_highlighted_idx = None
|
||||||
self.db = db
|
self.db = db
|
||||||
self.custom_columns = self.db.field_metadata.custom_field_metadata()
|
self.custom_columns = self.db.field_metadata.custom_field_metadata()
|
||||||
self.column_map = list(self.orig_headers.keys()) + \
|
self.column_map = list(self.orig_headers.keys()) + \
|
||||||
@ -241,43 +241,55 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
if self.last_search:
|
if self.last_search:
|
||||||
self.research()
|
self.research()
|
||||||
|
|
||||||
def get_current_highlighted_row(self):
|
def get_current_highlighted_id(self):
|
||||||
if len(self.rows_to_highlight) == 0 or self.current_highlighted_row is None:
|
if len(self.ids_to_highlight) == 0 or self.current_highlighted_idx is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return self.rows_to_highlight[self.current_highlighted_row]
|
return self.ids_to_highlight[self.current_highlighted_idx]
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_next_highlighted_row(self, forward):
|
def get_next_highlighted_id(self, current_row, forward):
|
||||||
if len(self.rows_to_highlight) == 0 or self.current_highlighted_row is None:
|
if len(self.ids_to_highlight) == 0 or self.current_highlighted_idx is None:
|
||||||
return None
|
return None
|
||||||
self.current_highlighted_row += 1 if forward else -1
|
if current_row is None:
|
||||||
if self.current_highlighted_row < 0:
|
row_ = self.current_highlighted_idx
|
||||||
self.current_highlighted_row = len(self.rows_to_highlight) - 1;
|
else:
|
||||||
elif self.current_highlighted_row >= len(self.rows_to_highlight):
|
row_ = current_row
|
||||||
self.current_highlighted_row = 0
|
while True:
|
||||||
return self.get_current_highlighted_row()
|
row_ += 1 if forward else -1
|
||||||
|
if row_ < 0:
|
||||||
|
row_ = self.count() - 1;
|
||||||
|
elif row_ >= self.count():
|
||||||
|
row_ = 0
|
||||||
|
if self.id(row_) in self.ids_to_highlight_set:
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
self.current_highlighted_idx = self.ids_to_highlight.index(self.id(row_))
|
||||||
|
except:
|
||||||
|
# This shouldn't happen ...
|
||||||
|
return None
|
||||||
|
return self.get_current_highlighted_id()
|
||||||
|
|
||||||
def search(self, text, reset=True):
|
def search(self, text, reset=True):
|
||||||
try:
|
try:
|
||||||
if self.highlight_only:
|
if self.highlight_only:
|
||||||
self.db.search('')
|
self.db.search('')
|
||||||
if not text:
|
if not text:
|
||||||
self.rows_to_highlight = []
|
self.ids_to_highlight = []
|
||||||
self.rows_to_highlight_set = set()
|
self.ids_to_highlight_set = set()
|
||||||
self.current_highlighted_row = None
|
self.current_highlighted_idx = None
|
||||||
else:
|
else:
|
||||||
self.rows_to_highlight = self.db.search(text, return_matches=True)
|
self.ids_to_highlight = self.db.search(text, return_matches=True)
|
||||||
self.rows_to_highlight_set = set(self.rows_to_highlight)
|
self.ids_to_highlight_set = set(self.ids_to_highlight)
|
||||||
if self.rows_to_highlight:
|
if self.ids_to_highlight:
|
||||||
self.current_highlighted_row = 0
|
self.current_highlighted_idx = 0
|
||||||
else:
|
else:
|
||||||
self.current_highlighted_row = None
|
self.current_highlighted_idx = None
|
||||||
else:
|
else:
|
||||||
self.rows_to_highlight = []
|
self.ids_to_highlight = []
|
||||||
self.rows_to_highlight_set = set()
|
self.ids_to_highlight_set = set()
|
||||||
self.current_highlighted_row = None
|
self.current_highlighted_idx = None
|
||||||
self.db.search(text)
|
self.db.search(text)
|
||||||
except ParseException as e:
|
except ParseException as e:
|
||||||
self.searched.emit(e.msg)
|
self.searched.emit(e.msg)
|
||||||
@ -700,7 +712,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
if role in (Qt.DisplayRole, Qt.EditRole):
|
if role in (Qt.DisplayRole, Qt.EditRole):
|
||||||
return self.column_to_dc_map[col](index.row())
|
return self.column_to_dc_map[col](index.row())
|
||||||
elif role == Qt.BackgroundColorRole:
|
elif role == Qt.BackgroundColorRole:
|
||||||
if self.id(index) in self.rows_to_highlight_set:
|
if self.id(index) in self.ids_to_highlight_set:
|
||||||
return QColor('lightgreen')
|
return QColor('lightgreen')
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
if self.column_to_dc_decorator_map[col] is not None:
|
if self.column_to_dc_decorator_map[col] is not None:
|
||||||
|
@ -681,13 +681,18 @@ class BooksView(QTableView): # {{{
|
|||||||
self._model.set_editable(editable)
|
self._model.set_editable(editable)
|
||||||
|
|
||||||
def move_highlighted_row(self, forward):
|
def move_highlighted_row(self, forward):
|
||||||
id_to_select = self._model.get_next_highlighted_row(forward)
|
rows = self.selectionModel().selectedRows()
|
||||||
|
if len(rows) > 0:
|
||||||
|
current_row = rows[0].row()
|
||||||
|
else:
|
||||||
|
current_row = None
|
||||||
|
id_to_select = self._model.get_next_highlighted_id(current_row, forward)
|
||||||
if id_to_select is not None:
|
if id_to_select is not None:
|
||||||
self.select_rows([id_to_select], using_ids=True)
|
self.select_rows([id_to_select], using_ids=True)
|
||||||
|
|
||||||
def search_proxy(self, txt):
|
def search_proxy(self, txt):
|
||||||
self._model.search(txt)
|
self._model.search(txt)
|
||||||
id_to_select = self._model.get_current_highlighted_row()
|
id_to_select = self._model.get_current_highlighted_id()
|
||||||
if id_to_select is not None:
|
if id_to_select is not None:
|
||||||
self.select_rows([id_to_select], using_ids=True)
|
self.select_rows([id_to_select], using_ids=True)
|
||||||
self.setFocus(Qt.OtherFocusReason)
|
self.setFocus(Qt.OtherFocusReason)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user