MEMBERSHIP_STATUS_COLUMN = 1
SERVER_MEMBERSHIP_STATUS_COLUMN = 2
+# maximum length of a name to display before clipping
+NAME_MAX_LEN = 48
+
user_status = { "in": "Already Selected",
"out": "Not Selected",
"add": "To be Added",
"remove": "To be Removed"}
+color_status = { "in": QColor.fromRgb(0, 250, 250),
+ "add": QColor.fromRgb(0, 250, 0),
+ "remove": QColor.fromRgb(250, 0, 0) }
+
+
+class UserNameDelegate(QStyledItemDelegate):
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+
+ def displayText(self, value, locale):
+ data = str(QStyledItemDelegate.displayText(self, value, locale))
+ if (len(data)>NAME_MAX_LEN):
+ data = data[:(NAME_MAX_LEN-3)] + "..."
+ return QString(data)
+
+ def paint(self, painter, option, index):
+ model = index.model()
+ data = str(self.displayText(index.data(), QLocale()))
+ status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
+ status_data = status_index.data().toString()
+
+ fm = QFontMetrics(option.font)
+ rect = QRect(option.rect)
+
+ rect.setHeight(rect.height() - 2)
+ rect.setWidth(fm.width(QString(data)) + 6)
+ rect.setX(rect.x() + 5)
+ rect.setY(rect.y() - 1)
+
+ textRect = QRect(option.rect)
+ textRect.setWidth(fm.width(QString(data)) + 6)
+ textRect.setX(rect.x())
+
+ x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width()
+
+ path = QPainterPath()
+ path.addRoundedRect(x - 1, y + 1, w, h, 4, 4)
+
+ painter.save()
+ painter.setRenderHint(QPainter.Antialiasing)
+
+ if option.state & QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.color(QPalette.Active, QPalette.Highlight))
+
+ color = None
+ for x in user_status.keys():
+ if (user_status[x] == status_data) and (x in color_status):
+ color = color_status[x]
+
+ if color != None:
+ painter.fillPath(path, color)
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(textRect, Qt.AlignVCenter, QString(data))
+
+ painter.restore()
+
class UserView(QTableView):
def __init__(self, parent=None):
QTableView.__init__(self, parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setToolTip("Double click on a row to change its status.")
+ self.setItemDelegateForColumn(0, UserNameDelegate(self))
+
+ def keyPressEvent(self, event):
+ if (event.key() == Qt.Key_Space):
+ self.toggleSelection()
+ else:
+ QTableView.keyPressEvent(self, event)
+
def mouseDoubleClickEvent(self, event):
+ self.toggleSelection()
+
+ def toggleSelection(self):
index = self.currentIndex()
model = index.model()
status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
node_data = node_index.data().toString()
self.emit(SIGNAL('hostnameClicked(QString)'), node_data)
+ def hideUnusableColumns(self):
+ self.hideColumn(SERVER_MEMBERSHIP_STATUS_COLUMN)
+
class UserModel(QStandardItemModel):
def __init__(self, rows=0, columns=4, parent=None):
QStandardItemModel.__init__(self, rows, columns, parent)
slice_persons.append({"name": name, "role": "researcher", "member": user_status["in"]})
added_persons.append(name)
- i=1
+ i=0
while (os.path.exists(config.getAuthorityListFile(i))):
rec = self.readUserRecord(i)
if rec:
rootItem = self.invisibleRootItem()
for person in slice_persons:
- rootItem.appendRow([QStandardItem(QString(person["name"])),
- #QStandardItem(QString(person["role"])),
- QStandardItem(QString(person["member"])),
- QStandardItem(QString(person["member"]))])
+ rootItem.appendRow([self.readOnlyItem(person["name"]),
+ self.readOnlyItem(person["member"]),
+ self.readOnlyItem(person["member"])])
headers = QStringList() << "User Name" << "Status" << "ServerStatus"
self.setHorizontalHeaderLabels(headers)
+ def readOnlyItem(self, x):
+ item = QStandardItem(QString(x))
+ item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
+ return item
+
def updateRecord(self, slicerec):
change = False
return change
+ def getResearchers(self):
+ researchers = []
+ item = self.invisibleRootItem()
+ children = item.rowCount()
+ for row in range(0, children):
+ childName = str(item.child(row, NAME_COLUMN).data(Qt.DisplayRole).toString())
+ childStatus = str(item.child(row, MEMBERSHIP_STATUS_COLUMN).data(Qt.DisplayRole).toString())
+
+ if (childStatus == user_status['add']) or (childStatus == user_status['in']):
+ researchers.append(childName)
+
+ return researchers
+
def readUserRecord(self, i):
rec_file = config.getAuthorityListFile(i)
if os.path.exists(rec_file):