already_in_nodes = []
+node_status = { "in": "Already Selected",
+ "out": "Not Selected",
+ "add": "To be Added",
+ "remove": "To be Removed"}
+
class NodeView(QTreeView):
def __init__(self, parent):
QTreeView.__init__(self, parent)
def mouseDoubleClickEvent(self, event):
index = self.currentIndex()
model = index.model()
- select_index = model.index(index.row(), 2, index.parent())
- select_data = select_index.data().toString()
+ status_index = model.index(index.row(), 2, index.parent())
+ status_data = status_index.data().toString()
hostname_index = model.index(index.row(), 1, index.parent())
hostname_data = hostname_index.data().toString()
- if select_data == "true":
- model.setData(select_index, QString("remove"))
- elif select_data == "false":
- model.setData(select_index, QString("add"))
- elif select_data in ("add", "remove"):
- if hostname_data in already_in_nodes: model.setData(select_index, QString("true"))
- else: model.setData(select_index, QString("false"))
+ if status_data == node_status['in']:
+ model.setData(status_index, QString(node_status['remove']))
+ elif status_data == node_status['out']:
+ model.setData(status_index, QString(node_status['add']))
+ elif status_data in (node_status['add'], node_status['remove']):
+ if hostname_data in already_in_nodes: model.setData(status_index, QString(node_status['in']))
+ else: model.setData(status_index, QString(node_status['out']))
model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), hostname_index, hostname_index)
def paint(self, painter, option, index):
model = index.model()
data = "%s" % index.data().toString()
- select_index = model.index(index.row(), 2, index.parent())
- select_data = select_index.data().toString()
-# if select_data == "false":
-# model.setData(select_index, QString("add"))
+ status_index = model.index(index.row(), 2, index.parent())
+ status_data = status_index.data().toString()
- if select_data not in ("true", "add", "remove"): # default view
+ if status_data not in (node_status['in'], node_status['remove'], node_status['add']):
+ # default view
QStyledItemDelegate.paint(self, painter, option, index)
return
painter.setRenderHint(QPainter.Antialiasing)
painter.drawRoundedRect(rect, 4, 4)
- if select_data == "true": # already in the slice
+ if status_data == node_status['in']: # already in the slice
painter.fillPath(path, QColor.fromRgb(0, 250, 0))
painter.setPen(QColor.fromRgb(0, 0, 0))
painter.drawText(option.rect, 0, QString(data))
- elif select_data == "add": # newly added to the slice
+ elif status_data == node_status['add']: # newly added to the slice
painter.fillPath(path, QColor.fromRgb(0, 250, 0))
painter.setPen(QColor.fromRgb(0, 0, 0))
painter.drawText(option.rect, 0, QString(data))
painter.drawRect(x + w + 10, y + 3, 10, 10)
painter.fillRect(x + w + 10, y + 3, 10, 10, QColor.fromRgb(0, 250, 0))
- elif select_data == "remove": # removed from the slice
+ elif status_data == node_status['remove']: # removed from the slice
painter.fillPath(path, QColor.fromRgb(250, 0, 0))
painter.setPen(QColor.fromRgb(0, 0, 0))
painter.drawText(option.rect, 0, QString(data))
self.__initRoot()
def __initRoot(self):
- self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Selected")])
+ self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Status")])
def getItem(self, index):
if index.isValid():
already_in_nodes += sliver_nodes
for node in sliver_nodes:
- nodeItem = TreeItem([QString(""), QString("%s" % node), QString("true")], networkItem)
+ nodeItem = TreeItem([QString(""), QString("%s" % node), QString(node_status['in'])], networkItem)
networkItem.appendChild(nodeItem)
for node in available_nodes:
- nodeItem = TreeItem([QString(""), QString(node), QString("false")], networkItem)
+ nodeItem = TreeItem([QString(""), QString(node), QString(node_status['out'])], networkItem)
networkItem.appendChild(nodeItem)
self.nodeModel.rootItem.appendChild(networkItem)