Пример #1
0
/**
  * Finding function : returns all ModItem whom classname equals argument className.
  */
QList<ModItem*> ModItemsTree::findInDescendantsByClass(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curClass;
    QList<ModItem*> curClasses;
    int iChild;

    int curDepth = parent->depth();



    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    // looking if one child corresponds
    for(iChild=0; iChild<parent->childCount(); iChild++)
    {
        curClass = parent->child(iChild);
        if(curClass->getModClassName()==className)
            curClasses.push_back(curClass);

        //look deeper in children
        curClasses <<  findInDescendantsByClass(className,curClass);
    }

    return curClasses;

}
Пример #2
0
QModelIndex ModItemsTree::index(int row, int column, const QModelIndex &parent)
const
{
    if(!_enabled)
        return QModelIndex();

    if(!hasIndex(row,column,parent))
        return QModelIndex();

    ModItem *parentComponent;

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

    // looking in children
    if(row>parentComponent->childCount())
        return QModelIndex();

    ModItem *childElement = parentComponent->child(row);

    if (!childElement)
        return QModelIndex();

    if(!_showComponents&&(childElement->getClassRestr()==Modelica::COMPONENT))
        return QModelIndex();
    else
        return createIndex(row, column, childElement);
}
Пример #3
0
/**
  * Finding function : returns all ModItem whom class equals or inherits className.
  */
QList<ModItem*> ModItemsTree::findInDescendantsByInheritedClass(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curChild;
    QString curChildClass;
    QList<ModItem*> result;
    int iChild;

    int curDepth = parent->depth();

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    // looking if one child corresponds
    for(iChild=0;iChild<parent->childCount();iChild++)
    {
        curChild = parent->child(iChild);
        curChildClass = curChild->getModClassName();
        if((curChildClass==className)||_moomc->inherits(curChildClass,className))
            result.push_back(curChild);

        //look deeper in children
        result <<  findInDescendantsByInheritedClass(className,curChild);
    }

    return result;
}
Пример #4
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;
}
Пример #5
0
/**
  * Finding function : returns all components whom classname inherits argument className.
  */
QList<ModItem*> ModItemsTree::findCompOfInheritingClassInDescendants(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curComponent;
    QList<ModItem*> curComponents;
    int iChild;
    QString curCompClass;

    int curDepth = parent->depth();

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    int nbCompChild = parent->compChildCount();
    int nbModelChild = parent->modelChildCount();
    int nbPackageChild = parent->packageChildCount();

    // looking if one child corresponds
    for(iChild=0;iChild<nbCompChild;iChild++)
    {
        curComponent = parent->compChild(iChild);
        curCompClass = curComponent->getModClassName();
        if((curCompClass==className)||_moomc->inherits(curCompClass,className))
            curComponents.push_back(curComponent);
    }

    //look deeper in components children
    iChild=0;
    while(iChild<nbCompChild)
    {
        curComponents <<  findCompOfInheritingClassInDescendants(className,parent->compChild(iChild));
        iChild++;
    }

    //look deeper in models children
    iChild=0;
    while(iChild<nbModelChild)
    {
        curComponents <<   findCompOfInheritingClassInDescendants(className,parent->modelChild(iChild));
        iChild++;
    }

    //look deeper in packages children
    iChild=0;
    while(iChild<nbPackageChild)
    {
        curComponents <<  findCompOfInheritingClassInDescendants(className,parent->packageChild(iChild));
        iChild++;
    }

    return curComponents;
}
Пример #6
0
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;
    }
}
Пример #7
0
void ModItemsTree::fetchMore ( const QModelIndex & parent )
{
    if(!_enabled)
        return;

    if (!parent.isValid())
        return;

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

    if(item)
    {
        if(!item->childrenReaden())
            readFromOMCWThread(item,_modLoader->getDepthMax());
    }
}
Пример #8
0
/**
  * Finding function : returns all components whom classname equals argument className.
  */
QList<ModItem*> ModItemsTree::findCompOfClassInDescendants(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curComponent;
    QList<ModItem*> curComponents;
    int iChild;

    int nbCompChild = parent->compChildCount();
    int nbModelChild = parent->modelChildCount();
    int nbPackageChild = parent->packageChildCount();

    // looking if one child corresponds
    for(iChild=0; iChild<nbCompChild; iChild++)
    {
        curComponent = parent->compChild(iChild);
        if(curComponent->getFieldValue(ModComponent::CLASSNAME)==className)
            curComponents.push_back(curComponent);
    }

    //look deeper in components children
    iChild=0;
    while(iChild<nbCompChild)
    {
        curComponents <<  findCompOfClassInDescendants(className,parent->compChild(iChild));
        iChild++;
    }

    //look deeper in models children
    iChild=0;
    while(iChild<nbModelChild)
    {
        curComponents <<   findCompOfClassInDescendants(className,parent->modelChild(iChild));
        iChild++;
    }

    //look deeper in packages children
    iChild=0;
    while(iChild<nbPackageChild)
    {
        curComponents <<  findCompOfClassInDescendants(className,parent->packageChild(iChild));
        iChild++;
    }

    return curComponents;
}
Пример #9
0
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();
}
Пример #10
0
bool ModItemsTree::canFetchMore ( const QModelIndex & parent ) const
{
    ModItem *item = static_cast<ModItem*>(parent.internalPointer());

    if(!_enabled)
        return false;

    if (!parent.isValid())
        return false;

    if(parent.column()<0 || parent.column()>=ModItem::nbFields)
        return false;

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

    if(item && !item->childrenReaden())
        return true;
    else
        return false;
}
Пример #11
0
QModelIndex ModItemsTree::parent(const QModelIndex &index) const
{
    if(!_enabled)
        return QModelIndex();

    if (!index.isValid())
        return QModelIndex();

    ModItem *childElement = static_cast<ModItem*>(index.internalPointer());
    if (childElement == _rootElement)
        return QModelIndex();

    ModItem *parentElement  = NULL;
    parentElement = childElement->parent();

    if (parentElement == _rootElement)
        return QModelIndex();

    ModItem *grandParentElement = NULL;
    grandParentElement = parentElement->parent();

    int iC = grandParentElement->children().indexOf(parentElement);

    if(iC==-1)
    {
        // ERROR
        return QModelIndex();
    }

    return createIndex(iC, 0, parentElement);
}
Пример #12
0
int ModItemsTree::rowCount(const QModelIndex &parent) const
{
    if(!_enabled)
        return 0;

    ModItem *parentElement;

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

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

    int count = parentElement->childCount();

    if(!_showComponents)
        count-=parentElement->compChildCount();

    return count;
}
Пример #13
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;
}
Пример #14
0
/**
  * Finding function : returns all components whom classname inherits argument className.
  * In a multimap since there are different classNames here.
  * @param classFilter : stop seeking in parent class does not go through this filter
  */
void  ModItemsTree::findCompOfInheritingClassesInDescendants(QStringList classNames,ModItem* parent,QMultiMap<QString,ModItem*> &result,QRegExp classFilter)
{
    if(parent==NULL)
        return;

    ModItem* curComponent;

    int iChild;
    QString curCompClass;

    QString parentClass = parent->getModClassName();
    if(classFilter.isValid() && !parentClass.contains(classFilter))
        return ;// no need to carry on

    int curDepth = parent->depth();
    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    int nbCompChild = parent->compChildCount();
    int nbModelChild = parent->modelChildCount();
    int nbPackageChild = parent->packageChildCount();

    // looking if one child corresponds
    for(iChild=0;iChild<nbCompChild;iChild++)
    {
        curComponent = parent->compChild(iChild);
        curCompClass = curComponent->getModClassName();

        foreach(QString  className, classNames)
        {
            if((curCompClass==className)||_moomc->inherits(curCompClass,className))
                result.insert(className,curComponent);
        }
    }

    //look deeper in components children
    iChild=0;
    while(iChild<nbCompChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->compChild(iChild),result);
        iChild++;
    }

    //look deeper in models children
    iChild=0;
    while(iChild<nbModelChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->modelChild(iChild),result);
        iChild++;
    }

    //look deeper in packages children
    iChild=0;
    while(iChild<nbPackageChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->packageChild(iChild),result);
        iChild++;
    }
}