예제 #1
0
bool ServerModel::setData(const QModelIndex &idx, const QVariant &value, int role) {
	if (role != Qt::EditRole || !idx.isValid())
		return false;
	ServerInfo si = m_servers.at(idx.row());

	bool ok = false;
	switch (idx.column()) {
		case 0:
			si.setName(value.toString());
			ok = true;
			break;
		case 1:
			si.setAddress(value.toString());
			ok = true;
			break;
		case 2:
			si.setPort(value.toInt(&ok));
			break;
		case 3:
			si.setPassword(value.toString());
			ok = true;
			break;
	}

	if (ok) {
		m_servers.replace(idx.row(), si);
		Config::instance()->setServers(m_servers);
		emit dataChanged(index(idx.row(), 0), index(idx.row(), 3));
		return true;
	}

	return false;
}