eric6/Helpviewer/ZoomManager/ZoomValuesModel.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2015 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a model for zoom values management.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import Qt, QModelIndex, QAbstractTableModel
13
14
15 class ZoomValuesModel(QAbstractTableModel):
16 """
17 Class implementing a model for zoom values management.
18 """
19 def __init__(self, manager, parent=None):
20 """
21 Constructor
22
23 @param manager reference to the zoom values manager (ZoomManager)
24 @param parent reference to the parent object (QObject)
25 """
26 super(ZoomValuesModel, self).__init__(parent)
27
28 self.__manager = manager
29 manager.changed.connect(self.__zoomValuesChanged)
30
31 self.__headers = [
32 self.tr("Website"),
33 self.tr("Zoom Value [%]"),
34 ]
35
36 def __zoomValuesChanged(self):
37 """
38 Private slot handling a change of the registered zoom values.
39 """
40 self.beginResetModel()
41 self.endResetModel()
42
43 def removeRows(self, row, count, parent=None):
44 """
45 Public method to remove entries from the model.
46
47 @param row start row (integer)
48 @param count number of rows to remove (integer)
49 @param parent parent index (QModelIndex)
50 @return flag indicating success (boolean)
51 """
52 if parent is None:
53 parent = QModelIndex()
54
55 if parent.isValid():
56 return False
57
58 if count <= 0:
59 return False
60
61 lastRow = row + count - 1
62
63 self.beginRemoveRows(parent, row, lastRow)
64
65 siteList = self.__manager.allSiteNames()
66 for index in range(row, lastRow + 1):
67 self.__manager.removeZoomValue(siteList[index])
68
69 return True
70
71 def rowCount(self, parent=None):
72 """
73 Public method to get the number of rows of the model.
74
75 @param parent parent index (QModelIndex)
76 @return number of rows (integer)
77 """
78 if parent is None:
79 parent = QModelIndex()
80
81 if parent.isValid():
82 return 0
83 else:
84 return self.__manager.sitesCount()
85
86 def columnCount(self, parent=None):
87 """
88 Public method to get the number of columns of the model.
89
90 @param parent parent index (QModelIndex) (Unused)
91 @return number of columns (integer)
92 """
93 return len(self.__headers)
94
95 def data(self, index, role):
96 """
97 Public method to get data from the model.
98
99 @param index index to get data for (QModelIndex)
100 @param role role of the data to retrieve (integer)
101 @return requested data
102 """
103 if index.row() >= self.__manager.sitesCount() or index.row() < 0:
104 return None
105
106 site = self.__manager.allSiteNames()[index.row()]
107 siteInfo = self.__manager.siteInfo(site)
108
109 if siteInfo is None:
110 return None
111
112 if role == Qt.DisplayRole:
113 if index.column() == 0:
114 return site
115 elif index.column() == 1:
116 return siteInfo
117
118 return None
119
120 def headerData(self, section, orientation, role=Qt.DisplayRole):
121 """
122 Public method to get the header data.
123
124 @param section section number (integer)
125 @param orientation header orientation (Qt.Orientation)
126 @param role data role (integer)
127 @return header data
128 """
129 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
130 try:
131 return self.__headers[section]
132 except IndexError:
133 pass
134
135 return None

eric ide

mercurial