Exemple #1
0
/**
  * Finding function : within parent, look for children whom fullname equals argument
  */
ModItem* ModItemsTree::findInDescendants(QString fullName,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curChild;
    QString curFullName = parent->name(ModItem::FULL);

    int curDepth = parent->depth();
    int lookingDepth = fullName.split(".").size()-1;

    // check if it is this component
    if(curFullName == fullName)
        return parent;

    //first check name compatibility
    if(fullName.indexOf(curFullName)!=0)
        return NULL;

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOmc(parent,lookingDepth,fullName,curDepth);
    }

    //get child name to visit
    //QString childShortName = fullName.section(".",curDepth,curDepth);
    QString childShortName = fullName;
    // first remove parent name
    // A ajouter la une condition if not executable else childShortName = curFullName !!!!!!
    if(!fullName.endsWith(".exe"))
    {
        childShortName.remove(QRegExp("^"+curFullName+"\\."));
        // then take first section
        childShortName = childShortName.section(".",0,0);


        // looking in children
        for(int iChild=0;iChild<parent->childCount();iChild++)
        {
            curChild = parent->child(iChild);
            if(curChild->name(ModItem::SHORT)==childShortName)
                return findInDescendants(fullName,curChild);
        }
    }
    else
    {
        for(int iChild=0;iChild<parent->childCount();iChild++)
        {
            curChild = parent->child(iChild);
            if(curChild->name(ModItem::FULL)==childShortName)
                return findInDescendants(fullName,curChild);
        }


    }
    return NULL;
}
bool ModItemsTree::hasChildren ( const QModelIndex & parent ) const
{
    bool hasChildren;
    bool triedToFind;

    if(!_enabled)
        return false;

    ModItem *parentElement;

    if (parent.column() > 0)
        return false;

    if (!parent.isValid())
        parentElement = rootElement();
    else
        parentElement = static_cast<ModItem*>(parent.internalPointer());

    if(parentElement->childrenReaden())
    {
        if(_showComponents)
            return (parentElement->childCount()>0);
        else
            return (parentElement->childCount()-parentElement->compChildCount()>0);
    }
    else
    {
        triedToFind = true;
        hasChildren = false;

        QStringList children = _moomc->getClassNames(parentElement->name());
        children.removeAll(QString());
        if(!children.isEmpty())
            hasChildren = true;
        else if(parentElement->getClassRestr()==Modelica::MODEL)
        {
            if(!_showComponents)
            {
                hasChildren = false;
                triedToFind = false;
            }
            else
            {
                // look if has component children
                QStringList compNames;
                QStringList compClasses;
                _moomc->getContainedComponents(parentElement->getModClassName(),compNames,compClasses,true);
                hasChildren = (!compNames.isEmpty());
            }
        }
        if(triedToFind && !hasChildren)
            parentElement->setChildrenReaden(true); // avoid re-reading

        return hasChildren;
    }
}
QVariant ModItemsTree::data(const QModelIndex &index, int role) const
{
    if(_enabled)
    {
        if (!index.isValid())
            return QVariant();


        if (role != Qt::DisplayRole && role !=Qt::ToolTipRole && role != Qt::DecorationRole)
            return QVariant();

        if(index.column()<0 || index.column()>=ModItem::nbFields)
            return QVariant();

        ModItem *item = static_cast<ModItem*>(index.internalPointer());

        if(item)
        {
            if(role==Qt::DecorationRole)
                return getModelicaNodeIcon(item);

            // fullfiling is now done in ::fetchmore
            // if(!item->childrenReaden())
            // readFromOmcV2(item,1);

            if (role == Qt::ToolTipRole)
            {
                QString tooltip = item->getStrToolTip();
                return tooltip;
            }

            // if display, only display short name (since hierarchy is visible)
            if((role == Qt::DisplayRole) && (index.column()==ModItem::NAME))
                return item->name(ModItem::SHORT);


            return item->getFieldValue(index.column(),role);
        }
        else
        {
            return QVariant();
        }
    }
    else
        return QVariant();
}
Exemple #4
0
QMimeData* ModItemsTree::mimeData(const QModelIndexList &indexes) const
{
    QMimeData *mimeData = new QMimeData();
    QString csv;

    // select only first column indexes (since selection is made by row)
    QModelIndexList rowIndexes;
    QList<ModItem*> items;
    for(int i=0;i<indexes.size();i++)
    {
        if(indexes.at(i).column()==0)
        {
            rowIndexes.push_back(indexes.at(i));
            items.push_back((ModItem*)indexes.at(i).internalPointer());
        }
    }

    // Remove children of contained parents -> avoid twice copying
    QList<ModItem*> uniqueItems;
    for(int i=0;i<items.size();i++)
    {
        //    if(!items.contains(items.at(i)->parent()) || (items.at(i)->parent()==_rootElement))
        uniqueItems.push_back(items.at(i));
    }

    // create text data
    for(int i=0;i<uniqueItems.size();i++)
    {
        ModItem* item = uniqueItems.at(i);
        csv.push_back(item->name(ModItem::FULL)+"\n");
    }
    if(csv.size()>0)
        csv.remove(csv.size()-QString("\n").size(),QString("\n").size());
    mimeData->setText(csv);
    mimeData->setData("application/ModItemName",csv.toAscii());
    return mimeData;
}