Пример #1
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);
    }
}
Пример #2
0
bool DeviceExplorerModel::checkAddressEditable(
        Device::Node& parent,
        const Device::AddressSettings& before,
        const Device::AddressSettings& after)
{
    ISCORE_ASSERT(!parent.is<InvisibleRootNodeTag>());

    if(after.name.isEmpty())
        return false;

    auto it = std::find_if(
                parent.begin(),
                parent.end(),
                [&] (const Device::Node& n) { return n.get<Device::AddressSettings>().name == after.name; });
    if(it != parent.end())
    {
        //  We didn't change name, it's ok
        if(after.name == before.name)
            return true;
        else
            return false;
    }
    else
    {
        // Ok, no conflicts
        return true;
    }
}
Пример #3
0
void
DeviceExplorerModel::debug_printIndexes(const QModelIndexList& indexes)
{
    std::cerr << "indexes: " << indexes.size() << " nodes: \n";
    foreach(const QModelIndex & index, indexes)
    {
        if(index.isValid())
        {
            std::cerr << " index.row=" << index.row() << " col=" << index.column() << " ";
            Device::Node* n = &nodeFromModelIndex(index);
            std::cerr << " n=" << n << " ";
            Device::Node* parent = n->parent();

            if(n == &m_rootNode)
            {
                std::cerr << " rootNode parent=" << parent << "\n";
            }
            else
            {
                std::cerr << " n->name=" << n->displayName().toStdString();
                std::cerr << " parent=" << parent;
                std::cerr << " parent->name=" << parent->displayName().toStdString() << "\n";
            }

        }
        else
        {
            std::cerr << " invalid index \n";
        }
    }
}
Пример #4
0
bool DeviceExplorerModel::checkAddressInstantiatable(
        Device::Node& parent,
        const Device::AddressSettings& addr)
{
    ISCORE_ASSERT(!parent.is<InvisibleRootNodeTag>());

    if(addr.name.isEmpty())
        return false;

    return std::none_of(parent.begin(),
                        parent.end(),
                        [&] (const Device::Node& n) {
        return n.get<Device::AddressSettings>().name == addr.name;
    });
}
Пример #5
0
QVariant nameColumnData(const Device::Node& node, int role)
{
    static const QFont italicFont{[] () { QFont f; f.setItalic(true); return f; }()};

    using namespace iscore;

    const Device::IOType ioType = node.get<Device::AddressSettings>().ioType;
    switch(role)
    {
        case Qt::DisplayRole:
        case Qt::EditRole:
            return node.displayName();
        case Qt::FontRole:
        {
            if(ioType == IOType::In || ioType == IOType::Out)
            {
                return italicFont;
            }
        }
        case Qt::ForegroundRole:
        {
            if(ioType == IOType::In || ioType == IOType::Out)
            {
                return QBrush(Qt::lightGray);
            }
        }
        default:
            return {};
    }
}
Пример #6
0
void NodeUpdateProxy::addLocalAddress(
        Device::Node& parentnode,
        const Device::AddressSettings& settings,
        int row)
{
    if(deviceExplorer)
    {
        deviceExplorer->addAddress(
                    &parentnode,
                    settings,
                    row);
    }
    else
    {
        parentnode.emplace(parentnode.begin() + row, settings, &parentnode);
    }
}
Пример #7
0
void DeviceExplorerModel::addNode(
        Device::Node* parentNode,
        Device::Node&& child,
        int row)
{
    ISCORE_ASSERT(parentNode);
    ISCORE_ASSERT(parentNode != &m_rootNode);

    Device::Node* grandparent = parentNode->parent();
    ISCORE_ASSERT(grandparent);
    int rowParent = grandparent->indexOfChild(parentNode);
    QModelIndex parentIndex = createIndex(rowParent, 0, parentNode);

    beginInsertRows(parentIndex, row, row);

    parentNode->emplace(parentNode->begin() + row, std::move(child));

    endInsertRows();
}
Пример #8
0
void DeviceExplorerModel::addAddress(
        Device::Node* parentNode,
        const Device::AddressSettings& addressSettings,
        int row)
{
    ISCORE_ASSERT(parentNode);
    ISCORE_ASSERT(parentNode != &m_rootNode);

    Device::Node* grandparent = parentNode->parent();
    ISCORE_ASSERT(grandparent);
    int rowParent = grandparent->indexOfChild(parentNode);
    QModelIndex parentIndex = createIndex(rowParent, 0, parentNode);

    beginInsertRows(parentIndex, row, row);

    parentNode->emplace(parentNode->begin() + row, addressSettings, parentNode);

    endInsertRows();
}
Пример #9
0
void NodeUpdateProxy::addLocalNode(
        Device::Node& parent,
        Device::Node&& node)
{
    ISCORE_ASSERT(node.template is<Device::AddressSettings>());

    int row = parent.childCount();
    if(deviceExplorer)
    {
        deviceExplorer->addNode(
                    &parent,
                    std::move(node),
                    row);
    }
    else
    {
        parent.emplace(parent.begin() + row,
                       std::move(node));
    }
}
Пример #10
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);
}
Пример #11
0
void DeviceInterface::addNode(const Device::Node& n)
{
    auto full = Device::FullAddressSettings::make<Device::FullAddressSettings::as_parent>(
                    n.get<Device::AddressSettings>(),
                    Device::address(*n.parent()));

    // Add in the device implementation
    addAddress(full);

    for(const auto& child : n)
    {
        addNode(child);
    }
}
Пример #12
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++);
    }
}
Пример #13
0
static void convertFromDomElement(const QDomElement& dom_element, Device::Node &parentNode)
{
    QDomElement dom_child = dom_element.firstChildElement("");
    QString name;

    if(dom_element.hasAttribute("address"))
    {
        name = dom_element.attribute("address");
    }
    else
    {
        name = dom_element.tagName();
    }

    Device::AddressSettings addr;
    addr.name = name;

    if(dom_element.hasAttribute("type"))
    {
        const auto type = dom_element.attribute("type");
        addr.value = read_valueDefault(dom_element, type);
        addr.ioType = read_service(dom_element);

        addr.priority = dom_element.attribute("priority").toInt();
        addr.repetitionFilter = dom_element.attribute("repetitionsFilter").toInt();

        addr.domain = read_rangeBounds(dom_element, type);
        if(addr.value.val.which() != State::ValueType::NoValue)
        {
            if(addr.domain.min.val.which() == State::ValueType::NoValue)
                addr.domain.min = addr.value;
            if(addr.domain.max.val.which() == State::ValueType::NoValue)
                addr.domain.max = addr.value;
        }
        addr.clipMode = read_rangeClipmode(dom_element);
    }

    auto& childNode = parentNode.emplace_back(addr, &parentNode);

    while(!dom_child.isNull() && dom_element.hasChildNodes())
    {
        convertFromDomElement(dom_child, childNode);

        dom_child = dom_child.nextSibling().toElement();
    }
    return;
}