15 |
15 |
16 class SqlConnectionWidget(QWidget): |
16 class SqlConnectionWidget(QWidget): |
17 """ |
17 """ |
18 Class implementing a widget showing the SQL connections. |
18 Class implementing a widget showing the SQL connections. |
19 |
19 |
20 @signal tableActivated(str) emitted after the entry for a table has been activated |
20 @signal tableActivated(str) emitted after the entry for a table has been |
|
21 activated |
21 @signal schemaRequested(str) emitted when the schema display is requested |
22 @signal schemaRequested(str) emitted when the schema display is requested |
22 @signal cleared() emitted after the connection tree has been cleared |
23 @signal cleared() emitted after the connection tree has been cleared |
23 """ |
24 """ |
24 tableActivated = pyqtSignal(str) |
25 tableActivated = pyqtSignal(str) |
25 schemaRequested = pyqtSignal(str) |
26 schemaRequested = pyqtSignal(str) |
38 |
39 |
39 self.__connectionTree = QTreeWidget(self) |
40 self.__connectionTree = QTreeWidget(self) |
40 self.__connectionTree.setObjectName("connectionTree") |
41 self.__connectionTree.setObjectName("connectionTree") |
41 self.__connectionTree.setHeaderLabels([self.trUtf8("Database")]) |
42 self.__connectionTree.setHeaderLabels([self.trUtf8("Database")]) |
42 if qVersion() >= "5.0.0": |
43 if qVersion() >= "5.0.0": |
43 self.__connectionTree.header().setSectionResizeMode(QHeaderView.Stretch) |
44 self.__connectionTree.header().setSectionResizeMode( |
|
45 QHeaderView.Stretch) |
44 else: |
46 else: |
45 self.__connectionTree.header().setResizeMode(QHeaderView.Stretch) |
47 self.__connectionTree.header().setResizeMode(QHeaderView.Stretch) |
46 refreshAction = QAction(self.trUtf8("Refresh"), self.__connectionTree) |
48 refreshAction = QAction(self.trUtf8("Refresh"), self.__connectionTree) |
47 self.__schemaAction = QAction(self.trUtf8("Show Schema"), self.__connectionTree) |
49 self.__schemaAction = QAction( |
|
50 self.trUtf8("Show Schema"), self.__connectionTree) |
48 |
51 |
49 refreshAction.triggered[()].connect(self.refresh) |
52 refreshAction.triggered[()].connect(self.refresh) |
50 self.__schemaAction.triggered[()].connect(self.showSchema) |
53 self.__schemaAction.triggered[()].connect(self.showSchema) |
51 |
54 |
52 self.__connectionTree.addAction(refreshAction) |
55 self.__connectionTree.addAction(refreshAction) |
56 layout.addWidget(self.__connectionTree) |
59 layout.addWidget(self.__connectionTree) |
57 |
60 |
58 self.__activating = False |
61 self.__activating = False |
59 |
62 |
60 self.__connectionTree.itemActivated.connect(self.__itemActivated) |
63 self.__connectionTree.itemActivated.connect(self.__itemActivated) |
61 self.__connectionTree.currentItemChanged.connect(self.__currentItemChanged) |
64 self.__connectionTree.currentItemChanged.connect( |
|
65 self.__currentItemChanged) |
62 |
66 |
63 self.__activeDb = "" |
67 self.__activeDb = "" |
64 |
68 |
65 def refresh(self): |
69 def refresh(self): |
66 """ |
70 """ |
121 def __currentItemChanged(self, current, previous): |
125 def __currentItemChanged(self, current, previous): |
122 """ |
126 """ |
123 Private slot handling a change of the current item. |
127 Private slot handling a change of the current item. |
124 |
128 |
125 @param current reference to the new current item (QTreeWidgetItem) |
129 @param current reference to the new current item (QTreeWidgetItem) |
126 @param previous reference to the previous current item (QTreeWidgetItem) |
130 @param previous reference to the previous current item |
|
131 (QTreeWidgetItem) |
127 """ |
132 """ |
128 self.__schemaAction.setEnabled( |
133 self.__schemaAction.setEnabled( |
129 current is not None and current.parent() is not None) |
134 current is not None and current.parent() is not None) |
130 |
135 |
131 def __dbCaption(self, db): |
136 def __dbCaption(self, db): |
164 |
169 |
165 def __setActive(self, itm): |
170 def __setActive(self, itm): |
166 """ |
171 """ |
167 Private slot to set an item to active. |
172 Private slot to set an item to active. |
168 |
173 |
169 @param itm reference to the item to set as the active item (QTreeWidgetItem) |
174 @param itm reference to the item to set as the active item |
|
175 (QTreeWidgetItem) |
170 """ |
176 """ |
171 for index in range(self.__connectionTree.topLevelItemCount()): |
177 for index in range(self.__connectionTree.topLevelItemCount()): |
172 if self.__connectionTree.topLevelItem(index).font(0).bold(): |
178 if self.__connectionTree.topLevelItem(index).font(0).bold(): |
173 self.__setBold(self.__connectionTree.topLevelItem(index), False) |
179 self.__setBold( |
|
180 self.__connectionTree.topLevelItem(index), False) |
174 |
181 |
175 if itm is None: |
182 if itm is None: |
176 return |
183 return |
177 |
184 |
178 self.__setBold(itm, True) |
185 self.__setBold(itm, True) |