This repository was archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodel.py
More file actions
50 lines (33 loc) · 1.3 KB
/
Copy pathmodel.py
File metadata and controls
50 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
# coding: utf-8
from PyQt5 import QtSql
class ModelPerso(QtSql.QSqlTableModel):
"""Subclassing the model to sort the data at will"""
def __init__(self, parent):
super(ModelPerso, self).__init__(parent)
self.parent = parent
def setQuery(self, query):
"""Reimplementation. Allows to load all the data at once, for a query.
Can cause performance issues"""
# http://stackoverflow.com/questions/17879013/
# reimplementing-qsqltablemodel-setquery
self.query = QtSql.QSqlQuery()
# If the user has checked the reverse order
if self.parent.sorting_reversed:
reverse = "ASC"
else:
reverse = "DESC"
# Sorting method wanted by the user
if self.parent.sorting_method == 1:
sorting = "date"
str_sorting = " ORDER BY {} {}".format(sorting, reverse)
else:
sorting = "percentage_match"
str_sorting = " ORDER BY {} {}".format(sorting, reverse)
if type(query) is str:
self.query.prepare(query + str_sorting)
else:
self.query.prepare(query.executedQuery() + str_sorting)
self.query.exec_()
results = QtSql.QSqlTableModel.setQuery(self, self.query)
return results