+ 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()
+ 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"))
+
+ model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), hostname_index, hostname_index)
+
+
+
+class NodeNameDelegate(QStyledItemDelegate):
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+
+ 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"))
+
+ if select_data not in ("true", "add", "remove"): # default view
+ QStyledItemDelegate.paint(self, painter, option, index)
+ return
+
+ fm = QFontMetrics(option.font)
+ rect = option.rect
+ rect.setWidth(fm.width(QString(data)) + 8)
+ rect.setHeight(rect.height() - 2)
+ rect.setX(rect.x() + 4)
+ x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width()
+
+ path = QPainterPath()
+ path.addRoundedRect(x, y, w, h, 4, 4)
+
+ painter.save()
+ painter.setRenderHint(QPainter.Antialiasing)
+ painter.drawRoundedRect(rect, 4, 4)
+
+ if select_data == "true": # 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
+ 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
+ painter.fillPath(path, QColor.fromRgb(250, 0, 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(250, 0, 0))
+
+ painter.restore()
+