示例#1
0
QMimeData* QtSkillModel::mimeData(const QModelIndexList& indexes) const {
	QMimeData* data = QAbstractItemModel::mimeData(indexes);

	if (indexes.size() < 1) {
		return data;
	}

	SkillItem::ref item = getItem(indexes[0]);
	SkillLevel::ref level = boost::dynamic_pointer_cast<SkillLevel>(item);

	if (!item || !item->getSkill()) {
		return data;
	}

	QByteArray getItemData;
	QDataStream dataStream(&getItemData, QIODevice::WriteOnly);

	dataStream << P2QSTRING(item->getSkill()->getID());
	int draggedLevel = -1;
	if (level) {
		if (boost::dynamic_pointer_cast<SkillPlan>(level->getParent())) {
			// If we're dragging inside a plan list, we just want to move the skill the plan
			// Otherwise leave it as 'next level'
			draggedLevel = level->getLevel();
		}
	}
	dataStream << draggedLevel;
	data->setData("application/vnd.evexin.skilllevel", getItemData);
	return data;
}
示例#2
0
SkillItem::ref SkillTree::mergeWithCharacterSkills(boost::shared_ptr<Character> character) {
	SkillItem::ref merged = boost::make_shared<SkillItem>(SkillItem::ref(), "merged_root", "merged_root");
	foreach (auto groupPair, groups_) {
		if (!groupPair.second) {
			//FIXME: Find what's inserting a "" null group in the tree
			continue;
		}
		std::vector<SkillItem::ref> children = groupPair.second->getChildren();
		SkillItem::ref groupItem = boost::make_shared<SkillItem>(merged, groupPair.second->getID(), groupPair.second->getName());
		merged->addChild(groupItem);
		SkillItem::ref characterGroup = character->getKnownSkills()->getChild(groupItem->getID());
		foreach (SkillItem::ref skillItem, children) {
			//std::cerr << "Char:" << character->getID() << ": Source item " << groupItem->getName() << "::" << skillItem->getName() << std::endl;
			SkillItem::ref newSkill;
			SkillLevel::ref level = characterGroup ? boost::dynamic_pointer_cast<SkillLevel>(characterGroup->getChild(skillItem->getID())) : SkillLevel::ref();
			if (level) {
				newSkill = boost::make_shared<SkillLevel>(groupItem, level->getSkill(), level->getLevel());
			}
			else {
				if (skillItem->getSkill()) {
					newSkill = boost::make_shared<SkillItem>(groupItem, skillItem->getSkill());
				}
				else {
					newSkill = boost::make_shared<SkillItem>(groupItem, skillItem->getID(), skillItem->getName());
				}
			}
			groupItem->addChild(newSkill);
		}
	}
示例#3
0
QVariant QtSkillModel::getLevelData(SkillLevel::ref level, int role) const {
	switch (role) {
		case Qt::DisplayRole: {
			std::string name = level->getName();
			return P2QSTRING(name);
		}
		case SkillLevelRole: return level->getLevel();
		case SkillTrainingTimeRole: return character_ ? SkillTime::minutesToTrain(character_, level) : 0;
		default: return getItemData(level, role);
	}
}