コード例 #1
0
ファイル: Drawer.cpp プロジェクト: tea2code/fantasy-rts
void frts::Drawer::setImageConfig(const SharedManagerPtr& shared, const std::string& rootNamespace,
                                  const ConfigNodePtr& imagesNode)
{
    assert(shared != nullptr);
    assert(imagesNode != nullptr);

    // Namepspace.
    std::string ns = rootNamespace;
    if (imagesNode->has("namespace"))
    {
        ns += imagesNode->getString("namespace") + ".";
    }

    // Plugin path.
    auto plugins = getDataValue<MainData>(shared, MainIds::mainData())->getPluginPath();

    // Images.
    auto node = imagesNode->getNode("image");
    for (auto imageNode : *node)
    {
        auto id = shared->makeId(ns + imageNode->getString("name"));
        std::string path = plugins + imageNode->getString("path");
        images.insert(std::make_pair(id, path));
    }
}
コード例 #2
0
CutKeyCommand::CutKeyCommand (QString type, ConfigNodePtr source, ConfigNodePtr target, int sourceIndex, QUndoCommand * parent)
: QUndoCommand (parent), m_sourceParentModel (source->getParentModel ()), m_source (new ConfigNode (*source)), m_target (target),
  m_isExpanded (target->isExpanded ()), m_sourceIndex (sourceIndex), m_targetIndex (-1)
{
	setText (type);

	QString newPath = m_target->getPath () + "/" + m_source->getName ();
	m_source->setPath (newPath);
}
コード例 #3
0
ファイル: DropBuilder.cpp プロジェクト: tea2code/fantasy-rts
frts::ComponentPtr frts::DropBuilder::build(const EntityPtr& entity, const SharedManagerPtr& shared, const ConfigNodePtr& node)
{
    assert(entity != nullptr);
    assert(shared != nullptr);
    assert(node != nullptr);

    auto component = std::static_pointer_cast<Drop>(build(entity, shared));
    for (auto& drop : node->getStrings("drops"))
    {
        auto id = shared->makeId(drop);
        component->addDrop(id);
    }
    return component;
}
コード例 #4
0
ファイル: treeviewmodel.cpp プロジェクト: beku/libelektra
bool TreeViewModel::setData(const QModelIndex& idx, const QVariant& modelData, int role)
{
	if (!idx.isValid() || idx.row() > (m_model.size() - 1))
	{
		emit showMessage(tr("Error"), tr("Index not valid."), QString("TreeViewModel::setData: Index = %1,\nModel size = %2").arg(idx.row()).arg(m_model.count()));
		return false;
	}

	ConfigNodePtr node = m_model.at(idx.row());

	switch (role)
	{

	case NameRole:
		node->setName(modelData.toString());
		node->setIsDirty(true);
		break;

	case ValueRole:
		node->setValue(modelData);
		break;

	case MetaValueRole:
	{
		QVariantList valueList = modelData.toList();
		node->setMeta(valueList.at(0).toString(), valueList.at(1));
		break;
	}

	case IsExpandedRole:
		node->setIsExpanded(modelData.toBool());
	}

	emit dataChanged(idx, idx);

	return true;
}
コード例 #5
0
ファイル: treeviewmodel.cpp プロジェクト: beku/libelektra
QVariant TreeViewModel::data(const QModelIndex& idx, int role) const
{
	if (!idx.isValid())
	{
		emit showMessage(tr("Error"), tr("Index not valid."), QString("TreeViewModel::data: Index = %1,\nModel size = %2").arg(idx.row()).arg(m_model.count()));
		return QVariant();
	}

	if (idx.row() > (m_model.size() - 1))
	{
		emit showMessage(tr("Error"), QString(tr("Index too high. ")), QString("TreeViewModel::data: Index: %1").arg(idx.row()));
		return QVariant();
	}

	ConfigNodePtr node = m_model.at(idx.row());

	switch (role)
	{

	case Qt::DisplayRole:

		// TODO: document fallthrough if it was desired
	case NameRole:
		return QVariant::fromValue(node->getName());

	case PathRole:
		return QVariant::fromValue(node->getPath());

	case ValueRole:
		return QVariant::fromValue(node->getValue());

	case ChildCountRole:
		return QVariant::fromValue(node->getChildCount());

	case ChildrenRole:
		return QVariant::fromValue(node->getChildren());

	case ChildrenHaveNoChildrenRole:
		return QVariant::fromValue(node->childrenHaveNoChildren());

	case MetaValueRole:
		return QVariant::fromValue(node->getMetaKeys());

	case NodeRole:
		return QVariant::fromValue(node.data());

	case ParentModelRole:
		return QVariant::fromValue(node->getParentModel());

	case IndexRole:
		return QVariant::fromValue(idx.row());

	case IsNullRole:
	{
		if (node->getKey())
			return QVariant::fromValue(false);
		else
			return QVariant::fromValue(true);
	}

	case IsExpandedRole:
		return QVariant::fromValue(node->isExpanded());

	default:
		emit showMessage(tr("Error"), tr("Unknown role: %1").arg(role), "TreeViewModel::data");
		return QVariant();
	}
}