Example #1
0
void NodeUpdateProxy::addAddress(
        const Device::NodePath& parentPath,
        const Device::AddressSettings& settings,
        int row)
{
    auto parentnode = parentPath.toNode(&devModel.rootNode());
    if(!parentnode)
        return;

    // Add in the device impl
    // Get the device node :
    // TODO row isn't managed here.
    const Device::Node& dev_node = devModel.rootNode().childAt(parentPath.at(0));
    ISCORE_ASSERT(dev_node.template is<Device::DeviceSettings>());

    // Make a full path
    Device::FullAddressSettings full = Device::FullAddressSettings::make<Device::FullAddressSettings::as_parent>(
                                   settings,
                                   Device::address(*parentnode));

    // Add in the device implementation
    devModel
            .list()
            .device(dev_node.template get<Device::DeviceSettings>().name)
            .addAddress(full);

    // Add in the device explorer
    addLocalAddress(*parentnode, settings, row);
}
Example #2
0
void NodeUpdateProxy::removeNode(
        const Device::NodePath& parentPath,
        const Device::AddressSettings& settings)
{
    Device::Node* parentnode = parentPath.toNode(&devModel.rootNode());
    if(!parentnode)
        return;

    auto addr = Device::address(*parentnode);
    addr.path.append(settings.name);

    // Remove from the device implementation
    const auto& dev_node = devModel.rootNode().childAt(parentPath.at(0));
    devModel.list().device(
                dev_node.template get<Device::DeviceSettings>().name)
            .removeNode(addr);

    // Remove from the device explorer
    auto it = std::find_if(
                  parentnode->begin(), parentnode->end(),
                  [&] (const Device::Node& n) { return n.get<Device::AddressSettings>().name == settings.name; });
    ISCORE_ASSERT(it != parentnode->end());

    if(deviceExplorer)
    {
        deviceExplorer->removeNode(it);
    }
    else
    {
        parentnode->erase(it);
    }
}
Example #3
0
void
DeviceExplorerModel::debug_printPath(const Device::NodePath& path)
{
    const int pathSize = path.size();

    for(int i = 0; i < pathSize; ++i)
    {
        std::cerr << path.at(i) << " ";
    }

    std::cerr << "\n";
}
Example #4
0
QModelIndex
DeviceExplorerModel::convertPathToIndex(const Device::NodePath& path)
{
    QModelIndex iter;
    const int pathSize = path.size();

    for(int i = 0; i < pathSize; ++i)
    {
        iter = index(path.at(i), 0, iter);
    }

    return iter;
}
Example #5
0
void NodeUpdateProxy::updateAddress(
        const Device::NodePath &nodePath,
        const Device::AddressSettings &settings)
{
    auto node = nodePath.toNode(&devModel.rootNode());
    if(!node)
        return;

    const auto addr = Device::address(*node);
    // Make a full path
    Device::FullAddressSettings full = Device::FullAddressSettings::make<Device::FullAddressSettings::as_child>(
                                   settings,
                                   addr);
    full.address.path.last() = settings.name;

    // Update in the device implementation
    devModel
            .list()
            .device(addr.device)
            .updateAddress(addr, full);

    // Update in the device explorer
    if(deviceExplorer)
    {
        deviceExplorer->updateAddress(
                    node,
                    settings);
    }
    else
    {
        node->set(settings);
    }
}
Example #6
0
void NodeUpdateProxy::rec_addNode(
        Device::NodePath parentPath,
        const Device::Node& n,
        int row)
{
    addAddress(parentPath, n.template get<Device::AddressSettings>(), row);

    parentPath.append(row);

    int r = 0;
    for(const auto& child : n.children())
    {
        rec_addNode(parentPath, child, r++);
    }
}
Example #7
0
/**
 * @brief DeviceExplorerModel::editData
 *
 * This functions gets called by the command
 * that edit the columns.
 */
void DeviceExplorerModel::editData(
        const Device::NodePath &path,
        Explorer::Column column,
        const State::Value &value,
        int role)
{
    Device::Node* node = path.toNode(&rootNode());
    ISCORE_ASSERT(node->parent());

    QModelIndex index = createIndex(node->parent()->indexOfChild(node), (int)column, node->parent());

    QModelIndex changedTopLeft = index;
    QModelIndex changedBottomRight = index;

    if(node->is<Device::DeviceSettings>())
        return;

    if(role == Qt::EditRole)
    {
        ISCORE_TODO;
        /*
        if(index.column() == (int)Column::Name)
        {
            const QString s = value.toString();

            if(! s.isEmpty())
            {
                node->get<Device::AddressSettings>().name = s;
            }
        }
        else */if(index.column() == (int)Column::Value)
        {
            node->get<Device::AddressSettings>().value = value;
        }
        // TODO min/max/tags editing
    }

    emit dataChanged(changedTopLeft, changedBottomRight);
}
Example #8
0
QVariant DeviceExplorerModel::getData(Device::NodePath node, Column column, int role)
{
    QModelIndex index = createIndex(convertPathToIndex(node).row(), (int)column, node.toNode(&rootNode())->parent());
    return data(index, role);
}