13 |
13 |
14 class SqlConnectionWidget(QWidget): |
14 class SqlConnectionWidget(QWidget): |
15 """ |
15 """ |
16 Class implementing a widget showing the SQL connections. |
16 Class implementing a widget showing the SQL connections. |
17 |
17 |
18 @signal tableActivated(QString) emitted after the entry for a table has been activated |
18 @signal tableActivated(string) emitted after the entry for a table has been activated |
19 @signal schemaRequested(QString) emitted when the schema display is requested |
19 @signal schemaRequested(string) emitted when the schema display is requested |
20 @signal cleared() emitted after the connection tree has been cleared |
20 @signal cleared() emitted after the connection tree has been cleared |
21 """ |
21 """ |
|
22 tableActivated = pyqtSignal(str) |
|
23 schemaRequested = pyqtSignal(str) |
|
24 cleared = pyqtSignal() |
|
25 |
22 def __init__(self, parent = None): |
26 def __init__(self, parent = None): |
23 """ |
27 """ |
24 Constructor |
28 Constructor |
25 |
29 |
26 @param parent reference to the parent widget (QWidget) |
30 @param parent reference to the parent widget (QWidget) |
44 self.__connectionTree.addAction(self.__schemaAction) |
48 self.__connectionTree.addAction(self.__schemaAction) |
45 self.__connectionTree.setContextMenuPolicy(Qt.ActionsContextMenu) |
49 self.__connectionTree.setContextMenuPolicy(Qt.ActionsContextMenu) |
46 |
50 |
47 layout.addWidget(self.__connectionTree) |
51 layout.addWidget(self.__connectionTree) |
48 |
52 |
49 self.connect(self.__connectionTree, |
53 self.__connectionTree.itemActivated.connect(self.__itemActivated) |
50 SIGNAL("itemActivated(QTreeWidgetItem*, int)"), |
54 self.__connectionTree.currentItemChanged.connect(self.__currentItemChanged) |
51 self.__itemActivated) |
|
52 self.connect(self.__connectionTree, |
|
53 SIGNAL("currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)"), |
|
54 self.__currentItemChanged) |
|
55 |
55 |
56 self.__activeDb = "" |
56 self.__activeDb = "" |
57 |
57 |
58 def refresh(self): |
58 def refresh(self): |
59 """ |
59 """ |
60 Public slot to refresh the connection tree. |
60 Public slot to refresh the connection tree. |
61 """ |
61 """ |
62 self.__connectionTree.clear() |
62 self.__connectionTree.clear() |
63 self.emit(SIGNAL("cleared()")) |
63 self.cleared.emit() |
64 |
64 |
65 connectionNames = QSqlDatabase.connectionNames() |
65 connectionNames = QSqlDatabase.connectionNames() |
66 |
66 |
67 foundActiveDb = False |
67 foundActiveDb = False |
68 for name in connectionNames: |
68 for name in connectionNames: |
90 """ |
90 """ |
91 cItm = self.__connectionTree.currentItem() |
91 cItm = self.__connectionTree.currentItem() |
92 if cItm is None or cItm.parent() is None: |
92 if cItm is None or cItm.parent() is None: |
93 return |
93 return |
94 self.__setActive(cItm.parent()) |
94 self.__setActive(cItm.parent()) |
95 self.emit(SIGNAL("schemaRequested(QString)"), cItm.text(0)) |
95 self.schemaRequested.emit(cItm.text(0)) |
96 |
96 |
97 def __itemActivated(self, itm, column): |
97 def __itemActivated(self, itm, column): |
98 """ |
98 """ |
99 Private slot handling the activation of an item. |
99 Private slot handling the activation of an item. |
100 |
100 |
106 |
106 |
107 if itm.parent() is None: |
107 if itm.parent() is None: |
108 self.__setActive(itm) |
108 self.__setActive(itm) |
109 else: |
109 else: |
110 self.__setActive(itm.parent()) |
110 self.__setActive(itm.parent()) |
111 self.emit(SIGNAL("tableActivated(QString)"), itm.text(0)) |
111 self.tableActivated.emit(itm.text(0)) |
112 |
112 |
113 def __currentItemChanged(self, current, previous): |
113 def __currentItemChanged(self, current, previous): |
114 """ |
114 """ |
115 Private slot handling a change of the current item. |
115 Private slot handling a change of the current item. |
116 |
116 |